您的位置:首页 > 其它

uboot支持ubi和ubifs遇到的问题

2017-01-20 18:08 337 查看
uboot version 2012.10

nand type:Micron MT29F16G08CBACA

一、执行ubi part kernel时报错-12
Creating 1 MTD partitions on "nand0":
0x000004200000-0x00001e200000 : "mtd=3"
UBI: attaching mtd1 to ubi0
UBI warning: io_init: EC and VID headers are in thesame minimal I/O unit, switch to read-only mode
UBI: physical eraseblock size: 1048576 bytes (1024KiB)
UBI: logical eraseblock size: 1044480 bytes
UBI: smallest flash I/O unit: 4096
UBI: VID header offset: 2048 (aligned 0)
UBI: data offset: 4096
UBI error: ubi_init: cannot attach mtd1
UBIerror: ubi_init: UBI error: cannot initialize UBI, error -12
UBI init error 12
Error, no UBI device/partition selected!
 
网上一般都是说将CONFIG_SYS_MALLOC_LEN,增大到1M(1024*1024)。但我修改后同样报错
找到源码中报错的地方(/drivers/mtd/ubi/build.cubi_attach_mtd_dev函数)
err = -ENOMEM;
ubi->peb_buf1 = vmalloc(ubi->peb_size);
if (!ubi->peb_buf1)
goto out_free;
 
ubi->peb_buf2 = vmalloc(ubi->peb_size);
if (!ubi->peb_buf2)
goto out_free;
malloc大小为ubi->peb_size,经过查找最终是在(/driver/mtd/nand/nand_base.cnand_get_flash_type函数)
/* Calc blocksize */
mtd->erasesize = (128 * 1024) <<
(((extid >> 1) & 0x04) | (extid &0x03));
实际该值就是物理擦出块大小,通过芯片ID获取芯片类型,查看手册

该值为1024KB,那么问题就来了,CONFIG_SYS_MALLOC_LEN设置成1M,现在一次malloc的大小也是1M,连续两次malloc就会报错了,所以当nand芯片的块大小大于等于1M时,CONFIG_SYS_MALLOC_LEN就应该相应增大,我设置成4M了

二、执行ubi part kernel时报错
Creating 1 MTD partitions on "nand0":
0x000004200000-0x00001e200000 : "mtd=3"
UBI: attaching mtd1 to ubi0
UBI warning: io_init: EC and VID headers are in the same minimal I/O unit, switch to read-only mode
UBI: physical eraseblock size: 1048576 bytes (1024 KiB)
UBI: logical eraseblock size: 1044480 bytes
UBI: smallest flash I/O unit: 4096
UBI: VID header offset: 2048 (aligned 0)
UBI: data offset: 4096
UBI: empty MTD device detected
UBI: create volume table (copy #1)
UBI error: ubi_io_sync_erase: read-only mode
UBI error: ubi_io_sync_erase: read-only mode
UBI error: ubi_io_sync_erase: read-only mode
UBI error: ubi_io_sync_erase: read-only mode
可以看到创建卷时提示ubi处于只读模式,同时注意到一个warning,找到源码位置(/drivers/mtd/ubi/build.c io_init函数)
/*
* It may happen that EC and VID headers are situated in one minimal
* I/O unit. In this case we can only accept this UBI image in
* read-only mode.
*/
if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) {
ubi_warn("EC and VID headers are in the same minimal I/O unit, "
"switch to read-only mode");
ubi->ro_mode = 1;
}
经过打印
UBI_VID_HDR_SIZE = 64
ubi->vid_hdr_offset = 2048
ubi->hdrs_min_io_size = 4096
确实有问题,从nand手册上来看,最小的页为4k,所以hdrs_min_io_size应该没问题
而vid_hdr_offset就有点奇怪,最后找到这个值是由ubi part传进来的参数
修正命令
ubi part kernel -->ubi part kernel 4096

三、执行 ubifsmount kernel报错-19
UBIFS error (pid 0): ubifs_get_sb: cannot open"ubi:kernel1", error -19
UBIFS error (pid 0): ubifs_mount: Error readingsuperblock on volume 'ubi:kernel1' errno=-19!
这应该是制作kernel镜像时mkfs.ubifs参数的问题了(都是跟nand相关的参数)
再次介绍mkfs.ubifs的用法 
Usage: mkfs.ubifs [OPTIONS] target 
Make a UBIFS file system image from an existingdirectory tree 
Examples: 
Build file system from directory /opt/img, writtingthe result in the ubifs.img file 
        mkfs.ubifs-m 512 -e 128KiB -c 100 -r /opt/img ubifs.img 
The same, but writting directly to an UBI volume 
        mkfs.ubifs-r /opt/img /dev/ubi0_0 
Creating an empty UBIFS filesystem on an UBIvolume 
        mkfs.ubifs/dev/ubi0_0 
Options: 
-r, -d, --root=DIR              buildfile 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    maximumlogical erase block count最大逻辑可擦出块数目 
-o, --output=FILE       output to FILE输出文件名 
-j, --jrn-size=SIZE     journal size 
-R, --reserved=SIZE      howmuch 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 compressionand defines 
                                howmany percent better zlib should compress to make 
                                mkfs.ubifsuse zlib instead of LZO (default 20%) 
-f, --fanout=NUM         fanout NUM (default:8) 
-F, --space-fixup        file-system free space has tobe fixed up on first moun
                          (requireskernel version 3.0 or greater) 
-k, --keyhash=TYPE      key hash type - "r5" or"test" (default: "r5") 
-p, --orph-lebs=COUNT     count oferase blocks for orphans (default: 1) 
-D, --devtable=FILE       usedevice table FILE 
-U, --squash-uids        squash owners making all filesowned by root 
-l, --log-lebs=COUNT     count oferase blocks for the log (used only for debugging) 
-v, --verbose            verboseoperation 
-V, --version            displayversion information 
-g, --debug=LEVEL        display debug information (0 -none, 1 - statistics, 2 - files, 3 - more details) 
-h, --help              displaythis help text 
 
例: 
mkfs.ubifs -x lzo -m 2KiB -e 124KiB -c 720 -osystem_ubifs.img -d $path_to_system 
压缩格式为lzo 
-m最小输入输出大小为2KiB(2048bytes),一般为页大小 
-e逻辑可擦除块大小为124KiB=(每块的页数-2)*页大小=(64-2)*2KiB=124KiB 
-c最多逻辑可擦除块数目为720(720*128KiB=90MiB),这个可根据ubi volume来设置,实际上是设置此卷的最大容量。 
按照例子,
-m参数应该是4096
-e参数应该是blocksize-2*pagesize=1M-2*4k=1040384(一般这2个page是用来存放ubi相关数据的,所以不能擦除)
-c参数应该是存放这个文件的分区大小有多少个块,我分了kernel分区为32M,那么这个值就是32M/1M= 32
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: