Creating external flash partition for littlefs get's overwritten by partition manager when CONFIG_BOOTLOADER_MCUBOOT=y

Zephyr board: nrf54l15dk_nrf54l15_cpuapp

Hi, we have a custom SPI NAND flash driver and are trying to create an external flash partition for our littlefs file system.

When we use sysbuild / CONFIG_BOOTLOADER_MCUBOOT (which I believe enables the partition manager) then zephyr overwrites the external flash partition and it forces littlefs to use the rram instead of the expected external flash partition we setup in our overlay (see below).

But, if we disable sysbuild / mcuboot then we are able to use the external flash partition as expected.

Here is our overlay

see 

ittlefs0: littlefs
mx35uf4: mx35uf4g24ad

// gpio expander has some wonky pin mapping after pin 10
#include "gpio_expander_pin_map.h"

/ {
    chosen {
        zephyr,console = &uart00;
        zephyr,shell-uart = &uart00;
        zephyr,uart-mcumgr = &uart00;
        zephyr,bt-mon-uart = &uart00;
        zephyr,bt-c2h-uart = &uart00;
        zephyr,flash-controller = &rram_controller;
        zephyr,flash = &cpuapp_rram;
        zephyr,ieee802154 = &ieee802154;
    };

    // littlefs_partition is from mx35uf4 NAND flash (see below)
    littlefs0: littlefs {
        compatible = "zephyr,fstab,littlefs";
        mount-point = "/lfs";
        partition = <&littlefs_partition>;
        read-size = <4096>;
        prog-size = <4096>;
        cache-size = <4096>;
        lookahead-size = <256>;
        block-cycles = <512>;
        automount;
    };

};


/delete-node/ &mx25r64;
&spi00 {
    status = "disabled";
};

/* NOTE: must disable uart20 to use spi20 for nand spi flash */
&spi20 {
    status = "okay";
    cs-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi20_default>;
    pinctrl-1 = <&spi20_sleep>;
    pinctrl-names = "default", "sleep";

    /* see local driver in drivers/flash/spi_nand.c */
    mx35uf4: mx35uf4g24ad@0 {
      compatible = "jedec,spi-nand";
      reg = <0>;
      spi-max-frequency = <8000000>; //8000000
      id = [c2 f5];
      cs-wait-delay = <0>;
      page-size = <4096>;
      flash-size = <536870912>; // 4Gbit
      ecc-bits = <8>;
      status = "okay";

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

            littlefs_partition: partition@0 {
                label = "nand_storage";
                reg = <0x00000000 0x02000000>; // 0x02000000 for 32MB example
            };
        };
    };
};

/* rest of overlay removed */

here is our prj.conf

# General Kernel config
CONFIG_REBOOT=y
CONFIG_DEBUG_THREAD_INFO=y
CONFIG_THREAD_NAME=y # allows us to use k_thread_name_set
# fs_dirent structures are big.
CONFIG_MAIN_STACK_SIZE=4096

# MCUBoot
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE=y
CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE=y

# Logging
CONFIG_LOG=y
CONFIG_LOG_CMDS=y
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=1

# Enable the FS log backend
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_BACKEND_FS=y
CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP=y
CONFIG_LOG_BACKEND_FS_AUTOSTART=y
CONFIG_LOG_BACKEND_FS_DIR="/lfs"
CONFIG_LOG_BACKEND_FS_FILE_SIZE=4096  
# Increase log processing thread stack (try 4096 first, bump to 8192 if needed)
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096


# Binary descriptors (used for version management in the build system)
CONFIG_BINDESC=y
CONFIG_BINDESC_DEFINE=y
CONFIG_BINDESC_DEFINE_BUILD_TIME=y
CONFIG_BINDESC_BUILD_DATE_TIME_STRING=y
CONFIG_BINDESC_DEFINE_VERSION=y
CONFIG_BINDESC_APP_VERSION_STRING=y

# heap 32768
CONFIG_HEAP_MEM_POOL_SIZE=8192

# shell
CONFIG_SHELL=y
CONFIG_SHELL_PROMPT_UART="shell:~$ "
CONFIG_LOG_PRINTK=n
CONFIG_SHELL_STACK_SIZE=4096


# flash config
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y

# littlefs filesystem config
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
# NOTE: 8192 isn't enough for CONFIG_FS_LITTLEFS_FC_HEAP_SIZE, fs wont work well, use 12kb
CONFIG_FS_LITTLEFS_FC_HEAP_SIZE=12288
CONFIG_FILE_SYSTEM_MKFS=y

CONFIG_FS_LITTLEFS_PROG_SIZE=4096
CONFIG_FS_LITTLEFS_CACHE_SIZE=4096
CONFIG_FS_LITTLEFS_READ_SIZE=4096
CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE=256

# littlefs uses NAND Flash IC
CONFIG_SPI=y
CONFIG_SPI_NOR=n 
CONFIG_SPI_NAND=y
# SW ECC required
CONFIG_SPI_NAND_SOFTWARE_ECC=y

# Optional for "fs" shell commands
CONFIG_FILE_SYSTEM_SHELL=y


what are we doing wrong?

Parents
  • Hello,

    Thanks for the details. If I understand correctly, you are defining the partition only in the DTS overlay. This could be the cause of the issue. Could you please try defining the partition using pm_static.yml and check if that resolves the problem? Sysbuild partition manager

    Also, could you check the generated partition file in the build folder and share what it shows?

    I am not entirely sure about this, as this is NAND flash and I have not personally tested it with the Partition Manager. However, I recommend giving it a try.

    Kind regards,
    Abhijith

Reply
  • Hello,

    Thanks for the details. If I understand correctly, you are defining the partition only in the DTS overlay. This could be the cause of the issue. Could you please try defining the partition using pm_static.yml and check if that resolves the problem? Sysbuild partition manager

    Also, could you check the generated partition file in the build folder and share what it shows?

    I am not entirely sure about this, as this is NAND flash and I have not personally tested it with the Partition Manager. However, I recommend giving it a try.

    Kind regards,
    Abhijith

Children
  • Hi,

    Ok yes we added a pm_static.yml and got it working.

    littlefs_storage:
      address: 0x0
      size: 0x02000000   # 32 MB
      region: external_flash

    with overlay looking like this:

    // gpio expander has some wonky pin mapping after pin 10
    #include "gpio_expander_pin_map.h"
    
    / {
        chosen {
            zephyr,console = &uart00;
            zephyr,shell-uart = &uart00;
            zephyr,uart-mcumgr = &uart00;
            zephyr,bt-mon-uart = &uart00;
            zephyr,bt-c2h-uart = &uart00;
            zephyr,flash-controller = &rram_controller;
            zephyr,flash = &cpuapp_rram;
            zephyr,ieee802154 = &ieee802154;
            nordic,pm-ext-flash=&mx35uf4;
        };
    
        // littlefs_partition is from mx35uf4 NAND flash (see below)
        littlefs0: littlefs {
            compatible = "zephyr,fstab,littlefs";
            mount-point = "/lfs";
            partition = <&littlefs_storage>;
            read-size = <4096>;
            prog-size = <4096>;
            cache-size = <4096>;
            lookahead-size = <256>;
            block-cycles = <512>;
            automount;
        };
    
    };
    
    
    /delete-node/ &mx25r64;
    &spi00 {
        status = "disabled";
    };
    
    /* NOTE: must disable uart20 to use spi20 for nand spi flash */
    &spi20 {
        status = "okay";
        cs-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;
        pinctrl-0 = <&spi20_default>;
        pinctrl-1 = <&spi20_sleep>;
        pinctrl-names = "default", "sleep";
    
        /* see local driver in drivers/flash/spi_nand.c */
        mx35uf4: mx35uf4g24ad@0 {
          compatible = "jedec,spi-nand";
          reg = <0>;
          spi-max-frequency = <8000000>; //8000000
          id = [c2 f5];
          cs-wait-delay = <0>;
          page-size = <4096>;
          flash-size = <536870912>; // 4Gbit
          ecc-bits = <8>;
          status = "okay";
    
            partitions {
                compatible = "fixed-partitions";
                #address-cells = <1>;
                #size-cells = <1>;
    
                littlefs_storage: partition@0 {
                    label = "nand_storage";
                    reg = <0x00000000 0x02000000>; // 0x02000000 for 32MB example
                };
            };
        };
    };
    
    /* rest of overlay removed */

    this does work, however I do see this during compile time:

    -- Found partition manager static configuration : /applications/project/pm_static.yml
    Partition 'littlefs_storage' is not included in the dynamic resolving since it is statically defined.

Related