Zifengshuhe imx6 uboot mtd partition summary (rootfs is ubi file system) imx6 uboot mtd partition summary (rootfs is ubi file system)

Copyright statement: This article is the original article of the blogger and may not be reproduced without the permission of the blogger. https://blog.csdn.net/qq_29729577/article/details/51130209

This article is based on U-Boot 2014.04 version, the burning tool is mfgtool, and the development environment is yocto

 

Foreword:

Special file systems such as JFFS2 and YAFFS2 have some technical bottlenecks, such as high memory consumption, linear dependence on FLASH capacity, file system size, content, access mode, etc., poor balance of profit and loss, or transitional gains and losses. In this context, the kernel has added support for the UBI file system

Like JFFS2, UBIFS is built on MTD devices and is only suitable for bare flash devices, not eMMC, SD and other devices

UBI is a logical volume management layer similar to LVM. Mainly realize profit and loss balance, logical erase block, volume management, bad block management, etc. And UBIFS is a FLASH log file system based on UBI

1. Kernel configuration

Select in make menuconfig:

Device Drivers  ---> Memory Technology Device (MTD) support  ---> Command line partition table parsing

Device Drivers → Memory Technology Device (MTD) support →Enable UBI - Unsorted block images

File systems → Miscellaneous filesystems→UBIFS file system support

I pass the MTD partition information to the MTD layer through the kernel command line of uboot. There is no need to configure the MTD partition in the kernel, just modify the uboot source code and environment variable parameters, but ensure that the partition information and environment variable partition information in the source code Unanimous

 

2. uboot source code modification

In the uboot source code directory, find the include/conifgs/mx6<custom>.h file (mx6<custom>.h is the header file of the custom board-level file):

#define CONFIG_MFG_NAND_PARTITION 

修改为"mtdparts=gpmi-nand:8m(boot),2m(env),8m(kernel),1m(dtb),-(rootfs)"

Among them, gpmi-nand is mtd-id, which should be consistent with the mtd-id of the platform flash. The following is my partition, for reference only

 

My mx6<custom>.h file also contains the include/configs/mx6sabre_common.h file, which I found:

#define CONFIG_EXTRA_ENV_SETTINGS

Modify it as follows:

#define CONFIG_EXTRA_ENV_SETTINGS \
    CONFIG_MFG_ENV_SETTINGS \
    "fdt_addr=0x18000000\0" \
    "fdt_high=0xffffffff\0"      \
    "bootargs=console=" CONFIG_CONSOLE_DEV ",115200 ubi.mtd=4 "  \
        "root=ubi0:rootfs rootfstype=ubifs "             \
        "mtdparts=gpmi-nand:8m(boot),2m(env),8m(kernel),1m(dtb),-(rootfs) "\
        CONFIG_SYS_VIDEO "\0" \
    "bootcmd=nand read ${loadaddr} 0xA00000 0x800000;"\
        "nand read ${fdt_addr} 0x1200000 0x100000;"\
        "bootz ${loadaddr} - ${fdt_addr}\0"

 

Mainly configure bootargs:

Since mtd0~4 are boot, env, kernel, dtb and rootfs in sequence, ubi.mtd=4 (this is the mtd partition number of rootfs);

root=ubi0: In rootfs, rootfs is the partition name of the ubi0 partition, and the ubi partition will be named later, and the two should be the same;

The rootfstype file system type is ubifs;

mtdparts should be consistent with CONFIG_MFG_NAND_PARTITION

 

3. Modification of mfgtool programming tool

mfgtool mainly modifies the cfg.ini configuration file and uxl2.xml file. For specific syntax, please refer to official documents

 

The cfg.ini file is as follows:

[profiles]
chip = Linux

[platform]
board = SabreSD

[LIST]
name = Custom-NAND

[variable]
board = Custom
part_uboot = 0
part_kernel = 1
part_dtb = 2
part_rootfs = 3

Among them, Custom is the name of the target board defined by yourself, and part_* is the partition number of each mtd

 

The uxl2.xml file should give the demo written by Nand, and you only need to modify it based on it:

Change LIST name to Custom-NAND

The BootStrap part will not go into details;

The uboot and kernel programming part continues to use the demo, only need to modify the programming file name and the mtd partition name, and it is also omitted. .

Focus on analyzing the ubi partition and burning of rootfs:

   <CMD state="Updater" type="push" body="$ flash_erase /dev/mtd%part_rootfs% 0 0">Erasing rootfs partition</CMD>
    <CMD state="Updater" type="push" body="$ ubiformat /dev/mtd%part_rootfs%"/>
    <CMD state="Updater" type="push" body="$ ubiattach /dev/ubi_ctrl -m %part_rootfs%">Attaching UBI partition</CMD>
    <CMD state="Updater" type="push" body="$ ubimkvol /dev/ubi0 -Nrootfs -m"/>
    <CMD state="Updater" type="push" body="$ mkdir -p /mnt/mtd%part_rootfs%"/>
    <CMD state="Updater" type="push" body="$ mount -t ubifs ubi0:rootfs /mnt/mtd%part_rootfs%"/>
    <CMD state="Updater" type="push" body="pipe tar -jxv -C /mnt/mtd%part_rootfs%" file="files/Custom-imx6q.rootfs.tar.bz2">Sending and writting rootfs</CMD>
    <CMD state="Updater" type="push" body="frf">Finishing rootfs write</CMD>
    <CMD state="Updater" type="push" body="$ umount /mnt/mtd%part_rootfs%">Unmounting rootfs partition</CMD>

    <CMD state="Updater" type="push" body="$ echo Update Complete!">Done</CMD>

The above is the partitioning and burning of rootfs, the following explains the use of ubi tools:

ubiformat /dev/mtdN is to format the mtd partition

Ubiattach is to attach the specified mtd partition, add the partition number after -m, which will generate the device file of /dev/ubi0, if you attach again, /dev/ubi1, /dev/ubi2, etc. will be generated in sequence . . .

ubimkvol is to perform ubi partition on the designated /dev/ubiN, that is, make volume, after -N is the partition name, here is designated as rootfs, which should be consistent with the ubi0:rootfs specified in the above bootargs, and -m is the designated size Is max (the size of all ubiN partitions), you can also use -s 500MiB to specify the size you need (the unit is MiB or KiB). If the space is enough, you can make multiple volume partitions on ubiN. You only need to follow The partition name can be mounted

mount -t ubifs ubi0:rootfs /mnt/... is to mount the ubi partition according to the ubi partition name

 

Summary of ubi partition:

In the ubiN partition, N corresponds to a certain mtd partition and needs to be attached to dynamically generate it under /dev. On the basis of this mtd partition, you can also use ubimkvol to perform multiple ubi volume partitions according to the partition name. When accessing, follow ubiN: The format of the name can be mounted

 

note:

After ubi partition on the mtd partition, use the ubinfo /dev/ubiN command to find that the actual ubi partition size will be smaller than that of the mtd partition. This is because the storage management of ubi maps its logical erase block (LEB) to the physical Erase block (PEB), in this process need to use a part of storage space for management, so the actual storage space we use will be smaller than the size of mtd.

In addition, if the mtd partition is too small, there may not be enough space for ubi partition. After I tried, 40M mtd space can provide about 17M ubi partition, but 20M mtd space cannot be ubi partition (ubinfo view will prompt no Available logical erase block)

Guess you like

Origin blog.csdn.net/daocaokafei/article/details/114873286