且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OK335xS 256M 512M nand flash make ubifs hacking

更新时间:2022-08-12 21:11:31

/*********************************************************************************
 *              OK335xs 256M 512M nand flash make ubifs hacking
 * 声明:
 *     本文主要是记录分析如何生成ubifs文件系统。
 *
 *                                         2015-11-14 晴 深圳 南山平山村 曾剑锋
 ********************************************************************************/

                        \\\\\\\\\\\-*- 目录 -*-///////////
                        |   一、for 256M nand flash
                        |   二、for 512M nand flash
                        |   三、mkfs.ubifs Options:
                        |   四、ubinize Options:
                        |   五、分析示例:
                        ---------------------------------


一、for 256M nand flash
    ./mkfs.ubifs –F -q -r rootfs -m 2048 -e 126976 -c 2047 -o  ubifs.img
    ./ubinize -o ubi.img -m 2048 -p 128KiB ubinize.cfg

二、for 512M nand flash
    ./mkfs.ubifs –F -q -r rootfs_v2 -m 2048 -e 126976 -c 4040 -o  ubifs.img
    ./ubinize -o ubi.img -m 2048 -p 128KiB ubinize.cfg

三、mkfs.ubifs Options:
    -r, -d, --root=DIR       build file system from directory DIR
    -m, --min-io-size=SIZE   minimum I/O unit size
    -e, --leb-size=SIZE      logical erase block size
    -c, --max-leb-cnt=COUNT  maximum logical erase block count
    -o, --output=FILE        output to FILE
    -j, --jrn-size=SIZE      journal size
    -R, --reserved=SIZE      how much space should be reserved for the super-user
    -x, --compr=TYPE         compression type - "lzo", "favor_lzo", "zlib" or
                             "none" (default: "lzo")
    -X, --favor-percent      may only be used with favor LZO compression and defines
                             how many percent better zlib should compress to make
                             mkfs.ubifs use zlib instead of LZO (default 20%)
    -f, --fanout=NUM         fanout NUM (default: 8)
    -F, --space-fixup        file-system free space has to be fixed up on first mount
                             (requires kernel version 3.0 or greater)
    -k, --keyhash=TYPE       key hash type - "r5" or "test" (default: "r5")
    -p, --orph-lebs=COUNT    count of erase blocks for orphans (default: 1)
    -D, --devtable=FILE      use device table FILE
    -U, --squash-uids        squash owners making all files owned by root
    -l, --log-lebs=COUNT     count of erase blocks for the log (used only for
                             debugging)
    -v, --verbose            verbose operation
    -V, --version            display version information
    -g, --debug=LEVEL        display debug information (0 - none, 1 - statistics,
                             2 - files, 3 - more details)
    -h, --help               display this help text

四、ubinize Options:
    Example: ubinize -o ubi.img -p 16KiB -m 512 -s 256 cfg.ini - create UBI image
             'ubi.img' as described by configuration file 'cfg.ini'
    -o, --output=<file name>     output file name
    -p, --peb-size=<bytes>       size of the physical eraseblock of the flash
                                 this UBI image is created for in bytes,
                                 kilobytes (KiB), or megabytes (MiB)
                                 (mandatory parameter)
    -m, --min-io-size=<bytes>    minimum input/output unit size of the flash
                                 in bytes
    -s, --sub-page-size=<bytes>  minimum input/output unit used for UBI
                                 headers, e.g. sub-page size in case of NAND
                                 flash (equivalent to the minimum input/output
                                 unit size by default)
    -O, --vid-hdr-offset=<num>   offset if the VID header from start of the
                                 physical eraseblock (default is the next
                                 minimum I/O unit or sub-page after the EC
                                 header)
    -e, --erase-counter=<num>    the erase counter value to put to EC headers
                                 (default is 0)
    -x, --ubi-ver=<num>          UBI version number to put to EC headers
                                 (default is 1)
    -Q, --image-seq=<num>        32-bit UBI image sequence number to use
                                 (by default a random number is picked)
    -v, --verbose                be verbose
    -h, --help                   print help message
    -V, --version                print program version

五、分析示例:
    1. for 256M nand flash:
        1. ./mkfs.ubifs –F -q -r rootfs -m 2048 -e 126976 -c 2047 -o  ubifs.img
            -F:file-system free space has to be fixed up on first mount
            -q:未知
            -r:build file system from directory DIR
            -m:最小输入输出大小为2KiB(2048bytes),一般为页大小
            -e:逻辑可擦除块大小为124KiB=(每块的页数-2)*页大小=(64-2)*2KiB=124KiB=126976bytes
            -c:最多逻辑可擦除块数目为2047(2047*128KiB=255.8MiB),这个可根据ubi volume来设置,实际上是设置此卷的最大容量。
            -o:output to FILE
        2. for 256M nand flash ubinize.cfg:
            [ubifs]
            mode=ubi
            image=ubifs.img         // mkfs.ubi生成的源镜像 
            vol_id=0                // 卷序号 
            vol_size=231MiB         // 卷大小
            vol_type=dynamic        // 动态卷
            vol_name=rootfs         // 卷名 
            vol_flags=autoresize
        3. ./ubinize -o ubi.img -m 2048 -p 128KiB ubinize.cfg
            -o:输出文件名
            -m:最小输入输出大小为2KiB(2048bytes),一般为页大小 
            -p:物理可擦出块大小为128KiB=每块的页数*页大小=64*2KiB=128KiB 
            -s:用于UBI头部信息的最小输入输出单元,一般与最小输入输出单元(-m参数)大小一样。
        
    2. for 512M nand flash:
        1. ./mkfs.ubifs –F -q -r rootfs_v2 -m 2048 -e 126976 -c 4040 -o  ubifs.img
            -F:file-system free space has to be fixed up on first mount
            -q:未知
            -r:build file system from directory DIR
            -m:最小输入输出大小为2KiB(2048bytes),一般为页大小
            -e:逻辑可擦除块大小为124KiB=(每块的页数-2)*页大小=(64-2)*2KiB=124KiB=126976bytes
            -c:最多逻辑可擦除块数目为2047(2047*128KiB=505MiB),这个可根据ubi volume来设置,实际上是设置此卷的最大容量。
        2. for 512M nand flash ubinize.cfg:
            [ubifs]
            mode=ubi
            image=ubifs.img         // mkfs.ubi生成的源镜像 
            vol_id=0                // 卷序号 
            // 卷大小(当然,个人感觉这里是错误的,在另外一份文件里面看到是492MiB,尚未验证)
            vol_size=231MiB         
            vol_type=dynamic        // 动态卷
            vol_name=rootfs         // 卷名 
            vol_flags=autoresize
        3. ./ubinize -o ubi.img -m 2048 -p 128KiB ubinize.cfg
            -o:输出文件名
            -m:最小输入输出大小为2KiB(2048bytes),一般为页大小 
            -p:物理可擦出块大小为128KiB=每块的页数*页大小=64*2KiB=128KiB 
            -s:用于UBI头部信息的最小输入输出单元,一般与最小输入输出单元(-m参数)大小一样。