From 315a968ae1f4fdbdcbbd89335ece4c30f55500fa Mon Sep 17 00:00:00 2001 From: Perry Melange Date: Fri, 28 Feb 2025 11:41:47 +0100 Subject: [PATCH] Barebox/UBoot/SmallUBootDriver: handle hex arguements properly Checks to see if the interrupt string starts with \x and when that is the case, converts the remained of the string to a bytearray before sending the interrupt to the boot loader. fixes #1622 Signed-off-by: Perry Melange --- labgrid/driver/bareboxdriver.py | 8 +++++++- labgrid/driver/smallubootdriver.py | 12 ++++++++++-- labgrid/driver/ubootdriver.py | 8 +++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/labgrid/driver/bareboxdriver.py b/labgrid/driver/bareboxdriver.py index 0aeb19d67..41f700b97 100644 --- a/labgrid/driver/bareboxdriver.py +++ b/labgrid/driver/bareboxdriver.py @@ -164,7 +164,13 @@ def _await_prompt(self): elif index == 1: # we need to interrupt autoboot - self.console.write(self.interrupt.encode('ASCII')) + interrupt = self.interrupt.encode('ASCII') + if self.interrupt.startswith('\\x'): + try: + interrupt = bytearray.fromhex(self.interrupt[2:]) + except ValueError: + pass + self.console.write(interrupt) elif index == 2: # we need to enter the password diff --git a/labgrid/driver/smallubootdriver.py b/labgrid/driver/smallubootdriver.py index 98327ab53..de4331deb 100644 --- a/labgrid/driver/smallubootdriver.py +++ b/labgrid/driver/smallubootdriver.py @@ -61,10 +61,18 @@ def _await_prompt(self): # wait for boot expression. Afterwards enter secret self.console.expect(self.boot_expression, timeout=self.login_timeout) + + secret = self.boot_secret.encode('ASCII') + if self.boot_secret.startswith('\\x'): + try: + secret = bytearray.fromhex(self.boot_secret[2:]) + except ValueError: + pass + if self.boot_secret_nolf: - self.console.write(self.boot_secret.encode('ASCII')) + self.console.write(secret) else: - self.console.sendline(self.boot_secret) + self.console.sendline(secret) self._status = 1 # wait until UBoot has reached it's prompt diff --git a/labgrid/driver/ubootdriver.py b/labgrid/driver/ubootdriver.py index cc1cd0d4b..c4c9d6501 100644 --- a/labgrid/driver/ubootdriver.py +++ b/labgrid/driver/ubootdriver.py @@ -163,7 +163,13 @@ def _await_prompt(self): break elif index == 1: - self.console.write(self.interrupt.encode('ASCII')) + interrupt = self.interrupt.encode('ASCII') + if self.interrupt.startswith('\\x'): + try: + interrupt = bytearray.fromhex(self.interrupt[2:]) + except ValueError: + pass + self.console.write(interrupt) elif index == 2: if not self.password: