Skip to content

src/: Add handling of programmer.binary configuration #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions osfv_cli/src/osfv/libs/rte.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class RTE(rtectrl):
PROGRAMMER_RTE = "linux_spi:dev=/dev/spidev1.0,spispeed=16000"
PROGRAMMER_CH341A = "ch341a_spi"
PROGRAMMER_DEDIPROG = "dediprog"
FLASHROM_CMD = "flashrom -p {programmer} {args}"
PROGRAMMER_BINARY_FLASHROM = "flashrom"
PROGRAMMER_BINARY_FLASHPROG = "flashprog"
SUPPORTED_PROGRAMMER_BINARIES = [
self.PROGRAMMER_BINARY_FLASHROM,
self.PROGRAMMER_BINARY_FLASHPROG,
]
FLASH_CMD = "{programmer_binary} -p {programmer} {args}"

def __init__(self, rte_ip, dut_model, sonoff):
self.rte_ip = rte_ip
Expand Down Expand Up @@ -348,8 +354,31 @@ def flash_cmd(self, args, read_file=None, write_file=None):
else:
flashrom_programmer = self.PROGRAMMER_RTE

command = self.FLASHROM_CMD.format(
programmer=flashrom_programmer, args=args
programmer_binary = self.dut_data["programmer"].get("binary", None)
if not programmer_binary:
print(
"[WARNING] [programmer]:[binary] is not set!"
f"Using the default value of {self.PROGRAMMER_BINARY_FLASHROM}"
)
programmer_binary = self.PROGRAMMER_BINARY_FLASHROM
elif programmer_binary not in self.SUPPORTED_PROGRAMMER_BINARIES:
print(
f"[ERROR] [programmer]:[binary] is set to an unsupported value '{programmer_binary}'"
)
print(
f"Supported values are: {self.SUPPORTED_PROGRAMMER_BINARIES}"
)
print(
"Unable to proceed. Please check the configuration file and try again."
)
raise UnsupportedProgrammerBinaryError(
f"Unable to use '{programmer_binary}' as a programmer binary"
)

command = self.FLASH_CMD.format(
programmer_binary=programmer_binary,
programmer=flashrom_programmer,
args=args,
)
print(f"Executing command: {command}")

Expand Down Expand Up @@ -474,3 +503,7 @@ class SPIWrongVoltage(Exception):

class SonoffNotFound(Exception):
pass


class UnsupportedProgrammerBinaryError(Exception):
pass