Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
sjg20 committed Jun 22, 2024
1 parent 241d750 commit a58d63b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 46 deletions.
3 changes: 3 additions & 0 deletions contrib/u-boot/lg-env
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export LG_CROSSBAR=ws://kea:20408/ws
export LG_ENV=/vid/software/devel/ubtest/lab/env_rpi_try.cfg
export UB_TEST_HOOKS=/vid/software/devel/ubtest/u-boot-test-hooks
export LG_CONSOLE=internal

# New
export LG_COORDINATOR=kea:20408
77 changes: 48 additions & 29 deletions labgrid/driver/qemudriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):
Args:
qemu_bin (str): reference to the tools key for the QEMU binary
machine (str): QEMU machine type
cpu (str): QEMU cpu type
memory (str): QEMU memory size (ends with M or G)
extra_args (str): extra QEMU arguments, they are passed directly to the QEMU binary
extra_args (str): optional, extra QEMU arguments, they are passed
directly to the QEMU binary
cpu (str): optional, QEMU cpu type
machine (str): optional, QEMU machine type
boot_args (str): optional, additional kernel boot argument
kernel (str): optional, reference to the images key for the kernel
disk (str): optional, reference to the images key for the disk image
Expand All @@ -51,10 +52,16 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):
nic (str): optional, configuration string to pass to QEMU to create a network interface
"""
qemu_bin = attr.ib(validator=attr.validators.instance_of(str))
machine = attr.ib(validator=attr.validators.instance_of(str))
cpu = attr.ib(validator=attr.validators.instance_of(str))
memory = attr.ib(validator=attr.validators.instance_of(str))
extra_args = attr.ib(validator=attr.validators.instance_of(str))
extra_args = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
cpu = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
machine = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
boot_args = attr.ib(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)))
Expand Down Expand Up @@ -98,6 +105,8 @@ def __attrs_post_init__(self):
self._tempdir = None
self._socket = None
self._clientsocket = None
self._bios_fname = None
self._sockpath = None
self._forwarded_ports = {}
atexit.register(self._atexit)

Expand All @@ -122,6 +131,9 @@ def get_qemu_version(self, qemu_bin):

return (int(m.group('major')), int(m.group('minor')), int(m.group('micro')))

def set_bios(self, bios):
self._bios_fname = bios

def get_qemu_base_args(self):
"""Returns the base command line used for Qemu without the options
related to QMP. These options can be used to start an interactive
Expand Down Expand Up @@ -156,7 +168,7 @@ def get_qemu_base_args(self):
cmd.append(
f"if=sd,format={disk_format},file={disk_path},id=mmc0{disk_opts}")
boot_args.append("root=/dev/mmcblk0p1 rootfstype=ext4 rootwait")
elif self.machine in ["pc", "q35", "virt"]:
elif self.machine in ["pc", "q35", "virt", None]:
cmd.append("-drive")
cmd.append(
f"if=virtio,format={disk_format},file={disk_path}{disk_opts}")
Expand Down Expand Up @@ -184,15 +196,20 @@ def get_qemu_base_args(self):
cmd.append("-bios")
cmd.append(
self.target.env.config.get_image_path(self.bios))

if "-append" in shlex.split(self.extra_args):
raise ExecutionError("-append in extra_args not allowed, use boot_args instead")

cmd.extend(shlex.split(self.extra_args))
cmd.append("-machine")
cmd.append(self.machine)
cmd.append("-cpu")
cmd.append(self.cpu)
elif self._bios_fname:
cmd.append("-bios")
cmd.append(self._bios_fname)
if self.extra_args:
if "-append" in shlex.split(self.extra_args):
raise ExecutionError("-append in extra_args not allowed, use boot_args instead")

cmd.extend(shlex.split(self.extra_args))
if self.machine:
cmd.append("-machine")
cmd.append(self.machine)
if self.cpu:
cmd.append("-cpu")
cmd.append(self.cpu)
cmd.append("-m")
cmd.append(self.memory)
if self.display == "none":
Expand Down Expand Up @@ -226,22 +243,11 @@ def get_qemu_base_args(self):

def on_activate(self):
self._tempdir = tempfile.mkdtemp(prefix="labgrid-qemu-tmp-")
sockpath = f"{self._tempdir}/serialrw"
self._sockpath = f"{self._tempdir}/serialrw"
self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self._socket.bind(sockpath)
self._socket.bind(self._sockpath)
self._socket.listen(0)

self._cmd = self.get_qemu_base_args()

self._cmd.append("-S")
self._cmd.append("-qmp")
self._cmd.append("stdio")

self._cmd.append("-chardev")
self._cmd.append(f"socket,id=serialsocket,path={sockpath}")
self._cmd.append("-serial")
self._cmd.append("chardev:serialsocket")

def on_deactivate(self):
if self.status:
self.off()
Expand All @@ -250,6 +256,7 @@ def on_deactivate(self):
self._clientsocket = None
self._socket.close()
self._socket = None
self._sockpath = None
shutil.rmtree(self._tempdir)

@step()
Expand All @@ -258,7 +265,19 @@ def on(self):
afterwards start the emulator using a QMP Command"""
if self.status:
return
self._cmd = self.get_qemu_base_args()

self._cmd.append("-S")
self._cmd.append("-qmp")
self._cmd.append("stdio")

self._cmd.append("-chardev")
self._cmd.append(f"socket,id=serialsocket,path={self._sockpath}")
self._cmd.append("-serial")
self._cmd.append("chardev:serialsocket")

self.logger.debug("Starting with: %s", self._cmd)
print('self._cmd', self._cmd)
self._child = subprocess.Popen(
self._cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

Expand Down
5 changes: 4 additions & 1 deletion labgrid/driver/ubootwriterdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from labgrid.driver.common import Driver
from labgrid.factory import target_factory
from labgrid.step import step
from ..util.managedfile import ManagedFile

@target_factory.reg_driver
@attr.s(eq=False)
Expand All @@ -25,6 +26,7 @@ class UBootWriterDriver(Driver):
'storage': {'USBStorageDriver', None},
'sdmux': {'USBSDWireDriver', None},
'emul': {'SFEmulatorDriver', None},
"qemu": {"QEMUDriver", None},
}

def __attrs_post_init__(self):
Expand Down Expand Up @@ -89,7 +91,8 @@ def write(self, image_dir):
self.storage.write_image(self.tzsw, seek=2111)
self.storage.write_image(image, seek=63)
elif self.method == 'qemu':
pass
rom = os.path.join(image_dir, 'u-boot.rom')
self.qemu.set_bios(rom)
else:
raise ValueError(f'Unknown writing method {self.method}')
if self.storage:
Expand Down
6 changes: 4 additions & 2 deletions labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ClientSession:
prog = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(str)))
args = attr.ib(default=None, validator=attr.validators.optional(attr.validators.instance_of(argparse.Namespace)))
monitor = attr.ib(default=False, validator=attr.validators.instance_of(bool))
var_dict = attr.ib(default={}, validator=attr.validators.instance_of(dict))

def gethostname(self):
return os.environ.get("LG_HOSTNAME", gethostname())
Expand All @@ -88,7 +89,7 @@ def __attrs_post_init__(self):
"""Actions which are executed if a connection is successfully opened."""
self.stopping = asyncio.Event()

self.var_dict = self.config.extra.get('var_dict', None)
#self.var_dict = self.config.extra.get('var_dict', None)

self.channel = grpc.aio.insecure_channel(self.url)
self.stub = labgrid_coordinator_pb2_grpc.CoordinatorStub(self.channel)
Expand Down Expand Up @@ -666,7 +667,7 @@ async def acquire(self):
f"place {place.name} is already acquired by {place.acquired}"
) # FIXME: done in coordinator?

if not getattr(self.args, 'allow_unmatched', False) or not self.args.allow_unmatched:
if not self.args.allow_unmatched:
self.check_matches(place)

request = labgrid_coordinator_pb2.AcquirePlaceRequest(placename=place.name)
Expand Down Expand Up @@ -2101,6 +2102,7 @@ def main():
if args.acquire:
place = session.get_place(args.place)
if not place.acquired:
args.allow_unmatched = True
coro = session.acquire()
session.loop.run_until_complete(coro)
auto_release = True
Expand Down
3 changes: 1 addition & 2 deletions labgrid/remote/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def update_from_pb2(self, place_pb2):
place = Place.from_pb2(place_pb2)
fields = attr.fields_dict(type(self))
for k, v in place.asdict().items():
print(f"{k}: {v}")
#print(f"{k}: {v}")
assert k in fields
if k == "name":
# we cannot rename places
Expand Down Expand Up @@ -495,7 +495,6 @@ async def queue_as_aiter(q):
return
yield item
q.task_done()
logging.debug("sent message %s", item)
except Exception:
logging.exception("error in queue_as_aiter")
raise
7 changes: 4 additions & 3 deletions labgrid/remote/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def __init__(self, config) -> None:
self.out_queue = asyncio.Queue()
self.pump_task = None

self.verbose = self.config.extra['verbose']
self.verbose = config['verbose']
self.poll_task = None
self.resource_count = 0

Expand Down Expand Up @@ -1070,7 +1070,8 @@ async def update_resource(self, group_name, resource_name):
msg.resource.path.group_name = group_name
msg.resource.path.resource_name = resource_name
self.out_queue.put_nowait(msg)
logging.info("queued update for resource %s/%s", group_name, resource_name)
logging.debug("queued update for resource %s/%s", group_name,
resource_name)


async def amain(config) -> bool:
Expand Down Expand Up @@ -1133,7 +1134,7 @@ def main():
"resources": args.resources,
"coordinator": args.coordinator,
"isolated": args.isolated,
'verbose': args.debug,
"verbose": args.debug,
}

print(f"exporter name: {config['name']}")
Expand Down
14 changes: 8 additions & 6 deletions labgrid/strategy/ubootstrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UBootStrategy(Strategy):
"console": "ConsoleProtocol",
"uboot": "UBootDriver",
"shell": "ShellDriver",
"reset": "ResetProtocol",
"reset": {"ResetProtocol", None},
}

status = attr.ib(default=Status.unknown)
Expand Down Expand Up @@ -111,11 +111,12 @@ def start(self):
writer.prepare_boot()
if not self.use_send():
self.target.activate(self.console)
self.target.activate(self.reset)
if self.reset:
self.target.activate(self.reset)

# Hold in reset across the power cycle, to avoid booting the
# board twice
self.reset.set_reset_enable(True)
# Hold in reset across the power cycle, to avoid booting the
# board twice
self.reset.set_reset_enable(True)
if self.reset != self.power:
self.power.cycle()

Expand All @@ -124,7 +125,8 @@ def start(self):
# dropped. However, this doesn't seem to work:
# self.target.await_resources([self.console.port], 10.0)
# self.target.activate(self.console) # for zynq_zybo
self.reset.set_reset_enable(False)
if self.reset:
self.reset.set_reset_enable(False)

def transition(self, status):
if not isinstance(status, Status):
Expand Down
11 changes: 8 additions & 3 deletions labgrid/util/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ async def run(serial, log_fd, listen_only):
data = serial.read(size=BUF_SIZE, timeout=0.001)
if data:
activity = True
#if b'\e' in data:
#print('size', size)
#pos = data.pos(b'e')
#data = data[:pos] + data[pos + 2:]
sys.stdout.buffer.write(data)
sys.stdout.buffer.flush()
if log_fd:
Expand All @@ -85,7 +89,7 @@ async def run(serial, log_fd, listen_only):

to_serial += data

if to_serial and time.monotonic() > next_serial:
if to_serial and txdelay is not None and time.monotonic() > next_serial:
serial._write(to_serial[:1])
to_serial = to_serial[1:]
next_serial += txdelay
Expand All @@ -101,7 +105,8 @@ async def run(serial, log_fd, listen_only):

async def internal(serial, logfile, listen_only):
try:
if not listen_only:
old = None
if not listen_only and os.isatty(sys.stdout.fileno()):
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
Expand All @@ -118,7 +123,7 @@ async def internal(serial, logfile, listen_only):
await run(serial, log_fd, listen_only)

finally:
if not listen_only:
if old:
termios.tcsetattr(fd, termios.TCSAFLUSH, old)
if log_fd:
log_fd.close()

0 comments on commit a58d63b

Please sign in to comment.