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.
This commit is contained in:
parent
c54410b9ba
commit
82898e701f
@ -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
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user