Error when adding mcuboot for a custom nrf5340 board in the get_flash_area_from_id and dynamic partitioning

I am using a custom board with a nrf5340 and vs code with sdk/toolchain version 3.0.2 and trying to get mcuboot working for FOTA. I have been stepping through mcuboot with my segger and have breakpoints in mcuboot/main.c

I am using dynamic partitioning as recommended.

The error is happening on the second pass through this code within context_boot_go in loader.c:

        for (slot = 0; slot < BOOT_NUM_SLOTS; slot++) {
            fa_id = flash_area_id_from_multi_image_slot(image_index, slot);
            rc = flash_area_open(fa_id, &BOOT_IMG_AREA(state, slot));
            assert(rc == 0);

            if (rc != 0) {
                BOOT_LOG_ERR("Failed to open flash area ID %d (image %d slot %d): %d, "
                             "cannot continue", fa_id, image_index, (int8_t)slot, rc);
                FIH_PANIC;
            }
        }

  • slot = 1
  • flash_map_entries = 5
  • fa_id = 6

which calls:

int flash_area_open(uint8_t id, const struct flash_area **fap)
{
	const struct flash_area *area;

	if (flash_map == NULL) {
		return -EACCES;
	}

	area = get_flash_area_from_id(id);
	if (area == NULL) {
		return -ENOENT;
	}

	if (!device_is_ready(area->fa_dev)) {
		return -ENODEV;
	}

	*fap = area;

	return 0;
}

  • id = 6

which calls flash_map_priv.h:

static inline struct flash_area const *get_flash_area_from_id(int idx)
{
	for (int i = 0; i < flash_map_entries; i++) {
		if (flash_map[i].fa_id == idx) {
			return &flash_map[i];
		}
	}

	return NULL;
}

  • i=4
  • flash_map[i].fa_id = 5

This call returns a -2:

rc = flash_area_open(fa_id, &BOOT_IMG_AREA(state, slot));

  • slot = 1

and finally dies on this call in nrf53_cpunet_mgmt.c 

static void onoff_stop(struct onoff_manager *mgr, onoff_notify_fn notify)
{
	nrf_reset_network_force_off(NRF_RESET, true);

	notify(mgr, 0);
}

Here is the flash:

When I have SB_CONFIG_BOOTLOADER_MCUBOOT=n it runs

I have read Simultaneous updates for both cores of the nRF5340, but get errors when I get to:

 # STEP 7.2 - Add b0n image
SB_CONFIG_SECURE_BOOT_NETCORE=y


the error is:
In file included from /opt/nordic/ncs/v3.0.2/nrf/include/dfu/pcd.h:28,
                 from /opt/nordic/ncs/v3.0.2/bootloader/mcuboot/boot/zephyr/main.c:96:
/opt/nordic/ncs/v3.0.2/nrf/include/dfu/pcd_common.h: In function 'pcd_write_cmd_lock_debug':
/opt/nordic/ncs/v3.0.2/nrf/include/dfu/pcd_common.h:39:25: error: 'PM__PCD_SRAM_ADDRESS' undeclared (first use in this function); did you mean 'PM_SRAM_ADDRESS'?

I have also looked at Exercise 5 – FOTA over Bluetooth Low Energy and loosly followed it, but there are a lot of differences with my using a custom board and spi external flash. 

My regions.yml looks like this when I build successfully:

external_flash:
  base_address: 0x0
  default_driver_kconfig: CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK
  device: DT_CHOSEN(nordic_pm_ext_flash)
  dynamic_partition: null
  name: external_flash
  placement_strategy: start_to_end
  size: 0x1000000
flash_primary:
  base_address: 0x0
  default_driver_kconfig: CONFIG_SOC_FLASH_NRF
  device: flash_controller
  dynamic_partition: null
  name: flash_primary
  placement_strategy: complex
  size: 0x100000
otp:
  base_address: 0xff8100
  default_driver_kconfig: ''
  device: ''
  dynamic_partition: null
  name: otp
  placement_strategy: start_to_end
  size: 0x2fc
sram_primary:
  base_address: 0x20000000
  default_driver_kconfig: ''
  device: ''
  dynamic_partition: sram_primary
  name: sram_primary
  placement_strategy: complex
  size: 0x80000

and my partitions.yml look like this:

app:
  address: 0xc200
  end_address: 0x100000
  region: flash_primary
  size: 0xf3e00
external_flash:
  address: 0xcf4000
  end_address: 0x1000000
  region: external_flash
  size: 0x30c000
littlefs_storage:
  address: 0x0
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0xc00000
  placement:
    before:
    - tfm_storage
    - end
  region: external_flash
  size: 0xc00000
mcuboot:
  address: 0x0
  end_address: 0xc000
  placement:
    align:
      end: 0x1000
    before:
    - mcuboot_primary
  region: flash_primary
  size: 0xc000
mcuboot_pad:
  address: 0xc000
  end_address: 0xc200
  placement:
    before:
    - mcuboot_primary_app
  region: flash_primary
  size: 0x200
mcuboot_primary:
  address: 0xc000
  end_address: 0x100000
  orig_span: &id001
  - mcuboot_pad
  - app
  region: flash_primary
  size: 0xf4000
  span: *id001
mcuboot_primary_app:
  address: 0xc200
  end_address: 0x100000
  orig_span: &id002
  - app
  region: flash_primary
  size: 0xf3e00
  span: *id002
mcuboot_secondary:
  address: 0xc00000
  device: DT_CHOSEN(nordic_pm_ext_flash)
  end_address: 0xcf4000
  placement:
    align:
      start: 0x4
  region: external_flash
  share_size:
  - mcuboot_primary
  size: 0xf4000
otp:
  address: 0xff8100
  end_address: 0xff83fc
  region: otp
  size: 0x2fc
rpmsg_nrf53_sram:
  address: 0x20070000
  end_address: 0x20080000
  placement:
    before:
    - end
  region: sram_primary
  size: 0x10000
sram_primary:
  address: 0x20000000
  end_address: 0x20070000
  region: sram_primary
  size: 0x70000

Parents Reply Children
  • I do have the custom board working with external flash when SB_CONFIG_BOOTLOADER_MCUBOOT=n:

    00> [00:00:02.291,046] <inf> littlefs: littlefs partition at /lfs1
    00> [00:00:02.291,076] <inf> littlefs: LittleFS version 2.9, disk version 2.1
    00> [00:00:02.293,182] <inf> littlefs: FS at w25q128@0:0x0 is 3072 0x1000-byte blocks with 512 cycle
    00> [00:00:02.293,182] <inf> littlefs: partition sizes: rd 512 ; pr 512 ; ca 512 ; la 4096
    00> [00:00:02.309,234] <inf> littlefs: Automount /lfs1 succeeded

    Also, I did mention I followed the article you reference, but got an error when adding this:

     # STEP 7.2 - Add b0n image
    SB_CONFIG_SECURE_BOOT_NETCORE=y

    Here is the error:

    In file included from /opt/nordic/ncs/v3.0.2/nrf/include/dfu/pcd.h:28,
                     from /opt/nordic/ncs/v3.0.2/bootloader/mcuboot/boot/zephyr/main.c:96:
    /opt/nordic/ncs/v3.0.2/nrf/include/dfu/pcd_common.h: In function 'pcd_write_cmd_lock_debug':
    /opt/nordic/ncs/v3.0.2/nrf/include/dfu/pcd_common.h:39:25: error: 'PM__PCD_SRAM_ADDRESS' undeclared (first use in this function); did you mean 'PM_SRAM_ADDRESS'?
       39 | #define PCD_CMD_ADDRESS PM__PCD_SRAM_ADDRESS

    Also since I'm not using qspi, I cannot use this:

    # STEP 6.2 - MCUboot should use external flash
    CONFIG_NORDIC_QSPI_NOR=y
    

    Is there something else I use in it's place?

    When I have all of these:

    SB_CONFIG_NETCORE_HCI_IPC=y
    SB_CONFIG_BOOTLOADER_MCUBOOT=y
    SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
    
    SB_CONFIG_SECURE_BOOT_NETCORE=y
    SB_CONFIG_MCUBOOT_UPDATEABLE_IMAGES=2
    SB_CONFIG_NETCORE_APP_UPDATE=y
    SB_CONFIG_MCUBOOT_NRF53_MULTI_IMAGE_UPDATE=y
    SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY=y

    I get this error:

    /opt/nordic/ncs/toolchains/ef4fc6722e/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/zephyr_pre0.elf section `datas' will not fit in region `FLASH'
    /opt/nordic/ncs/toolchains/ef4fc6722e/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: region `FLASH' overflowed by 560 bytes

  • Hi,

    lcj said:
    Also, I did mention I followed the article you reference, but got an error when adding this:

    If you got the external SPI flash workign then you should have the configs for that in place (and this ASPI config is not relevant).

    lcj said:
    Here is the error:

    PM__PCD_SRAM_ADDRESS should be calculated by the partition manager script during build and end up in pm_config.h in your build folder (bor both b0n and ipc_radio). But perhaps you are missing CONFIG_PCD_CMD_ADDRESS? See this post.

    The linker error in the end indicate that the paplication is a bit too large to fit in flash. Perhaps disable debug/asserts or similar, or other optimization (some suggestions here though most focus on RAM which is not relevant in this case)?

  • I'm new at this but I've never used PCD_CMD_ADDRESS and I had most of this working on a DK without it. I'm using dynamic partitioning to try and manage the memory until things are set so I haven't wanted to tweak memory settings aside from what I need to size the external flash.

    I have barely anything running for this test. Flash (which I need), one sensor and the power stuff but nothing else. This is mainly a test to get mcuboot running.

    Maybe I should not be using dynamic partitioning but that seemed to be the recommendation from Noric at this stage.

  • Hi,

    Dynamic partitioning makes sense for the most part, but subsequently you need to go with static patititioning (typically by using the dynamically allocated) as partition layout should not change by DFU in the field. But regarding the issues you are seeing, did you look at the thread I linked to?

    The linker error complains about 'datas', is that some section you have added yourself?

  • I did look at the link but am not really sure how to proceed. Which prj.conf setting I turn on and off. Also there are a lot more confs in the mcuboot I need to contend with (hci, mcuboot, board, etc.) which makes it complex for a noivice.

    Not. No special section that I can tell. I only do very vanilla things.

Related