原文地址:http://blog.csdn.net/yuanlulu/archive/2010/08/31/5853676.aspx
最近需要讓u-boot支援ubi,方便下載ubi根檔案系統。
由於參照網上的文章http://blog.chinaunix.net/u3/96428/showart_2275685.html做還是有一些錯誤,所以總結一下自己的移植。
軟體版本:
Linux核心:2.6.27.8
u-boot:201006
LZO:LZO-2.03
zlib:zlib-1.2.5
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)增加以下宏定義:
#if 1
#define MTDIDS_DEFAULT "nand0=nandflash0"
//定義預設的分區,這個分區盡量和你所使用的linux核心的分區一致,並且不要跳過任何不用的地區(比如我的params分區實際只有256k,它後面是256k保留的地區,由於後面分區的位移是根據前面分區的大小推算的,因此我把保留分區合并到params)。我的分區有五個,編號從0~4。
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:"1536k(bootloder)"/
"512k(params)"/
"4m(kernel)"/
"16m(safefs)"/
"-(root)"
#endif //end of yll
#if 1 //yll:UBI support
#define CONFIG_MTD_DEVICE 1
#define CONFIG_MTD_PARTITIONS 1
#define CONFIG_CMD_MTDPARTS
#define CONFIG_CMD_UBIFS
#define CONFIG_CMD_UBI
#define CONFIG_LZO 1
#define CONFIG_RBTREE 1
#endif//end of yll
(2)修改傳給Linux核心的參數
#define CONFIG_BOOTARGS "ubi.mtd=4 root=ubi0:rootfs console=ttyS0,115200 mem=64M rootfstype=ubifs rw"
ubi在最後一個分區(第四個分區)上,根檔案系統的類型是ubifs。
(3)修改malloc空間上限
#define CONFIG_SYS_MALLOC_LEN (1024 * 1024)
事實證明,CONFIG_SYS_MALLOC_LEN 的大小至少要有1M(1024*1024),否則u-boot會報告12號錯誤。
順便說一下,u-boot的錯誤號碼定義在include/asm-generic/error.h,其中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中。
下面還需要修改核心配置。