2018-05-11 19:27:50 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2018-05-11 21:08:31 +00:00
|
|
|
# based off of flashrom-x230
|
2018-05-11 19:27:50 +00:00
|
|
|
#
|
|
|
|
set -e -o pipefail
|
|
|
|
. /etc/functions
|
2018-12-06 23:24:28 +00:00
|
|
|
. /tmp/config
|
2018-05-11 19:27:50 +00:00
|
|
|
|
2020-02-19 21:33:43 +00:00
|
|
|
case "$CONFIG_FLASHROM_OPTIONS" in
|
2020-02-19 17:04:56 +00:00
|
|
|
-* )
|
|
|
|
echo "Board $CONFIG_BOARD detected, continuing..."
|
2018-05-11 21:08:31 +00:00
|
|
|
;;
|
2018-05-11 19:27:50 +00:00
|
|
|
* )
|
2018-05-11 21:08:31 +00:00
|
|
|
die "ERROR: No board has been configured!\n\nEach board requires specific flashrom options and it's unsafe to flash without them.\n\nAborting."
|
2018-05-11 19:27:50 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
flash_rom() {
|
|
|
|
ROM=$1
|
2018-05-15 23:24:24 +00:00
|
|
|
if [ "$READ" -eq 1 ]; then
|
2020-02-19 21:33:43 +00:00
|
|
|
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.1" \
|
2018-05-15 23:24:24 +00:00
|
|
|
|| die "$ROM: Read failed"
|
2020-02-19 21:33:43 +00:00
|
|
|
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.2" \
|
2018-05-15 23:24:24 +00:00
|
|
|
|| die "$ROM: Read failed"
|
2020-02-19 21:33:43 +00:00
|
|
|
flashrom $CONFIG_FLASHROM_OPTIONS -r "${ROM}.3" \
|
2018-05-15 23:24:24 +00:00
|
|
|
|| die "$ROM: Read failed"
|
|
|
|
if [ `sha256sum ${ROM}.[123] | cut -f1 -d ' ' | uniq | wc -l` -eq 1 ]; then
|
|
|
|
mv ${ROM}.1 $ROM
|
|
|
|
rm ${ROM}.[23]
|
|
|
|
else
|
|
|
|
die "$ROM: Read inconsistent"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cp "$ROM" /tmp/${CONFIG_BOARD}.rom
|
|
|
|
sha256sum /tmp/${CONFIG_BOARD}.rom
|
|
|
|
if [ "$CLEAN" -eq 0 ]; then
|
|
|
|
preserve_rom /tmp/${CONFIG_BOARD}.rom \
|
|
|
|
|| die "$ROM: Config preservation failed"
|
|
|
|
fi
|
2019-08-01 03:53:04 +00:00
|
|
|
# persist serial number from CBFS
|
|
|
|
if cbfs -r serial_number > /tmp/serial 2>/dev/null; then
|
|
|
|
echo "Persisting system serial"
|
|
|
|
cbfs -o /tmp/${CONFIG_BOARD}.rom -d serial_number 2>/dev/null || true
|
|
|
|
cbfs -o /tmp/${CONFIG_BOARD}.rom -a serial_number -f /tmp/serial
|
|
|
|
fi
|
2018-05-11 19:27:50 +00:00
|
|
|
|
2020-02-19 21:33:43 +00:00
|
|
|
flashrom $CONFIG_FLASHROM_OPTIONS -w /tmp/${CONFIG_BOARD}.rom \
|
2018-05-15 23:24:24 +00:00
|
|
|
|| die "$ROM: Flash failed"
|
|
|
|
fi
|
2018-05-11 19:27:50 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 23:24:24 +00:00
|
|
|
if [ "$1" == "-c" ]; then
|
2018-05-11 21:08:31 +00:00
|
|
|
CLEAN=1
|
2018-05-15 23:24:24 +00:00
|
|
|
READ=0
|
|
|
|
ROM="$2"
|
|
|
|
elif [ "$1" == "-r" ]; then
|
|
|
|
CLEAN=0
|
|
|
|
READ=1
|
2018-05-11 21:08:31 +00:00
|
|
|
ROM="$2"
|
2018-05-15 23:24:24 +00:00
|
|
|
touch $ROM
|
2018-05-11 19:27:50 +00:00
|
|
|
else
|
2018-05-11 21:08:31 +00:00
|
|
|
CLEAN=0
|
2018-05-15 23:24:24 +00:00
|
|
|
READ=0
|
2018-05-11 21:08:31 +00:00
|
|
|
ROM="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "$ROM" ]; then
|
2018-05-15 23:24:24 +00:00
|
|
|
die "Usage: $0 [-c|-r] <path_to_image.rom>"
|
2018-05-11 19:27:50 +00:00
|
|
|
fi
|
|
|
|
|
2018-05-11 21:08:31 +00:00
|
|
|
flash_rom $ROM
|
2018-05-11 19:27:50 +00:00
|
|
|
exit 0
|