|
| 1 | +# script for automating the use of labgrid to write a new image to a raspberry pi |
| 2 | +# using rpiboot. |
| 3 | +# input place to write new image to and path to image. |
| 4 | + |
| 5 | +import os |
| 6 | +import sys |
| 7 | +from time import sleep |
| 8 | +from labgrid import Environment |
| 9 | +from labgrid.driver import USBStorageDriver |
| 10 | +from labgrid.driver import DigitalOutputPowerDriver |
| 11 | +from labgrid.driver import DigitalOutputResetDriver |
| 12 | +from labgrid.driver import RpibootDriver |
| 13 | + |
| 14 | +image_path = sys.argv[1] |
| 15 | + |
| 16 | +# if there is a 3. argument set is as the place labgrid should use. |
| 17 | +# if not set the current value for LG_PLACE is used. |
| 18 | +if len(sys.argv) >= 3: |
| 19 | + os.environ["LG_PLACE"] = sys.argv[2] |
| 20 | + |
| 21 | +if os.environ.get("LG_PLACE", None) is None: |
| 22 | + print("No place to write image to given, set one with LG_PLACE or giving it as an extra argument") |
| 23 | + exit(1) |
| 24 | + |
| 25 | +config_path = os.path.dirname(__file__) + "client.yaml" |
| 26 | +env = Environment(config_path) |
| 27 | +t = env.get_target("main") |
| 28 | + |
| 29 | +power = t.get_driver("DigitalOutputPowerDriver") |
| 30 | +t.activate(power) |
| 31 | +gpio_reset = t.get_driver("GpioDigitalOutputDriver", name="reset-driver") |
| 32 | +t.activate(gpio_reset) |
| 33 | + |
| 34 | +# put panel into usbboot mode. |
| 35 | +power.off() |
| 36 | +gpio_reset.set(True) |
| 37 | +sleep(1) |
| 38 | +power.on() |
| 39 | + |
| 40 | +# use rpiboot to enable MSD mode |
| 41 | +rpiboot = RpibootDriver(t, name=None) |
| 42 | +t.activate(rpiboot) |
| 43 | +rpiboot.enable() |
| 44 | + |
| 45 | +# wait a little bit to make sure the MSD is available. |
| 46 | +sleep(5) |
| 47 | + |
| 48 | +# write new image to panel |
| 49 | +storage = USBStorageDriver(t, name=None) |
| 50 | +t.activate(storage) |
| 51 | +storage.write_image(filename=image_path) |
| 52 | + |
| 53 | +# switch panel back into normal bootmode. |
| 54 | +power.off() |
| 55 | +gpio_reset.set(False) |
| 56 | +sleep(1) |
| 57 | +power.on() |
0 commit comments