關于uboot的UBI的移植幾乎沒有說明介紹,移植首先要保證你的flash驅動能夠跑起來,我是在nand flash 上跑的UBI。剛開始的時候我也沒有什么頭緒,只能夠從uboot的readme開始查找一些蛛絲馬跡。
- MTD Support (mtdparts command, UBI support)
CONFIG_MTD_DEVICE
Adds the MTD device infrastructure from the Linux kernel.
Needed for mtdparts command support.
CONFIG_MTD_PARTITIONS
Adds the MTD partitioning infrastructure from the Linux
kernel. Needed for UBI support.
因此,要UBI支持首先得要MTD支持,因此在配置文件中要添加以上兩項的定義。
要移植UBI還要添加:
#define CONFIG_CMD_UBIFS
#define CONFIG_CMD_UBI
總的關于UBI的部分是以下幾個宏:
#define CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
#define CONFIG_RBTREE
#define CONFIG_LZO
同時要給NAND建立個默認的分區(qū),方便以后操作。分區(qū)如下:
#define MTDIDS_DEFAULT "nand0=nand0"
#define MTDPARTS_DEFAULT "mtdparts=nand0:0x100000@0x0(u-boot),0x300000@0x120000(kernel),0x7b00000@0x420000(rootfs),-(reserved)"
#define MTD_ACTIVE_PART "nand0,2"
以上的配置都在uboot_imx/include/configs/mx51_vdphone.h文件中進行配置。
需要注意的是增加UBI的支持之后uboot會增大到300多KB,在NAND中啟動,需要修改以下文件uboot-imx\cpu\arm_cortexa8\mx51\mxc_nand_load.S
add r6, r0, #0x1E00
ldr r5, =_end /* Try get right image size */
add r5, r2, #0x00060000 /* Fixme to get actual image size */
這里使用0x60000(384K)大小,已經足夠,如果實際有變化,可以進行相應調節(jié)。如果uboot傳給Copy_Good_Blk 拷貝的uboot的大小小于uboot的長度的話,uboot跑不起來,移植的時候被這個問題必須注意。
這個時候就可以make 了,執(zhí)行以下命令:
make clean
make mx51_vdphone_config
make all
如果正常的話會編譯出u-boot.bin在根目錄下。
通過mtdpart命令配置u-boot下的nand 分區(qū),本項目已經在配置頭文件里面設置了默認nand 分區(qū),
#define MTDPARTS_DEFAULT "mtdparts=nand0:0x100000@0x0(u-boot),0x300000@0x120000(kernel),0x7b00000@0x420000(rootfs),-(reserved)"
如果需要修改,可以通過修改默認分區(qū)列表,也可以通過命令mtdpart進行重新分區(qū)。這里使用默認分區(qū),通過以下命令使默認分區(qū)生效:
mtdpart default //設置默認分區(qū)
saveevn //保存分區(qū)信息
通過以上的配置編譯,如果成功生成u-boot.bin,那就可以通過SD卡啟動,直接燒寫u-boot.bin到nand flash了。操作步驟如下:
1) 下載u-boot.bin 到內存
tftp 0x90800000 /tftpboot/mx51/u-boot.bin
2) 擦除u-boot分區(qū)
nand erase u-boot
3) 燒寫u-boot到nand flash分區(qū)
nand write 0x90800000 u-boot 0x60000
內核的燒寫和平常燒寫方式一樣,只需用nand 命令寫入nand 即可,操作步驟如下:
1) 擦除kernel分區(qū)
nand erase kernel
2) 下載kernel到內存
tftp 0x90800000 /tftpboot/mx51/uImage 將內核通過tftp下載到內存中
3) 燒寫kernel 到nand kernel分區(qū)
nand write 0x90800000 kernel 0x300000
本項目使用的文件系統(tǒng)將根文件系統(tǒng)和system文件系統(tǒng)整合在一起。所以,只需要燒寫整合后的文件系統(tǒng)即可。如果要使用ubifs文件系統(tǒng)作為根文件系統(tǒng),在燒寫之前必須通過mkfs.ubifs工具將做好的文件系統(tǒng)制作鏡像文件。mkfs.ubifs 工具是通過編譯mtd-utils工具下的mkfs.ubifs目錄即可生成的PC端UBIFS文件系統(tǒng)鏡像制作工具。操作步驟如下:
1) 制作根文件系統(tǒng)
mkfs.ubifs -r root/ -m 2048 -e 129024 -c 2364 -o root-fs.img
root目錄為整合android root和system文件系統(tǒng)后的目錄,應當能夠通過NFS系統(tǒng)的
2) 擦除root分區(qū)
nand erase root
3) 激活root 分區(qū)為UBI格式
ubi part root
4) 創(chuàng)建root分區(qū)
ubi create root
5) 將文件系統(tǒng)下載到內存
tftp 0x90800000 root-fs.img
6) 將文件系統(tǒng)燒寫到rootfs 中
ubi write 0x90800000 rootfs 0x339600//0x339600為tftp 下載到的root-fs.img鏡像大小,
設置bootargs:
setenv bootargs ubi.mtd=2 root=ubi0:rootfs rootfstype=ubifs console=ttymxc0,115200 wvga calibration init=/init rw
啟動撥碼開關5,8位置設置為ON,上電重新啟動,即可從Nand flash 啟動。
1.3 android FLASH UBI文件系統(tǒng)的制作和燒寫
將android編譯為UBI文件系統(tǒng)格式,生成的system.img,userdata.img,recover.img就可以直接在u-boot中通過ubi write命令燒寫,前提條件是uboot已經支持或完成ubi和UBIFS的移植工作,并且linux kernel也要支持UBIFS文件系統(tǒng)。
1.3.1 設置mtdpart分區(qū)
1) U-Boot中配置默認分區(qū)參數(shù),路徑如下:
# 板級相關的配置文件include/configs/mx51/xxxx.h
mtdparts:mtdparts=nand0:0x100000@0x0(u-boot),0x300000@0x120000(kernel),0x100000@0x420000(ramdisk),0x4B00000@0x520000(system),0x1E00000@0x5020000(userdata),0xD00000@0x6E20000(cache),-(reserved)
2) 第一次燒寫完boot后,設置mtdpart分區(qū):
BBG U-Boot > mtdparts default # 加載默認分區(qū)配置
BBG U-Boot > save # 保存配置
BBG U-Boot > mtdpart # 查看分區(qū)配置
device nand0 <nand0>, # parts = 7
#: name size offset mask_flags
0: u-boot 0x00100000 0x00000000 0
1: kernel 0x00300000 0x00120000 0
2: ramdisk 0x00100000 0x00420000 0
3: system 0x04b00000 0x00520000 0
4: userdata 0x01e00000 0x05020000 0
5: cache 0x00d00000 0x06e20000 0
6: reserved 0x004e0000 0x07b20000 0
active partition: nand0,0 - (u-boot) 0x00100000 @ 0x00000000
defaults:
mtdids : nand0=nand0
3) 燒寫U-Boot到FLASH
BBG U-Boot > tftp 0x90800000 u-boot.bin # 獲取U-Boot到內存
BBG U-Boot > nand erase u-boot # 格式化u-boot分區(qū)
BBG U-Boot > nand write 0x90800000 u-boot 0x100000 # 燒寫u-boot到對應分區(qū)
4) 燒寫Linux內核到FLASH
BBG U-Boot > tftp 0x90800000 uImage # 獲取內核到內存
BBG U-Boot > nand erase kernel # 格式化內存分區(qū)
BBG U-Boot > nand write 0x90800000 kernel 0x300000 # 燒寫內核到對應分區(qū)
5) 燒寫Ramdisk到FLASH
BBG U-Boot > tftp 0x90800000 uramdisk.img # 獲取uramdisk到內存
BBG U-Boot > nand erase ramdisk # 格式化uramdisk分區(qū)
BBG U-Boot > nand write 0x90800000 ramdisk 0x100000 # 燒寫uramdisk到對應分區(qū)
6) 燒寫System到FLASH
BBG U-Boot > nand erase system # 擦除system分區(qū)
BBG U-Boot > tftp 0x90800000 system.img # 獲取system到內存
BBG U-Boot > ubi part system # 激活system分區(qū)為ubi格式
Creating 1 MTD partitions on "nand0":
0x000097855f98-0x000000520000 : "<NULL>"
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: attached mtd1 to ubi0
UBI: MTD device name: "mtd=3"
UBI: MTD device size: 78643200 MiB
UBI: number of good PEBs: 600
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: 590
UBI: total number of reserved PEBs: 10
UBI: number of PEBs reserved for bad PEB handling: 6
UBI: max/mean erase counter: 1/1
BBG U-Boot > ubi create system # 創(chuàng)建system分區(qū)
Creating dynamic volume system of size 76124160
# 燒寫sytem分區(qū),大小為tftp下載完成后提示的大小
BBG U-Boot > ubi write 0x90800000 system 0x3ca9800
Volume "system" found at volume id 0
7) 燒寫userdata到FLASH
BBG U-Boot > nand erase userdata # 擦除userdata分區(qū)
BBG U-Boot > ubi part userdata # 激活userdata分區(qū)為ubi格式
UBI: mtd1 is detached from ubi0
Creating 1 MTD partitions on "nand0":
0x000097855f98-0x000005020000 : "<NULL>"
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=4"
UBI: MTD device size: 31457280 MiB
UBI: number of good PEBs: 240
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: 234
UBI: total number of reserved PEBs: 6
UBI: number of PEBs reserved for bad PEB handling: 2
UBI: max/mean erase counter: 0/0
BBG U-Boot > ubi create userdata # 創(chuàng)建userdata分區(qū)
Creating dynamic volume userdata of size 30191616
BBG U-Boot > tftp 0x90800000 userdata.img # 獲取userdata到內存
# 燒寫userdata分區(qū),大小為tftp下載完成后提示的大小
BBG U-Boot > ubi write 0x90800000 userdata 0x979800
Volume "userdata" found at volume id 0
8) 初始化Cache分區(qū)
BBG U-Boot > ubi part cache # 激活cache分區(qū)為ubi格式
UBI: mtd1 is detached from ubi0
Creating 1 MTD partitions on "nand0":
0x000097855f98-0x000006e20000 : "<NULL>"
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=5"
UBI: MTD device size: 13631488 MiB
UBI: number of good PEBs: 104
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: 98
UBI: total number of reserved PEBs: 6
UBI: number of PEBs reserved for bad PEB handling: 2
UBI: max/mean erase counter: 0/0
BBG U-Boot > ubi create cache # 創(chuàng)建cache分區(qū)
9) FLASH上Android的加載與啟動
設置啟動參數(shù)
setenv bootcmd_nand 'run bootargs_nand;nand read ${loadaddr}kernel; nand read ${rd_loadaddr} ramdisk; bootm ${loadaddr}${rd_loadaddr}'
setenv bootargs_nand 'setenv bootargs ubi.mtd=3 ubi.mtd=4 ubi.mtd=5console=ttymxc0,115200 androidboot.console=ttymxc0 wvga calibrationinit=/init rw'
setenv bootcmd 'run bootcmd_nand'
saveenv
重啟即可從nand flash 啟動燒寫的ubi文件系統(tǒng)
聯(lián)系客服