AM1808u-boot支持ubifs

u-boot版本:2010-12

kernel:2.6.32

nandflash:128MB K9F1G08U0D

已经对ubifs有很好的支持,支持ubi之前需要支持mtd,具体信息可参看u-boot目录下README

这是默认格式化rootfs为ubi分区

U-Boot > ubi part rootfs
Creating 1 MTD partitions on "nand0":
0x000000500000-0x000004500000 : "mtd=2"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size:   131072 bytes (128 KiB)
UBI: logical eraseblock size:    129024 bytes
UBI: smallest flash I/O unit:    2048
UBI: sub-page size:              512
UBI: VID header offset:          512 (aligned 512)
UBI: data offset:                2048
UBI: empty MTD device detected
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd1 to ubi0
UBI: MTD device name:            "mtd=2"
UBI: MTD device size:            64 MiB
UBI: number of good PEBs:        512
UBI: number of bad PEBs:         0
UBI: max. allowed volumes:       128
UBI: wear-leveling threshold:    4096
UBI: number of internal volumes: 1
UBI: number of user volumes:     0
UBI: available PEBs:             503
UBI: total number of reserved PEBs: 9
UBI: number of PEBs reserved for bad PEB handling: 5
UBI: max/mean erase counter: 1/0
红色部分是比较重要的部分,启动后出现

Creating 4 MTD partitions on "davinci_nand.1":
0x000000000000-0x000000200000 : "u-boot"
0x000000200000-0x000000500000 : "kernel"
0x000000500000-0x000004500000 : "rootfs"
0x000004500000-0x000008000000 : "nvram"
davinci_nand davinci_nand.1: controller rev. 2.5
UBI: attaching mtd2 to ubi0
UBI: physical eraseblock size:   131072 bytes (128 KiB)
UBI: logical eraseblock size:    126976 bytes
UBI: smallest flash I/O unit:    2048
UBI: VID header offset:          2048 (aligned 2048)
UBI: data offset:                4096
UBI error: validate_ec_hdr: bad VID header offset 512, expected 2048
UBI error: validate_ec_hdr: bad EC header
UBI error: ubi_io_read_ec_hdr: validation failed for PEB 0
UBI error: ubi_init: cannot attach mtd2
UBI error: ubi_init: UBI error: cannot initialize UBI, error -22
PPP generic driver version 2.4.2

在格式化分区时需要显示制定VID的偏移
U-Boot > ubi part rootfs 2048
UBI: mtd1 is detached from ubi0
Creating 1 MTD partitions on "nand0":
0x000000500000-0x000004500000 : "mtd=2"
UBI: attaching mtd1 to ubi0
UBI: physical eraseblock size:   131072 bytes (128 KiB)
UBI: logical eraseblock size:    126976 bytes
UBI: smallest flash I/O unit:    2048
UBI: sub-page size:              512
UBI: VID header offset:          2048 (aligned 2048)
UBI: data offset:                4096
UBI: empty MTD device detected
UBI: create volume table (copy #1)
UBI: create volume table (copy #2)
UBI: attached mtd1 to ubi0
UBI: MTD device name:            "mtd=2"
UBI: MTD device size:            64 MiB
UBI: number of good PEBs:        512
UBI: number of bad PEBs:         0
UBI: max. allowed volumes:       128
UBI: wear-leveling threshold:    4096
UBI: number of internal volumes: 1
UBI: number of user volumes:     0
UBI: available PEBs:             503
UBI: total number of reserved PEBs: 9
UBI: number of PEBs reserved for bad PEB handling: 5
UBI: max/mean erase counter: 1/0
制作命令:

 mkfs.ubifs -m 2048 -e 126976 -c 500  -r target/ -o rootfs.ubi
检验烧写进u-boot是否能挂载成功:
U-Boot > ubifsmount rootfs
UBIFS: mounted UBI device 0, volume 0, name "rootfs"
UBIFS: mounted read-only
UBIFS: file system size:   62218240 bytes (60760 KiB, 59 MiB, 490 LEBs)
UBIFS: journal size:       8253440 bytes (8060 KiB, 7 MiB, 65 LEBs)
UBIFS: media format:       w4/r0 (latest is w4/r0)
UBIFS: default compressor: LZO
UBIFS: reserved for root:  0 bytes (0 KiB)

再使用ubinize加卷信息后不能挂载

ubinize -o ubifs.img -m 2048 -p 128KiB -s 2048 ubifs.cfg

信息1:
U-Boot > ubifsmount rootfs
UBIFS error (pid 0): ubifs_read_node: bad node type (0 but expected 6)
UBIFS error (pid 0): ubifs_read_node: bad node at LEB 0:0
Error reading superblock on volume 'ubi:rootfs'!

ubinize -o ubifs.img -m 2048 -p 128KiB -s 512 -O 2048 ubifs.cfg 

信息2:
U-Boot > ubifsmount rootfs
UBIFS error (pid 0): ubifs_read_node: bad node type (0 but expected 6)
UBIFS error (pid 0): ubifs_read_node: bad node at LEB 0:0
Error reading superblock on volume 'ubi:rootfs'!
未解决,只使用mkfs.ubifs,不添加卷信息


常见问题汇总:

1.检查VID,PEB,逻辑擦除块大小是否正确

即-m -p -s -e -c 这几个参数。

2。检查u-boot传递参数

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

以下收集于网络关于ubi常见的错误:

(1)u-boot启动后提示“*** Warning - bad CRC or NAND, using default environment”

这一般不是大问题,不理它也没事。它是提醒你在falsh中读不到环境变量,只能使用软件中定义的默认环境变量。如果要解决,只要在u-boot中输入saveenv就行了,下次启动应该不会再出现了,如果还出现,可能是你的nand驱动有问题,也可能是坏块。

u-boot默认使用flash中的环境变量,如果软件中修改了环境变量,最好saveenv一次。

(2)u-boot的12号错误。

这是我加入ubi支持后出现的错误。

UBI error: ubi_init: UBI error: cannot initialize UBI, error -12
 UBI init error -12
查  阅include/asm-generic/error.h发现12号错误的定义为“#define ENOMEM  12 /* Out of  memory */”。经过追踪,是在driver/mtd/ubi/build.c的ubi_attach_mtd_dev函数中第二次  vmalloc时死掉,因此修改smartarm3250.h(我的配置文件)中CONFIG_SYS_MALLOC_LEN,增大到  1M(1024*1024)。问题解决。

(3)u-boot的5号错误。

 UBI error: ubi_io_write: error -5 while writing 512 bytes to PEB 0:512, written 0 bytes
查阅include/asm-generic/error.h发现5号错误的定义为“#define EIO  5 /* I/O error */”。
http://www.linux-mtd.infradead.org/faq/ubi.html#L_subpage_verify_fail有对这个问题的专门描述:
I get "ubi_io_write: error -5 while writing 512 bytes to PEB 5:512"
If  you have a 2048 bytes per NAND page device, and have  CONFIG_MTD_NAND_VERIFY_WRITE enabled in your kernel, you will need to  turn it off. The code does not currently (as of 2.6.26) perform  verification of sub-page writes correctly. As UBI is one of the few  users of sub-page writes, not much else seems to be affected by this  bug.
虽然是说Linux内核配置,可是u-boot中同样有CONFIG_MTD_NAND_VERIFY_WRITE  ,在smartarm3250.h中将这个宏注释掉,问题解决。看来是内核的问题,既然u-boot很大程度上使用了Linux内核的驱动,应该是ubi  驱动的问题。

(4)Cannot start volume update。

在common/cmd_ubi.c中的ubi_volume_write函数中找到打印这句话的地方,打印err发现仍然为12号错误。解决办法在上面第2条。

(5)启动时内核打印出ubi的19号错误(NO SUCH DEVICE)。

也就是内核找不到某个分区,一般应该是u-boot中定义的CONFIG_BOOTARGS不对。

我的正确定义是

#define CONFIG_BOOTARGS "ubi.mtd=4 root=ubi0:rootfs  console=ttyS0,115200 mem=64M rootfstype=ubifs rw"
原来的错误写法是#define CONFIG_BOOTARGS "ubi.mtd=6 root=ubi0:rootfs   console=ttyS0,115200 mem=64M rootfstype=ubifs rw"。其实原因在于u-boot对nand  falsh的分区方式和你所用的Linux内核不一致 。

我的u-boot定义的分区如下:

#if 1
#define MTDIDS_DEFAULT "nand0=nandflash0"
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:"1536k(bootloder)"\
      "512k(params)"\
      "4m(kernel)"\
      "16m(safefs)"\
      "-(root)"
#endif //end of yll 

(6)linux内核启动时输出以下信息,并停住:
UBIFS error (pid 1): ubifs_read_node: bad node type (0 but expected 6)
UBIFS error (pid 1): ubifs_read_node: bad node at LEB 0:0
List of all partitions:
1f00       1536 mtdblock0 (driver?)
1f01        256 mtdblock1 (driver?)
1f02       4096 mtdblock2 (driver?)
1f03      16384 mtdblock3 (driver?)
1f04     239616 mtdblock4 (driver?)
No filesystem could mount root, tried:  ubifs
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

这个问题是由于写入命令错误引起的,原来的写入命令为ubi write 0x01600000 rootfs $(filesize),应该为ubi write 0x080008000 rootfs $(filesize)。
也就是说原来根本没有把文件系统写入flash。
如果你也有此类错误,要么是你的文件系统镜像没有写入(或者没正确写入),要么是你做的文件系统镜像有问题。其他问题可能不大。

(7)软件版本问题。

linux内核启动过程中出现以下信息并停住:

UBIFS error (pid 1): ubifs_check_node: bad CRC: calculated 0x9f186f96, read 0x3baee010
UBIFS error (pid 1): ubifs_check_node: bad node at LEB 0:0
UBIFS error (pid 1): ubifs_read_node: expected node type 6
VFS: Cannot open root device "ubi0:rootfs" or unknown-block(0,0)
Please append a correct "root=" boot option; here are the available partitions:
1f00       1536 mtdblock0 (driver?)
1f01        256 mtdblock1 (driver?)
1f02       4096 mtdblock2 (driver?)
1f03      16384 mtdblock3 (driver?)
1f04     239616 mtdblock4 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
我的文件系统镜像使用mtd-utils2010做的,我后来改为mtd-utils2009,问题解决。

我的内核版本是2.6.27.8。我猜测因为我的内核版本比较旧,所以内核和mtd-utils2010中的crc算法有差异才会出现bad CRC。

如果你也碰到类似问题,请确保内核版本和mtd-utils版本匹配。看是否匹配只要看内核和mtd-utils是不是一年出的就行,或者时间接近。总之,两个出现时间较远的软件协同工作会有可能出错。

mtd-utils下载地址 http://ftp.debian.org/pool/main/m/mtd-utils/  (下载orig.tar.gz结尾的包)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值