Skip to content
Snippets Groups Projects
write_flash.sh 975 B
Newer Older
#!/bin/sh

set -e

if [ $# -lt 1 ]; then
    echo "Usage: $0 <file>"
    echo "\tWrites a file to the NOR flash"
    exit 1
fi

cleanup()
{
    [ -z "${UUU_SCRIPT}" ] || rm -f "${UUU_SCRIPT}" 
}
trap cleanup EXIT

FILE=$1

SIZE=$(stat --printf="%s" ${FILE})
SIZE=$(echo "(${SIZE}/4096+1)*4096" | bc)
HEX_SIZE=$(printf "0x%x" ${SIZE})
UUU_SCRIPT=$(mktemp -p ./)

cat << EOF > ${UUU_SCRIPT}
uuu_version 1.0.1
# Use uboot to write a file to the rootfs

SDP: boot -f files/u-boot-librem5-recovery.imx
# This command will be run when use SPL
SDPU: delay 1000
SDPU: write -f files/u-boot-librem5-recovery.imx -offset 0x57c00
SDPU: jump
SDPV: delay 1000
SDPV: write -f files/u-boot-librem5-recovery.imx -skipspl
SDPV: jump
FB: ucmd setenv fastboot_buffer 0x43000000
FB: download -f ${FILE}
FB: ucmd sf probe
FB: acmd sf erase 0 ${HEX_SIZE}
FB: delay 5000
FB: acmd sf write 0x43000000 0 ${HEX_SIZE}
EOF

echo "About to run ${UUU_SCRIPT}"
cat ${UUU_SCRIPT}

sudo uuu -v ${UUU_SCRIPT}