imx6 通过SD卡启动后,对emmc进行分区和程序更新

1.运行的前提是,sd卡上的系统包含sfdisk工具

2.sd启动后,运行脚本分区

 目前是分了3个区(EMMC-4G大小,可用空间大约3.9G,本次分区并全部使用)

150M   --mmcblk0p1 ,偏移量为10M开始

2G       --mmcblk0p2,偏移量为200M开始

1G      -- mmcblk0p3,偏移量为2200M开始

 

#!/bin/sh

# partition size in MB

#mmcblk0p01
BOOT_SYSTEM_OFFSET=10
ROOT_SYSTEM_SIZE=150

#mmcblk0p2
MMC_PARTITION1_OFFSET=200
MMC_PARTITION1_SIZE=2000

#mmcblk0p3
MMC_PARTITION2_OFFSET=2200
MMC_PARTITION2_SIZE=1100
# call sfdisk to create partition table
# destroy the partition table
node=$1
dd if=/dev/zero of=${node} bs=1024 count=1


sfdisk --force -uM ${node} << EOF
${BOOT_SYSTEM_OFFSET},${ROOT_SYSTEM_SIZE},0c
${MMC_PARTITION1_OFFSET},${MMC_PARTITION1_SIZE},83
${MMC_PARTITION2_OFFSET},${MMC_PARTITION2_SIZE},83
EOF

 

 

 

 

 

3.更新uboot

执行脚本

 

#!/bin/sh


echo "download u-boot.imx from server"
tftp -gr u-boot.imx $1
if [ ! -e u-boot.imx ];then
	help
fi
echo "clear uboot args ... "
dd if=/dev/zero of=/dev/mmcblk0 bs=1k seek=384 conv=fsync count=129

echo "access boot partition 1"
echo 0 > /sys/block/mmcblk0boot0/force_ro

echo "write U-Boot to eMMC "
#from 1k bytes to write uboot, 
#note: chip first 1024bytes stored disk-partition table discription.
dd if=u-boot.imx of=/dev/mmcblk0boot0 bs=512 seek=2

echo "re-enable read-only access"
echo 1 > /sys/block/mmcblk0boot0/force_ro

echo "enable boot partion 1 to boot"
mmc bootpart enable 1 1 /dev/mmcblk0


需要说明的是,uboot烧写的位置是从1024字节,即1k位置开始写的。因为前1k字节为分区表位置,不能写。

 

 

4.更新 kernel fdt的步骤,类似uboot

 

5.更新rootfs

执行脚本

 

 

#!/bin/sh

mkfs.ext3 -E nodiscard /dev/mmcblk0p2
mkdir -p /mnt/mmcblk0p2
mount -t ext3 /dev/mmcblk0p2 /mnt/mmcblk0p2

cd /mnt/mmcblk0p2

tftp -gr root.tgz $1

if [  ! -e root.tgz ]
then
	echo "download root fs failed"
else
	tar zxf root.tgz
	rm  -rf root.tgz
	echo "unpack rootfs img success!"
fi

umount /mnt/mmcblk0p2

echo "Update Complete!"


其中root.tgz为打包好的根文件系统

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(imx6)