diff --git a/config/sources/families/spacemit.conf b/config/sources/families/spacemit.conf index aa89b586f4..15a41af5c9 100644 --- a/config/sources/families/spacemit.conf +++ b/config/sources/families/spacemit.conf @@ -55,22 +55,34 @@ pre_prepare_partitions() { } write_uboot_platform() { - local device=${2} + local device N + + declare -A d + d=( + ["bootinfo_emmc.bin"]="0:$(du -b ${1}/bootinfo_emmc.bin | awk '{print $1}')" + ["FSBL.bin"]="1:$(du -b ${1}/FSBL.bin | awk '{print $1}')" + ["fw_dynamic.itb"]="1280:$(du -b ${1}/fw_dynamic.itb | awk '{print $1}')" + ["u-boot.itb"]="2048:$(du -b ${1}/u-boot.itb | awk '{print $1}')" + ) + + device=${2} if [ -b ${2}boot0 ]; then - echo "eMMC" - DEVICE=`ls /dev/mmcblk*boot0 | sed 's/^.....//'` - echo 0 > /sys/block/${DEVICE}/force_ro - sleep .50 - dd if="$1/bootinfo_emmc.bin" of="/dev/${DEVICE}" bs=512 conv=notrunc - dd if="$1/FSBL.bin" of="/dev/${DEVICE}" bs=512 seek=1 conv=notrunc - dd if="$1/FSBL.bin" of="/dev/${DEVICE}" bs=512 seek=512 conv=notrunc - else - echo "SD card" - dd if="$1/bootinfo_emmc.bin" of=$2 bs=512 conv=notrunc - dd if="$1/FSBL.bin" of="$2" bs=512 seek=1 conv=notrunc - dd if="$1/FSBL.bin" of="$2" bs=512 seek=512 conv=notrunc + device=${2}boot0 + echo 0 > /sys/block/$(basename ${device})/force_ro + sync fi - dd if="$1/fw_dynamic.itb" of="$2" bs=512 seek=1280 conv=notrunc - dd if="$1/u-boot.itb" of="$2" bs=512 seek=2048 conv=notrunc - sync + + for f in "${!d[@]}"; do + + N=$((${d[$f]%:*} * 512)) + if dd "if=${device}" bs=1 "skip=$N" "count=${d[$f]#*:}" \ + conv=notrunc status=noxfer 2> /dev/null | cmp --quiet "${1}/${f}"; then + + echo "Skip $f, it is equal to the existing one" + else + echo "# Write $f to ${device}" + dd "if=${1}/${f}" "of=${device}" bs=512 "seek=${d[$f]%:*}" conv=notrunc,fsync status=noxfer + fi + done + }