您的位置:首页 > 移动开发 > Android开发

uboot UBIFS移植及android UBIFS文件系统烧写 .

2013-06-25 20:24 561 查看

1.1
Uboot UBI的移植

关于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建立个默认的分区,方便以后操作。分区如下:

#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)大小,已经足够,如果实际有变化,可以进行相应调节。如果uboot传给Copy_Good_Blk 拷贝的uboot的大小小于uboot的长度的话,uboot跑不起来,移植的时候被这个问题必须注意。

这个时候就可以make 了,执行以下命令:

make clean

make mx51_vdphone_config

make all

如果正常的话会编译出u-boot.bin在根目录下。

1.2
u-boot 下ubi的使用

1.2.1
配置u-boot nand 分区

通过mtdpart命令配置u-boot下的nand 分区,本项目已经在配置头文件里面设置了默认nand 分区,

#define MTDPARTS_DEFAULT "mtdparts=nand0:0x100000@0x0(u-boot),0x300000@0x120000(kernel),0x7b00000@0x420000(rootfs),-(reserved)"

如果需要修改,可以通过修改默认分区列表,也可以通过命令mtdpart进行重新分区。这里使用默认分区,通过以下命令使默认分区生效:

mtdpart default //设置默认分区

saveevn //保存分区信息

1.2.2
nand u-boot 烧写

通过以上的配置编译,如果成功生成u-boot.bin,那就可以通过SD卡启动,直接烧写u-boot.bin到nand flash了。操作步骤如下:

1) 下载u-boot.bin 到内存

tftp 0x90800000 /tftpboot/mx51/u-boot.bin

2) 擦除u-boot分区

nand erase u-boot

3) 烧写u-boot到nand flash分区

nand write 0x90800000 u-boot 0x60000

1.2.3
内核的烧写

内核的烧写和平常烧写方式一样,只需用nand
命令写入nand
即可,操作步骤如下:

1)
擦除kernel分区

nand erase kernel

2)
下载kernel到内存

tftp 0x90800000 /tftpboot/mx51/uImage 将内核通过tftp下载到内存中

3)
烧写kernel 到nand kernel分区

nand write 0x90800000 kernel 0x300000

1.2.4
UBI文件系统的烧写

本项目使用的文件系统将根文件系统和system文件系统整合在一起。所以,只需要烧写整合后的文件系统即可。如果要使用ubifs文件系统作为根文件系统,在烧写之前必须通过mkfs.ubifs工具将做好的文件系统制作镜像文件。mkfs.ubifs 工具是通过编译mtd-utils工具下的mkfs.ubifs目录即可生成的PC端UBIFS文件系统镜像制作工具。操作步骤如下:

1)
制作根文件系统

mkfs.ubifs -r root/ -m 2048 -e 129024 -c 2364 -o root-fs.img

root目录为整合android root和system文件系统后的目录,应当能够通过NFS系统的

2)
擦除root分区

nand erase root

3) 激活root 分区为UBI格式

ubi part root

4) 创建root分区

ubi create root

5)
将文件系统下载到内存

tftp 0x90800000 root-fs.img

6)
将文件系统烧写到rootfs 中

ubi write 0x90800000 rootfs 0x339600//0x339600为tftp 下载到的root-fs.img镜像大小,

1.2.5
设置启动参数

设置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文件系统的制作和烧写

将android编译为UBI文件系统格式,生成的system.img,userdata.img,recover.img就可以直接在u-boot中通过ubi write 命令烧写,前提条件是uboot已经支持或完成ubi和UBIFS的移植工作,并且linux kernel也要支持UBIFS文件系统。

1.3.1 设置mtdpart分区

1) U-Boot中配置默认分区参数,路径如下:

# 板级相关的配置文件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分区:

BBG U-Boot > mtdparts default # 加载默认分区配置

BBG U-Boot > save # 保存配置

BBG U-Boot > mtdpart # 查看分区配置

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分区

BBG U-Boot > nand write 0x90800000 u-boot 0x100000 # 烧写u-boot到对应分区

4) 烧写Linux内核到FLASH

BBG U-Boot > tftp 0x90800000 uImage # 获取内核到内存

BBG U-Boot > nand erase kernel # 格式化内存分区

BBG U-Boot > nand write 0x90800000 kernel 0x300000 # 烧写内核到对应分区

5) 烧写Ramdisk到FLASH

BBG U-Boot > tftp 0x90800000 uramdisk.img # 获取uramdisk到内存

BBG U-Boot > nand erase ramdisk # 格式化uramdisk分区

BBG U-Boot > nand write 0x90800000 ramdisk 0x100000 # 烧写uramdisk到对应分区

6) 烧写System到FLASH

BBG U-Boot > nand erase system # 擦除system分区

BBG U-Boot > tftp 0x90800000 system.img # 获取system到内存

BBG U-Boot > ubi part system # 激活system分区为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 # 创建system分区

Creating dynamic volume system of size 76124160

# 烧写sytem分区,大小为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分区

BBG U-Boot > ubi part userdata # 激活userdata分区为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 # 创建userdata分区

Creating dynamic volume userdata of size 30191616

BBG U-Boot > tftp 0x90800000 userdata.img # 获取userdata到内存

# 烧写userdata分区,大小为tftp下载完成后提示的大小

BBG U-Boot > ubi write 0x90800000 userdata 0x979800

Volume "userdata" found at volume id 0

8) 初始化Cache分区

BBG U-Boot > ubi part cache # 激活cache分区为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 # 创建cache分区

9) FLASH上Android的加载与启动

设置启动参数

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=5 console=ttymxc0,115200 androidboot.console=ttymxc0 wvga calibration init=/init rw'

setenv bootcmd 'run bootcmd_nand'

saveenv

重启即可从nand flash 启动烧写的ubi文件系统
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: