I.MX6 Manufacturing Tool V2 (MFGTool2) Emmc mksdcard.sh hacking

时间:2022-10-04 09:27:15
#!/bin/sh

# 参考文章:
#   1. MFGTool Emmc mksdcard.sh MFGTool Emmc mksdcard.sh comment
#       http://jordonwu.github.io/blog/2015/05/14/mfgtool-emmc-mksdcard-dot-sh/
#   2. linux sfdisk partition
#       http://blog.csdn.net/shell_albert/article/details/8425530

#<!-- partitioning the eMMC: -->
#<CMD state="Updater" type="push" body="$ echo 8 > /sys/devices/platform/sdhci-esdhc-imx.3/mmc_host/mmc0/mmc0:0001/boot_config">access user partition and enable boot partion 1 to boot</CMD>
#<CMD state="Updater" type="push" body="send" file="mksdcard.sh.tar">Sending partition shell</CMD>
#<CMD state="Updater" type="push" body="$ tar xf $FILE "> Partitioning...</CMD>
#<CMD state="Updater" type="push" body="$ sh mksdcard.sh /dev/mmcblk0"> Partitioning SD card now...</CMD>

# partition size in MB
# 这里定义的是启动ROM 10MB
BOOT_ROM_SIZE=10


# call sfdisk to create partition table
# destroy the partition table           
# $1:   为命令行第一个传递的参数
# node: /dev/mmcblk0
# 将前导一个1024字节(1KB)大小的分区零0,也就是分区表擦除
node=$1
dd if=/dev/zero of=${node} bs=1024 count=1

# sfdisk reads lines of the form
#   <start> <size> <id>< bootable> <c,h,s> <c,h,s>
# where each line fills one partition descriptor.
#
# --force: disable all consistency checking
# -uS, -uB, -uC, -uM: 以扇面/块/柱面数/MB为单位 显示或形成报告
# SmartFdisk –uM表示以MB为单位生成报告  即: sfdisk --force -um  /dev/mmcblk0 <<EOF
#
# BOOT_ROM_SIZE: 10
# 而分区则是使用sfdisk进行的,空出了uboot和kernel的位置,从起始地址10MB开始的:
# (10,,83) 将其10M以后所有空间分成一个区,,此处应该就是mmcblk0p1,其中83是Linux分区标识 
#
# Uboot和kernel是直接使用dd写入mmcblk0中的:
#     <!-- burn the uboot: -->
#   <CMD state="Updater" type="push" body="send" file="files/u-boot.bin">Sending U-Boot</CMD>
#   <CMD state="Updater" type="push" body="$ dd if=/dev/zero of=/dev/mmcblk0 bs=512 seek=2 count=2000">Clean U-Bootenvironment</CMD>
#   <CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk0 bs=512 seek=2 skip=2">write U-Boot to sdcard</CMD>
#   
#   <!-- burn the kernel: -->
#   <CMD state="Updater" type="push" body="send" file="files/uImage">Sending kernel uImage</CMD>
#   <CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk0 bs=1M seek=1 conv=fsync">write kernel image to emmc</CMD>

sfdisk --force -uM ${node} << EOF
${BOOT_ROM_SIZE},,83
EOF