MCUBoot header

Hi,

I'm using MCUBoot in my application but this last would hardfault all the time. I figured that the a MCUBoot header was inserted at the beginning of the code partition and that this header is considered as a partition by MCUBoot . Therefore, when the MCUBoot would read the header to validate it, it would use index 2 in the flash_map[] array which would point to an invalid address since only two partitions are defined (at index 0 and 1) in the board description file:

&flash0 {
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        boot_partition: partition@0 {
            label = "mcuboot";
            reg = <0x0 0xC000>;
        };

        slot0_partition: partition@C000 {
            label = "image-0";
            reg = <0xC000 0x74000>;
        };
    };
};

In function boot_go from single_loader.c file, the flash_area_open function is called (line 448) with argument "FLASH_AREA_IMAGE_PRIMARY(0)" as the index of the partition to look for in flash_map[] array. This macro is replaced at compile time by the value 2.

I found a work around. I create a partition for the header which overlaps the code partition. This creates a new entry in flash_map[] array at index 1 and the application is moved to index 2 therefore the partition exist in the flash_map array and I got rid of the hardfault.

Here is what I did in the board configuration file:

&flash0 {
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        boot_partition: partition@0 {
            label = "mcuboot";
            reg = <0x0 0xC000>;
        };

        slot0_header: partition@C000 {
            label = "header-0";
            reg = <0xC000 0x200>;
        };

        slot0_partition: partition@C200 {
            label = "image-0";
            reg = <0xC000 0x74000>;
        };
    };
};

Here is my MCUboot configuration file:

#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_BOOT_BANNER=n
CONFIG_SIZE_OPTIMIZATIONS=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y

# Disable memory guard to avoid false faults in application after boot
CONFIG_HW_STACK_PROTECTION=n

# CONFIG_SYSTEM_CLOCK_NO_WAIT=y
# CONFIG_PM=n

# CONFIG_BOOT_BOOTSTRAP=n

CONFIG_BOOT_ENCRYPT_RSA=n
CONFIG_BOOT_SIGNATURE_TYPE_RSA=n
CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256=y

CONFIG_SINGLE_APPLICATION_SLOT=y

# Debug
CONFIG_THREAD_MONITOR=y
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_DEBUG_OPTIMIZATIONS=y

# Segger RTT
CONFIG_CONSOLE=y
CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_MODE_IMMEDIATE=y

# Logs
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
# CONFIG_LOG_PRINTK=y

# Flash
# CONFIG_FLASH=y
# CONFIG_FLASH_HAS_DRIVER_ENABLED=y
# CONFIG_PROTECTED=y
# CONFIG_BOOT_ERASE_PROGRESSIVELY=y
# CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y

# Serial
# CONFIG_SERIAL=y
# CONFIG_UART_LINE_CTRL=y
# CONFIG_UART_NRFX=n
# CONFIG_UART_INTERRUPT_DRIVEN=n

# MCUBoot serial
# CONFIG_GPIO=y
CONFIG_MCUBOOT_SERIAL=y
# CONFIG_BOOT_SERIAL_CDC_ACM=n
CONFIG_BOOT_SERIAL_UART=y
# CONFIG_CONSOLE=y
# CONFIG_UART_CONSOLE=y

Is there something I missed which would allow me not to configure this "fake" partition for the boot header?

Regards,

Hugo

Related