MCUBoot and external NOR Flash

Hi again guys,

So sorry to bother you again but I really cannot make MCUBoot works properly. After the latest post I had, at least, a bootable system. So, I can compile my primary image with my application and the mcuboot child image. Once flashed the primary application starts just after mcuboot as expected. Now I'm trying to setup MCUboot to store the second slot on the external flash (I'm working with a 52840DK, so there is quite a lot of external flash available).

At boot I get:

D: lfclk: Clock started
D: RDSR 40 QE 1 need 1: no-change
*** Booting Zephyr OS build v3.3.99-ncs1-1 ***
I: Starting bootloader
W: flash_area: 3, flash_map_entries:536875476
W: flash_area: 1, flash_map_entries:536871380
W: flash_area_get_sectors: -22
W: boot_initialize_area: -22
W: Failed reading sectors;rc=9
W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=512 - too small?
W: Cannot upgrade: not a compatible amount of sectors
I: Bootloader chainload address offset: 0xc000
▒: Jumping to the first image slot

I added a couple of debug lines to the loader.c to better understand the problem. The problem seems be related to the NOR flash driver not properly compiled in MCUBoot as per many older post I read but I cannot figure out how to solve it.

I'm working with the 2.4.2 SDK, so partition_manager.cmake is already fixed for the DEVICE "DT_CHOSEN(nordic_pm_ext_flash)" problem.

my child_image/mcuboot.conf looks like:

CONFIG_MULTITHREADING=y

CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
CONFIG_BOOT_SIGNATURE_KEY_FILE="root-rsa-2048.pem"

CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_NORDIC_QSPI_NOR=y

CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

CONFIG_BOOT_MAX_IMG_SECTORS=256


and, last, my pm_config.h

/* File generated by C:/Users/agall/OneDrive/Lavoro/NRFDomoticWorkspace/NRFDomotic/nrf/scripts/partition_manager_output.py, do not modify */
#ifndef PM_CONFIG_H__
#define PM_CONFIG_H__
#define PM_MCUBOOT_OFFSET 0x0
#define PM_MCUBOOT_ADDRESS 0x0
#define PM_MCUBOOT_END_ADDRESS 0xc000
#define PM_MCUBOOT_SIZE 0xc000
#define PM_MCUBOOT_NAME mcuboot
#define PM_MCUBOOT_ID 0
#define PM_mcuboot_ID PM_MCUBOOT_ID
#define PM_mcuboot_IS_ENABLED 1
#define PM_0_LABEL MCUBOOT
#define PM_MCUBOOT_DEV flash_controller
#define PM_MCUBOOT_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
#define PM_MCUBOOT_SECONDARY_OFFSET 0x0
#define PM_MCUBOOT_SECONDARY_ADDRESS 0x0
#define PM_MCUBOOT_SECONDARY_END_ADDRESS 0xf4000
#define PM_MCUBOOT_SECONDARY_SIZE 0xf4000
#define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
#define PM_MCUBOOT_SECONDARY_ID 1
#define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
#define PM_mcuboot_secondary_IS_ENABLED 1
#define PM_1_LABEL MCUBOOT_SECONDARY
#define PM_MCUBOOT_SECONDARY_DEV DT_CHOSEN(nordic_pm_ext_flash)
#define PM_MCUBOOT_SECONDARY_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
#define PM_MCUBOOT_PAD_OFFSET 0xc000
#define PM_MCUBOOT_PAD_ADDRESS 0xc000
#define PM_MCUBOOT_PAD_END_ADDRESS 0xc200
#define PM_MCUBOOT_PAD_SIZE 0x200
#define PM_MCUBOOT_PAD_NAME mcuboot_pad
#define PM_MCUBOOT_PAD_ID 2
#define PM_mcuboot_pad_ID PM_MCUBOOT_PAD_ID
#define PM_mcuboot_pad_IS_ENABLED 1
#define PM_2_LABEL MCUBOOT_PAD
#define PM_MCUBOOT_PAD_DEV flash_controller
#define PM_MCUBOOT_PAD_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
#define PM_MCUBOOT_PRIMARY_OFFSET 0xc000
#define PM_MCUBOOT_PRIMARY_ADDRESS 0xc000
#define PM_MCUBOOT_PRIMARY_END_ADDRESS 0x100000
#define PM_MCUBOOT_PRIMARY_SIZE 0xf4000
#define PM_MCUBOOT_PRIMARY_NAME mcuboot_primary
#define PM_MCUBOOT_PRIMARY_ID 3
#define PM_mcuboot_primary_ID PM_MCUBOOT_PRIMARY_ID
#define PM_mcuboot_primary_IS_ENABLED 1
#define PM_3_LABEL MCUBOOT_PRIMARY
#define PM_MCUBOOT_PRIMARY_DEV flash_controller
#define PM_MCUBOOT_PRIMARY_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
#define PM_APP_OFFSET 0xc200
#define PM_APP_ADDRESS 0xc200
#define PM_APP_END_ADDRESS 0x100000
#define PM_APP_SIZE 0xf3e00
#define PM_APP_NAME app
#define PM_APP_ID 4
#define PM_app_ID PM_APP_ID
#define PM_app_IS_ENABLED 1
#define PM_4_LABEL APP
#define PM_APP_DEV flash_controller
#define PM_APP_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
#define PM_MCUBOOT_PRIMARY_APP_OFFSET 0xc200
#define PM_MCUBOOT_PRIMARY_APP_ADDRESS 0xc200
#define PM_MCUBOOT_PRIMARY_APP_END_ADDRESS 0x100000
#define PM_MCUBOOT_PRIMARY_APP_SIZE 0xf3e00
#define PM_MCUBOOT_PRIMARY_APP_NAME mcuboot_primary_app
#define PM_MCUBOOT_PRIMARY_APP_ID 5
#define PM_mcuboot_primary_app_ID PM_MCUBOOT_PRIMARY_APP_ID
#define PM_mcuboot_primary_app_IS_ENABLED 1
#define PM_5_LABEL MCUBOOT_PRIMARY_APP
#define PM_MCUBOOT_PRIMARY_APP_DEV flash_controller
#define PM_MCUBOOT_PRIMARY_APP_DEFAULT_DRIVER_KCONFIG CONFIG_SOC_FLASH_NRF
#define PM_EXTERNAL_PARTITION_OFFSET 0xf4000
#define PM_EXTERNAL_PARTITION_ADDRESS 0xf4000
#define PM_EXTERNAL_PARTITION_END_ADDRESS 0xf8000
#define PM_EXTERNAL_PARTITION_SIZE 0x4000
#define PM_EXTERNAL_PARTITION_NAME external_partition
#define PM_EXTERNAL_PARTITION_ID 6
#define PM_external_partition_ID PM_EXTERNAL_PARTITION_ID
#define PM_external_partition_IS_ENABLED 1
#define PM_6_LABEL EXTERNAL_PARTITION
#define PM_EXTERNAL_PARTITION_DEV DT_CHOSEN(nordic_pm_ext_flash)
#define PM_EXTERNAL_PARTITION_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
#define PM_SETTINGS_STORAGE_OFFSET 0xf8000
#define PM_SETTINGS_STORAGE_ADDRESS 0xf8000
#define PM_SETTINGS_STORAGE_END_ADDRESS 0xfc000
#define PM_SETTINGS_STORAGE_SIZE 0x4000
#define PM_SETTINGS_STORAGE_NAME settings_storage
#define PM_SETTINGS_STORAGE_ID 7
#define PM_settings_storage_ID PM_SETTINGS_STORAGE_ID
#define PM_settings_storage_IS_ENABLED 1
#define PM_7_LABEL SETTINGS_STORAGE
#define PM_SETTINGS_STORAGE_DEV DT_CHOSEN(nordic_pm_ext_flash)
#define PM_SETTINGS_STORAGE_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
#define PM_EXTERNAL_FLASH_OFFSET 0xfc000
#define PM_EXTERNAL_FLASH_ADDRESS 0xfc000
#define PM_EXTERNAL_FLASH_END_ADDRESS 0x800000
#define PM_EXTERNAL_FLASH_SIZE 0x704000
#define PM_EXTERNAL_FLASH_NAME external_flash
#define PM_EXTERNAL_FLASH_ID 8
#define PM_external_flash_ID PM_EXTERNAL_FLASH_ID
#define PM_external_flash_IS_ENABLED 1
#define PM_8_LABEL EXTERNAL_FLASH
#define PM_EXTERNAL_FLASH_DEV DT_CHOSEN(nordic_pm_ext_flash)
#define PM_EXTERNAL_FLASH_DEFAULT_DRIVER_KCONFIG CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
#define PM_SRAM_PRIMARY_OFFSET 0x0
#define PM_SRAM_PRIMARY_ADDRESS 0x20000000
#define PM_SRAM_PRIMARY_END_ADDRESS 0x20040000
#define PM_SRAM_PRIMARY_SIZE 0x40000
#define PM_SRAM_PRIMARY_NAME sram_primary
#define PM_NUM 9
#define PM_ALL_BY_SIZE "mcuboot_pad external_partition settings_storage mcuboot sram_primary app mcuboot_primary_app mcuboot_secondary mcuboot_primary external_flash"
#define PM_ADDRESS 0x0
#define PM_SIZE 0xc000
#define PM_SRAM_ADDRESS 0x20000000
#define PM_SRAM_SIZE 0x40000
#endif /* PM_CONFIG_H__ */

The documentation say that setting CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y should do the trick but, it did not change the outcome.

I have a pm_static.yml on the project root that is:

mcuboot_secondary:
  address: 0x00000
  region: external_flash
  size: 0xf4000
  
external_partition:
  address: 0xf4000
  end_address: 0xf8000
  region: external_flash
  size: 0x4000

settings_storage:
  address: 0xf8000
  region: external_flash
  size: 0x4000

It is used to place external storage, settings and the secondary slot on the external flash

This is the generated pm.yml located in mcuboot/zephyr/include/generated and, as far as I understand, seems correct, I see primary slot on main flash, secondary on external_flash :

mcuboot:
  size: 0xc000
  placement:
    before: [mcuboot_primary]
mcuboot_primary_app:
  # All images to be placed in MCUboot's slot 0 should be placed in this
  # partition
  span: [app]
mcuboot_primary:
  span: [mcuboot_pad, mcuboot_primary_app]
# Partition for secondary slot is not created if building in single application
# slot configuration.
mcuboot_secondary:
  share_size: [mcuboot_primary]
  region: external_flash
  placement:
    align: {start: 4}
# Padding placed before image to boot. This reserves space for the MCUboot image header
# and it ensures that the boot image gets linked with the correct address offset in flash.
mcuboot_pad:
    # MCUboot pad must be placed before the primary application partition.
    # The primary application partition includes the secure firmware if present.
  size: 0x200
  placement:
    before: [mcuboot_primary_app]
    align: {start: 0x1000}

In my opinion everything seems right but someway it didnt...

Anyone has any idea? 

Thanks

Alessio

Parents Reply Children
Related