From 0f377d875382ffb96023926c485ca6b091efaad5 Mon Sep 17 00:00:00 2001 From: Martin Kepplinger Date: Tue, 22 May 2018 09:26:16 +0200 Subject: [PATCH] x230: add preliminary support for CH341A based programmers --- x230/README.md | 13 ++++++++----- x230/external_install_bottom.sh | 22 ++++++++++++++-------- x230/external_install_top.sh | 20 ++++++++++++-------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/x230/README.md b/x230/README.md index 6cfb108..2f8e40a 100644 --- a/x230/README.md +++ b/x230/README.md @@ -83,8 +83,7 @@ or alternatively hooks, for example from [jumper wires](https://en.wikipedia.org/wiki/Jump_wire) to connect the clip to a hardware flasher * a hardware flasher -[supported by flashrom](https://www.flashrom.org/Flashrom/0.9.9/Supported_Hardware#USB_Devices) -but we currently only support using a [Raspberry Pi](https://www.raspberrypi.org/products/) +[supported by flashrom](https://www.flashrom.org/Flashrom/0.9.9/Supported_Hardware#USB_Devices), see below for the examples we support #### open up the X230 Remove the 7 screws of your X230 to remove the keyboard (by pushing it towards the @@ -102,7 +101,7 @@ below. This is how the SPI connection looks on both of the X230's chips: Edge (closest to you) -... choose one of the following supported flashing hardware examples: +... choose __one of the following__ supported flashing hardware examples: #### Hardware Example: Raspberry Pi 3 A Raspberry Pi can directly be a flasher through it's I/O pins, see below. @@ -141,9 +140,13 @@ or ethernet to `sudo apt-get install flashrom` Now copy the Skulls release tarball over to the Rasperry Pi and continue on the Pi. #### Hardware Example: CH341A based -CH341A, a USB interface chip, is used by some cheap memory programmers. +The CH341A from [Winchiphead](http://www.wch.cn/), a USB interface chip, +is used by some cheap memory programmers. +The one we describe can be bought +[here](http://www.aliexpress.com/item/Free-Shipping-CH341A-24-25-Series-EEPROM-Flash-BIOS-DVD-USB-Programmer-DVD-programmer-router-Nine/32583059603.html) -TODO +* Connect the programmer to your PC's USB port +* Connect your clip or hooks to the programmer's SPI pins #### unpack the Skulls release archive diff --git a/x230/external_install_bottom.sh b/x230/external_install_bottom.sh index 6d5509c..617086e 100755 --- a/x230/external_install_bottom.sh +++ b/x230/external_install_bottom.sh @@ -25,7 +25,7 @@ usage() echo "Usage: $0 [-c ] [-a] [-m] [-k ] [-l]" echo "" echo " -f " - echo " supported flashers: rpi" + echo " supported flashers: rpi, ch341a" echo "" echo " -c flashrom chip description to use" echo " -m apply me_cleaner -S" @@ -106,12 +106,16 @@ if [ ! "$have_flasher" -gt 0 ] ; then done fi +programmer="" if [ "${FLASHER}" = "rpi" ] ; then echo "Ok. Run this on a Rasperry Pi." + programmer="linux_spi:dev=/dev/spidev0.0,spispeed=128" elif [ "${FLASHER}" = "ch341a" ] ; then - echo "The CH341A is not yet supported" - exit 0 + echo "Ok. Connect a CH341A programmer" + programmer="ch341a_spi" else + echo "invalid flashrom programmer" + usage exit 1 fi @@ -120,7 +124,7 @@ hash flashrom || echo -e "${RED}Please install flashrom and run as root${NC}" TEMP_DIR=`mktemp -d` if [ ! "$have_chipname" -gt 0 ] ; then echo "trying to detect the chip..." - flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 &> ${TEMP_DIR}/chips || true + flashrom -p ${programmer} &> ${TEMP_DIR}/chips || true flashrom_error="" flashrom_error=$(cat ${TEMP_DIR}/chips | grep -i error || true) if [ ! -z "${flashrom_error}" ] ; then @@ -143,7 +147,7 @@ if [ ! "$have_chipname" -gt 0 ] ; then fi if [ ! "$chip_found" -gt 0 ] ; then echo "chip not detected." - flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 + flashrom -p ${programmer} rm -rf ${TEMP_DIR} echo "chip not detected. Please find it manually and rerun with the -c parameter." exit 1 @@ -186,8 +190,9 @@ if [[ ! "$TEMP_DIR" || ! -d "$TEMP_DIR" ]]; then rm -rf ${TEMP_DIR} exit 1 fi -flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -r ${TEMP_DIR}/test1.rom -flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -r ${TEMP_DIR}/test2.rom + +flashrom -p ${programmer} -c ${CHIPNAME} -r ${TEMP_DIR}/test1.rom +flashrom -p ${programmer} -c ${CHIPNAME} -r ${TEMP_DIR}/test2.rom cmp --silent ${TEMP_DIR}/test1.rom ${TEMP_DIR}/test2.rom if [ "$have_backupname" -gt 0 ] ; then cp ${TEMP_DIR}/test1.rom ${BACKUPNAME} @@ -230,6 +235,7 @@ fi 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 + +flashrom -p ${programmer} -c ${CHIPNAME} -w ${TEMP_DIR}/work.rom.new rm -rf ${TEMP_DIR} echo -e "${GREEN}DONE${NC}" diff --git a/x230/external_install_top.sh b/x230/external_install_top.sh index 80d69f1..c4d4c9a 100755 --- a/x230/external_install_top.sh +++ b/x230/external_install_top.sh @@ -22,7 +22,7 @@ usage() echo "Usage: $0 -i [-c ] [-k ]" echo "" echo " -f " - echo " supported flashers: rpi" + echo " supported flashers: rpi, ch341a" echo "" echo " -i " echo " -c to use for flashrom" @@ -125,12 +125,16 @@ if [ ! "$have_flasher" -gt 0 ] ; then done fi +programmer="" if [ "${FLASHER}" = "rpi" ] ; then echo "Ok. Run this on a Rasperry Pi." + programmer="linux_spi:dev=/dev/spidev0.0,spispeed=128" elif [ "${FLASHER}" = "ch341a" ] ; then - echo "The CH341A is not yet supported" - exit 0 + echo "Ok. Connect a CH341A programmer" + programmer="ch341a_spi" else + echo "invalid flashrom programmer" + usage exit 1 fi @@ -139,7 +143,7 @@ hash flashrom || echo -e "${RED}Please install flashrom and run as root${NC}" TEMP_DIR=`mktemp -d` if [ ! "$have_chipname" -gt 0 ] ; then echo "trying to detect the chip..." - flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 &> ${TEMP_DIR}/chips || true + flashrom -p ${programmer} &> ${TEMP_DIR}/chips || true flashrom_error="" flashrom_error=$(cat ${TEMP_DIR}/chips | grep -i error || true) if [ ! -z "${flashrom_error}" ] ; then @@ -156,7 +160,7 @@ if [ ! "$have_chipname" -gt 0 ] ; then fi if [ ! "$chip_found" -gt 0 ] ; then echo "chip not detected." - flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 + flashrom -p ${programmer} rm -rf ${TEMP_DIR} echo "Please find it manually in the list above and rerun with the -c parameter." exit 1 @@ -178,8 +182,8 @@ if [[ ! "$TEMP_DIR" || ! -d "$TEMP_DIR" ]]; then echo "Could not create temp dir" exit 1 fi -flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -r ${TEMP_DIR}/test1.rom -flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -r ${TEMP_DIR}/test2.rom +flashrom -p ${programmer} -c ${CHIPNAME} -r ${TEMP_DIR}/test1.rom +flashrom -p ${programmer} -c ${CHIPNAME} -r ${TEMP_DIR}/test2.rom cmp --silent ${TEMP_DIR}/test1.rom ${TEMP_DIR}/test2.rom if [ "$have_backupname" -gt 0 ] ; then cp ${TEMP_DIR}/test1.rom ${BACKUPNAME} @@ -193,5 +197,5 @@ fi rm -rf ${TEMP_DIR} echo -e "${GREEN}connection ok${NC}. flashing ${INPUT_IMAGE_NAME}" -flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=128 -c ${CHIPNAME} -w ${INPUT_IMAGE_PATH} +flashrom -p ${programmer} -c ${CHIPNAME} -w ${INPUT_IMAGE_PATH} echo -e "${GREEN}DONE${NC}"