Minimizing MCUBOOT size to prevent overflow

Porting from SDK 0.7.0 to 0.11.0 my mcuboot now overflows the flash size. I understand I could make the partition bigger but that doesn’t work since it would break remote updating for devices in the field. Are there any config options that would get my mcuboot size lower?

I reproduced the overvlow in the latest GitHub - golioth/reference-design-template: Template for making new Golioth Reference Design repositories (post v2.0.0)

I add these lines into Cmake.lists

list(APPEND mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/mcuboot.conf)
list(APPEND mcuboot_CONF_DIR ${CMAKE_CURRENT_SOURCE_DIR})

Create a mcuboot.conf in the same directory as prj.conf with the lines below

CONFIG_MULTITHREADING=y
CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
CONFIG_BOOT_SIGNATURE_KEY_FILE="../my-key.pem"
CONFIG_PRIVILEGED_STACK_SIZE=1024
CONFIG_PARTITION_MANAGER_ENABLED=y
CONFIG_FLASH_MAP_CUSTOM=y

CONFIG_UART_CONSOLE=n
CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU=y
CONFIG_BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT=2000
#CONFIG_MCUBOOT_LOG_LEVEL_OFF=y

and generate my-key.pem RSA key one level up so it’s not in the GIT project.

The result is a 1.3kB overflow of the MCUboot flash region.

...zephyr/zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
...region `FLASH' overflowed by 1288 bytes 
collect2: error: ld returned 1 exit status

For now, I un-comment the MCUBOOT_LOG_LEVEL_OFF line above and it just fits but I’d like to leave logging enabled.

Memory region         Used Size  Region Size  %age Used
           FLASH:       48192 B        48 KB     98.05%
             RAM:       28712 B        32 KB     87.62%

Are there any config options that would get my mcuboot size lower?

Hey @john.stuewe, your MCUBoot Flash region is overflowing by ~2.7%, and the Kconfig option that is using a lot of resources is MCUBOOT_SERIAL with ~13% (~7kB) of reserved Flash memory space for MCUBoot.

Setting the MCUBOOT_LOG_LEVEL_OFF Kconfig option results in lower Flash usage because the LOG messages aren’t compiled in the binary image; you can try to reduce the Flash usage by compiling in only ERR or ERR + WRN messages by setting the LOG level with:

CONFIG_MCUBOOT_LOG_LEVEL_ERR=y
or
CONFIG_MCUBOOT_LOG_LEVEL_WRN=y

Setting the LOG level to WRN should result in a ~2.8% lower Flash usage, and setting it to ERR should result in a decrease of ~3.9 %.

I though I had tried these before and I still overflow by 244 bytes with CONFIG_MCUBOOT_LOG_LEVEL_WRN=y but it will compile with CONFIG_MCUBOOT_LOG_LEVEL_ERR=y.
That still compiles out most debugging messages. any other ideas on how to reduce the size?

Hey @john.stuewe, I don’t have any other ideas besides increasing the MCUBoot partition size, which sadly isn’t an option due to existing devices in the field.