工作中需要将imx6的android系统从SD卡启动,所以就分析了MfgTool中的脚本,分析android的分区情况,并尝试自己操作,竟然成功了,记录于此。
参考文档
http://www.kancloud.cn/digest/imx6-android/148864
http://m.codes51.com/article/detail_239610_4.html
sd卡重新分区
分区使用MfgTool中的mksdcard-android.sh脚本。下面对其进行分析。
需要将SD卡umount才能够从新进行分区。
#!/bin/bash# 运行 sh mksdcard-android.sh /dev/mmcblk0# partition size in MBBOOTLOAD_RESERVE=8 # bootloaderBOOT_ROM_SIZE=8 SYSTEM_ROM_SIZE=512 # system.imgCACHE_SIZE=512 # cacheRECOVERY_ROM_SIZE=8 # recoveryVENDER_SIZE=8 # vendorMISC_SIZE=8#显示帮助信息help() {bn=`basename $0`cat << EOFusage $bn
镜像拷贝到SD卡
这些内容也是从Mfgtool的ucl2.mxl文件中提取出来的。
制作成脚本repartition.sh,如下所示:
#!/bin/sh# Tony Liu 2016-8-3IMAGE_DIR="./image/" #镜像文件存放的目录UBOOT=$IMAGE_DIR/u-boot.binBOOT_IMG=$IMAGE_DIR/boot.imgSYSTEM_IMG=$IMAGE_DIR/system.imgRECOVERY_IMG=$IMAGE_DIR/recovery.imgDEVICE=/dev/sdb #SD卡在linux中的设备节点,视实际情况而定MKSDCARD_SCRIPT=./mksdcard-android.sh # android分区的脚本# 将SD卡分区 sh $MKSDCARD_SCRIPT $DEVICE# 对设备写0,每次块大小是512字节,从2 block的位置开始写,写2000次# 这里我猜想前面的1024字节应该是留给分区表的。dd if=/dev/zero of=$DEVICE bs=512 seek=2 count=2000 #Clean U-Bootenvironment# 写入u-boot.img。从u-boot.img开始2 block(skip=2)的位置开始读取数据# 写入的地址是设备偏移2block(seek=2)的位置(1M),块大小512字节。dd if=$UBOOT of=$DEVICE bs=512 seek=2 skip=2 #write U-Boot to sdcard# 写入boot.imgdd if=$BOOT_IMG of=${DEVICE}1 #write boot.img# 将SD卡的第4个分区格式化位ext4文件系统,并指定卷标名称为datamkfs.ext4 -L data ${DEVICE}4 #Formatting sd partitionmkfs.ext4 -L system ${DEVICE}5 #Formatting system partitionmkfs.ext4 -L cache -O^extent ${DEVICE}6 #Formatting cache partitionmkfs.ext4 -L vender ${DEVICE}7 #Formatting data partitionmkfs.ext4 ${DEVICE}8 #Formatting misc partition# 写入system.imgdd if=$SYSTEM_IMG of=${DEVICE}5 bs=512 #Sending and writting system.img# 写入recovery.imgdd if=$RECOVERY_IMG of=${DEVICE}2 bs=512 #Sending and writting recovery.img
更改kernel启动位置
imx6从SD卡uboot启动之后,需要在SD卡中的uboot指定内核运行的SD卡序号,否者会运行开发板的emmc中。
可以在uboot中通过"mmc list",查看有几块mmc。使用"booti mmc1",更改mmc序号,看是否能从SD卡启动,来判断SD卡的编号。
我的板子上SD卡的序号是mmc1。将uboot配置文件中mmc2更改为mmc1。这样一来,就选择从SD卡的内核启动。
vi mx6dl_sabresd_android.h
#define CONFIG_ANDROID_RECOVERY_BOOTCMD_MMC \"booti mmc1 recovery"// Tony 2016-8-3//"booti mmc2 recovery"#define CONFIG_ANDROID_RECOVERY_CMD_FILE "/recovery/command"#define CONFIG_INITRD_TAG#undef CONFIG_LOADADDR#undef CONFIG_RD_LOADADDR#undef CONFIG_EXTRA_ENV_SETTINGS#define CONFIG_LOADADDR 0x10800000 /* loadaddr env var */#define CONFIG_RD_LOADADDR 0x11000000#define CONFIG_INITRD_TAG#define CONFIG_EXTRA_ENV_SETTINGS \ "netdev=eth0\0" \ "ethprime=FEC0\0" \ "fastboot_dev=mmc1\0" \ "bootcmd=booti mmc1\0" \ "splashimage=0x30000000\0" \ "splashpos=m,m\0" \ "android_test=keyvalue\0" \ "bootargs=console=ttymxc0,115200 init=/init video=mxcfb0:dev=ldb,bpp=32 video=mxcfb1:off video=mxcfb2:off fbmem=40M fb0base=0x27b00000 vmalloc=400M androidboot.console=ttymxc0 androidboot.hardware=freescale\0" \ "lvds_num=1\0" #endif
更改ramdisk挂载位置
内核更改之后,需要将文件系统挂载到SD卡的分区上。
根据自己SD卡编号进行更改/dev/block/mmcblk后面的序号,我的是1。
vi fstab.freescale
# Android fstab file.## The filesystem that contains the filesystem checker binary (typically /system) cannot# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK#Tony add for SD card boot/dev/block/mmcblk1p5 /system ext4 ro wait/dev/block/mmcblk1p4 /data ext4 nosuid,nodev,nodiratime,noatime,nomblk_io_submit,noauto_da_alloc,errors=panic wait,encryptable=footer/dev/block/mmcblk1p6 /cache ext4 nosuid,nodev,nomblk_io_submit wait/dev/block/mmcblk1p7 /device ext4 ro,nosuid,nodev wait
运行脚本输出内容:
Tony@Tony:~/imx6_sdcard_boot$ sudo ./repartition.sh ### 首先进行SD卡分区1+0 records in1+0 records out1024 bytes (1.0 kB) copied, 0.00902186 s, 114 kB/sChecking that no-one is using this disk right now ...OKDisk /dev/sdb: 1022 cylinders, 245 heads, 62 sectors/tracksfdisk: ERROR: sector 0 does not have an msdos signature /dev/sdb: unrecognized partition table typeOld situation:No partitions foundWarning: given size (6520) exceeds max allowable size (6460)New situation:Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End MiB #blocks Id System/dev/sdb1 0+ 22- 23- 22784+ 83 Linux/dev/sdb2 22+ 37- 15- 15190 83 Linux/dev/sdb3 37+ 1119- 1083- 1108870 5 Extended/dev/sdb4 1119+ 7639- 6520- 6676005 83 Linux/dev/sdb5 37+ 556- 520- 531649+ 83 Linux/dev/sdb6 556+ 1075- 520- 531649+ 83 Linux/dev/sdb7 1075+ 1090- 15- 15189+ 83 Linux/dev/sdb8 1090+ 1105- 15- 15189+ 83 LinuxWarning: partition 4 extends past end of diskSuccessfully wrote the new partition tableRe-reading the partition table ...If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1(See fdisk(8).)Checking that no-one is using this disk right now ...OKDisk /dev/sdb: 1022 cylinders, 245 heads, 62 sectors/trackOld situation:Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End MiB #blocks Id System/dev/sdb1 0+ 22- 23- 22784+ 83 Linux/dev/sdb2 22+ 37- 15- 15190 83 Linux/dev/sdb3 37+ 1119- 1083- 1108870 5 Extended/dev/sdb4 1119+ 7639- 6520- 6676005 83 Linux/dev/sdb5 37+ 556- 520- 531649+ 83 Linux/dev/sdb6 556+ 1075- 520- 531649+ 83 Linux/dev/sdb7 1075+ 1090- 15- 15189+ 83 Linux/dev/sdb8 1090+ 1105- 15- 15189+ 83 LinuxNew situation:Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End MiB #blocks Id System/dev/sdb1 7+ 22- 15- 15190 83 Linux/dev/sdb2 22+ 37- 15- 15190 83 Linux/dev/sdb3 37+ 1119- 1083- 1108870 5 Extended/dev/sdb4 1119+ 7639- 6520- 6676005 83 Linux/dev/sdb5 37+ 556- 520- 531649+ 83 Linux/dev/sdb6 556+ 1075- 520- 531649+ 83 Linux/dev/sdb7 1075+ 1090- 15- 15189+ 83 Linux/dev/sdb8 1090+ 1105- 15- 15189+ 83 LinuxWarning: partition 4 extends past end of diskSuccessfully wrote the new partition tableRe-reading the partition table ...If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1(See fdisk(8).)#-------------------------------------------------------------------------------# 上面的内容是SD卡从新分区,下面进行dd文件拷贝2000+0 records in2000+0 records out1024000 bytes (1.0 MB) copied, 2.21602 s, 462 kB/s # dd命令还能够测读写速度533+1 records in533+1 records out273172 bytes (273 kB) copied, 1.33912 s, 204 kB/s9916+0 records in9916+0 records out5076992 bytes (5.1 MB) copied, 11.7538 s, 432 kB/smke2fs 1.42 (29-Nov-2011)Filesystem label=dataOS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks413712 inodes, 1654536 blocks82726 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=169449881651 block groups32768 blocks per group, 32768 fragments per group8112 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done mke2fs 1.42 (29-Nov-2011)Filesystem label=systemOS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks33280 inodes, 132912 blocks6645 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=1384120325 block groups32768 blocks per group, 32768 fragments per group6656 inodes per groupSuperblock backups stored on blocks: 32768, 98304Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: donemke2fs 1.42 (29-Nov-2011)Filesystem label=cacheOS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks33280 inodes, 132912 blocks6645 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=1384120325 block groups32768 blocks per group, 32768 fragments per group6656 inodes per groupSuperblock backups stored on blocks: 32768, 98304Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: donemke2fs 1.42 (29-Nov-2011)Filesystem label=venderOS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks3808 inodes, 15188 blocks759 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=157286402 block groups8192 blocks per group, 8192 fragments per group1904 inodes per groupSuperblock backups stored on blocks: 8193Allocating group tables: done Writing inode tables: done Creating journal (1024 blocks): doneWriting superblocks and filesystem accounting information: donemke2fs 1.42 (29-Nov-2011)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks3808 inodes, 15188 blocks759 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=157286402 block groups8192 blocks per group, 8192 fragments per group1904 inodes per groupSuperblock backups stored on blocks: 8193Allocating group tables: done Writing inode tables: done Creating journal (1024 blocks): doneWriting superblocks and filesystem accounting information: done573440+0 records in573440+0 records out293601280 bytes (294 MB) copied, 61.2452 s, 4.8 MB/s10580+0 records in10580+0 records out5416960 bytes (5.4 MB) copied, 14.8084 s, 366 kB/s
Author
Tony Liu
2016-8-3, Shenzhen