def set_toolchain( ma: linux.LinuxShell, arch = "armv7-eabihf", libc = "glibc", typ = "stable", date = "2018.11-1", ) -> None: """ download and set a toolchain from: https://toolchains.bootlin.com/downloads/releases/toolchains/ !! Bootlin toolchain does not work for U-Boot as there are problems with relocate-sdk.sh script !! Also, this part is integrated into tbot now: tbot/machine/linux/build/toolchain.py search for EnvSetBootlinToolchain :param LinuxMachine: Linux machine: :param str arch: architecture, default "armv7-eabihf" :param str libc: used libc. default "glibc" :param str typ: "stable" or "bleeding-edge", defaule "stable" :param str date: "2018.11-1" """ log_event.doc_tag("set_bootlin_toolchain_arch_fixlen", arch) log_event.doc_tag("set_bootlin_toolchain_libc_fixlen", libc) log_event.doc_tag("set_bootlin_toolchain_typ_fixlen", typ) log_event.doc_tag("set_bootlin_toolchain_date_fixlen", date) log_event.doc_begin("set_toolchain_check_installed") td = get_toolchain_dir(ma) ma.exec0("cd", td) fn = arch + "--" + libc + "--" + typ + "-" + date fn2 = arch + "/tarballs/" + fn ending = ".tar.bz2" tooldir = td / fn / "bin" ret = ma.exec("test", "-d", tooldir) log_event.doc_end("set_toolchain_check_installed") if ret[0] == 1: log_event.doc_begin("set_toolchain_install") msg = "Get toolchain " + fn tbot.log.message(msg) ma.exec0("wget", "https://toolchains.bootlin.com/downloads/releases/toolchains/" + fn2 + ending) ma.exec0("tar", "xfj", fn + ending) ma.exec0("cd", fn) ma.exec0("./relocate-sdk.sh") log_event.doc_end("set_toolchain_install") ret = ma.exec("printenv", "PATH", tbot.machine.linux.Pipe, "grep", "--color=never", tooldir) if ret[0] == 1: log_event.doc_begin("set_toolchain_add") tbot.log.message(f"Add toolchain to PATH ({tooldir})") old_path = ma.env("PATH") ma.env("PATH", linux.F("{}:{}", tooldir, old_path)) log_event.doc_end("set_toolchain_add") ma.exec0("printenv", "PATH") if "arm" in arch: log_event.doc_begin("set_toolchain_set_shell_vars") ma.exec0("export", "ARCH=arm" ) ma.exec0("CROSS_COMPILE=arm-linux-") log_event.doc_end("set_toolchain_set_shell_vars")
def lx_cmd_exists( ma: linux.LinuxShell, cmd, ) -> bool: ret = ma.exec(linux.Raw(("command -v " + cmd + " >/dev/null 2>&1"))) if ret[0] == 0: return True return False
def get_blockdev(host: linux.LinuxShell) -> Optional[linux.Path]: blockdevices = host.exec( "find", "/dev", "-type", "b", linux.RedirStderr(host.fsroot / "dev" / "null") )[1].splitlines() if blockdevices == []: return None blockdev = linux.Path(host, blockdevices[0]) assert blockdev.is_block_device() return blockdev
def lx_gpio( ma: linux.LinuxShell, nr: str, state: str, mode: str = "set", ) -> str: """ if {mode} == "set" (default): set gpio {nr} to {state} "on" or "off" else if {mode} == "get" return state of gpio 0 = "off", 1 = "on" returns state """ ret = ma.exec("ls", f"{path_gpio}/gpio{nr}") if ret[0] != 0: ma.exec0("echo", nr, linux.Raw(">"), f"{path_gpio}/export") ma.exec0("ls", f"{path_gpio}/gpio{nr}") if mode == "get": ma.exec0("echo", "in", linux.Raw(">"), f"{path_gpio}/gpio{nr}/direction") ret = ma.exec0("cat", f"{path_gpio}/gpio{nr}/value") if ret.strip() == "0": return "off" elif ret.strip() == "1": return "on" else: raise RuntimeError(f"unknown gpio state {ret}") elif mode == "set": if state == "on": val = "1" else: val = "0" ma.exec0("echo", "out", linux.Raw(">"), f"{path_gpio}/gpio{nr}/direction") ma.exec0("echo", val, linux.Raw(">"), f"{path_gpio}/gpio{nr}/value") else: raise RuntimeError(f"unknown mode {mode}") return state