现在的位置: 首页 > 综合 > 正文

增加u-boot对ubi的支持

2013年06月07日 ⁄ 综合 ⁄ 共 3027字 ⁄ 字号 评论关闭

原文地址:

http://blog.csdn.net/yuanlulu/archive/2010/08/31/5853676.aspx

最近需要让u-boot支持ubi,方便下载ubi根文件系统。

由于参照网上的文章http://blog.chinaunix.net/u3/96428/showart_2275685.html做还是有一些错误,所以总结一下自己的移植。

  1. 软件版本:
  2. Linux内核:2.6.27.8
  3. u-boot:201006
  4. LZO:LZO-2.03
  5. zlib:zlib-1.2.5
  6. mtd-utils:mtd-utils-20090606

我使用的是smartarm3250开发板,首先移植开发板提供的u-boot-1.3.3到u-boot-201006。因为旧版本的u-boot不支持ubifs,当然是先移植u-boot了。

然后 cd u-boot-2010.06/
修改 include/configs/smartarm3250.h
(1)增加以下宏定义:

  1. #if 1
  2. #define MTDIDS_DEFAULT "nand0=nandflash0"
  3. //定义默认的分区,这个分区尽量和你所使用的linux内核的分区一致,并且不要跳过任何不用的区域(比如我的params分区实际只有256k,它后面是256k保留的区域,由于后面分区的偏移是根据前面分区的大小推算的,因此我把保留分区合并到params)。我的分区有五个,编号从0~4。
  4. #define MTDPARTS_DEFAULT "mtdparts=nandflash0:"1536k(bootloder)"/
  5. "512k(params)"/
  6. "4m(kernel)"/
  7. "16m(safefs)"/
  8. "-(root)"
  9. #endif //end of yll
  10. #if 1 //yll:UBI support
  11. #define CONFIG_MTD_DEVICE 1
  12. #define CONFIG_MTD_PARTITIONS 1
  13. #define CONFIG_CMD_MTDPARTS
  14. #define CONFIG_CMD_UBIFS
  15. #define CONFIG_CMD_UBI
  16. #define CONFIG_LZO 1
  17. #define CONFIG_RBTREE 1
  18. #endif //end of yll

(2)修改传给Linux内核的参数

  1. #define CONFIG_BOOTARGS "ubi.mtd=4 root=ubi0:rootfs console=ttyS0,115200 mem=64M rootfstype=ubifs rw"
  2. // ubi在最后一个分区(第四个分区)上,根文件系统的类型是ubifs。

(3)修改malloc空间上限

  1. #define CONFIG_SYS_MALLOC_LEN (1024 * 1024)
  2. // 事实证明,CONFIG_SYS_MALLOC_LEN 的大小至少要有1M(1024*1024),否则u-boot会报告12号错误。
  3. // 顺便说一下,u-boot的错误号定义在include/asm-generic/error.h,
  4. // 其中12号错误的定义是“#define ENOMEM 12 /* Out of memory */”,内存不够了嘛。

(4)保证没有定义CONFIG_MTD_NAND_VERIFY_WRITE
如果定义了这个宏,请注释掉,否则会有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驱动的问题。

好了,我对u-boot的修改就这么多,而且所有的修改都在include/configs/smartarm3250.h中。

下面还需要修改内核配置。

抱歉!评论已关闭.