-
Notifications
You must be signed in to change notification settings - Fork 3
/
lxatacstrategy.py
196 lines (149 loc) · 5.79 KB
/
lxatacstrategy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import enum
import attr
from labgrid import step, target_factory
from labgrid.driver import ExecutionError
from labgrid.strategy import Strategy, StrategyError
# Possible state transitions:
#
# +--------+------------+----------+
# v v v |
# unknown -> off -1-> bootstrap -> barebox -> shell
#
# 1) Via bootstrap() but only once
class Status(enum.Enum):
unknown = 0
off = 1
bootstrap = 2
barebox = 3
shell = 4
@target_factory.reg_driver
@attr.s(eq=False)
class LXATACStrategy(Strategy):
"""
LXATACStrategy - Strategy to bootstrap the LAG LXATAC's rootfs and switch to barebox and shell.
"""
bindings = {
"dfu_mode": "DigitalOutputProtocol",
"httpprovider": "HTTPProviderDriver",
"power": "PowerProtocol",
"console": "ConsoleProtocol",
"dfu": "DFUDriver",
"fastboot": "AndroidFastbootDriver",
"barebox": "BareboxDriver",
"shell": "ShellDriver",
"network": "NetworkService",
"eet": {"LxatacEETDriver", None},
"ethmux": {"LXAIOBusPIODriver", None},
}
status = attr.ib(default=Status.unknown)
mmc_bootstrapped = attr.ib(default=False)
@property
def target_hostname(self):
fqdn = self.network.address
hostname = fqdn.split(".", maxsplit=1)[0] if "." in fqdn else fqdn
return hostname
def bootstrap(self):
self.transition(Status.off)
self.dfu_mode.set(True)
self.power.cycle()
self.target.activate(self.dfu)
# download tf-a to "FSBL"
tfa_img = self.target.env.config.get_image_path("tfa")
self.dfu.download(1, tfa_img)
# download emmc-boot-image to "Partition3"
mmc_boot_fip_img = self.target.env.config.get_image_path("mmc_boot_fip")
self.dfu.download(3, mmc_boot_fip_img)
self.dfu.detach(0)
self.target.deactivate(self.dfu)
self.target.activate(self.barebox)
self.target.activate(self.fastboot)
# write eMMC user partition
mmc_img = self.target.env.config.get_image_path("mmc")
self.fastboot.flash("mmc", mmc_img)
# write eMMC boot partition
mmc_boot_img = self.target.env.config.get_image_path("mmc_boot")
self.fastboot.flash("bbu-mmc", mmc_boot_img)
self.target.deactivate(self.fastboot)
self.target.deactivate(self.barebox)
self.dfu_mode.set(False)
self.mmc_bootstrapped = True
def wait_online(self):
self.shell.poll_until_success("ping -c1 _gateway", timeout=60.0)
# Also make sure we have accurate time, so that TLS works.
self.shell.run_check("chronyc waitsync", timeout=120.0)
def wait_system_ready(self):
try:
self.shell.run("systemctl is-system-running --wait", timeout=90)
except ExecutionError:
# gather information about failed units
self.shell.run("systemctl list-units --failed --no-legend --plain --no-pager")
raise
@step(args=["status"])
def transition(self, status, *, step):
if not isinstance(status, Status):
status = Status[status]
if status == Status.unknown:
raise StrategyError(f"can not transition to {status}")
elif status == self.status:
step.skip("nothing to do")
return
elif status == Status.off:
if self.status == Status.shell:
# Cleanly shut down the labgrid exporter to help the
# coordinator clean up stale resources.
self.shell.run("systemctl stop labgrid-exporter", timeout=90)
self.target.deactivate(self.barebox)
self.target.deactivate(self.shell)
self.target.deactivate(self.fastboot)
self.target.activate(self.power)
self.power.off()
# assure the board is not jumpered for dfu mode
self.target.activate(self.dfu_mode)
self.dfu_mode.set(False)
self.target.activate(self.console)
self.activate_optionals()
elif status == Status.bootstrap:
self.transition(Status.off)
if not self.mmc_bootstrapped:
self.bootstrap()
elif status == Status.barebox:
self.transition(Status.bootstrap)
# cycle power
self.power.cycle()
# interrupt barebox
self.target.activate(self.barebox)
self.barebox.run_check("global linux.bootargs.loglevel=loglevel=6")
elif status == Status.shell:
# transition to barebox
self.transition(Status.barebox)
self.barebox.boot("")
self.barebox.await_boot()
self.target.activate(self.shell)
self.wait_system_ready()
self.wait_online()
else:
raise StrategyError(f"no transition found from {self.status} to {status}")
self.status = status
@step(args=["status"])
def force(self, status):
if not isinstance(status, Status):
status = Status[status]
self.target.activate(self.power)
self.target.activate(self.console)
self.activate_optionals()
if status == Status.barebox:
self.target.activate(self.barebox)
elif status == Status.shell:
self.target.activate(self.shell)
elif status == Status.bootstrap:
pass
else:
raise StrategyError(f"can not force state {status}")
self.mmc_bootstrapped = True
self.status = status
def activate_optionals(self):
if self.eet:
self.target.activate(self.eet)
if self.ethmux:
self.target.activate(self.ethmux)
self.ethmux.set(True) # Connect upstream Ethernet to Lab network as default