Skip to content

Commit

Permalink
feat: write MAC address in uEnv.txt
Browse files Browse the repository at this point in the history
Signed-off-by: Julia Pineda <[email protected]>
  • Loading branch information
jpineda3 committed Jul 21, 2023
1 parent 9f99014 commit 9130883
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nebula/resources/template_gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ board-config:
help: "Serial number of external IIO instrument connected to the carrier"
optional: True
netbox_field: devices.custom_fields.instr_serial
field_8:
name: hw-mac
default: 00:0a:35:05:ca:00
help: "Hardware MAC address of DUT carrier"
optional: True
netbox_field: devices.custom_fields.hw_mac
network-config:
field_1:
name: dutip
Expand Down
28 changes: 28 additions & 0 deletions nebula/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,33 @@ def set_static_ip(
except Exception as ex:
print(ex)

@task(
help={
"mac": "MAC Address to write in /boot/uEnv.txt",
"address": "UART device address (/dev/ttyACMO). If a yaml config exist it will override,"
+ " if no yaml file exists and no address provided auto is used",
"yamlfilename": "Path to yaml config file. Default: /etc/default/nebula",
"board_name": "Name of DUT design (Ex: zynq-zc706-adv7511-fmcdaq2). Require for multi-device config files",
},
)
def write_mac_uEnv(
c,
mac,
address="auto",
yamlfilename="/etc/default/nebula",
board_name=None,
):
"""Set Static IP address of board of DUT from UART connection"""
try:
u = nebula.uart(
address=address, yamlfilename=yamlfilename, board_name=board_name
)
u.print_to_console = False
u.write_mac_uEnv(mac)
del u
except Exception as ex:
print(ex)


@task(
help={
Expand Down Expand Up @@ -1167,6 +1194,7 @@ def update_boot_files_uart(
uart.add_task(get_ip)
uart.add_task(set_dhcp)
uart.add_task(set_static_ip)
uart.add_task(write_mac_uEnv)
uart.add_task(get_carriername)
uart.add_task(get_mezzanine)
uart.add_task(get_uart_log)
Expand Down
17 changes: 17 additions & 0 deletions nebula/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,23 @@ def set_ip_static(self, address, nic="eth0"):
self._read_for_time(period=1)
self.start_log(logappend=True)

def write_mac_uEnv(self, address):
restart = False
if self.listen_thread_run:
restart = True
self.stop_log()
# Check if we need to login to the console
if not self._check_for_login():
raise Exception("Console inaccessible due to login failure")
cmd = "sed -i 's/ethaddr=\([0-9A-Fa-f]\{2\}[:-]\)\{5\}[0-9A-Fa-f]\{2\}"
cmd += "//g' /boot/uEnv.txt; "
cmd += 'printf " ethaddr=' + address + '" >> /boot/uEnv.txt; '
cmd += "ex -s +'v/\\S/d' -cwq /boot/uEnv.txt"
self._write_data(cmd)
if restart:
self._read_for_time(period=1)
self.start_log(logappend=True)

def request_ip_dhcp(self, nic="eth0"):
restart = False
if self.listen_thread_run:
Expand Down

0 comments on commit 9130883

Please sign in to comment.