Browse Source

x230: flashrom scripts: add -a option for autodetecting the chip

This adds an experimental option to choose a chip from flashrom's list
using our own heuristics. If successful this should become the default
behaviour when when "-c" is not specified.

Basically this should completely replace the documentation section
"flashrom chip config" at some point.

Adresses issue #26
pull/35/head
Martin Kepplinger 6 years ago
parent
commit
6791931256
2 changed files with 95 additions and 16 deletions
  1. +50
    -8
      x230/flashrom_rpi_bottom_unlock.sh
  2. +45
    -8
      x230/flashrom_rpi_top_write.sh

+ 50
- 8
x230/flashrom_rpi_bottom_unlock.sh View File

@ -13,16 +13,20 @@ have_chipname=0
have_backupname=0
me_clean=0
lock=0
autodetect_chip=0
usage()
{
echo "Usage: $0 -c <chipname> [-m] [-k <backup_filename>] [-l]"
echo "Usage: $0 [-c <chipname>] [-a] [-m] [-k <backup_filename>] [-l]"
echo ""
echo "-c <chipname> flashrom chip description to use"
echo "-a try to autodetect the chipname"
echo "-m apply me_cleaner -S"
echo "-l lock the flash instead of unlocking it"
echo "-k <file> save the read image as <file>"
}
args=$(getopt -o mlc:k:h -- "$@")
args=$(getopt -o mlc:ak:h -- "$@")
if [ $? -ne 0 ] ; then
usage
exit 1
@ -38,6 +42,9 @@ do
-l)
lock=1
;;
-a)
autodetect_chip=1
;;
-c)
CHIPNAME=$2
have_chipname=1
@ -64,12 +71,45 @@ do
shift
done
TEMP_DIR=`mktemp -d`
if [ ! "$have_chipname" -gt 0 ] ; then
echo "no chipname provided. To get it, we run::"
echo "flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128"
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
usage
exit 1
if [ ! "$autodetect_chip" -gt 0 ] ; then
echo -e "${RED}no chipname provided${NC}. To get it, we run:"
echo "flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128"
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
usage
rm -rf ${TEMP_DIR}
exit 1
else
echo "trying to detect the chip..."
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 &> ${TEMP_DIR}/chips || true
flashrom_error=""
flashrom_error=$(cat ${TEMP_DIR}/chips | grep -i error)
if [ ! -z "${flashrom_error}" ] ; then
cat ${TEMP_DIR}/chips
rm -rf ${TEMP_DIR}
exit 1
fi
CHIPNAME=""
chip_found=0
CHIPNAME=$(cat ${TEMP_DIR}/chips | grep Found | grep "MX25L6406E/MX25L6408E" | grep -o '".*"')
if [ ! -z "${CHIPNAME}" ] ; then
chip_found=1
fi
CHIPNAME=$(cat ${TEMP_DIR}/chips | grep Found | grep "EN25QH64" | grep -o '".*"')
if [ ! -z "${CHIPNAME}" ] ; then
chip_found=1
fi
if [ ! "$chip_found" -gt 0 ] ; then
echo -e "${RED}Error:${NC} chip not detected. Please find it manually:"
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
rm -rf ${TEMP_DIR}
exit 1
else
echo -e "Detected ${GREEN}${CHIPNAME}${NC}."
fi
fi
fi
make -C util/ifdtool
@ -93,14 +133,15 @@ fi
if [ "$me_clean" -gt 0 ] ; then
if [ ! -e ${ME_CLEANER_PATH} ] ; then
echo "me_cleaner not found at ${ME_CLEANER_PATH}"
rm -rf ${TEMP_DIR}
exit 1
fi
fi
echo "Start reading 2 times. Please be patient..."
TEMP_DIR=`mktemp -d`
if [[ ! "$TEMP_DIR" || ! -d "$TEMP_DIR" ]]; then
echo -e "${RED}Error:${NC} Could not create temp dir"
rm -rf ${TEMP_DIR}
exit 1
fi
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -r ${TEMP_DIR}/test1.rom
@ -148,4 +189,5 @@ make clean -C util/ifdtool
echo "start writing..."
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -w ${TEMP_DIR}/work.rom.new
rm -rf ${TEMP_DIR}
echo -e "${GREEN}DONE${NC}"

+ 45
- 8
x230/flashrom_rpi_top_write.sh View File

@ -10,13 +10,19 @@ set -e
have_input_image=0
have_chipname=0
have_backupname=0
autodetect_chip=0
usage()
{
echo "Usage: $0 -i <image.rom> -c <chipname> [-k <backup_filename>]"
echo "Usage: $0 -i <image.rom> [-c <chipname>] [-a] [-k <backup_filename>]"
echo ""
echo " -i <path to image to flash>"
echo " -c <chipname> for flashrom"
echo " -a ... try autodetecting the chipname"
echo " -k <path to backup to save>"
}
args=$(getopt -o i:c:k:h -- "$@")
args=$(getopt -o i:c:ak:h -- "$@")
if [ $? -ne 0 ] ; then
usage
exit 1
@ -36,6 +42,9 @@ do
have_chipname=1
shift
;;
-a)
autodetect_chip=1
;;
-k)
BACKUPNAME=$2
have_backupname=1
@ -63,12 +72,41 @@ if [ ! "$have_input_image" -gt 0 ] ; then
exit 1
fi
TEMP_DIR=`mktemp -d`
if [ ! "$have_chipname" -gt 0 ] ; then
echo "no chipname provided. To get it out, we run:"
echo "flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128"
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
usage
exit 1
if [ ! "$autodetect_chip" -gt 0 ] ; then
echo -e "${RED}no chipname provided${NC}. To get it, we run:"
echo "flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128"
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
usage
rm -rf ${TEMP_DIR}
exit 1
else
echo "trying to detect the chip..."
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 &> ${TEMP_DIR}/chips || true
flashrom_error=""
flashrom_error=$(cat ${TEMP_DIR}/chips | grep -i error)
if [ ! -z "${flashrom_error}" ] ; then
cat ${TEMP_DIR}/chips
rm -rf ${TEMP_DIR}
exit 1
fi
CHIPNAME=""
chip_found=0
CHIPNAME=$(cat ${TEMP_DIR}/chips | grep Found | grep "MX25L3206E" | grep -o '".*"')
if [ ! -z "${CHIPNAME}" ] ; then
chip_found=1
fi
if [ ! "$chip_found" -gt 0 ] ; then
echo -e "${RED}Error:${NC} chip not detected. Please find it manually:"
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128
rm -rf ${TEMP_DIR}
exit 1
else
echo -e "Detected ${GREEN}${CHIPNAME}${NC}."
fi
fi
fi
INPUT_IMAGE_NAME=$(basename ${INPUT_IMAGE_PATH})
@ -80,7 +118,6 @@ if [ ! "$INPUT_IMAGE_SIZE" -eq "$reference_filesize" ] ; then
fi
echo "verifying SPI connection by reading 2 times. please wait."
TEMP_DIR=`mktemp -d`
if [[ ! "$TEMP_DIR" || ! -d "$TEMP_DIR" ]]; then
echo "Could not create temp dir"
exit 1


Loading…
Cancel
Save