diff options
author | Tom Hughes <tomhughes@chromium.org> | 2019-02-15 14:17:55 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-18 05:05:12 +0000 |
commit | c6526675656717e1bbbc6fa61b4e3d033909adf1 (patch) | |
tree | 6a09d4051872e9fbbd112f7083c13c590e928f17 /util | |
parent | 92b3e86b23b59ebec3e59132cae2b32288fcf1b4 (diff) | |
download | chrome-ec-c6526675656717e1bbbc6fa61b4e3d033909adf1.tar.gz |
flash_fp_mcu: add options for flash read/write protection
Defaults to disabling both read and write flash protection, but you can
disable either or both with these new commandline flags. This is
primarily going to be used for testing (e.g., RDP1 to RDP0 causing mass
erase).
BRANCH=nocturne,nami
BUG=chromium:890059
TEST=dut-control fw_wp_state:force_off
flash_fp_mcu /opt/google/biod/fw/nami_fp_v2.2.133-31dfe0b1a.bin
ectool --name=cros_fp version
TEST=flash_fp_mcu -r /tmp/rb.bin
diff /tmp/rb.in /opt/google/biod/fw/nami_fp_v2.2.133-31dfe0b1a.bin
TEST=dut-control fw_wp_state:force_on
ectool --name=cros_fp flashprotect enable
ectool --name=cros_fp reboot_ec
dut-control fw_wp_state:force_off
flash_fp_mcu -r --noremove_flash_read_protect /tmp/rb.bin
echo $? => 1
ectool --name=cros_fp version => works
flash_fp_mcu -r /tmp/rb-erase.bin
hexdump /tmp/rb-erase.bin => all 0xff
Change-Id: I42f7daf08dcf229a4980c88a24e6882be7c0e8d6
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1474743
Diffstat (limited to 'util')
-rw-r--r-- | util/flash_fp_mcu | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/util/flash_fp_mcu b/util/flash_fp_mcu index 6a23aa691c..76965470a9 100644 --- a/util/flash_fp_mcu +++ b/util/flash_fp_mcu @@ -6,6 +6,12 @@ . /usr/share/misc/shflags DEFINE_boolean 'read' "${FLAGS_FALSE}" 'Read instead of write' 'r' +# Both flash read and write protection are removed by default, but you +# can optionally enable them (for testing purposes). +DEFINE_boolean 'remove_flash_read_protect' "${FLAGS_TRUE}" \ + 'Remove flash read protection while performing command' 'U' +DEFINE_boolean 'remove_flash_write_protect' "${FLAGS_TRUE}" \ + 'Remove flash write protection while performing command' 'u' FLAGS_HELP="Usage: ${0} [flags] ec.bin" # Process commandline flags @@ -111,10 +117,20 @@ flash_fp_mcu_stm32() { local file="${5}" local spiid - local STM32MON_READ_FLAGS=" -U -u -p -s ${spidev} -r" - local STM32MON_WRITE_FLAGS="-U -u -p -s ${spidev} -e -w" + local STM32MON_READ_FLAGS=" -p -s ${spidev} -r" + local STM32MON_WRITE_FLAGS="-p -s ${spidev} -e -w" local stm32mon_flags="" + if [[ "${FLAGS_remove_flash_write_protect}" -eq "${FLAGS_TRUE}" ]]; then + STM32MON_READ_FLAGS=" -u ${STM32MON_READ_FLAGS}" + STM32MON_WRITE_FLAGS="-u ${STM32MON_WRITE_FLAGS}" + fi + + if [[ "${FLAGS_remove_flash_read_protect}" -eq "${FLAGS_TRUE}" ]]; then + STM32MON_READ_FLAGS=" -U ${STM32MON_READ_FLAGS}" + STM32MON_WRITE_FLAGS="-U ${STM32MON_WRITE_FLAGS}" + fi + if [[ "${FLAGS_read}" -eq "${FLAGS_TRUE}" ]]; then if [[ -e "${file}" ]]; then echo "Output file already exists: ${file}" @@ -168,7 +184,12 @@ flash_fp_mcu_stm32() { echo 1 > "/sys/class/gpio/gpio${gpio_nrst}/value" echo "in" > "/sys/class/gpio/gpio${gpio_nrst}/direction" - stm32mon ${stm32mon_flags} "${file}" + # Print out the actual underlying command we're running and run it + local cmd="stm32mon ${stm32mon_flags} ${file}" + echo "${cmd}" + ${cmd} + + local cmd_exit_status=$? # unload spidev echo "${spiid}" > /sys/bus/spi/drivers/spidev/unbind @@ -193,6 +214,11 @@ flash_fp_mcu_stm32() { if [[ -n "${gpio_pwren}" ]]; then echo "${gpio_pwren}" > /sys/class/gpio/unexport fi + + if [[ "${cmd_exit_status}" -ne 0 ]]; then + exit 1 + fi + # Test it ectool --name=cros_fp version } |