Zephyr nRF52832 FLASH overflow when MCUBOOT enable

Hello everyone,

I'm developing an application on the nRF52832 development kit. It is nrf52dk_nrf52832(PCA10040). It is based on Zephyr.

Zephyr version: 3.0.99
Zephyr SDK version: zephyr-sdk-0.13.2
This project is based on the example of Bluetooth Peripheral ("zephyr/samples/bluetooth/peripheral").

Now, I want to add a feature of DFU to update firmware using the nRFConnect application. My existing code is working fine without a boot loader (MCUBOOT). It uses 226Kb memory in FLASH.
Memory region Used Size Region Size %age Used
Memory region Used Size Region Size %age Used
FLASH: 226408 B 512 KB 43.18%
SRAM: 29744 B 64 KB 45.39%
IDT_LIST: 0 GB 2 KB 0.00%

When I enable MCUBOOT in prj.conf file, it failed to compile due to insufficient space in the FLASH memory segment. Please find the below log for reference. 

Zephyr version: 3.0.99 (/home/user/zephyr_project/zephyr), build: zephyr-v3.0.0-1072-gc31cb0075ad1
[270/280] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/user/zephyr_project/build/zephyr/zephyr_pre0.map
: && ccache /home/user/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -fuse-ld=bfd -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=/home/user/zephyr_project/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/newlib/liblib__libc__newlib.a zephyr/lib/posix/liblib__posix.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a zephyr/subsys/bluetooth/common/libsubsys__bluetooth__common.a zephyr/subsys/bluetooth/host/libsubsys__bluetooth__host.a zephyr/subsys/bluetooth/controller/libsubsys__bluetooth__controller.a zephyr/subsys/mgmt/mcumgr/libsubsys__mgmt__mcumgr.a zephyr/subsys/dfu/boot/libsubsys__dfu__boot.a zephyr/subsys/net/libsubsys__net.a zephyr/subsys/random/libsubsys__random.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/i2c/libdrivers__i2c.a zephyr/drivers/pwm/libdrivers__pwm.a zephyr/drivers/sensor/nrf5/libdrivers__sensor__nrf5.a zephyr/drivers/flash/libdrivers__flash.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/entropy/libdrivers__entropy.a zephyr/drivers/timer/libdrivers__timer.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a modules/mcuboot/libmcuboot_util.a modules/segger/libmodules__segger.a modules/tinycbor/lib..__modules__lib__tinycbor__zephyr.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L"/home/user/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/thumb/v7e-m/nofp" -L/home/user/zephyr_project/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a -no-pie -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -lm -Wl,-lc -L"/home/user/zephyr-sdk-0.13.2/arm-zephyr-eabi/arm-zephyr-eabi"/lib/thumb/v7e-m/nofp -Wl,-lgcc -lc -specs=nano.specs && cd /home/user/zephyr_project/build/zephyr && /usr/bin/cmake -E echo
/home/user/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `rodata' will not fit in region `FLASH'
/home/user/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `FLASH' overflowed by 38128 bytes
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/user/zephyr_project/build

Please find my prj.config file for the reference.

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_NFCT_PINS_AS_GPIOS=y
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_SIGNING=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_ATT_PREPARE_COUNT=5
CONFIG_NEWLIB_LIBC=y
CONFIG_PWM=y
CONFIG_BT_PRIVACY=y
CONFIG_BT_DEVICE_NAME="Loop"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=65

 

CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

 

CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_ASSERT=y
CONFIG_I2C=y

 

CONFIG_STDOUT_CONSOLE=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y

 

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y 

CONFIG_IMG_MANAGER=y
CONFIG_MCUBOOT_IMG_MANAGER=y

 

CONFIG_MCUMGR=y
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_BOOTLOADER_MCUBOOT=y

 

CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n 

CONFIG_BT_L2CAP_TX_MTU=252
CONFIG_BT_BUF_ACL_RX_SIZE=256

Please find below the segment of FLASH from the nRF52832 DTS file.

&flash0 {

 

   partitions {
      compatible = "fixed-partitions";
      #address-cells = <1>;
      #size-cells = <1>;

 

      boot_partition: partition@0 {
         label = "mcuboot";
         reg = <0x00000000 0xc000>;
      };
      slot0_partition: partition@c000 {
         label = "image-0";
         reg = <0x0000C000 0x32000>;
      };
      slot1_partition: partition@3e000 {
         label = "image-1";
         reg = <0x0003E000 0x32000>;
      };
      scratch_partition: partition@70000 {
         label = "image-scratch";
         reg = <0x00070000 0xa000>;
      };
      storage_partition: partition@7a000 {
         label = "storage";
         reg = <0x0007a000 0x00006000>;
      };
   };
};

I want to add one last point here. When I am testing with Bluetooth example sample code, it could compile and I could perform the DFU. But with my project code which consumes more FLASH memory, I couldn't compile my project with MCUBOOT. Please suggest an alternate solution.

Kind Regards,

Neel 

Parents
  • What nRF Connect SDK version are you using?

    I think the problem is similar to this issue:  RE: nrf52840 DFU with external flash (three partitions are created, primary slot, secondary slot and mcuboot and they doesn't all fit into your flash). However, in your case you only have 512 kB available. Try reducing the size of your application. The file nrf/samples/belutooth/peripheral_uart/prj_minial.conf shows you how to reduce the memory usage in a Bluetooth project.

    Also try to to reduce the size of mcuboot by using the file bootloader/mcuboot/boot/zephyr/prj_minimal.conf and following the advice given in this ticket: How to resize MCUBoot partition in zephyr?.

    If you're not able to reduce the partitions enough to fit into flash, you could use single slot dfu update with serial recovery. If you would like to use two slot for the DFU update, you could put the secondary slot into external flash.

    Please let me know if anything is unclear, and I will go into more details.

    Best regards,

    Simon

  • Hi Simon,

    Thank you for you quick response. We are able to reduce the size of mcuboot and application size to the minimum configurations as you have suggested.

    We are facing an issue with the rollover image when DFU is completed. I think it is related to the DTS flash partition. Here is the flash partition table with a 30 KB mcuboot partition.

    &flash0 {
    
    partitions {
    compatible = "fixed-partitions";
    #address-cells = <1>;
    #size-cells = <1>;
    
    boot_partition: partition@0 {
    label = "mcuboot";
    reg = <0x00000000 0x7800>;
    };
    slot0_partition: partition@7800 {
    label = "image-0";
    reg = <0x00007800 0x37000>;
    };
    slot1_partition: partition@3e800 {
    label = "image-1";
    reg = <0x0003e800 0x37000>;
    };
    scratch_partition: partition@75800 {
    label = "image-scratch";
    reg = <0x00070000 0x8800>;
    };
    storage_partition: partition@7e000 {
    label = "storage";
    reg = <0x0007e000 0x00002000>;
    };
    };
    };

    Que-1: Does mcuboot partition have any minimum flash size requirement?

    Que-2: What is the bare minimum flash size for each flash partition? When we tried to reduce the "storage" partition, the Bluetooth stack failed to boot in initialization. 

    Thanks!

Reply
  • Hi Simon,

    Thank you for you quick response. We are able to reduce the size of mcuboot and application size to the minimum configurations as you have suggested.

    We are facing an issue with the rollover image when DFU is completed. I think it is related to the DTS flash partition. Here is the flash partition table with a 30 KB mcuboot partition.

    &flash0 {
    
    partitions {
    compatible = "fixed-partitions";
    #address-cells = <1>;
    #size-cells = <1>;
    
    boot_partition: partition@0 {
    label = "mcuboot";
    reg = <0x00000000 0x7800>;
    };
    slot0_partition: partition@7800 {
    label = "image-0";
    reg = <0x00007800 0x37000>;
    };
    slot1_partition: partition@3e800 {
    label = "image-1";
    reg = <0x0003e800 0x37000>;
    };
    scratch_partition: partition@75800 {
    label = "image-scratch";
    reg = <0x00070000 0x8800>;
    };
    storage_partition: partition@7e000 {
    label = "storage";
    reg = <0x0007e000 0x00002000>;
    };
    };
    };

    Que-1: Does mcuboot partition have any minimum flash size requirement?

    Que-2: What is the bare minimum flash size for each flash partition? When we tried to reduce the "storage" partition, the Bluetooth stack failed to boot in initialization. 

    Thanks!

Children
Related