From 3d55f1024b49723eeb5dd10174fe2c180bd4615f Mon Sep 17 00:00:00 2001 From: Kieran Levin Date: Wed, 4 Sep 2024 01:22:36 -0700 Subject: [PATCH 1/7] pr: can flash using bus pirate a little bit hacky, as we are just sending commands to the BP and then dropping into bridge mode on the same uart. Requires user to press the BP button during the flash Signed-off-by: Kieran Levin --- scripts/flash_ec_buspirate.sh | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 scripts/flash_ec_buspirate.sh diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh new file mode 100755 index 0000000..f1f11a0 --- /dev/null +++ b/scripts/flash_ec_buspirate.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +DEVICE=${DEVICE:-"/dev/serial/by-id/usb-Bus_Pirate_Bus_Pirate_5"} +CTRLUART=(${DEVICE}*-if00) +FLASHUART=$(basename $(readlink ${DEVICE}*-if00)) + +if [ $# -eq 0 ]; then + #no argument, try default locations + search_paths=("${HOME}/software/ec-lotus/src/platform/ec/build/zephyr/azalea/output"\ + "${HOME}/chromiumos/src/platform/ec/build/zephyr/azalea/output") + + for search in ${search_paths[@]} + do + if [ -d $search ] + then + echo "${search} exists" + FLASH_SRC="${search}/ec.bin" + MONITOR="${search}/npcx_monitor.bin" + fi + done +else + #allow specifying a file as argument + FLASH_SRC="$1/ec.bin" + MONITOR="$1/npcx_monitor.bin" +fi +echo "USING ${FLASH_SRC} to flash EC" + +#clear any invalid commands from uart buffer +echo -e "n\r\n" > ${CTRLUART} +#put ec into reset +echo -e "\r\na 2\r\n" > ${CTRLUART} +#read INPUT < ${CTRLUART} +sleep 1 + +#enable 10k external pulldown on UART RX wired to pin 20 +echo -e "\r\na 6\r\n" > ${CTRLUART} +sleep 1 + +# take out of reset + echo -e "\r\n@ 2\r\n" > ${CTRLUART} +sleep 1 + +echo -e "\r\nbridge\r\n" > ${CTRLUART} + +sleep 1 + +#### DO FLASH +echo "Using NUVOTON Tool ./uartupdatetool" +./uartupdatetool --port ${FLASHUART} --opr wr --addr 0x200c3020 --file ${MONITOR} +./uartupdatetool --port ${FLASHUART} --opr wr --auto --addr 0x0000 --file ${FLASH_SRC} + +read -p "Press button on buspirate" userinput + +#### TAKE OUT OF RESET + +#put ec into reset +echo -e "\r\na 2\r\n" > ${CTRLUART} +#read INPUT < ${CTRLUART} +sleep 1 + +#disable 10k external pulldown on UART RX wired to pin 20 +echo -e "\r\n@ 6\r\n" > ${CTRLUART} +sleep 1 + + +# take out of reset +echo -e "\r\n@ 2\r\n" > ${CTRLUART} From 506e533dee81bb3e412dedb2f8099fc7fd5aa03d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 13 Oct 2024 14:38:56 +0800 Subject: [PATCH 2/7] Update scripts/flash_ec_buspirate.sh --- scripts/flash_ec_buspirate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh index f1f11a0..2b9b704 100755 --- a/scripts/flash_ec_buspirate.sh +++ b/scripts/flash_ec_buspirate.sh @@ -27,7 +27,7 @@ echo "USING ${FLASH_SRC} to flash EC" #clear any invalid commands from uart buffer echo -e "n\r\n" > ${CTRLUART} -#put ec into reset +# Put EC into reset by pulling nRESETI_R (pin 2 on buspirate) low echo -e "\r\na 2\r\n" > ${CTRLUART} #read INPUT < ${CTRLUART} sleep 1 From dbc99be0b7263e89f3cae3a3c5373e62f4ef5c4e Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 13 Oct 2024 14:39:02 +0800 Subject: [PATCH 3/7] Update scripts/flash_ec_buspirate.sh --- scripts/flash_ec_buspirate.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh index 2b9b704..201bace 100755 --- a/scripts/flash_ec_buspirate.sh +++ b/scripts/flash_ec_buspirate.sh @@ -40,6 +40,9 @@ sleep 1 echo -e "\r\n@ 2\r\n" > ${CTRLUART} sleep 1 +# Bridge UART via the BusPirate +# This turns the current UART consle to the bus pirate into a bridge to the EC +# After we're done, to exit, you have press the buspirate button echo -e "\r\nbridge\r\n" > ${CTRLUART} sleep 1 From 50f03fe8bed8cf10dc82718bf589406875ea1065 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 13 Oct 2024 14:39:08 +0800 Subject: [PATCH 4/7] Update scripts/flash_ec_buspirate.sh --- scripts/flash_ec_buspirate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh index 201bace..fdb6e50 100755 --- a/scripts/flash_ec_buspirate.sh +++ b/scripts/flash_ec_buspirate.sh @@ -61,7 +61,7 @@ echo -e "\r\na 2\r\n" > ${CTRLUART} #read INPUT < ${CTRLUART} sleep 1 -#disable 10k external pulldown on UART RX wired to pin 20 +# Enable BusPirate's 10k internal pulldown on UART RX wired to IO6 echo -e "\r\n@ 6\r\n" > ${CTRLUART} sleep 1 From 69477b8b100757747457e9b9655cce86964dda86 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 13 Oct 2024 14:39:14 +0800 Subject: [PATCH 5/7] Update scripts/flash_ec_buspirate.sh --- scripts/flash_ec_buspirate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh index fdb6e50..79dbdbd 100755 --- a/scripts/flash_ec_buspirate.sh +++ b/scripts/flash_ec_buspirate.sh @@ -36,7 +36,7 @@ sleep 1 echo -e "\r\na 6\r\n" > ${CTRLUART} sleep 1 -# take out of reset +# Take out of reset, set pin 2 (connected to nRESETI_R) as a pullup input on the buspirate echo -e "\r\n@ 2\r\n" > ${CTRLUART} sleep 1 From f794dfaa73dec9b55d5e41e52b5546696556c94a Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 13 Oct 2024 14:39:19 +0800 Subject: [PATCH 6/7] Update scripts/flash_ec_buspirate.sh --- scripts/flash_ec_buspirate.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh index 79dbdbd..962ab03 100755 --- a/scripts/flash_ec_buspirate.sh +++ b/scripts/flash_ec_buspirate.sh @@ -1,4 +1,18 @@ -#!/bin/bash +#!/usr/bin/env bash +# +# Wiring: +# | JECDB | BusPirate 5 | +# | 1 EC_DEBUG_VCC | VOUT/VREF | +# | 2 UART_0_CRXD_DTXD | | +# | 3 JTAG_TMS | | +# | 4 JTAG_CLK | | +# | 5 JTAG_DTO | | +# | 6 EC_UART0_TX | IO5 | +# | 7 EC_UART0_RX | IO4 | +# | 8 UART_0_CTXD_DRXD | | +# | 9 nRESETI_R | IO2 | +# | 10 GND | GND | + DEVICE=${DEVICE:-"/dev/serial/by-id/usb-Bus_Pirate_Bus_Pirate_5"} CTRLUART=(${DEVICE}*-if00) From e985359b3dcd3a5b1c6ad4ff95b8c22775cebeb3 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 13 Oct 2024 15:13:13 +0800 Subject: [PATCH 7/7] Update scripts/flash_ec_buspirate.sh --- scripts/flash_ec_buspirate.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/flash_ec_buspirate.sh b/scripts/flash_ec_buspirate.sh index 962ab03..28cd94e 100755 --- a/scripts/flash_ec_buspirate.sh +++ b/scripts/flash_ec_buspirate.sh @@ -46,7 +46,8 @@ echo -e "\r\na 2\r\n" > ${CTRLUART} #read INPUT < ${CTRLUART} sleep 1 -#enable 10k external pulldown on UART RX wired to pin 20 +# Enable BusPirate's 10k internal pulldown on UART RX wired to IO6 +# This switches the Nuvoton EC's UART from console mode into UUT update mode echo -e "\r\na 6\r\n" > ${CTRLUART} sleep 1