Arm Mbed OS support forum

Target.restrict_size doesn't pad out the .bin file

I use target.restrict_size like so in the mbed_app.json file.

{
    "target_overrides": {
        "MAX32630FTHR": {
            "target.device_name": "MAX32630",
            "target.bootloader_supported": true,
            "target.pad_to_restrict_size": true,
            "target.restrict_size": "0x16000"
        }
    }
}

I even added the extra parameter “pad_to_restrict_size” after coming across this old Github post: Add padding up to restrict_size by statropy · Pull Request #11043 · ARMmbed/mbed-os · GitHub .

However, that still doesn’t seem to pad out the image. After compiling, this is what the output looks like:

Merging Regions
Filling region application with BUILD/MAX32630FTHR/ARMC6\bootloader_application.bin
Space used after regions merged: 0x9670
| Module                    |     .text |   .data |     .bss |
|---------------------------|-----------|---------|----------|
| Serialflash\SerialFlash.o |   296(+0) |   0(+0) |    0(+0) |
| [lib]\c_w.l               |  4330(+0) |  16(+0) |  348(+0) |
| [lib]\fz_wm.l             |    26(+0) |   0(+0) |    0(+0) |
| [lib]\libcppabi_w.l       |    44(+0) |   0(+0) |    0(+0) |
| anon$$obj.o               |    32(+0) |   0(+0) | 1024(+0) |
| main.o                    |   548(+0) |   0(+0) |  264(+0) |
| mbed-os\cmsis             | 10281(+0) | 168(+0) | 6609(+0) |
| mbed-os\connectivity      |   497(+0) |   0(+0) |    0(+0) |
| mbed-os\drivers           |  2534(+0) |   0(+0) |   60(+0) |
| mbed-os\hal               |  2230(+0) |   4(+0) |   58(+0) |
| mbed-os\platform          |  9002(+0) |  64(+0) |  416(+0) |
| mbed-os\rtos              |   340(+0) |   0(+0) |    0(+0) |
| mbed-os\targets           |  7711(+0) | 580(+0) |  407(+0) |
| Subtotals                 | 37871(+0) | 832(+0) | 9186(+0) |
Total Static RAM memory (data + bss): 10018(+0) bytes
Total Flash memory (text + data): 38703(+0) bytes

As you can see, it fills the space up to 0x9670 which comes down to 38.512 bytes (strangely enough, less than the total flash memory!).

This coincides with the file size in the BUILD directory:
image

According to the tutorial on bootloaders, using restrict_size should pad out the .bin file: Creating and using a bootloader - Program setup | Mbed OS 6 Documentation

So what gives? Why isn’t the .bin file being padded out to 0x16000 (90.112) bytes?

I have found a fix for this issue.
It seems the restrict_size padding functionality was broken in a previous version of mbed-tools, and never fixed. A fix has been made: Fix expansion of application to target.restrict_size by icsys-omh · Pull Request #14994 · ARMmbed/mbed-os · GitHub.

But this was never implemented because it fixed something in the old mbed-tools repo which has been frozen. However, copying the changes in the PR above into the tools/region.py directory actually fixes the issue described above!

I hope more people see this, as finding out what was wrong took me quite some time.

1 Like