USB Mass Storage with MCUBOOT

Hi Devzone,

I am facing an issue on my nrf52840-based custom board when I try to set up the USB mass storage class on an external NOR Flash as well as having MCUBoot enabled with the secondary slot partition on that same external flash.

I am able to reproduce the issue on a nRF52840 DK with Zephyr's USB Mass storage sample and the following configuration:

Windows, NCS v2.6.1 (my original issue also happens on v2.7.0, I have not tried v2.7.0 with the DK)

I have a pm_static.yml file defined as follows:

mcuboot_secondary:
  address: 0x00000
  region: external_flash
  size: 0xdb000

storage_partition:
  affiliation: disk
  extra_params: {
      disk_name: "NAND",
      disk_cache_size: 4096,
      disk_sector_size: 512,
      disk_read_only: 0
  }
  address: 0xdb000
  region: external_flash
  size: 0xf25000

I modified the sample overlay for the nrf52840DK:

/*
 * Copyright (c) 2019 Peter Bigot Consulting, LLC
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/delete-node/ &storage_partition;

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

		mcuboot_secondary: partition@0 {
			reg = <0x0 0xdb000>;
			read-only;
		};
		storage_partition: partition@db000 {
			reg = <0xdb000 0xf25000>;
		};
	};
};

/ {

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

And finally the proj.conf file. I added two configurations to the sample file: CONFIG_APP_MSC_STORAGE_FLASH_FATFS to enable FAT filesystem on the flash device, and  CONFIG_BOOTLOADER_MCUBOOT to add MCUBoot

CONFIG_STDOUT_CONSOLE=y

#USB related configs
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
CONFIG_USB_DEVICE_PID=0x0008
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_USB_DEVICE_INITIALIZE_AT_BOOT=n

CONFIG_MAIN_STACK_SIZE=1536

CONFIG_BOOTLOADER_MCUBOOT=y

CONFIG_APP_MSC_STORAGE_FLASH_FATFS=y

With MCUBoot disabled, the program compiles and performs fine, however when I enable MCUBoot I get the following error:

[101/195] Building C object zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj
FAILED: zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj 
C:\ncs\toolchains\cf2149caf2\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52840_XXAA -DPICOLIBC_LONG_LONG_PRINTF_SCANF -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/samples/subsys/usb/mass/build/zephyr/include/generated -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/soc/common/nordic_nrf/. -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/soc/arm/nordic_nrf/common/. -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/subsys/usb/device -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/usb/common/nrf_usbd_common/. -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/eqs-motion-s-zephyr.git/include -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/eqs-motion-s-zephyr.git/include/shared_types -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/nrf/include -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/nrf/tests/include -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/modules/hal/cmsis/CMSIS/Core/Include -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/modules/cmsis/. -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/modules/hal/nordic/nrfx -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/modules/hal/nordic/nrfx/drivers/include -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/modules/hal/nordic/nrfx/mdk -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/modules/hal_nordic/nrfx/. -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/modules/debug/segger/SEGGER -IC:/Users/LPC-008/Documents/eqs-motion-s-zephyr/modules/debug/segger/Config -isystem C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/lib/libc/common/include -isystem C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/nrfxlib/crypto/nrf_cc310_platform/include -Wshadow -fno-strict-aliasing -Os -imacros C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/samples/subsys/usb/mass/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=C:/ncs/toolchains/cf2149caf2/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/samples/subsys/usb/mass=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/Users/LPC-008/Documents/eqs-motion-s-zephyr=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj -MF zephyr\drivers\disk\CMakeFiles\drivers__disk.dir\flashdisk.c.obj.d -o zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/flashdisk.c.obj -c C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:484:1: error: return type defaults to 'int' [-Werror=implicit-int]
  484 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_CACHE)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c: In function 'PM_FOREACH_AFFILIATED_TO_disk':
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:523:30: error: storage class specified for parameter 'flash_disks'
  523 | static struct flashdisk_data flash_disks[] = {
      |                              ^~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:523:15: error: parameter 'flash_disks' is initialized
  523 | static struct flashdisk_data flash_disks[] = {
      |               ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:524:39: error: 'DEFINE_FLASHDISKS_DEVICE' undeclared (first use in this function)
  524 |         PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_DEVICE)
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:524:39: note: each undeclared identifier is reported only once for each function it appears in
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:533:1: error: expected declaration specifiers before 'PM_FOREACH_AFFILIATED_TO_disk'
  533 | PM_FOREACH_AFFILIATED_TO_disk(VERIFY_CACHE_SIZE_IS_NOT_ZERO_IF_NOT_READ_ONLY)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/gcc.h:98,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain.h:50,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/sys/__assert.h:11,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:10:
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:44: error: storage class specified for parameter '__init_disk_flash_init'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                            ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:36: note: in expansion of macro '_CONCAT'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                    ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:208:17: note: in expansion of macro 'Z_INIT_ENTRY_NAME'
  208 |                 Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}}
      |                 ^~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:190:9: note: in expansion of macro 'SYS_INIT_NAMED'
  190 |         SYS_INIT_NAMED(init_fn, init_fn, level, prio)
      |         ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:206:42: error: parameter '__init_disk_flash_init' is initialized
  206 |         static const Z_DECL_ALIGN(struct init_entry)                           \
      |                                          ^~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/common.h:195:55: note: in definition of macro 'Z_DECL_ALIGN'
  195 | #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type
      |                                                       ^~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:190:9: note: in expansion of macro 'SYS_INIT_NAMED'
  190 |         SYS_INIT_NAMED(init_fn, init_fn, level, prio)
      |         ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:44: error: section attribute not allowed for '__init_disk_flash_init'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                            ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:36: note: in expansion of macro '_CONCAT'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                    ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:208:17: note: in expansion of macro 'Z_INIT_ENTRY_NAME'
  208 |                 Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}}
      |                 ^~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:190:9: note: in expansion of macro 'SYS_INIT_NAMED'
  190 |         SYS_INIT_NAMED(init_fn, init_fn, level, prio)
      |         ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:206:42: warning: 'used' attribute ignored [-Wattributes]
  206 |         static const Z_DECL_ALIGN(struct init_entry)                           \
      |                                          ^~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/common.h:195:55: note: in definition of macro 'Z_DECL_ALIGN'
  195 | #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type
      |                                                       ^~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:190:9: note: in expansion of macro 'SYS_INIT_NAMED'
  190 |         SYS_INIT_NAMED(init_fn, init_fn, level, prio)
      |         ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:44: error: alignment may not be specified for '__init_disk_flash_init'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                            ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:36: note: in expansion of macro '_CONCAT'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                    ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:208:17: note: in expansion of macro 'Z_INIT_ENTRY_NAME'
  208 |                 Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}}
      |                 ^~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:190:9: note: in expansion of macro 'SYS_INIT_NAMED'
  190 |         SYS_INIT_NAMED(init_fn, init_fn, level, prio)
      |         ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
In file included from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/device.h:13,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/sw_isr_table.h:18,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/arch/arm/irq.h:19,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/arch/arm/arch.h:27,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/arch/cpu.h:19,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/kernel_includes.h:37,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/kernel.h:17,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/drivers/disk.h:28,
                 from C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:12:
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:10: error: 'disk_flash_init' undeclared (first use in this function)
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      |          ^~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:208:64: note: in definition of macro 'SYS_INIT_NAMED'
  208 |                 Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}}
      |                                                                ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:484:1: error: type of 'DEFINE_FLASHDISKS_CACHE' defaults to 'int' [-Werror=implicit-int]
  484 | PM_FOREACH_AFFILIATED_TO_disk(DEFINE_FLASHDISKS_CACHE)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:44: error: declaration for parameter '__init_disk_flash_init' but no such parameter
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                            ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:141:36: note: in expansion of macro '_CONCAT'
  141 | #define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
      |                                    ^~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:208:17: note: in expansion of macro 'Z_INIT_ENTRY_NAME'
  208 |                 Z_INIT_ENTRY_NAME(name) = {.init_fn = {.sys = (init_fn_)}}
      |                 ^~~~~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/include/zephyr/init.h:190:9: note: in expansion of macro 'SYS_INIT_NAMED'
  190 |         SYS_INIT_NAMED(init_fn, init_fn, level, prio)
      |         ^~~~~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:563:1: note: in expansion of macro 'SYS_INIT'
  563 | SYS_INIT(disk_flash_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
      | ^~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:523:30: error: declaration for parameter 'flash_disks' but no such parameter
  523 | static struct flashdisk_data flash_disks[] = {
      |                              ^~~~~~~~~~~
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:565: error: expected '{' at end of input
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:565: warning: control reaches end of non-void function [-Wreturn-type]
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c: At top level:
C:/Users/LPC-008/Documents/eqs-motion-s-zephyr/zephyr/drivers/disk/flashdisk.c:415:37: warning: 'flash_disk_ops' defined but not used [-Wunused-const-variable=]
  415 | static const struct disk_operations flash_disk_ops = {
      |                                     ^~~~~~~~~~~~~~
cc1.exe: some warnings being treated as errors
[109/195] Building C object zephyr/drivers/usb/device/CMakeFiles/drivers__usb__device.dir/usb_dc_nrfx.c.obj

On different projects I have been able to use both functionalities separately (mass storage on an external flash, and MCUBoot's secondary partition on an external flash), so I am confident the configuration for these individual things is correct, but for some reason I am not able to use these both at the same time ? Can you help me how to resolve the issue please ?

I am happy to provide more information if needed

Thanks in advance

Best regards,

Nicolas Goualard

Parents
  • Hello,

    Sorry for getting back to you a bit late. I have reviewed the information you provided, and thank you for explaining the issue in detail.

    What is the size of your flash? While checking the pm_static.yml file you shared, I noticed that mcuboot_secondary is set to 0xdb000 (approximately 900KB) and storage_partition is set to 0xf25000 (approximately 15.5MB). So, the total required space would be around 16.4MB. I assume your flash size is larger than 16MB. If it is not, you may need to change the start address of the storage partition to a later position to avoid overlap.

    I also want to mention that integrating flash disk management directly with MCUboot is not officially supported and is considered a non-supported feature. Using MCUboot to manage complex flash disk features or a file system can be tricky and might lead to issues with security and performance. This is not a use case MCUboot was designed for, so I’m afraid the support I can provide for this issue is very limited. I apologize for that.

    Kind regards,
    Abhijith

Reply
  • Hello,

    Sorry for getting back to you a bit late. I have reviewed the information you provided, and thank you for explaining the issue in detail.

    What is the size of your flash? While checking the pm_static.yml file you shared, I noticed that mcuboot_secondary is set to 0xdb000 (approximately 900KB) and storage_partition is set to 0xf25000 (approximately 15.5MB). So, the total required space would be around 16.4MB. I assume your flash size is larger than 16MB. If it is not, you may need to change the start address of the storage partition to a later position to avoid overlap.

    I also want to mention that integrating flash disk management directly with MCUboot is not officially supported and is considered a non-supported feature. Using MCUboot to manage complex flash disk features or a file system can be tricky and might lead to issues with security and performance. This is not a use case MCUboot was designed for, so I’m afraid the support I can provide for this issue is very limited. I apologize for that.

    Kind regards,
    Abhijith

Children
  • Hi Abhijith, thanks for your answer,

    The external flash I am using is indeed 16MB.

    There is something I do not understand, I have a few more questions if you don't mind.

    The end goal is for my application to:

    - be updateable, thus enabling MCUBoot and NSIB as a bootloader chain.

    - store log files generated by Zephyr's logging subsystem with filesystem backend enabled. Using flash disk would make it easy to get those log files by plugging the device to a computer.

    MCUBoot does not need to handle the storage_partition as far as I'm concerned, but maybe it is the case under the hood ? Having two separate partitions is not enough to differentiate between the two functionalities ?

    Thanks in advance for your help

  • Hello,

    Nicolas Goualard said:
    The external flash I am using is indeed 16MB

    While reviewing the error messages in the build logs you shared, I suspect the issue might be with the pm_static.yml file. Could you try reducing the storage_partition size so that both mcuboot_secondary and storage_partition do not exceed 0x1000000? The two partitions you mentioned, from 0x00000 to 0xF80000, exceed the available 16 MB by about 512 KB.

    Nicolas Goualard said:
    MCUBoot does not need to handle the storage_partition as far as I'm concerned, but maybe it is the case under the hood ? Having two separate partitions is not enough to differentiate between the two functionalities ?

    I’m not entirely sure, but I believe having two separate partitions should work to distinguish between the MCUboot and flash disk for your application's logging.

    Kind Regards,

    Abhijith

  • But, shouldn't it already be fitting in the flash ?

    0xdb000 (size of mcuboot_secondary) + 0xf25000 (size of storage_partition) = 0x1000000 (size of flash)

    Unless I am missing something ?

    I tried on the DK with storage_partition of size 0x25000, with the same result

    mcuboot_secondary:
      address: 0x00000
      region: external_flash
      size: 0xdb000
    
    storage_partition:
      affiliation: disk
      extra_params: {
          disk_name: "NAND",
          disk_cache_size: 4096,
          disk_sector_size: 512,
          disk_read_only: 0
      }
      address: 0xdb000
      region: external_flash
      size: 0x25000

    Best regards,

    Nicolas

  • Hi Nicolas,

    Abhjith is out of office, and I will continue supporting you in his stead.

    I have encountered a similar issue in the past. Could you please change the pm_static.yml to list the affiliation as followed instead?

      affiliation:
        - disk

    If that fixes it, then the root cause is some issue in processing the affiliation in Partition Manager script.

    If not, do you think you can help me confirm the following steps can reproduce your issue?

    • Start from hello_world
    • Add your pm_static.yml
    • Add your overlay
    • Add CONFIG_APP_MSC_STORAGE_FLASH_FATFS and CONFIG_BOOTLOADER_MCUBOOT

    If the steps work, I will try to replicate the issue and investigate further.

    Best regards,

    Hieu

Related