def ari_ub_check_multi_dtb_select( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as bx: b = bx.enter_context(tbot.acquire_board(lh)) with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) cur_panel = ge.ub_get_var(ub, "panel") old_panel = cur_panel check_panel(ub, cur_panel) cur_panel = switch_panel(ub, cur_panel) ub.ch.sendline("res") with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) cur_panel = ge.ub_get_var(ub, "panel") if old_panel == cur_panel: raise RuntimeError( f"{cur_panel} == {old_panel}, should change") old_panel = cur_panel check_panel(ub, cur_panel) cur_panel = switch_panel(ub, cur_panel) ub.ch.sendline("res") with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) cur_panel = ge.ub_get_var(ub, "panel") if old_panel == cur_panel: raise RuntimeError( f"{cur_panel} == {old_panel}, should change") check_panel(ub, cur_panel)
def selftest_board_uboot(lab: typing.Optional[tbot.selectable.LabHost] = None) -> None: """Test if tbot intercepts U-Boot correctly.""" with contextlib.ExitStack() as cx: lh = cx.enter_context(lab or tbot.acquire_lab()) try: b: board.Board = cx.enter_context(tbot.acquire_board(lh)) ub: board.UBootShell = cx.enter_context( tbot.acquire_uboot(b) # type: ignore ) except NotImplementedError: b = cx.enter_context(TestBoard(lh)) ub = cx.enter_context(TestBoardUBoot(b)) ub.exec0("version") env = ub.exec0("printenv").strip().split("\n") for line in env[:-1]: if line != "" and line[0].isalnum(): assert "=" in line, repr(line) out = ub.exec0("echo", hex(0x1234)).strip() assert out == "0x1234", repr(out) mach.selftest_machine_shell(ub)
def socrates_ub_update_i( lab: typing.Optional[linux.LinuxShell] = None, uboot: typing.Optional[board.UBootShell] = None, interactive = True, ) -> None: with contextlib.ExitStack() as cx: lh = cx.enter_context(lab or tbot.acquire_lab()) if uboot is not None: ub = uboot else: b = cx.enter_context(tbot.acquire_board(lh)) ub = cx.enter_context(tbot.acquire_uboot(b)) ret = ub.exec("ping", "192.168.1.1") while ret[0] != 0: ret = ub.exec("ping", "192.168.1.1") if "restore_old_ub" in tbot.flags: tbot.log.message("restore old U-Boot") ub.env("uboot_addr", "FFFA0000") ub.env("uboot_file", "socrates-abb/20190627/socrates-u-boot.bin-voncajus") else: ub.env("uboot_addr", "FFF60000") ub.env("uboot_file", f"socrates-abb/{b.date}/u-boot-socrates.bin") ub.env("update_uboot", "tftp 110000 ${uboot_file};protect off ${uboot_addr} ffffffff;era ${uboot_addr} ffffffff;cp.b 110000 ${uboot_addr} ${filesize}") ub.exec0("printenv") ub.exec0("run", "update_uboot") if interactive: ub.interactive()
def socrates_ub_bdi_update( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubma: typing.Optional[board.UBootShell] = None, ) -> None: with contextlib.ExitStack() as cx: if lab is not None: lh = lab else: lh = cx.enter_context(tbot.acquire_lab()) if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) bd.bdi_connect(lh, b) bd.bdi_reset_board() bd.exec("era") if "restore_old_ub" in tbot.flags: bd.exec("prog", "0xfffa0000", f"socrates-abb/{b.date}/socrates-u-boot.bin-voncajus", "BIN") else: bd.exec("era", "0xfff60000") bd.exec("prog", "0xfff60000", f"socrates-abb/{b.date}/u-boot-socrates.bin", "BIN") bd.bdi_reset_board_run() if ubma is not None: ub = ubma else: ub = cx.enter_context(tbot.acquire_uboot(b)) ub.interactive()
def ari_ub_check_version( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ u-boot check if version on board is the same as in binary """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) t = lh.tftp_dir / "u-boot-dtb.imx.signed" #bin_vers = lh.exec0("strings", t, linux.Pipe, "grep", '"U-Boot 2"') bin_vers = lh.exec0( linux.Raw( f"strings /tftpboot/aristainetos/tbot/u-boot-dtb.imx.signed | grep --color=never 'U-Boot 2'" )) ub_vers = ub.exec0("version") if bin_vers in ub_vers: tbot.log.message( tbot.log.c("Info: U-Boot version is the same").green) else: raise RuntimeError(f"{bin_vers} != {ub_vers}")
def ub_check_version( resfiles: list, lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ check if installed U-Boot version is the same as in tftp directory. """ with lab or tbot.acquire_lab() as lh: r = get_path(lh.tftp_root_path) + "/" + get_path(lh.tftp_dir_board) spl_vers = None ub_vers = None splfiles = ["MLO", "SPL"] ubfiles = ["u-boot.img", "u-boot-socrates.bin", "u-boot.bin", "u-boot-dtb.imx", "u-boot-dtb.bin"] for f in resfiles: if spl_vers == None: if any(s in f for s in splfiles): log_event.doc_begin("get_spl_vers") spl_vers = lh.exec0(linux.Raw(f'strings {r}/{f} | grep --color=never "U-Boot SPL 2"')) spl_vers = spl_vers.strip() log_event.doc_tag("ub_spl_new_version", spl_vers) log_event.doc_end("get_spl_vers") tbot.log.message(tbot.log.c(f"found in image U-Boot SPL version {spl_vers}").green) if ub_vers == None: if any(s in f for s in ubfiles): log_event.doc_begin("get_ub_vers") ub_vers = lh.exec0(linux.Raw(f'strings {r}/{f} | grep --color=never "U-Boot 2"')) for l in ub_vers.split('\n'): if ":" in l: ub_vers = l.strip() if ub_vers[0] == 'V': ub_vers = ub_vers[1:] log_event.doc_tag("ub_ub_new_version", ub_vers) log_event.doc_end("get_ub_vers") tbot.log.message(tbot.log.c(f"found in image U-Boot version {ub_vers}").green) with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) if spl_vers != None: if spl_vers not in ub.bootlog: raise RuntimeError(f"{spl_vers} not found.") tbot.log.message(tbot.log.c(f"found U-Boot SPL version {spl_vers} installed").green) if ub_vers == None: raise RuntimeError(f"No U-Boot version defined") else: if ub_vers not in ub.bootlog: raise RuntimeError(f"{ub_vers} not found.") tbot.log.message(tbot.log.c(f"found U-Boot version {ub_vers} installed").green)
def selftest_with_uboot(lab: typing.Optional[tbot.selectable.LabHost] = None) -> None: """Test the tbot.with_uboot decorator.""" with lab or selftest.SelftestHost() as lh: with SubstituteBoard(): # Call without anything selftest_decorated_uboot() # Call with labhost selftest_decorated_uboot(lh) # Call with U-Boot with tbot.acquire_board(lh) as b: with tbot.acquire_uboot(b) as ub: selftest_decorated_uboot(ub)
def qemu_uboot_testcases( lab: typing.Optional[tbot.selectable.LabHost] = None) -> None: with contextlib.ExitStack() as cx: lh = cx.enter_context(lab or tbot.acquire_lab()) try: b = cx.enter_context(tbot.acquire_board(lh)) ub = cx.enter_context(tbot.acquire_uboot(b)) except NotImplementedError: b = cx.enter_context(QemuBoard(lh)) ub = cx.enter_context(QemuUBoot(b)) tbot.tc.testsuite( uboot_verify_version, ub=ub, )
def ari_ub_check_hab( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ u-boot check hab_auth works as expected """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) load_addr = "10000000" t = lh.tftp_dir / "testhabfile-pad-ivt.bin.signed" ub.exec0("tftp", load_addr, ge.get_ub_tftp_path(lh, t)) ret = ub.exec0("hab_auth_img", load_addr, linux.special.Raw("${filesize}")) if "No HAB Events Found" in ret: tbot.log.message(tbot.log.c("Info: no HAB events.").green) else: raise RuntimeError("HAB events found") t = lh.tftp_dir / "boot-pad-ivt.scr.bin.signed" ub.exec0("tftp", load_addr, ge.get_ub_tftp_path(lh, t)) ret = ub.exec0("hab_auth_img", load_addr, linux.special.Raw("${filesize}")) if "No HAB Events Found" in ret: tbot.log.message(tbot.log.c("Info: no HAB events.").green) else: raise RuntimeError("HAB events found") t = lh.tftp_dir / "testhabfile-pad-ivt.bin.signed.error" ub.exec0("tftp", load_addr, ge.get_ub_tftp_path(lh, t)) ret = ub.exec0("hab_auth_img", load_addr, linux.special.Raw("${filesize}")) if "HAB_FAILURE" in ret: tbot.log.message( tbot.log.c("Info: HAB events, expected!").green) else: raise RuntimeError("HAB events not found")
def ari_ub_update( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ update u-boot """ with lab or tbot.acquire_lab() as lh: # now we know what we have normally as bootmode # we want to update this bootmode with new U-Boot # so delete bootmode in flags and set other bootmode if "bootmodesd" in tbot.flags: bm = "sd" tbot.flags.remove("bootmodesd") lh.set_bootmode("spi") elif "bootmodespi" in tbot.flags: bm = "spi" tbot.flags.remove("bootmodespi") lh.set_bootmode("sd") else: raise RuntimeError("Set bootmode") with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) ari_ub_set_env(ub) loadaddr = "0x12000000" ret = ub.exec("ping", "192.168.1.1") while ret[0] != 0: ret = ub.exec("ping", "192.168.1.1") ub.exec0("mw", loadaddr, "0", "0x4000") ub.exec0("tftp", loadaddr, b.envdir) ub.exec0("env", "import", "-t", loadaddr) if bm == "sd": ub.exec0("run", "upd_uboot_sd") else: ub.exec0("run", "upd_uboot") return
def ari_ub_basic_checks( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ u-boot check basic stuff """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) ari_ub_set_env(ub) ari_ub_check_bootlog(ub) # check version ari_ub_check_version(lh, b, ub) # ethernet works? ub.exec0("ping", lh.serverip) # mmc work ub.exec0("mmc", "info") # check led / gpio ari_ub_check_led(ub) # check i2c ari_ub_check_i2c(lh, b, ub) # check hab_auth_img command ari_ub_check_hab(lh, b, ub) # must start from scratch # check multi dtb select ari_ub_check_multi_dtb_select() ari_ub_check_empty_environment()
def ari_ub_check_i2c( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ check i2c probe and dumps """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) ub.exec0("i2c", "dev", "0") log = ub.exec0("i2c", "probe") if "58 59 71" not in log: raise RuntimeError("Probing bus 0 failed res: {log}") ub.exec0("i2c", "dev", "1") log = ub.exec("i2c", "probe") if log[0] == 0: raise RuntimeError("Probing bus 1 failed res: {log}") ub.exec0("i2c", "dev", "2") log = ub.exec0("i2c", "probe") dump_file = i2c_dump_0_58_7 if "20 4D 68" not in log: if "20 4B 68" not in log: raise RuntimeError("Probing bus 2 failed res: {log}") else: dump_file = i2c_dump_0_58_4 ge.ub_check_i2c_dump(ub, "0", "0x58", dump_file)
def socrates_ub_usb( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubma: typing.Optional[board.UBootShell] = None, ) -> None: """ start usb and check if there is a usb storage device """ with contextlib.ExitStack() as cx: if lab is not None: lh = lab else: lh = cx.enter_context(tbot.acquire_lab()) if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubma is not None: ub = ubma else: ub = cx.enter_context(tbot.acquire_uboot(b)) ret = ub.exec0("usb", "start") if "1 Storage Device" not in ret: raise RuntimeError("no usb storage device found") ret = ub.exec0("usb", "storage") if "Vendor: Kingston" not in ret: raise RuntimeError("vendor not Kingston") if "Capacity: 954.0 MB" not in ret: raise RuntimeError("wrong Capacity") ub.exec0("usb", "read", "100000", "0", "1000") ret = ub.exec0("crc", "100000", "80000") if "e336ee43" not in ret: raise RuntimeError(f"wrong checksum f{ret}")
def ari_ub_check_register( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ check U-Boot register """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) if "lg4573" in ub.bootlog: ub.exec0("lgset") path = "tc/aristainetos/files/" files = [ "ccm.dump", "ccm_an.dump", "pinmux.dump", "usdhc1.dump", "usdhc2.dump", "gpio1.dump", "gpio2.dump", "gpio3.dump", "gpio4.dump", "gpio5.dump", "gpio6.dump", "gpio7.dump", "pwm1.dump", "pwm2.dump", "pwm3.dump", "pwm4.dump", "ecspi1.dump", "ecspi2.dump", "ecspi3.dump", "ecspi4.dump", "enet1.dump", "ipu1.dump", "ipu1_dmac.dump", "ipu1_dp.dump", "ipu1_ic.dump", "ipu1_csi0.dump", "ipu1_csi1.dump", "ipu1_diu0.dump", "ipu1_diu1.dump", "ipu1_dc.dump", "ldb.dump", ] files = ["pinmux.dump"] files = [ "ipu1.dump", "ipu1_dmac.dump", "ipu1_dp.dump", "ipu1_ic.dump", "ipu1_csi0.dump", "ipu1_csi1.dump", "ipu1_diu0.dump", "ipu1_diu1.dump", "ipu1_dc.dump", "ldb.dump", ] files = [ "gpio1.dump", "gpio2.dump", "gpio3.dump", "gpio4.dump", "gpio5.dump", "gpio6.dump", "gpio7.dump", ] files = [ "ccm.dump", "ccm_an.dump", ] files = [ "ipu1.dump", "ipu1_dmac.dump", "ipu1_dp.dump", "ipu1_ic.dump", "ipu1_csi0.dump", "ipu1_csi1.dump", "ipu1_diu0.dump", "ipu1_diu1.dump", "ipu1_dc.dump", "ldb.dump", "ccm.dump", "ccm_an.dump", ] files = ["pinmux.dump"] for f in files: #ge.ub_check_revfile(ub, path + f, "diff_pinmux.txt", "/home/hs/data/Entwicklung/prozessordoku/imx6/IMX6SDLRM.txt") ge.ub_check_revfile(ub, path + f)
def interactive_uboot() -> None: """Start an interactive U-Boot shell on the selected board.""" with tbot.acquire_lab() as lh: with tbot.acquire_board(lh) as b, tbot.acquire_uboot(b) as ub: ub.interactive()
def ari_ub_dump_register( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ dump U-Boot register into file """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) ge.ub_create_revfile(ub, path + "ccm.dump", "0x20c4000", "0x20c408c") ge.ub_create_revfile(ub, path + "ccm_an.dump", "0x20c8000", "0x20c8190") ge.ub_create_revfile(ub, path + "pinmux.dump", "0x20e0000", "0x20e093c") ge.ub_create_revfile(ub, path + "usdhc1.dump", "0x2190000", "0x21900cc") ge.ub_create_revfile(ub, path + "usdhc2.dump", "0x2194000", "0x21940cc") ge.ub_create_revfile(ub, path + "gpio1.dump", "0x209c000", "0x209c020") ge.ub_create_revfile(ub, path + "gpio2.dump", "0x20a0000", "0x20a0020") ge.ub_create_revfile(ub, path + "gpio3.dump", "0x20a4000", "0x20a4020") ge.ub_create_revfile(ub, path + "gpio4.dump", "0x20a8000", "0x20a8020") ge.ub_create_revfile(ub, path + "gpio5.dump", "0x20ac000", "0x20ac020") ge.ub_create_revfile(ub, path + "gpio6.dump", "0x20b0000", "0x20b0020") ge.ub_create_revfile(ub, path + "gpio7.dump", "0x20b4000", "0x20b4020") ge.ub_create_revfile(ub, path + "pwm1.dump", "0x2080000", "0x2080018") ge.ub_create_revfile(ub, path + "pwm2.dump", "0x2084000", "0x2084018") ge.ub_create_revfile(ub, path + "pwm3.dump", "0x2088000", "0x2088018") ge.ub_create_revfile(ub, path + "pwm4.dump", "0x208c000", "0x208c018") ge.ub_create_revfile(ub, path + "ecspi1.dump", "0x2008000", "0x2008044") ge.ub_create_revfile(ub, path + "ecspi2.dump", "0x200c000", "0x200c044") ge.ub_create_revfile(ub, path + "ecspi3.dump", "0x2010000", "0x2010044") ge.ub_create_revfile(ub, path + "ecspi4.dump", "0x2014000", "0x2014044") ge.ub_create_revfile(ub, path + "enet1.dump", "0x2188000", "0x21881c4") ge.ub_create_revfile(ub, path + "ipu1.dump", "0x2600000", "0x260028c") ge.ub_create_revfile(ub, path + "ipu1_dmac.dump", "0x2608000", "0x2608108") ge.ub_create_revfile(ub, path + "ipu1_dp.dump", "0x2618000", "0x2618118") ge.ub_create_revfile(ub, path + "ipu1_ic.dump", "0x2620000", "0x262028") ge.ub_create_revfile(ub, path + "ipu1_csi0.dump", "0x2630000", "0x26300f0") ge.ub_create_revfile(ub, path + "ipu1_csi1.dump", "0x2638000", "0x26380f0") ge.ub_create_revfile(ub, path + "ipu1_diu0.dump", "0x2640000", "0x2640178") ge.ub_create_revfile(ub, path + "ipu1_diu1.dump", "0x2648000", "0x2648178") ge.ub_create_revfile(ub, path + "ipu1_dc.dump", "0x2658000", "0x26581cc")
def ari_ub_update_i( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, interactive=True, ) -> None: """ update U-Boot and go into interactive U-Boot shell """ with lab or tbot.acquire_lab() as lh: ari_ub_update(lh, board, ubx) lh.set_bootmode("sd") with contextlib.ExitStack() as cx: if board is not None: b = board else: b = cx.enter_context(tbot.acquire_board(lh)) b.poweroff() time.sleep(5) b.poweron() if ubx is not None: ub = ubx else: ub = cx.enter_context(tbot.acquire_uboot(b)) # try to get fb address """ if "Framebuffer at" in ub.bootlog: line = ub.bootlog.split("Framebuffer at ") #line = line[1].split["\n"] #print (line[0]) addr = line[1] if "\n" in addr: addr = addr.split("\n")[0] else: ret = ub.exec0("bdinfo") line = ret.split("FB base = ") addr = line[1] addr = addr.split("\n") addr = addr[0].strip() #ub.exec0("mw", "4fb5c000", "f79e3206", "10000") # # all white #ge.ub_set_mem_addr(ub, addr, "l", "ffffffff", "100000") # # dump logo to offset 0x5dc00 # addr + 0x5dc00 #ia = int(addr, 16) #of = int("0x5dc00", 16) #newaddr = ia + of #ge.ub_write_dump(ub, path + "fb_logo.dump", hex(newaddr)) # # or use video dump created with bdi #loadaddr = "0x12000000" #ret = ub.exec("ping", "192.168.1.1") #while ret[0] != 0: # ret = ub.exec("ping", "192.168.1.1") #ub.exec0("tftp", loadaddr, "aristainetos/20190507/fb.dump") #ub.exec0("cp", loadaddr, addr, "40000") #ub.exec0("lgset") """ if interactive: ub.interactive()
def ari_ub_check_empty_environment( lab: typing.Optional[linux.LinuxShell] = None, board: typing.Optional[board.Board] = None, ubx: typing.Optional[board.UBootShell] = None, ) -> None: """ check if u-boot works with empty environment """ with lab or tbot.acquire_lab() as lh: with contextlib.ExitStack() as bx: b = bx.enter_context(tbot.acquire_board(lh)) with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) if "Dual Lite Board 4" in ub.bootlog: altpanelstr = "lb07wv8" panelstr = "lg4573" elif "Dual Lite Board 7" in ub.bootlog: altpanelstr = "lg4573" panelstr = "lb07wv8" else: tbot.log.message( tbot.log.c( "should boot with Dual Lite Board 4 or 7").green) return # delete env -> must boot with default Board 7 ub.exec0("sf", "probe") ub.exec0("sf", "erase", "env", "10000") ub.exec0("sf", "erase", "env-red", "10000") ub.ch.sendline("res") with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) if not "Dual Lite Board 7" in ub.bootlog: raise RuntimeError("should boot with Dual Lite Board 7") if not "bad CRC" in ub.bootlog: raise RuntimeError("should boot with bad CRC") ub.env("ethaddr", "00:30:D6:10:B8:9D") # config alt panel ub.env("panel", altpanelstr) ret = ub.exec0("saveenv") if not "Saving Environment to SPI Flash" in ret: raise RuntimeError(f"Error saving Environment") ub.ch.sendline("res") # check bootet with alt panel with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) if "bad CRC" in ub.bootlog: raise RuntimeError("should not boot with bad CRC") if "lb07wv8" in altpanelstr: if not "Dual Lite Board 7" in ub.bootlog: raise RuntimeError( "should boot with Dual Lite Board 7") else: if not "Dual Lite Board 4" in ub.bootlog: raise RuntimeError( "should boot with Dual Lite Board 4") if not "Loading Environment from SPI Flash" in ub.bootlog: raise RuntimeError("board does not load Environment") # config panel ub.env("panel", panelstr) ret = ub.exec0("saveenv") if not "Saving Environment to SPI Flash" in ret: raise RuntimeError(f"Error saving Environment") ub.ch.sendline("res") # check bootet with panel with contextlib.ExitStack() as cx: ub = cx.enter_context(tbot.acquire_uboot(b)) if "bad CRC" in ub.bootlog: raise RuntimeError("should not boot with bad CRC") if "lb07wv8" in panelstr: if not "Dual Lite Board 7" in ub.bootlog: raise RuntimeError( "should boot with Dual Lite Board 7") else: if not "Dual Lite Board 4" in ub.bootlog: raise RuntimeError( "should boot with Dual Lite Board 4")
def interactive_uboot() -> None: with tbot.acquire_lab() as lh: with tbot.acquire_board(lh) as b: with tbot.acquire_uboot(b) as ub: ub.interactive()
def testpy( lh: linux.Lab, *, build_host: typing.Optional[linux.Builder] = None, uboot_builder: typing.Optional[uboot_tc.UBootBuilder] = None, boardenv: typing.Optional[str] = None, testpy_args: typing.List[str] = [], ) -> None: """ Run U-Boot's test/py test-framework against the selected board. This testcase can be called from the command-line as ``uboot_testpy``. :param tbot.machine.linux.Builder build_host: Optional build-host where U-Boot should be built (and in this case, where test/py will run). By default, ``tbot.acquire_lab().build()`` is used. :param tbot.tc.uboot.UBootBuilder uboot_builder: Optional configuration for U-Boot checkout. By default, ``tbot.acquire_uboot().build`` is used (exactly like ``uboot_build`` does). :param str boardenv: Optional contents for the ``boardenv.py`` file. If this option is not given, ``UBootBuilder.testpy_boardenv`` is used (or nothing). :param list(str) testpy_args: Additional arguments to be passed to test/py. Can be used, for example, to limit which tests should be run (using ``testpy_args=["-k", "sf"]``). **Example**: The following additions to a board-config make it possible to call ``tbot ... -vv uboot_testpy``: .. code-block:: python from tbot.tc import uboot class DHComUBootBuilder(uboot.UBootBuilder): name = "dhcom-pdk2" defconfig = "dh_imx6_defconfig" toolchain = "imx6q" testpy_boardenv = r\"""# Config for dhcom pdk2 board # A list of sections of Flash memory to be tested. env__sf_configs = ( { # Where in SPI Flash should the test operate. 'offset': 0x140000, # This value is optional. # If present, specifies if the test can write to Flash offset # If missing, defaults to False. 'writeable': True, }, ) \""" class DHComUBoot(board.Connector, board.UBootShell): name = "dhcom-uboot" prompt = "=> " # Don't forget this! build = DHComUBootBuilder() """ with contextlib.ExitStack() as cx: if build_host is not None: bh = cx.enter_context(build_host) else: bh = cx.enter_context(lh.build()) if bh is lh: tbot.log.warning("""\ The build() method for the selected lab should not return `self` but instead `self.clone()`. Otherwise, `uboot_testpy` might not be able to run test/py in parallel to switching board power. Attempting to call build_host.clone() automatically now ...""") bh = cx.enter_context(bh.clone()) # Spawn a subshell to not mess up the parent shell's environment and PWD cx.enter_context(bh.subshell()) chan_console, chan_command = setup_testhooks( bh, cx.enter_context(bh.clone()), cx.enter_context(bh.clone())) if uboot_builder is None: builder = uboot_tc.UBootBuilder._get_selected_builder() else: builder = uboot_builder uboot_repo = uboot_tc.checkout(builder, clean=False, host=bh) # test/py wants to read U-Boot's config. Run the builder's configure # step if no `.config` is available and then also generate `autoconf.mk`. dotconfig_missing = not (uboot_repo / ".config").exists() autoconfmk_missing = not (uboot_repo / "include" / "autoconf.mk").exists() if dotconfig_missing or autoconfmk_missing: with tbot.testcase("uboot_configure"), builder.do_toolchain(bh): tbot.log.message("Configuring U-Boot checkout ...") bh.exec0("cd", uboot_repo) if dotconfig_missing: builder.do_configure(bh, uboot_repo) if autoconfmk_missing: bh.exec0("make", "include/autoconf.mk") # Initialize the board # TODO: Add a parameter to allow passing in a board b = cx.enter_context(tbot.acquire_board(lh)) # type: ignore assert isinstance(b, board.PowerControl) ub = cx.enter_context(tbot.acquire_uboot(b)) chan_uboot = ub.ch # If a boardenv was passed in, copy it to the build-host and set # a board-type to make test/py pick it up. board_type = "unknown" if boardenv is None: # If no explicit boardenv was given, maybe the builder has one. try: boardenv = getattr(builder, "testpy_boardenv") except AttributeError: pass if boardenv is not None: board_type = f"tbot-{b.name}" bt_filename = board_type.replace("-", "_") be_file = uboot_repo / "test" / "py" / f"u_boot_boardenv_{bt_filename}.py" be_file.write_text(boardenv) # Start test/py as an interactive command bh.exec0("cd", uboot_repo) chan_testpy = cx.enter_context( bh.run( "./test/py/test.py", "--build-dir", ".", "--board-type", board_type, *testpy_args, )) # We have to deal with incoming data on any of the following channels. # The comments denote what needs to be done for each channel: readfds = [ chan_console, # Send data to U-Boot chan_uboot, # Send data to chan_console (test/py) chan_command, # Powercycle the board chan_testpy, # Read data so the log-event picks it up ] while True: r, _, _ = select.select(readfds, [], []) if chan_console in r: # Send data to U-Boot data = os.read(chan_console.fileno(), 4096) os.write(chan_uboot.fileno(), data) if chan_uboot in r: # Send data to chan_console (test/py) data = os.read(chan_uboot.fileno(), 4096) os.write(chan_console.fileno(), data) if chan_command in r: # Powercycle the board msg = chan_command.read() if msg[:2] == b"RE": b.poweroff() b.poweron() else: raise Exception(f"Got unknown command {msg!r}!") if chan_testpy in r: # Read data so the log-event picks it up. If a # DeathStringException occurs here, test/py finished and we # need to properly terminate the LinuxShell.run() context. try: chan_testpy.read() except linux.CommandEndedException: chan_testpy.terminate0() break