工作中需要将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/s

Author

Tony Liu

2016-8-3, Shenzhen

转载于:https://www.cnblogs.com/helloworldtoyou/p/5734180.html

imx6 android SD卡启动相关推荐

  1. IMX6 EMMC、SD卡启动引脚配置及uboot修改为SD2启动

    开发环境 平台:imx6dl 内核:linux-4.1.15 uboot:2014 问题描述 在IMX6中SD卡启动通常都是用SD3系列的引脚去作为SD卡槽的引脚,如下图. 总有些意外,比如这次的这块 ...

  2. imx533 配置 制作SD卡启动文件系统

    制作SD卡启动文件系统 [1]对SD卡分区 按飞思卡尔文档列出的分区表用fdisk分区: Partition Type/Index Name Start Offset Size File System ...

  3. 【迅为iMX6Q】开发板 u-boot 2020.04 SD卡 启动

    前言 iMX6Q 支持多种启动方式,如 emmc启动.SD 卡启动等,这里简单的记录一下 SD卡启动的流程 下载u-boot 使用 NXP 官方提供的 uboot-imx,代码地址为: https:/ ...

  4. 快速更新android sd卡,如何修复损坏的Android SD卡和SD卡恢复[2020更新]

    SD卡不是将您的数据保存在手机上的100%安全的地方,因为有一天它可能会损坏. 如果不幸发生,请冷静. 在这里,您将了解一些方法 修复损坏的Android SD卡 并避免您的数据丢失在损坏的SD卡中. ...

  5. Rockchip RK3588 SD卡启动

    Rockchip RK3588 SD卡启动 RK3588的BOOTROM 流程 RK3588 内部都有集成一个 BOOTROM,系统上电时先会运行 BOOTROM 代码,然后 BOOTROM 代码会探 ...

  6. 制作SD卡启动自己编译的uboot.bin

    README for FriendlyARM Tiny4412 ----------------------------------------------------- 1. Build uboot ...

  7. ZYNQ-7000如何生成从Flash和SD卡启动的镜像文件

    将PL与PS部分一起使用,并且通过JTAG下载到板子运行.对于ZYNQ,有多种启动方式,比如从JTAG启动.从QSPI(即Flash)启动,从SD卡启动等.对于从JTAG启动的,我们直接运行程序就OK ...

  8. WINCE6.0+S3C6410基于SD卡启动

    ********************************LoongEmbedded******************************** 作者:LoongEmbedded(kandi ...

  9. S5PV210体系结构与接口09:SD卡启动详解

    目录 1. MMC技术演进 1.1 NandFlash & NorFlash芯片 1.2 MMC卡 & SD卡 & MicroSD卡(TF卡) 1.2.1 代际关系 1.2.2 ...

最新文章

  1. html禁止f12键代码,网站禁用f12 禁止调试代码方法
  2. Android最佳的开源库(四)
  3. C++学习笔记:(五)继承 多态
  4. Django---启动admin的报no such table: auth_user错误
  5. Java-Exception异常
  6. rabbitmq 手动提交_第四章----SpringBoot+RabbitMQ发送确认和消费手动确认机制
  7. python接口自动化(十三)--cookie绕过验证码登录(详解)
  8. qwebkit 网页无法加载图片_网页图片无法显示了?这样就能解决
  9. [渝粤教育] 西南科技大学 机电传动控制 在线考试复习资料
  10. 将网页发布到远程windows server
  11. wordpress音乐播放器插件–PoiPlayer
  12. 【有利可图网】PS实战系列:PS制作人像印章效果
  13. linux进程阻塞例子,linux阻塞与非阻塞驱动例子
  14. TDD、FDD是什么意思?
  15. win7下桌面IE快捷方式无法删除解决方法
  16. cocos2d android 音乐,cocos2d-之音乐背景播放(示例代码)
  17. 苹果审核状态为Metadata Rejected下的问题
  18. 弱电布线工程实战攻略
  19. python字典(dictionary)
  20. 当今天下大势——个人观点

热门文章

  1. jsp ajax三级联动,Spring MVC+JSP实现三级联动
  2. iOS 13 真机调试包
  3. iOS socket 套接字编程
  4. Android编译错误: The project cannot be built until build path errors are resolved
  5. 非常值得一看—九种滤波算法C语言实现
  6. c++ primer 5th,练习11.19,编写代码验证
  7. C++string中find_first_not_of()函数和find_last_not_of()函数
  8. 4.1 多层感知机从0开始 4.2 多层感知机简洁实现(API调用)
  9. 对于原生代码使用Java线程的优缺点
  10. 解决Eclipse Debug 的source not found问题