sanitycheck: support pre/post flash scripts

This is needed when a board needs to be reset using an external commands
or tools that are not part of the flash command. For example, power
reset or by poking a GPIO header on the board using external wiring.

add post_flash/pre_flash to the platform section in the hardware map.
For example:

- available: true
  connected: true
  id: OSHW000032254e4500128002ab98002784d1000097969900
  platform: reel_board
  post_script: /tmp/post_flash.sh
  pre_script: /tmp/pre_flash.sh
  product: DAPLink CMSIS-DAP
  runner: pyocd
  serial: /dev/ttyACM11

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-12-19 11:59:54 -05:00
commit fc85ff052f

View file

@ -759,6 +759,21 @@ class DeviceHandler(Handler):
read_pipe, write_pipe = os.pipe() read_pipe, write_pipe = os.pipe()
start_time = time.time() start_time = time.time()
pre_script = hardware.get('pre_script')
post_script = hardware.get('post_script')
if pre_script:
with subprocess.Popen(pre_script, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc:
try:
(stdout, stderr) = proc.communicate(timeout=30)
logger.debug(stdout.decode())
except subprocess.TimeoutExpired:
proc.kill()
(stdout, stderr) = proc.communicate()
logger.error("{} timed out".format(post_script))
t = threading.Thread(target=self.monitor_serial, daemon=True, t = threading.Thread(target=self.monitor_serial, daemon=True,
args=(ser, read_pipe, harness)) args=(ser, read_pipe, harness))
t.start() t.start()
@ -812,6 +827,17 @@ class DeviceHandler(Handler):
else: else:
self.set_state(out_state, handler_time) self.set_state(out_state, handler_time)
if post_script:
with subprocess.Popen(post_script, stderr=subprocess.PIPE, stdout=subprocess.PIPE) as proc:
try:
(stdout, stderr) = proc.communicate(timeout=30)
logger.debug(stdout.decode())
except subprocess.TimeoutExpired:
proc.kill()
(stdout, stderr) = proc.communicate()
logger.error("{} timed out".format(post_script))
self.make_device_available(serial_device) self.make_device_available(serial_device)
self.record(harness) self.record(harness)