1
0
Fork 0

add script to clean SD card before flashing U-Boot

This commit is contained in:
Pratham Patel 2024-03-02 17:51:06 +05:30
parent 2f84cb38b8
commit a68fdda8ff
Signed by: thefossguy
SSH Key Fingerprint: SHA256:/B3wAg7jnMEBQ2JwkebbS/eXVZANDmqRfnd9QkIhxMI
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -xeuf -o pipefail
DEVICE="$1"
UBOOT="$2"
DD_COMMON='dd conv=sync status=progress'
if [[ "${EUID}" != '0' ]]; then
echo 'Run as root'
exit 1
fi
if [[ ! -f "${UBOOT}" ]]; then
echo "file not found: ${UBOOT}"
exit 2
fi
if [[ ! -b "${DEVICE}" ]]; then
echo "device not found: ${DEVICE}"
exit 3
fi
${DD_COMMON} bs=1M count=64 of="${DEVICE}" if=/dev/urandom
sync
${DD_COMMON} bs=1M count=64 of="${DEVICE}" if=/dev/zero
sync
if [[ -n "${3:-}" ]]; then
${DD_COMMON} bs=512 seek=64 of="${DEVICE}" if="${UBOOT}"
else
${DD_COMMON} bs="$3" seek="$4" of="${DEVICE}" if="${UBOOT}"
fi
sync