Mass storage initialization error with nsib and mcuboot

Board: nRF52840Dk

ncs: v2.3.0.

Hi, I am working on a project in which i need to update bootloader itself and application from the external flash. I also need to make partition where i can store my files using FatFs file system.

My project configuration and overlay setting are below:

CONFIG_STDOUT_CONSOLE=y

#USB related configs
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
CONFIG_LOG=y
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y

CONFIG_MAIN_STACK_SIZE=4096


#CONFIG_APP_MSC_STORAGE_FLASH_LITTLEFS=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y
CONFIG_FS_FATFS_LFN=y

# External partitions
#CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
#CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
#CONFIG_PM_PARTITION_REGION_NVS_STORAGE_EXTERNAL=y

CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

#memory related configs
CONFIG_NVS=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_REBOOT=y
CONFIG_HWINFO=y
CONFIG_IMG_MANAGER=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

#immutable boot
CONFIG_SECURE_BOOT=y
CONFIG_SB_SIGNING_KEY_FILE="nsib_priv.pem"
CONFIG_BUILD_S1_VARIANT=y
# Need to lower the number of counter slots to be able to update several times. Do not know the best number yet.
CONFIG_SB_NUM_VER_COUNTER_SLOTS=120

CONFIG_FW_INFO_FIRMWARE_VERSION=1
CONFIG_MCUBOOT_IMAGE_VERSION="1.1.1"

/delete-node/ &boot_partition;
/delete-node/ &slot0_partition;
/delete-node/ &slot1_partition;

&flash0 {
	partitions {
		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0x000000000 0x00010000>;
		};
		slot0_partition: partition@10000 {
			label = "image-0";
			reg = <0x000010000 0x0000e8000>;
		};
	};
};

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

		slot1_partition: partition@0 {
			label = "image-1";
			reg = <0x000000000 0x0000e8000>;
		};
		external_flash: partition@e8000 {
			label = "external flash";
			reg = <0x0000e8000 0x000718000>;
		};
	};
};

/ {
	chosen {
		nordic,pm-ext-flash = &mx25r64;
	};
	msc_disk0 {
		compatible = "zephyr,flash-disk";
		partition = <&external_flash>;
		disk-name = "NAND";
		cache-size = <4096>;
	};
};

When i am running the code then getting error of msc init:

Attempting to boot slot 0.
Attempting to boot from address 0x9200.
Verifying signature against key 0.
Hash: 0x8f...3b
Firmware signature verified.
Firmware version 5
Setting monotonic counter (version: 5, slot: 0)
*** Booting Zephyr OS build v3.2.99-ncs2-3159-g1e1697d881a9 ***
[00:00:00.376,220] <inf> mcuboot: Starting bootloader
[00:00:00.376,983] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
[00:00:00.377,349] <inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
[00:00:00.377,349] <inf> mcuboot: Boot source: none
[00:00:00.377,838] <inf> mcuboot: Swap type: none
[00:00:00.378,295] <inf> mcuboot: Primary image: magic=bad, swap_type=0x1, copy_done=0x2, image_ok=0x2
[00:00:00.378,662] <inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
[00:00:00.378,692] <inf> mcuboot: Boot source: none
[00:00:00.379,150] <inf> mcuboot: Swap type: none
*** Booting Zephyr OS build v3.2.99-ncs2-3159-g1e1697d881a9 ***
[00:00:00.000,396] <inf> flashdisk: Initialize device NAND
[00:00:00.000,427] <inf> flashdisk: offset e8000, sector size 512, page size 4096, volume size 7438336
[00:00:00.000,488] <err> flashdisk: Error -22 getting page info at offset 100000
[00:00:00.000,488] <err> usb_msc: Storage init ERROR !!!! - Aborting USB init
[00:00:00.000,518] <wrn> main: Image build time: Jul 10 2023 09:44:53
[00:00:00.000,579] <inf> main: Image is confirmed OK

Please help me, what I am doing wrong.

Thanks.

Parents Reply
  • Hi Hieu,

    I just want to know, just like application update we can use secure and unsecure image, but in case of mcuboot update, Can I use unsecure image?

    When I disabled the following macro:

    #CONFIG_SB_SIGNING_KEY_FILE="nsib_priv.pem"
    Getting following error:
    Attempting to boot slot 0.
    Attempting to boot from address 0x9200.
    Verifying signature against key 0.
    Hash: 0x8f...3b
    Public key didn't match, try next.
    Failed to validate signature.
    Failed to validate, permanently invalidating!
    Attempting to boot slot 1.
    Attempting to boot from address 0x1a200.
    Verifying signature against key 0.
    Hash: 0x8f...3b
    Public key didn't match, try next.
    Failed to validate signature.
    Failed to validate, permanently invalidating!
    No bootable image found. Aborting boot.
Children
  • Hi Mithi,

    Mithilesh Yadav said:

    Currently I am using Windows system in which Littlefs is not supported. 

    Is there any way to copy/paste to the littlefs Mass storage device in windows.

    Regarding LittleFS, you will need to make sure you are using it with Flash Map API, and not the mode that support Block Devices.

    The root cause of the FAT FS not working with Partition Manager is that the flash disk API is not compatible with Partition Manager. LittleFS for Block Devices runs the same API, and will have the same issue.
    Refer: CONFIG_FS_LITTLEFS_FMP_DEV and CONFIG_FS_LITTLEFS_BLK_DEV.

    I am not knowledgeable about supporting LittleFS on Windows, but a general internet search results in some open source options. Could you please try one and let me know if there are any issues?

    Mithilesh Yadav said:

    I just want to know, just like application update we can use secure and unsecure image, but in case of mcuboot update, Can I use unsecure image?

    When I disabled the following macro:

    #CONFIG_SB_SIGNING_KEY_FILE="nsib_priv.pem"

    This is a different topic, and I would like to ask you to open a new DevZone case for it.

    Finally, I will be out of office from tomorrow. However, if you have any follow-up on the topic here, another engineer would surely be assigned to support you. Please excuse us if there are any delays though. We are understaffed, as previously mentioned. Our apologies for the inconveniences.

  • Hi,

    By which version of NCS will the compatibility issue between the flash disk API and the partition manager be resolved?

  • Hi Mithilesh,

    Hieu is on vacation and I am looking into the case for the time being. I have inquired your request internally and will get back to you as soon as I get a response. Please expect a slight delay as we are currently short staffed because of the summer holidays here in Norway.

    Thank you very much for your patience and understanding.

    -Priyanka

  • As this is merged: https://github.com/nrfconnect/sdk-nrf/pull/11802/ it will be resolved in the NCS 2.5 release. However if you want to start testing it out you can cherry-pick this patch.

    I made a prototype implementation for how you could potentially integrate parts of this into the build system see:
    https://github.com/sigvartmh/fw-nrfconnect-nrf-1/pull/38/

    and here is the diff to the MSC sample in zephyr:

    diff --git a/samples/subsys/usb/mass/prj.conf b/samples/subsys/usb/mass/prj.conf
    index 0954afcd0e..a8bc60848d 100644
    --- a/samples/subsys/usb/mass/prj.conf
    +++ b/samples/subsys/usb/mass/prj.conf
    @@ -12,3 +12,4 @@ CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=y
     CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
    
     CONFIG_MAIN_STACK_SIZE=1536
    +CONFIG_PM_PARTITION_FATFS_DISK_NAME="NAND"
    diff --git a/samples/subsys/usb/mass/src/main.c b/samples/subsys/usb/mass/src/main.c
    index 0d8d6ba982..b40681ef76 100644
    --- a/samples/subsys/usb/mass/src/main.c
    +++ b/samples/subsys/usb/mass/src/main.c
    @@ -28,8 +28,8 @@ LOG_MODULE_REGISTER(main);
     FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
     #endif
    
    -#define STORAGE_PARTITION              storage_partition
    -#define STORAGE_PARTITION_ID           FIXED_PARTITION_ID(STORAGE_PARTITION)
    +#define STORAGE_PARTITION              fatfs_storage
    +#define STORAGE_PARTITION_ID           FIXED_PARTITION_ID(FATFS_STORAGE)
    
     static struct fs_mount_t fs_mnt;

  • Thank You! I will check it once I get time. Does it work with LittleFs?

    When is nordic planning to release the NCS v2.5?

Related