imx6 android SD卡启动
工作中需要將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 MB BOOTLOAD_RESERVE=8 # bootloader BOOT_ROM_SIZE=8 SYSTEM_ROM_SIZE=512 # system.img CACHE_SIZE=512 # cache RECOVERY_ROM_SIZE=8 # recovery VENDER_SIZE=8 # vendor MISC_SIZE=8 #顯示幫助信息 help() {bn=`basename $0` cat << EOF usage $bn <option> device_nodeoptions:-h displays this help message-s only get partition size-np not partition.-f flash android image. EOF}# check the if root? userid=`id -u` if [ $userid -ne "0" ]; thenecho "you're not root?"exit fi# parse command line moreoptions=1 node="na" cal_only=0 flash_images=0 not_partition=0 not_format_fs=0 while [ "$moreoptions" = 1 -a $# -gt 0 ]; docase $1 in-h) help; exit ;;-s) cal_only=1 ;;-f) flash_images=1 ;;-np) not_partition=1 ;;-nf) not_format_fs=1 ;;*) moreoptions=0; node=$1 ;;esac[ "$moreoptions" = 0 ] && [ $# -gt 1 ] && help && exit[ "$moreoptions" = 1 ] && shift doneif [ ! -e ${node} ]; thenhelpexit fi# node /dev/mmcblk0# call sfdisk to create partition table # get total card size seprate=40 # 查看分區大小,字節數 total_size=`sfdisk -s ${node}` # 將字節轉為M total_size=`expr ${total_size} / 1024` boot_rom_sizeb=`expr ${BOOT_ROM_SIZE} + ${BOOTLOAD_RESERVE}` # 8M + 8M = 16M # 512M + 512M + 8M + 8M + 40M = 1240M extend_size=`expr ${SYSTEM_ROM_SIZE} + ${CACHE_SIZE} + ${VENDER_SIZE} + ${MISC_SIZE} + ${seprate}` # data_size = total_size - 16M - 8M - 1240M + 40M = total_size - 1224M data_size=`expr ${total_size} - ${boot_rom_sizeb} - ${RECOVERY_ROM_SIZE} - ${extend_size} + ${seprate}` # 這一部分只是顯示計算的大小 # create partitions if [ "${cal_only}" -eq "1" ]; then cat << EOF BOOT : ${boot_rom_sizeb}MB RECOVERY: ${RECOVERY_ROM_SIZE}MB SYSTEM : ${SYSTEM_ROM_SIZE}MB CACHE : ${CACHE_SIZE}MB DATA : ${data_size}MB MISC : ${MISC_SIZE}MB EOF exit fi# 刪除分區表 # destroy the partition table dd if=/dev/zero of=${node} bs=1024 count=1# 創建分區 # sfdisk 命令 man 文檔中有記錄。 # Id is given in hex, without the 0x prefix, or is [E|S|L|X], # where L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), # E is EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85). # 指定分區大小,以及分區的類型,83,LINUX_NATIVE,5:擴展分區 # 查案每種文件系統類型,可以通過命令 sfdisk -T 查看 sfdisk --force -uM ${node} << EOF ,${boot_rom_sizeb},83 # 16M ,${RECOVERY_ROM_SIZE},83 # 8M ,${extend_size},5 # 1240M ,${data_size},83 # total_size - 1224M ,${SYSTEM_ROM_SIZE},83 # 512M ,${CACHE_SIZE},83 # 512M ,${VENDER_SIZE},83 # 8M ,${MISC_SIZE},83 # 8M EOF# adjust the partition reserve for bootloader. # if you don't put the uboot on same device, you can remove the BOOTLOADER_ERSERVE # to have 8M space. # the minimal sylinder for some card is 4M, maybe some was 8M # just 8M for some big eMMC 's sylinder # 將/dev/mmcblk0分區之后的第一個分區進行調整 sfdisk --force -uM ${node} -N1 << EOF ${BOOTLOAD_RESERVE},${BOOT_ROM_SIZE},83 EOF# For MFGTool Notes: # MFGTool use mksdcard-android.tar store this script # if you want change it. # do following: # tar xf mksdcard-android.sh.tar # vi mksdcard-android.sh # [ edit want you want to change ] # rm mksdcard-android.sh.tar; tar cf mksdcard-android.sh.tar mksdcard-android.sh鏡像拷貝到SD卡
這些內容也是從Mfgtool的ucl2.mxl文件中提取出來的。
制作成腳本repartition.sh,如下所示:
#!/bin/sh # Tony Liu 2016-8-3IMAGE_DIR="./image/" #鏡像文件存放的目錄 UBOOT=$IMAGE_DIR/u-boot.bin BOOT_IMG=$IMAGE_DIR/boot.img SYSTEM_IMG=$IMAGE_DIR/system.img RECOVERY_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.img dd if=$BOOT_IMG of=${DEVICE}1 #write boot.img# 將SD卡的第4個分區格式化位ext4文件系統,并指定卷標名稱為data mkfs.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.img dd if=$SYSTEM_IMG of=${DEVICE}5 bs=512 #Sending and writting system.img # 寫入recovery.img dd if=$RECOVERY_IMG of=${DEVICE}2 bs=512 #Sending and writting recovery.img</CMD>更改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. # <src> <mnt_point> <type> <mnt_flags> <fs_mgr_flags> # 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 in 1+0 records out 1024 bytes (1.0 kB) copied, 0.00902186 s, 114 kB/s Checking 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 type Old situation: No partitions found Warning: given size (6520) exceeds max allowable size (6460) New situation: Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0Device 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 Linux Warning: partition 4 extends past end of disk Successfully 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/track Old situation: Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0Device 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 Linux New situation: Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0Device 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 Linux Warning: partition 4 extends past end of disk Successfully 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 in 2000+0 records out 1024000 bytes (1.0 MB) copied, 2.21602 s, 462 kB/s # dd命令還能夠測讀寫速度 533+1 records in 533+1 records out 273172 bytes (273 kB) copied, 1.33912 s, 204 kB/s 9916+0 records in 9916+0 records out 5076992 bytes (5.1 MB) copied, 11.7538 s, 432 kB/s mke2fs 1.42 (29-Nov-2011) Filesystem label=data OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 413712 inodes, 1654536 blocks 82726 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1694498816 51 block groups 32768 blocks per group, 32768 fragments per group 8112 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done mke2fs 1.42 (29-Nov-2011) Filesystem label=system OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 33280 inodes, 132912 blocks 6645 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=138412032 5 block groups 32768 blocks per group, 32768 fragments per group 6656 inodes per group Superblock backups stored on blocks: 32768, 98304Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: donemke2fs 1.42 (29-Nov-2011) Filesystem label=cache OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 33280 inodes, 132912 blocks 6645 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=138412032 5 block groups 32768 blocks per group, 32768 fragments per group 6656 inodes per group Superblock backups stored on blocks: 32768, 98304Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: donemke2fs 1.42 (29-Nov-2011) Filesystem label=vender OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 3808 inodes, 15188 blocks 759 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=15728640 2 block groups 8192 blocks per group, 8192 fragments per group 1904 inodes per group Superblock backups stored on blocks: 8193Allocating group tables: done Writing inode tables: done Creating journal (1024 blocks): done Writing superblocks and filesystem accounting information: donemke2fs 1.42 (29-Nov-2011) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 3808 inodes, 15188 blocks 759 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=15728640 2 block groups 8192 blocks per group, 8192 fragments per group 1904 inodes per group Superblock backups stored on blocks: 8193Allocating group tables: done Writing inode tables: done Creating journal (1024 blocks): done Writing superblocks and filesystem accounting information: done573440+0 records in 573440+0 records out 293601280 bytes (294 MB) copied, 61.2452 s, 4.8 MB/s 10580+0 records in 10580+0 records out 5416960 bytes (5.4 MB) copied, 14.8084 s, 366 kB/sAuthor
Tony Liu
2016-8-3, Shenzhen
轉載于:https://www.cnblogs.com/helloworldtoyou/p/5734180.html
總結
以上是生活随笔為你收集整理的imx6 android SD卡启动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Zmodem transfer canc
- 下一篇: 免 sudo 使用 docker