Skip to content

Commit

Permalink
add network and manager support for DE10 Nano
Browse files Browse the repository at this point in the history
Signed-off-by: kimpaller <[email protected]>
  • Loading branch information
kimpaller committed Feb 15, 2024
1 parent 51b0fe1 commit 8d7ba23
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 42 deletions.
142 changes: 101 additions & 41 deletions nebula/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def get_status(self):
def load_boot_bin(self):
pass

def _check_files_exist(self, args):
def _check_files_exist(self, *args):
for filename in args:
if not filename:
continue
Expand Down Expand Up @@ -211,13 +211,24 @@ def recover_board( # noqa:C901
bootbinpath,
uimagepath,
devtreepath,
extlinux_path=None,
scr_path=None,
preloader_path=None,
fsblpath=None,
ubootpath=None,
sdcard=False,
):
"""Recover boards with UART, PDU, JTAG, USB-SD-Mux and Network if available"""
self._check_files_exist(
system_top_bit_path, bootbinpath, uimagepath, devtreepath
system_top_bit_path,
bootbinpath,
uimagepath,
devtreepath,
extlinux_path,
scr_path,
preloader_path,
fsblpath,
ubootpath,
)
try:
# Flush UART
Expand Down Expand Up @@ -268,6 +279,9 @@ def recover_board( # noqa:C901
bootbin_loc=bootbinpath,
kernel_loc=uimagepath,
devicetree_loc=devtreepath,
extlinux_loc=extlinux_path,
scr_loc=scr_path,
preloader_loc=preloader_path
)
# if devtreepath:
# self.usbsdmux.update_devicetree_for_mux(devtreepath)
Expand Down Expand Up @@ -403,11 +417,24 @@ def board_reboot_jtag_uart(

@_release_thread_lock
def board_reboot_uart_net_pdu(
self, system_top_bit_path, bootbinpath, uimagepath, devtreepath
self,
system_top_bit_path,
bootbinpath,
uimagepath,
devtreepath,
extlinux_path=None,
scr_path=None,
preloader_path=None
):
"""Manager when UART, PDU, and Network are available"""
self._check_files_exist(
system_top_bit_path, bootbinpath, uimagepath, devtreepath
system_top_bit_path,
bootbinpath,
uimagepath,
devtreepath,
extlinux_path,
scr_path,
preloader_path
)
try:
# Flush UART
Expand Down Expand Up @@ -443,7 +470,12 @@ def board_reboot_uart_net_pdu(
# Update board over SSH and reboot
log.info("Update board over SSH and reboot")
self.net.update_boot_partition(
bootbinpath=bootbinpath, uimagepath=uimagepath, devtreepath=devtreepath
bootbinpath=bootbinpath,
uimagepath=uimagepath,
devtreepath=devtreepath,
extlinux_path=extlinux_path,
scr_path=scr_path,
preloader_path=preloader_path,
)
log.info("Waiting for reboot to complete")

Expand Down Expand Up @@ -688,39 +720,52 @@ def _find_boot_files(self, folder):
if len(res) != 0:
raise Exception("Empty files:" + str(res))

if "BOOT.BIN" not in files:
raise Exception("BOOT.BIN not found")
if "devicetree.dtb" not in files:
if "system.dtb" not in files:
raise Exception("Device tree not found")
else:
dt = "system.dtb"
else:
dt = "devicetree.dtb"
if "uImage" not in files:
if "Image" not in files:
raise Exception("kernel not found")
else:
kernel = "Image"
else:
kernel = "uImage"
if "system_top.bit" not in files:
if "bootgen_sysfiles.tgz" not in files:
raise Exception("system_top.bit not found")
else:
tar = os.path.join(folder, "bootgen_sysfiles.tgz")
tf = tarfile.open(tar, "r:gz")
tf.extractall(folder)
tf.close()
files2 = os.listdir(folder)
if "system_top.bit" not in files2:
raise Exception("system_top.bit not found")

kernel = os.path.join(folder, kernel)
dt = os.path.join(folder, dt)
bootbin = os.path.join(folder, "BOOT.BIN")
bit = os.path.join(folder, "system_top.bit")
return (bootbin, kernel, dt, bit)
if "bootgen_sysfiles.tgz" in files:
tar = os.path.join(folder, "bootgen_sysfiles.tgz")
tf = tarfile.open(tar, "r:gz")
tf.extractall(folder)
tf.close()
# populate again files after tgz extraction
files = os.listdir(folder)

targets = {
"bit": ["system_top.bit"],
"bootbin": ["BOOT.BIN","soc_system.rbf"],
"kernel": ["uImage","Image","zImage"],
"dt": ["devicetree.dtb","system.dtb","socfpga.dtb"],
"ext": ["extlinux.conf"],
"scr": ["u-boot.scr"],
"preloader" : ["u-boot-with-spl.sfp"],
"uboot": [
"u-boot_zynq.elf",
"u-boot_adi_zynqmp_adrv9009_zu11eg_adrv2crr_fmc.elf",
"u-boot_xilinx_zynqmp_zcu102_revA.elf"
]
}
required = ["bootbin", "dt", "kernel"]
found_files = {}
for filetype in targets.keys():
for pattern in targets[filetype]:
if pattern in files:
found_files.update({filetype: os.path.join(folder, pattern)})
continue
if not filetype in found_files.keys():
if filetype in required:
raise Exception(f"{filetype} - {pattern} not found")
else:
found_files.update({filetype: None})

return (
found_files["bit"],
found_files["bootbin"],
found_files["kernel"],
found_files["dt"],
found_files["ext"],
found_files["scr"],
found_files["preloader"],
found_files["uboot"],
)


def board_reboot_auto_folder(
self, folder, sdcard=False, design_name=None, recover=False, jtag_mode=False
Expand All @@ -735,7 +780,6 @@ def board_reboot_auto_folder(
raise Exception("jtag_mode not supported for firmware device")
try:
files = glob.glob(os.path.join(folder, "*.zip"))
print(files[0])
except IndexError:
files = glob.glob(os.path.join(folder, "*.frm"))
if not files:
Expand All @@ -751,8 +795,9 @@ def board_reboot_auto_folder(

else:
log.info("SD-Card/microblaze based device selected")
(bootbin, kernel, dt, bit) = self._find_boot_files(folder)
print(bootbin, kernel, dt, bit)
(bit, bootbin, kernel, dt, ext, scr, preloader, uboot) = \
self._find_boot_files(folder)

if jtag_mode:
self.board_reboot_jtag_uart(
system_top_bit_path=bit,
Expand All @@ -765,6 +810,9 @@ def board_reboot_auto_folder(
bootbinpath=bootbin,
uimagepath=kernel,
devtreepath=dt,
extlinux_path=ext,
scr_path=scr,
preloader_path=preloader,
sdcard=sdcard,
recover=recover,
)
Expand All @@ -775,6 +823,9 @@ def board_reboot_auto(
bootbinpath,
uimagepath,
devtreepath,
extlinux_path=None,
scr_path=None,
preloader_path=None,
sdcard=False,
recover=False,
):
Expand All @@ -786,6 +837,9 @@ def board_reboot_auto(
bootbinpath=bootbinpath,
uimagepath=uimagepath,
devtreepath=devtreepath,
extlinux_path=extlinux_path,
scr_path=scr_path,
preloader_path=preloader_path,
sdcard=sdcard,
)
else:
Expand All @@ -795,13 +849,19 @@ def board_reboot_auto(
bootbinpath=bootbinpath,
uimagepath=uimagepath,
devtreepath=devtreepath,
extlinux_path=extlinux_path,
scr_path=scr_path,
preloader_path=preloader_path
)
else:
self.board_reboot_uart_net_pdu(
system_top_bit_path=system_top_bit_path,
bootbinpath=bootbinpath,
uimagepath=uimagepath,
devtreepath=devtreepath,
extlinux_path=extlinux_path,
scr_path=scr_path,
preloader_path=preloader_path
)

def shutdown_powerdown_board(self):
Expand Down
17 changes: 16 additions & 1 deletion nebula/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ def copy_file_to_remote(self, src, dest):
raise ne.SSHError

def update_boot_partition(
self, bootbinpath=None, uimagepath=None, devtreepath=None
self,
bootbinpath=None,
uimagepath=None,
devtreepath=None,
extlinux_path=None,
scr_path=None,
preloader_path=None,
):
"""update_boot_partition:
Update boot files on existing card which from remote files
Expand Down Expand Up @@ -229,6 +235,15 @@ def update_boot_partition(
self.copy_file_to_remote(uimagepath, "/tmp/sdcard/")
if devtreepath:
self.copy_file_to_remote(devtreepath, "/tmp/sdcard/")
if extlinux_path:
self.run_ssh_command("mkdir -p /tmp/sdcard/extlinux")
self.copy_file_to_remote(extlinux_path, "/tmp/sdcard/extlinux/")
if scr_path:
self.copy_file_to_remote(scr_path, "/tmp/sdcard/")
if preloader_path:
preloader_file = os.path.basename(preloader_path)
self.copy_file_to_remote(preloader_path, "/tmp/sdcard/")
self.run_ssh_command(f"dd if=/tmp/sdcard/{preloader_file} of=/dev/mmcblk0p3 bs=512 && sync")
self.run_ssh_command("sudo reboot", ignore_exceptions=True)

def update_boot_partition_existing_files(self, subfolder=None):
Expand Down

0 comments on commit 8d7ba23

Please sign in to comment.