Reducing ROM size for the nRF52833

I think I've followed practically every "minimal configuration" example I could find, and implemented as many Kconfig options as possible, but our firmware image is still too large for DFU. I also created a static partition scheme and reduced MCU boot partition to 32 kilobytes and NVS partition to 8 kilobytes.

Despite this, our ROM size comes out to be around 13 kilobytes too large for MCU boot.

Here's my full project configuration file, with the Kconfig options I've found that actually reduce ROM size at the top. Please let me know if there's any Kconfig options I'm missing or anything else I can do to reduce the ROM size.

# not yet sure if this is helpful, harmful, or just unnecessary... but it actually decreases the project size!
CONFIG_NCS_SAMPLES_DEFAULTS=y

# to reduce image size
CONFIG_CBPRINTF_NANO=y
CONFIG_CBPRINTF_LIBC_SUBSTS=n
CONFIG_MINIMAL_LIBC=y
CONFIG_SIZE_OPTIMIZATIONS=y
CONFIG_BT_ASSERT=n
CONFIG_BT_DATA_LEN_UPDATE=n
#CONFIG_BT_GATT_SERVICE_CHANGED=n # unfortunately this is required by DFU
CONFIG_BT_GATT_READ_MULTIPLE=n
CONFIG_BT_GATT_READ_MULT_VAR_LEN=n
CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n
CONFIG_BT_PHY_UPDATE=n
CONFIG_BT_CTLR_LE_PING=n
CONFIG_BT_CTLR_PRIVACY=n
CONFIG_BT_CTLR_PHY_2M=n
CONFIG_TIMEOUT_64BIT=n
CONFIG_TIMESLICING=n
CONFIG_LOG=n
CONFIG_FPU=y # despite guidance from "Minimal" examples, enabling this actually decreases ROM size
CONFIG_SPI=n
CONFIG_ASSERT=n # should be enabled while developing, disabled for production
CONFIG_CONSOLE=n # should be enabled while developing, disabled for production
CONFIG_SERIAL=n # should be enabled while developing, disabled for production
CONFIG_USE_SEGGER_RTT=n # is this required for development? what does this really do?

# for DFU (remote firmware upgrades)
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

# for reading / writing to flash
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

# software resets
CONFIG_REBOOT=y

# for button, LED, accelerometer
CONFIG_GPIO=y
CONFIG_I2C=y

# for printing heap usage stats
CONFIG_SYS_HEAP_RUNTIME_STATS=y

# for bluetooth (general)
CONFIG_BT=y

# for bluetooth (advertising)
CONFIG_BT_PERIPHERAL=y # technically our application only requires "broadcaster" but "peripheral" is required for DFU
CONFIG_BT_DEVICE_APPEARANCE=512
CONFIG_BT_DEVICE_NAME="AirA7v100"
CONFIG_BT_EXT_ADV=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=3

# for bluetooth (tx power control)
CONFIG_BT_HCI_VS_EXT=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y

# for bluetooth (scanning)
CONFIG_BT_CENTRAL=y
CONFIG_BT_SCAN=y
CONFIG_BT_ID_MAX=1
CONFIG_BT_SCAN_FILTER_ENABLE=y
CONFIG_BT_SCAN_NAME_CNT=2

# for bluetooth (connecting)
CONFIG_BT_SMP=y
CONFIG_BT_SMP_SC_ONLY=n
CONFIG_BT_SMP_APP_PAIRING_ACCEPT=n
CONFIG_BT_SMP_ENFORCE_MITM=y
CONFIG_BT_BONDABLE=n

# for blueooth (GATT)
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_BT_GATT_DM_DATA_PRINT=y

# for reading voltage
CONFIG_NRFX_SAADC=y
CONFIG_NRFX_TIMER2=y
CONFIG_NRFX_PPI=y

# for power management
CONFIG_PM_DEVICE=y

# for power-off state
CONFIG_POWEROFF=y

Parents Reply Children
  • Thanks Dejan, however I believe I've gone through everything you've linked.

    My question is, outside of what you've posted, are there any additional Kconfig parameters or guidance to reduce ROM size? Because I've found some on my own, and I imagine there are more, but I'm not an expert in Zephyr so I'm sort-of shooting in the dark.

    We need to reduce the ROM size by at least 10 more kilobytes for DFU to be functional, so mainly I'm wondering: does that seem feasible based on the information I've given you?

    Thanks for your help,
    Cal


    "For example, there are some general recommendations how to optimize memory footprint, how to optimize Zephyr for footprint, and minimal footprint sample."

    Yes, I've looked through those and I believe I've implemented everything possible (i.e. didn't break our application, actually reduced ROM size, and wasn't already disabled by default). Unfortunately most of the guidance combines ROM and RAM reduction tips, however I spent a bunch of time going through each one to see which Kconfigs actually reduced ROM size.

    Also, I've even found some more Kconfigs that weren't mentioned the documentation you listed. For instance, today I just found a couple more that reduced ROM size in this Github issue

    "On the Bluetooth side, you can look at configuration options which deal with stack sizes and buffers."

    I've found that none of those configuration options reduce the ROM size. They reduce the RAM size. 

    "Finally, you can look at minimal configuration given in minimal.conf file of the Peripheral LBS and Peripheral UART samples."

    Yes, this is where I found many of the Kconfig options that reduced ROM size.

  • Hi,

    Can you share your MCUboot configuration file?

    Best regards,
    Dejan

  • Here you go! This is my mcuboot.conf placed in the child_image folder inside my application directory:

    CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
    #CONFIG_BOOT_SIGNATURE_KEY_FILE="..."
    
    CONFIG_BOOT_SERIAL_UART=n
    CONFIG_UART_CONSOLE=n
    CONFIG_CONSOLE=n
    CONFIG_CONSOLE_HANDLER=n
    CONFIG_MCUBOOT_SERIAL=n
    
    
    CONFIG_SINGLE_APPLICATION_SLOT=y

    According to the build output, this is how much space mcuboot is taking currently:

    Memory region         Used Size  Region Size  %age Used
               FLASH:       26322 B        32 KB     80.33%
                 RAM:       20672 B       128 KB     15.77%
            IDT_LIST:          0 GB         2 KB      0.00%

    UPDATE: I didn't realize it was possible to make MCU boot smaller. I've got it down to 24 kilobytes, which still isn't quite enough. What's the smallest MCU boot can be? and what configuration options are required to make it that size? I think this is all the possible options: github.com/.../Kconfig

  • Hi,

    Which board do you use?

    Best regards,
    Dejan

Related