3 # Copyright © 2020 Google LLC
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 from serial_buffer
import SerialBuffer
30 def __init__(self
, cpu
, ec
):
31 self
.ec_ser
= SerialBuffer(ec
, "artifacts/serial-ec.txt", "R SERIAL-EC> ")
32 self
.cpu_ser
= SerialBuffer(cpu
, "artifacts/serial.txt", "R SERIAL-CPU> ")
34 def ec_write(self
, s
):
35 print("W SERIAL-EC> %s" % s
)
36 self
.ec_ser
.serial
.write(s
.encode())
38 def cpu_write(self
, s
):
39 print("W SERIAL-CPU> %s" % s
)
40 self
.cpu_ser
.serial
.write(s
.encode())
43 # Flush any partial commands in the EC's prompt, then ask for a reboot.
45 self
.ec_write("reboot\n")
47 # This is emitted right when the bootloader pauses to check for input.
48 # Emit a ^N character to request network boot, because we don't have a
49 # direct-to-netboot firmware on cheza.
50 for line
in self
.cpu_ser
.lines():
51 if re
.match("load_archive: loading locale_en.bin", line
):
52 self
.cpu_write("\016")
56 for line
in self
.cpu_ser
.lines():
57 if re
.match("---. end Kernel panic", line
):
60 # The Cheza boards have issues with failing to bring up power to
61 # the system sometimes, possibly dependent on ambient temperature
63 if re
.match("POWER_GOOD not seen in time", line
):
66 # The Cheza firmware seems to occasionally get stuck looping in
67 # this error state during TFTP booting, possibly based on amount of
68 # network traffic around it, but it'll usually recover after a
70 if re
.match("R8152: Bulk read error 0xffffffbf", line
):
72 if tftp_failures
>= 100:
75 result
= re
.match("bare-metal result: (\S*)", line
)
77 if result
.group(1) == "pass":
82 print("Reached the end of the CPU serial log without finding a result")
86 parser
= argparse
.ArgumentParser()
87 parser
.add_argument('--cpu', type=str, help='CPU Serial device', required
=True)
88 parser
.add_argument('--ec', type=str, help='EC Serial device', required
=True)
89 args
= parser
.parse_args()
91 servo
= CrosServoRun(args
.cpu
, args
.ec
)
98 # power down the CPU on the device
99 servo
.ec_write("power off\n")
103 if __name__
== '__main__':