From 27a187ed12901f3873755a6d50dcb60c94b30bad Mon Sep 17 00:00:00 2001 From: Martin Kepplinger Date: Sun, 15 Apr 2018 09:04:35 +0200 Subject: [PATCH] flashrom_rpi_write: add size check before flashing flashrom might do it anyways, but we have the read image and can make sure the user didn't by accident provide the other image, for example. --- flashrom_rpi_write.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/flashrom_rpi_write.sh b/flashrom_rpi_write.sh index 8563030..360be5c 100755 --- a/flashrom_rpi_write.sh +++ b/flashrom_rpi_write.sh @@ -70,6 +70,7 @@ if [ ! "$have_chipname" -gt 0 ] ; then fi INPUT_IMAGE_NAME=$(basename ${INPUT_IMAGE_PATH}) +INPUT_IMAGE_SIZE=$(wc -c <"$INPUT_IMAGE_PATH") echo "verifying SPI connection by reading" TEMP_DIR=`mktemp -d` @@ -84,6 +85,11 @@ if [ "$have_backupname" -gt 0 ] ; then mv ${TEMP_DIR}/test1.rom ${BACKUPNAME} echo "current image saved as ${BACKUPIMAGE}" fi +TEMP_SIZE=$(wc -c <"$TEMP_DIR/test1.rom") +if [ ! "$INPUT_IMAGE_SIZE" -eq "$TEMP_SIZE" ] ; then + echo "Error: read image (${TEMP_SIZE}) has different size that new image $INPUT_IMAGE_NAME (${INPUT_IMAGE_SIZE})" + exit 1 +fi rm -rf ${TEMP_DIR} echo -e "connection ok. flashing ${GREEN}${INPUT_IMAGE_NAME}${NC}"