I am trying to make a build with a slightly modified copy of the Zephyr button example on a nrf9160 board with a upgradable bootloader.
The following command can build our firmware:
west build --build-dir build/SG1500-board-tester --board ${BOARD}_ns SG1500-board-tester --pristine -- \
-DCONFIG_SECURE_BOOT=y \
-DCONFIG_BOOTLOADER_MCUBOOT=y \
-DCONFIG_BUILD_S1_VARIANT=y \
-Db0_CONF_FILE=prj_minimal.conf \
-Dmcuboot_CONF_FILE=${HOME}/ncs/v2.0.2/bootloader/mcuboot/boot/zephyr/prj_minimal.conf \
-DCONF_FILE:STRING="${BUILD_ROOT}/SG1500-board-tester/prj.conf"
I added 2 partitions by making a pm_static.yml:
data_partition_flash:
address: 0xf0000
end_address: 0x100000
region: flash_primary
size: 0x10000
data_partition_sram:
address: 0x20020000
end_address: 0x20040000
region: sram_primary
size: 0x20000
Compiling this result in BO size:
Memory region Used Size Region Size %age Used
FLASH: 12240 B 32 KB 37.35%
SRAM: 37088 B 47896 B 77.43%
IDT_LIST: 0 GB 2 KB 0.00%
For mcuboot this results in:
Memory region Used Size Region Size %age Used
FLASH: 18916 B 32 KB 57.73%
SRAM: 18120 B 47896 B 37.83%
IDT_LIST: 0 GB 2 KB 0.00%
This seems to work fine but the partition_manager_report reserved show that a lot of memeory is wasted: too much space is reserved for the bootloaders and it has very large EMPTY_X regions:
+--------------------------------------------------+
+---0x0: b0_container (0x8000 - 32kB)--------------+
| 0x0: b0 (0x8000 - 32kB) |
+---0x8000: s0 (0x8200 - 32kB)---------------------+
| 0x8000: s0_pad (0x200 - 512B) |
+---0x8200: s0_image (0x8000 - 32kB)---------------+
| 0x8200: mcuboot (0x8000 - 32kB) |
+--------------------------------------------------+
| 0x10200: EMPTY_0 (0x7e00 - 31kB) |
+---0x18000: s1 (0x8200 - 32kB)--------------------+
| 0x18000: s1_pad (0x200 - 512B) |
| 0x18200: s1_image (0x8000 - 32kB) |
+--------------------------------------------------+
| 0x20200: EMPTY_1 (0x7e00 - 31kB) |
+---0x28000: mcuboot_primary (0x60000 - 384kB)-----+
+---0x28000: tfm_secure (0x8200 - 32kB)------------+
| 0x28000: mcuboot_pad (0x200 - 512B) |
+---0x28200: app_image (0x5fe00 - 383kB)-----------+
+---0x28200: mcuboot_primary_app (0x5fe00 - 383kB)-+
| 0x28200: tfm (0x8000 - 32kB) |
+---0x30200: tfm_nonsecure (0x57e00 - 351kB)-------+
| 0x30200: app (0x57e00 - 351kB) |
+--------------------------------------------------+
| 0x88000: mcuboot_secondary (0x60000 - 384kB) |
| 0xe8000: EMPTY_2 (0x8000 - 32kB) |
| 0xf0000: data_partition_flash (0x10000 - 64kB) |
+--------------------------------------------------+
otp (0x2f4 - 756B):
+------------------------------------+
| 0xff8108: provision (0x280 - 640B) |
| 0xff8388: otp (0x74 - 116B) |
+------------------------------------+
sram_primary (0x40000 - 256kB):
+---------------------------------------------------+
+---0x20000000: sram_secure (0x10000 - 64kB)--------+
| 0x20000000: tfm_sram (0x10000 - 64kB) |
+---0x20010000: sram_nonsecure (0x10000 - 64kB)-----+
+---0x20010000: nrf_modem_lib_sram (0x44e8 - 17kB)--+
| 0x20010000: nrf_modem_lib_ctrl (0x4e8 - 1kB) |
| 0x200104e8: nrf_modem_lib_tx (0x2000 - 8kB) |
| 0x200124e8: nrf_modem_lib_rx (0x2000 - 8kB) |
+---------------------------------------------------+
| 0x200144e8: sram_primary (0xbb18 - 46kB) |
| 0x20020000: data_partition_sram (0x20000 - 128kB) |
+---------------------------------------------------+
I have no former experience using zephyr so i have no clue why this happens, so please can somebody explain:
- what are those empty reqions used for? How can they be made minimal?
- the wasted space looks like an alignment issue.
- why is the reserved space for the bootloaders much larger then the bootloader code size?
- How can i change this so no memory will be wasted?