scripts/proto2-power-cycle: Disable firmware write-protect
For most of our development, we want firmware write-protect off. Added a
flag to restore the old behavior of having it on.
BUG=b:202683061
TEST=./scripts/proto2-power-cycle; hps --mcp status
TEST=./scripts/proto2-power-cycle --write-protect; hps --mcp status
Change-Id: I2b7ad3c4c27d152768cbf656abe48bf2bfd414aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/hps-firmware/+/3233490
Reviewed-by: Jakub Młynarczyk <jakubm@chromium.org>
Commit-Queue: David Lattimore <dml@chromium.org>
Tested-by: David Lattimore <dml@chromium.org>
diff --git a/scripts/proto2-power-cycle.py b/scripts/proto2-power-cycle.py
index 241e852..53ab645 100755
--- a/scripts/proto2-power-cycle.py
+++ b/scripts/proto2-power-cycle.py
@@ -10,13 +10,25 @@
from pyftdi.gpio import GpioAsyncController
import time
+import argparse
+
+parser = argparse.ArgumentParser(description='HPS dev board controller')
+parser.add_argument(
+ '--write-protect', action='store_true',
+ help='Enable write protect.')
+args = parser.parse_args()
gpio = GpioAsyncController()
-# Set GPIO pin 6 (hps power enable) as an output, then make sure it's pulled
-# low (power off)
-gpio.configure('ftdi://ftdi:ft4232/1', direction=0x40)
-gpio.write(0)
+power_pin = 1 << 6
+write_protect_pin = 1 << 4
+direction = power_pin
+# Both power enable and firmware write-protect have pull-up resistors, so we set
+# them low by making the pins outputs and pulling them low, but we set them high
+# by making them inputs and letting the pull-ups do their work.
+if not args.write_protect:
+ direction |= write_protect_pin
+gpio.configure('ftdi://ftdi:ft4232/1', direction=direction, initial=0)
time.sleep(0.1)
# Set GPIO pin 6 back to being an input. It'll get pulled high by the pull-up
# resistor (power on).
-gpio.set_direction(0x40, 0)
+gpio.set_direction(power_pin, 0)