From 481e7d3b764f49bdbc1636084e1b06e322cc0903 Mon Sep 17 00:00:00 2001 From: kimpaller Date: Mon, 13 Jan 2025 14:20:07 +0800 Subject: [PATCH] Add finally clause to make sure sd-card mux is reverted back to dut mode in very use --- nebula/manager.py | 106 ++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/nebula/manager.py b/nebula/manager.py index 1cd69ef..5df7e4a 100644 --- a/nebula/manager.py +++ b/nebula/manager.py @@ -279,26 +279,32 @@ def recover_board( # noqa:C901 return except (ne.LinuxNotReached, TimeoutError): - log.warn("Linux is not accessible") + log.warning("Linux is not accessible") try: if self.usbsdmux: - log.info("Will try to recover using usb-sd mux...") - self.power.power_down_board() - if sdcard: - # TODO: Recover using SD card boot files - pass - else: - self.usbsdmux.update_boot_files_from_external( - bootbin_loc=bootbinpath, - kernel_loc=uimagepath, - devicetree_loc=devtreepath, - extlinux_loc=extlinux_path, - scr_loc=scr_path, - preloader_loc=preloader_path, + try: + log.info("Will try to recover using usb-sd mux...") + self.power.power_down_board() + if sdcard: + self.usbsdmux.update_boot_files_from_sdcard_itself() + else: + self.usbsdmux.update_boot_files_from_external( + 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) + except Exception as e: + log.error( + "Updating boot files using usbsdmux failed to complete" ) - # if devtreepath: - # self.usbsdmux.update_devicetree_for_mux(devtreepath) - self.usbsdmux.set_mux_mode("dut") + raise e + finally: + self.usbsdmux.set_mux_mode("dut") # powercycle board log.info("Power cycling to boot") @@ -357,7 +363,7 @@ def recover_board( # noqa:C901 except Exception as e: if self.jtag: - log.warn("Recovery failed. Will try JTAG") + log.warning("Recovery failed. Will try JTAG") self.board_reboot_jtag_uart( system_top_bit_path, uimagepath, @@ -567,37 +573,37 @@ def board_reboot_sdmux_pdu( ): """Manager when sdcardmux, pdu is available""" + # Flush UART + self.monitor[0]._read_until_stop() # Flush + self.monitor[0].start_log(logappend=True) + # Check if Linux is accessible + log.info("Checking if Linux is accessible") try: - # Flush UART - self.monitor[0]._read_until_stop() # Flush - self.monitor[0].start_log(logappend=True) - # Check if Linux is accessible - log.info("Checking if Linux is accessible") - try: - out = self.monitor[0].get_uart_command_for_linux("uname -a", "Linux") - if not out: - raise ne.LinuxNotReached - except Exception as e: - # raise LinuxNotReached for other exceptions - log.info(str(e)) + out = self.monitor[0].get_uart_command_for_linux("uname -a", "Linux") + if not out: raise ne.LinuxNotReached - - # Get IP over UART + except Exception as e: + # raise LinuxNotReached for other exceptions + log.info(str(e)) + raise ne.LinuxNotReached + + # Get IP over UART + ip = self.monitor[0].get_ip_address() + if not ip: + self.monitor[0].request_ip_dhcp() ip = self.monitor[0].get_ip_address() - if not ip: - self.monitor[0].request_ip_dhcp() - ip = self.monitor[0].get_ip_address() - if not ip: - raise ne.NetworkNotFunctional - if ip != self.net.dutip: - log.info("DUT IP changed to: " + str(ip)) - self.net.dutip = ip - self.driver.uri = "ip:" + ip - # Update config file - self.help.update_yaml( - self.configfilename, "network-config", "dutip", ip, self.board_name - ) + if not ip: + raise ne.NetworkNotFunctional + if ip != self.net.dutip: + log.info("DUT IP changed to: " + str(ip)) + self.net.dutip = ip + self.driver.uri = "ip:" + ip + # Update config file + self.help.update_yaml( + self.configfilename, "network-config", "dutip", ip, self.board_name + ) + try: log.info("Update board over usb-sd-mux") if sdcard: self.usbsdmux.update_boot_files_from_sdcard_itself() @@ -614,14 +620,14 @@ def board_reboot_sdmux_pdu( ) # if devtreepath: # self.usbsdmux.update_devicetree_for_mux(devtreepath) - self.usbsdmux.set_mux_mode("dut") - # powercycle board - log.info("Power cycling to boot") - self.power_cycle_to_boot() - except Exception as e: log.error("Updating boot files using usbsdmux failed to complete") raise e + finally: + self.usbsdmux.set_mux_mode("dut") + # powercycle board + log.info("Power cycling to boot") + self.power_cycle_to_boot() # Check is networking is working self.network_check()