I can't use mcuboot to boot a firmware on my external flash

Hi,

I am trying to use mcuboot to load a version that is stored in my external flash, and I cannot get it to boot. My project is being built using sysbuild and my target is an nrf9161 with an external flash connected through SPI. Tests have been made where the flash could be read from the main application, so physical connections between the memory and the processor should not be an issue for this problem. The SDK version I am using is still the 2.9.1.

The process I am following is that I am building a version which I code using the VERSION file with a version higher than the program I plan to run on the processor. I generate the zephyr.signed.bin file like that and I write it on the flash.

Then, I build another version with a lower version number coded in the VERSION file, and I flash the merged.hex on the processor.

Each version has a print at the beginning where I check if the version that is running is the flashed one or the one that I wrote on the flash, and all the time I am seeing the one that I actively flash on the processor directly. The external flash does have the version because I could read the flash with my J-Link and I could confirm that the version was stored.

I have used the following configuration out of the devacademy examples.

sysbuild.conf:

# Activate the MCUBOOT bootloader for sysbuild
SB_CONFIG_BOOTLOADER_MCUBOOT=y

# STEP 3.1 - MCUboot should use external flash
SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
# STEP 3.1 - For SPI, we need to set this
SB_CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y

SB_CONFIG_BOOT_SIGNATURE_TYPE_RSA=y
SB_CONFIG_MCUBOOT_MODE_OVERWRITE_ONLY=y

SB_CONFIG_PARTITION_MANAGER=y
SB_CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

sysbuild/mcuboot/prj.conf:

CONFIG_PM=n

CONFIG_MAIN_STACK_SIZE=10240
CONFIG_MBEDTLS_CFG_FILE="mcuboot-mbedtls-cfg.h"

CONFIG_BOOT_SWAP_SAVE_ENCTLV=n
CONFIG_BOOT_ENCRYPT_IMAGE=n

CONFIG_BOOT_UPGRADE_ONLY=n
CONFIG_BOOT_BOOTSTRAP=n

# Configurations added for mcuboot
CONFIG_BOOT_UPGRADE_ONLY=n
CONFIG_MCUBOOT_DOWNGRADE_PREVENTION=n
CONFIG_BOOT_BOOTSTRAP=n

CONFIG_PM_EXTERNAL_FLASH_BASE=0x0
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
CONFIG_GPIO=y
CONFIG_FLASH=y
CONFIG_SPI=y
CONFIG_SPI_NOR=y
CONFIG_SPI_NOR_SFDP_DEVICETREE=y
CONFIG_NORDIC_QSPI_NOR=n
# required by SPI driver
CONFIG_MULTITHREADING=y

CONFIG_FPROTECT=y
# This must be increased to accommodate the bigger images.
CONFIG_BOOT_MAX_IMG_SECTORS=256
CONFIG_LOG=y
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_DBG=y
### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
CONFIG_CBPRINTF_NANO=y
CONFIG_NRF_RTC_TIMER_USER_CHAN_COUNT=0
### Use the minimal C library to reduce flash usage
CONFIG_MINIMAL_LIBC=y

# Increase the monotonic firmware version before building a firmware update
CONFIG_FW_INFO=y
CONFIG_FW_INFO_FIRMWARE_VERSION=1

I also added to the sysbuild/mcuboot/app.overlay the external flash:

// The external flash must be added to the mcuboot overlay
&spi_main {
    ext_flash: w25q16@1 {
        compatible = "jedec,spi-nor";
        status = "okay";
        reg = <1>;
        spi-max-frequency = <800000>;
        size = <16777216>;
        has-dpd;
        t-enter-dpd = <10000>;
        t-exit-dpd = <35000>;
    };
};

/ {
    chosen {
        zephyr,code-partition = &boot_partition;
        nordic,pm-ext-flash = &ext_flash;
    };
};

I also tried to use it without the &spi_main definition here and just adding the flash to the chosen and the behavior was the same.

When I generate both the merged.hex as the zephyr.signed.bin I also use this config in the main application to sign the firmwares:

CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"

I am also trying to make debug prints on the mcuboot files to try to find out if there is any problem while trying to authenticate, but I have not been able to make any newer logging prints on my console.

There is probably something on the overall configuration that I am missing or any step that I unconsciously missed, so any advice can be useful.

Thank you very much,

Daniel

Related