牛卧堂MCU技术交流

标题: [NUC980] Running UBIFS rootfs on SPI NOR Flash [打印本页]

作者: admin    时间: 4 天前
标题: [NUC980] Running UBIFS rootfs on SPI NOR Flash

NUC980 Chili Board + Linux 5.10 + Buildroot 2024

This article documents a working setup to use UBIFS as the root filesystem on SPI NOR flash (Winbond W25Q256, 32 MB) on the NUC980 Chili board.



1. Preparation

Strongly recommended: clone a fresh Buildroot repository to avoid residual kernel / rootfs artifacts inflating the image.

$ git clone https://github.com/OpenNuvoton/buildroot_2024
$ cd buildroot_2024
$ make nuvoton_nuc980_chili_defconfig



2. Buildroot Configuration (RootFS = UBIFS)

Enter Buildroot menuconfig:

$ make menuconfig

2.1 Remove RAM filesystem (initramfs)

Disable initramfs completely:

Filesystem images  --->
    [ ] initial RAM filesystem linked into linux kernel
    [ ] cpio the root filesystem (for use as an initial RAM filesystem)

2.2 Enable UBIFS image

Enable UBIFS as the root filesystem:

Filesystem images  --->
   

  • ubi image containing an ubifs root filesystem

    2.3 UBIFS parameters for W25Q256 (SPI NOR, 32 MB)

    Configure UBIFS with parameters matching the SPI NOR erase geometry:

    Parameter

    Value

    Notes


    Physical eraseblock size

    0x10000

    64 KB erase sector (W25Q256)


    Sub-page size

    1

    SPI NOR has no sub-page


    Logical eraseblock size

    0xFF80

    64 KB - UBI headers


    Minimum I/O unit size

    0x1

    Byte-addressable


    Maximum logical eraseblock count

    384

    ~24 MB rootfs partition


    Additional mkfs.ubifs options

    -F

    Force creation on NOR


    These settings are critical. If they don’t match the flash erase size, UBIFS will fail at mount time.


    3. Linux Kernel Configuration (5.10)

    $ make linux-menuconfig

    3.1 Remove initramfs support

    General setup  --->
        [ ] Boot config support
        [ ] Initial RAM filesystem and RAM disk (initramfs/initrd) support

    Kernel must not expect an initramfs since rootfs lives on SPI NOR.

    3.2 Enable MTD / UBI / SPI NOR

    Device Drivers  --->
        Memory Technology Device (MTD) support  --->
            

  • Partition parsers  --->
                <*> Command line partition table parsing
            
  • Enable UBI - Unsorted block images  --->
                
  • UBI Fastmap (experimental feature)
            SPI NOR device support  --->
                [ ] Use small 4096 B erase sectors

    Key points:


    4. Device Tree: SPI NOR Partition Layout

    Edit the buildroot_2024/output/build/linux-custom/arch/arm/boot/dts/nuc980-chili.dts to define SPI NOR partitions in the DTS.

    qspi0: spi@b0060000 {
        status = "okay";

        flash: flash@0 {
            compatible = "jedec,spi-nor";
            #address-cells = <1>;
            #size-cells = <1>;
            reg = <0>;
            spi-max-frequency = <30000000>;

            partition@0 {
                label = "uboot";
                reg = <0x00000000 0x00100000>;
            };
            partition@1 {
                label = "kernel";
                reg = <0x00200000 0x00600000>;
            };
            partition@2 {
                label = "rootfs";
                reg = <0x00800000 0x01800000>;
            };
        };
    };


    5. U-Boot Environment (env.txt)

    Create a env.txt file with the following contents:

    baudrate=115200
    bootdelay=1
    stderr=serial
    stdin=serial
    stdout=serial
    setspi=sf probe 0 30000000
    loadkernel=sf read 0x7fc0 0x200000 0x600000
    loaddtb=sf read 0x1800000 0xA0000 0x10000
    bootcmd=run setspi;run loadkernel;run loaddtb;bootm 0x7fc0 - 0x1800000
    bootargs=noinitrd ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs rw console=ttyS0 rdinit=/sbin/init mem=64M

    Notes


    6. Build and Flash Images

    Build everything:

    $ make

    After build completes, flash the following images to SPI NOR:

    File

    Type

    Exec Addr/Offset


    uboot.bin

    Loader

    0xE00000


    env.txt

    Environment

    0x80000


    nuc980-chili.dtb

    Data

    0xA0000


    uImage

    Data

    0x200000


    rootfs.ubi

    Data

    0x800000



    7. Result

    If everything is configured correctly:








    欢迎光临 牛卧堂MCU技术交流 (http://nuvoton-mcu.com/) Powered by Discuz! X3.2