Skip to content
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

DE10 Nano support #105

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
162 changes: 118 additions & 44 deletions nebula/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def load_boot_bin(self):

def _check_files_exist(self, *args):
for filename in args:
if not filename:
continue
if not os.path.exists(filename):
raise Exception(filename + " not found or does not exist")

Expand Down Expand Up @@ -209,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 @@ -266,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 @@ -401,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 @@ -441,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 @@ -500,12 +534,19 @@ def board_reboot_uart_net_pdu(

@_release_thread_lock
def board_reboot_sdmux_pdu(
self, system_top_bit_path, bootbinpath, uimagepath, devtreepath
self,
system_top_bit_path=None,
bootbinpath=None,
uimagepath=None,
devtreepath=None,
devtree_overlay_path=None,
devtree_overlay_config_path=None,
extlinux_path=None,
scr_path=None,
preloader_path=None,
):
"""Manager when sdcardmux, pdu is available"""
self._check_files_exist(
system_top_bit_path, bootbinpath, uimagepath, devtreepath
)

try:
# Flush UART
self.monitor[0]._read_until_stop() # Flush
Expand Down Expand Up @@ -542,6 +583,11 @@ def board_reboot_sdmux_pdu(
bootbin_loc=bootbinpath,
kernel_loc=uimagepath,
devicetree_loc=devtreepath,
devicetree_overlay_loc=devtree_overlay_path,
devicetree_overlay_config_loc=devtree_overlay_config_path,
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 @@ -674,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 @@ -721,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 @@ -737,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 @@ -751,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 @@ -761,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 @@ -772,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 @@ -781,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
Loading
Loading