Skip to content

Commit d60f357

Browse files
committed
examples: add RpibootDriver example
1 parent 4c0f8f8 commit d60f357

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

examples/rpiboot/client.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
targets:
2+
main:
3+
resources:
4+
- RemotePlace:
5+
name: !template '$LG_PLACE'
6+
drivers:
7+
- GpioDigitalOutputDriver:
8+
name: 'power-driver'
9+
bindings:
10+
gpio: 'GpioPower'
11+
- GpioDigitalOutputDriver:
12+
name: 'reset-driver'
13+
bindings:
14+
gpio: 'GpioReset'
15+
- DigitalOutputPowerDriver:
16+
delay: 2.0
17+
bindings:
18+
output: 'power-driver'
19+
- DigitalOutputResetDriver:
20+
delay: 2.0
21+
bindings:
22+
output: 'reset-driver'
23+
- SerialDriver: {}
24+
- SSHDriver: {}
25+
- ShellDriver:
26+
login_prompt: '[\w-]+ login: '
27+
username: root
28+
password: root
29+
prompt: 'root@[\w-]+:[^ ]+# '
30+
- DUTStrategy: {}

examples/rpiboot/exporter.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
rpi-cm4-101-panel:
2+
location: 101 display panel on desk
3+
USBSerialPort:
4+
match:
5+
ID_SERIAL: "FTDI_USB_Serial_Converter_FTBZ30UM"
6+
speed: 115200
7+
NetworkService:
8+
address: '192.168.1.123'
9+
port: 22
10+
username: root
11+
password: root
12+
USBMassStorage:
13+
match:
14+
ID_SERIAL: 'mmcblk0_Raspberry_Pi_multi-function_USB_device_10000000124e610f-0:0'
15+
RpibootDevice:
16+
match:
17+
ID_SERIAL: 'Broadcom_BCM2711_Boot_124e610f'
18+
# gpio pins are set to control relay hat from waveshare
19+
# https://www.waveshare.com/product/rpi-relay-board.htm
20+
GpioPower:
21+
cls: 'SysfsGPIO'
22+
index: 533
23+
GpioReset:
24+
cls: 'SysfsGPIO'
25+
index: 532

examples/rpiboot/write-image.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
35+
# put panel into usbboot mode.
36+
power.off()
37+
gpio_reset.set(True)
38+
sleep(1)
39+
power.on()
40+
41+
# use rpiboot to enable MSD mode
42+
rpiboot = RpibootDriver(t, name=None)
43+
t.activate(rpiboot)
44+
rpiboot.enable()
45+
46+
# wait a little bit to make sure the MSD is available.
47+
sleep(5)
48+
49+
# write new image to panel
50+
storage = USBStorageDriver(t, name=None)
51+
t.activate(storage)
52+
storage.write_image(filename=image_path)
53+
54+
# switch panel back into normal bootmode.
55+
power.off()
56+
gpio_reset.set(False)
57+
sleep(1)
58+
power.on()

0 commit comments

Comments
 (0)