Size of build image for mcuboot with serial or usb DFU enabled?

Working on a nrf5340 project, and running into limits of the size of the flash to store my application image along with mcuboot bootloader.

I had a mucboot setup that fitted into 56Kb (signed images, secondary slot on external flash). This did NOT include the serial DFU however, and (of course) one of my first units out in the field got bricked during a DFU (using dfu_target lib to update the secondary slot from a file loaded on USB FAT FS mounted on the external flash... not yet got the unit to see what got corrupted...)

I expose the USB interface, so would like to enable the serial DFU functionality in mcuboot so that at least I have a method to DFU even if my main app image gets corrupted...Some questions to get this to work:

1/ The buttons on the device are via a gpio expander on the i2c interface, it seems mcuboot likes a 'dfu button' to be a direct gpio (at least if I set the alias:

mcuboot-button0 = &button2;
then it doesn't build because button2 is 
button2: button_2 {
            gpios = <&ioexp0 4 (GPIO_ACTIVE_LOW)>;    // GPA4
). Is this correct or should it work via a ioexpander?
BTW This is not a deal breaker as I see I can have a 'DFU delay' at boot to always check if the dfu is to be activated on the serial/USB
2/ serial DFU (virtual com port on USB) vs USB DFU : which is better to use? Which gives me a smaller mcuboot image?
3/ Image size : mcuboot with DFU_USB is now 76+Kb
Is this normal? Are there ways to slim this down? also, the mcuboot child_image build has its own mcuboot.conf - does this addon to the usual prj.conf, or replace it completely?
The image size is an issue because my main app uses https over wifi networking (nrf7002) and the wifi code+networking+TLS takes up a LOT of space....
thanks for any tips to get a solid mcuboot in the least flash space!
  • Oh, and when I hold down the defined button during boot, it starts the USB virtual comm ports. Haven't tried to run mcumgr yet, but thats the next step!

  • So, I applied the config to my test build using nrf70 wifi with the DFU images in the external flash... It built under multi-image system, but not with sysbuild (due to the 'hack' for the cpu-net primary slot it seems).

    If you have any insights for sysbuild, the ticket is here:

     (Missing Forum Thread) 

    thanks!. 

  • Great! It sounds like we've resolved the issue with reducing the size of MCUboot in this case.

    BrianW said:
    I will try this now building with sysbuild...

    I assume you refer to your sample with sysbuild specific, since the sample I supplied builds with sysbuild as a default, but I'm glad to hear you were able test it with the child/parent setup.

    I will have a look at your other case and give you a reply there shortly

    Kind regards,
    Andreas

  • I assume you refer to your sample with sysbuild specific, since the sample I supplied builds with sysbuild as a default, but I'm glad to hear you were able test it with the child/parent setup.

    yes, it has an issue with definition of the PRIMARY_1 slot for the CPU-NET DFU when built with sysbuild. 

  • I confirm it builds to around 56kB for me, without logs

    I hate not having logs on the UART especially given trying to get the various DFUs to work.

    But with CONFIG_LOG=y, its about 67kB.... even with 

    CONFIG_LOG_MODE_MINIMAL=y
    CONFIG_MCUBOOT_LOG_LEVEL_WRN=y
     
    However, if I leave CONFIG_LOG=n, and then hack bootloader/mcuboot/boot/bootutil/include/bootutil/bootutil_log.h (way too many 'boot's in that heirarchy..) like this:
    ...

    #ifdef MCUBOOT_HAVE_LOGGING
    #include <mcuboot_config/mcuboot_logging.h>

    #define BOOT_LOG_ERR(...) MCUBOOT_LOG_ERR(__VA_ARGS__)
    #define BOOT_LOG_WRN(...) MCUBOOT_LOG_WRN(__VA_ARGS__)
    #define BOOT_LOG_INF(...) MCUBOOT_LOG_INF(__VA_ARGS__)
    #define BOOT_LOG_DBG(...) MCUBOOT_LOG_DBG(__VA_ARGS__)
    #define BOOT_LOG_SIM(...) MCUBOOT_LOG_SIM(__VA_ARGS__)

    #define BOOT_LOG_MODULE_DECLARE(module)  MCUBOOT_LOG_MODULE_DECLARE(module)
    #define BOOT_LOG_MODULE_REGISTER(module) MCUBOOT_LOG_MODULE_REGISTER(module)

    #else
    // HACK: force log output using printk directly
    #include <zephyr/sys/printk.h>
    #define BOOT_LOG_ERR(...) printk(__VA_ARGS__);printk("\n")
    #define BOOT_LOG_WRN(...) printk(__VA_ARGS__);printk("\n")
    #define BOOT_LOG_INF(...) printk(__VA_ARGS__);printk("\n")
    #define BOOT_LOG_DBG(...) IGNORE(__VA_ARGS__)
    #define BOOT_LOG_SIM(...) IGNORE(__VA_ARGS__)

    #define BOOT_LOG_MODULE_DECLARE(module)
    #define BOOT_LOG_MODULE_REGISTER(module)

    #endif /* MCUBOOT_HAVE_LOGGING */
    I add back in the zephyr console to get printk to work, keep CONFIG_LOG as n (in child_image/mcuboot.conf)
    CONFIG_CONSOLE=y
    CONFIG_CONSOLE_HANDLER=n
    CONFIG_SERIAL=y
    CONFIG_UART_CONSOLE=y
    CONFIG_STDOUT_CONSOLE=y
    # turn off log to save image size
    CONFIG_LOG=n
     
    and voila: mcuboot error, warning, info logs :
    *** Booting MCUboot v2.1.0-dev-12e5ee106034 ***
    *** Using nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    Starting bootloader
    Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    Secondary image: magic=bad, swap_type=0x1, copy_done=0x2, image_ok=0x2
    Boot source: none
    Image index: 0, Swap type: none
    Bootloader chainload address offset: 0x10000
    and it builds to :
    Memory region Used Size Region Size %age Used
    FLASH: 61952 B 64 KB 94.53%
    RAM: 299560 B 440 KB 66.49%
    IDT_LIST: 0 GB 32 KB 0.00%
    Pity having to hack the mcuboot source though... I had hoped the CONFIG_LOG_MODE_MINIMAL would give me the same result, but it requires 8kB more for essentially the same output....
    If there is a better way to achieve this let me know...
Related