From 82898e701f29ff9051fd14ef0f605e68065fb6ca Mon Sep 17 00:00:00 2001 From: The-going <48602507+The-going@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:29:40 +0300 Subject: [PATCH] spacemit: write_uboot_platform: check first, then write down The files included in u-boot are rarely changed or do not change at all. Compare bit by bit the memory region in which the file will be located and the file itself. If they match, then skip the recording. This saves the life of the memory chip. --- config/sources/families/spacemit.conf | 44 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) 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 + }