diff --git a/contrib/ub-try-int b/contrib/ub-try-int new file mode 100755 index 00000000..183623f6 --- /dev/null +++ b/contrib/ub-try-int @@ -0,0 +1,65 @@ +#!/bin/bash + +set -e + +lab=kea.py +V= +clean=False + +usage() { + echo Error: $1 + + echo "Usage: [-cv] $0 []" + echo + echo " -c - clean before building" + echo " -v - use verbose output" + echo + echo " is a branch/commit on the tree used by tbot" + echo "If is empty, the current source is used" + exit 1 +} + +while getopts "cv" opt; do + case $opt in + c ) + clean=True + ;; + v ) + V=-vv + ;; + \? ) + echo "Invalid option: $OPTARG" 1>&2 + ;; + esac +done + +shift $((OPTIND -1)) + +board=$1 +[[ -z "$board" ]] && usage "No board $board" + +commit=$2 + +if [[ -z "$commit" ]]; then + commit=HEAD + patch=/tmp/$$.patch + git diff --no-ext-diff HEAD >$patch + [[ ! -s $patch ]] && patch= + patch="${patch:+"-p patch=\"$patch\""}" + if [[ -n "$patch" ]]; then + echo "Sending patch file with uncommitted changes" + fi +fi + +rev=$(git rev-parse $commit) + +if [[ -z "$rev" ]]; then + usage "No revision $rev" +fi + +cd /vid/software/devel/ubtest +echo +echo "Checking revision ${rev}" +tbot -l ${lab} -b ${board}.py -T tbot/contrib -p rev=\"${rev}\" \ + -p clean=${clean} $patch $V uboot_build_and_flash +tbot -l ${lab} -b ${board}.py interactive_board diff --git a/contrib/uboot_flash.py b/contrib/uboot_flash.py new file mode 100644 index 00000000..855661f8 --- /dev/null +++ b/contrib/uboot_flash.py @@ -0,0 +1,64 @@ +import typing +import contextlib +import tbot +from tbot.machine import linux, board +from tbot.tc import uboot, git + + +def safe_flash(board: board.Board, repo: git.GitRepository) -> None: + """Flash but drop into shell on failure (if -f safe).""" + flasher: typing.Callable[[git.GitRepository], None] = getattr(board, "flash") + + with tbot.testcase("uboot_flash"): + flasher(repo) + +@tbot.testcase +def uboot_build_and_flash( + lab: typing.Optional[tbot.selectable.LabHost] = None, + clean: bool = True, + rev: typing.Optional[str] = None, + patch: typing.Optional[linux.Path] = None, +) -> None: + with lab or tbot.acquire_lab() as lh: + # Build U-Boot + with lh.build() as bh: + with contextlib.ExitStack() as cx: + b = cx.enter_context(tbot.acquire_board(lh)) + repo = uboot.build(host=bh, clean=clean, rev=rev, patch=patch) + #ub = cx.enter_context(tbot.acquire_uboot(b)) + + safe_flash(b, repo) + """ + # Reboot and check version + with tbot.testcase("uboot_check_version"), contextlib.ExitStack() as cx: + b = cx.enter_context(tbot.acquire_board(lh)) + ub = cx.enter_context(tbot.acquire_uboot(b)) + + vers = ub.exec0("version").split("\n")[0] + tbot.log.message(f"Found version '{vers}' on hardware") + + strings = bh.exec0( + "strings", + repo / "u-boot.bin", + linux.Pipe, + "/usr/bin/grep", + "U-Boot", + ).strip() + + assert vers in strings, "U-Boot version does not seem to match!" + """ + + +@tbot.testcase +def uboot_bare_flash(lab: typing.Optional[tbot.selectable.LabHost] = None,) -> None: + with lab or tbot.acquire_lab() as lh: + with lh.build() as bh: + repo = uboot.checkout(host=bh, clean=False) + + assert (repo / "u-boot.bin").exists(), "U-Boot was not built!" + + with contextlib.ExitStack() as cx: + b = cx.enter_context(tbot.acquire_board(lh)) + ub = cx.enter_context(tbot.acquire_uboot(b)) + + safe_flash(ub, repo) diff --git a/contrib/uboot_send.py b/contrib/uboot_send.py new file mode 100644 index 00000000..75eb159f --- /dev/null +++ b/contrib/uboot_send.py @@ -0,0 +1,38 @@ +import typing +import contextlib +import tbot +from tbot.machine import linux, board +from tbot.tc import uboot, git + + +def send(board: board.Board, repo: git.GitRepository) -> None: + """Send a new U-Boot to the board, typically over USB.""" + sender: typing.Callable[[git.GitRepository], None] = getattr(board, "send") + + with tbot.testcase("uboot_send"): + sender(repo) + +@tbot.testcase +def uboot_build_and_send( + lab: typing.Optional[tbot.selectable.LabHost] = None, clean: bool = True +) -> None: + with lab or tbot.acquire_lab() as lh: + # Build U-Boot + with lh.build() as bh: + with contextlib.ExitStack() as cx: + repo = uboot.build(host=bh, clean=clean) + with tbot.acquire_board(lh) as b: + send(b, repo) + +@tbot.testcase +def uboot_build_send_interactive( + lab: typing.Optional[tbot.selectable.LabHost] = None, clean: bool = True +) -> None: + with lab or tbot.acquire_lab() as lh: + # Build U-Boot + with lh.build() as bh: + with contextlib.ExitStack() as cx: + repo = uboot.build(host=bh, clean=clean) + with tbot.acquire_board(lh) as b: + send(b, repo) + b.interactive() diff --git a/tbot/log.py b/tbot/log.py index b2067445..2614b71d 100644 --- a/tbot/log.py +++ b/tbot/log.py @@ -101,7 +101,7 @@ def __init__( Create a log event. A log event is a :class:`io.StringIO` and everything written to - the stram will be added to the log event. + the stream will be added to the log event. :param str message: First line of the log event (the log message). If the message contains newlines, only the first line will be printed as diff --git a/tbot/machine/board/uboot.py b/tbot/machine/board/uboot.py index 5a3eb086..259228d0 100644 --- a/tbot/machine/board/uboot.py +++ b/tbot/machine/board/uboot.py @@ -99,7 +99,7 @@ class MyUBoot( def _init_machine(self) -> typing.Iterator: if self.autoboot_prompt is not None: with self.ch.with_stream(self._uboot_startup_event()): - timeout = None + timeout = 30 if self.boot_timeout is not None: assert self._timeout_start is not None timeout = self.boot_timeout - ( diff --git a/tbot/tc/git.py b/tbot/tc/git.py index c17a4791..17affb8d 100644 --- a/tbot/tc/git.py +++ b/tbot/tc/git.py @@ -100,17 +100,19 @@ def __init__( elif fetch: self.git0("fetch") - if clean and already_cloned: + if already_cloned: # Try resetting the branch to upstream, if the branch has an upstream - if rev and self.git("rev-parse", f"{rev}@{{u}}")[0] == 0: - self.reset(f"{rev}@{{u}}", ResetMode.HARD) + if rev: + self.reset(rev, ResetMode.HARD) elif self.git("rev-parse", "@{u}")[0] == 0: self.reset("@{u}", ResetMode.HARD) else: self.reset("HEAD", ResetMode.HARD) - self.clean(untracked=True, noignore=True) + if clean: + self.clean(untracked=True, noignore=True) + - if clean or not already_cloned: + else: if rev: self.checkout(rev) else: @@ -121,8 +123,8 @@ def __init__( self.reset("HEAD", ResetMode.HARD) self.clean(untracked=True, noignore=True) - if rev: - self.checkout(rev) + if rev: + self.checkout(rev) def git( self, *args: typing.Union[str, linux.Path[H], linux.special.Special] diff --git a/tbot/tc/uboot/build.py b/tbot/tc/uboot/build.py index 6391552f..c29940df 100644 --- a/tbot/tc/uboot/build.py +++ b/tbot/tc/uboot/build.py @@ -18,7 +18,7 @@ import typing import tbot from tbot.machine import linux -from tbot.tc import git +from tbot.tc import git, shell H = typing.TypeVar("H", bound=linux.LinuxShell) BH = typing.TypeVar("BH", bound=linux.Builder) @@ -60,7 +60,8 @@ def name(self) -> str: """Name of this builder.""" pass - remote = "https://gitlab.denx.de/u-boot/u-boot.git" + #remote = "https://gitlab.denx.de/u-boot/u-boot.git" + remote = "git://ellesmere/u-boot.git" """ Where to fetch U-Boot from. """ @@ -161,7 +162,7 @@ def do_configure(self, bh: BH, repo: git.GitRepository[BH]) -> None: if self.defconfig is None: raise NotImplementedError("Can't build U-Boot without a defconfig") - bh.exec0("make", self.defconfig) + bh.exec0("make", "-s", self.defconfig) def do_build(self, bh: BH, repo: git.GitRepository[BH]) -> None: """ @@ -170,7 +171,7 @@ def do_build(self, bh: BH, repo: git.GitRepository[BH]) -> None: By default, this steps runs ``make -j $(nproc)``. """ nproc = int(bh.exec0("nproc", "--all")) - bh.exec0("make", "-j", str(nproc), "all") + bh.exec0("make", "-j", str(nproc), "-s", "all") # --------------------------------------------------------------------------- # @staticmethod @@ -198,6 +199,7 @@ def _checkout( rev: typing.Optional[str] = None, path: typing.Optional[linux.Path[H]] = None, host: typing.Optional[H] = None, + patch: typing.Optional[linux.Path[H]] = None, ) -> git.GitRepository[H]: """ Just checkout and patch a version of U-Boot without attempting to build it. @@ -232,6 +234,12 @@ def _checkout( repo = builder.do_checkout(path, clean=clean, rev=rev or builder.revision) builder.do_patch(repo) + if patch: + with tbot.acquire_local() as lo: + file_on_localhost = lo.workdir / patch + file_on_labhost = repo / "001.patch" + shell.copy(file_on_localhost, file_on_labhost) + repo.apply(file_on_labhost) return repo @@ -240,9 +248,11 @@ def _build( builder: "typing.Optional[UBootBuilder]" = None, *, clean: bool = True, + rev: typing.Optional[str] = None, repo: typing.Optional[git.GitRepository[BH]] = None, unpatched_repo: typing.Optional[git.GitRepository[BH]] = None, path: typing.Optional[linux.Path[BH]] = None, + patch: typing.Optional[linux.Path[H]] = None, host: typing.Optional[BH] = None, lab: typing.Optional[linux.Lab] = None, ) -> git.GitRepository[BH]: @@ -314,7 +324,8 @@ def _build( if repo is None: # Set host to none if we have a path checkout_host = host if path is None else None - repo = checkout(builder, clean=clean, path=path, host=checkout_host) + repo = checkout(builder, clean=clean, rev=rev, path=path, + patch=patch, host=checkout_host) with builder.do_toolchain(host): host.exec0("cd", repo) @@ -322,9 +333,8 @@ def _build( if clean: tbot.log.message("Cleaning previous build ...") host.exec0("make", "mrproper") - if not (repo / ".config").exists(): - tbot.log.message("Configuring build ...") - builder.do_configure(host, repo) + tbot.log.message("Configuring build ...") + builder.do_configure(host, repo) with tbot.testcase("uboot_make"): builder.do_build(repo.host, repo) @@ -338,7 +348,9 @@ def checkout( self, *, clean: bool = True, + rev: typing.Optional[str] = None, path: typing.Optional[linux.Path[H]] = None, + patch: typing.Optional[linux.Path[H]] = None, host: typing.Optional[H] = None, ) -> git.GitRepository[H]: """ @@ -346,7 +358,8 @@ def checkout( See :func:`tbot.tc.uboot.checkout`. """ - return UBootBuilder._checkout(self, clean=clean, path=path, host=host) + return UBootBuilder._checkout(self, clean=clean, rev=rev, path=path, + patch=patch, host=host) def build( self, @@ -355,6 +368,7 @@ def build( repo: typing.Optional[git.GitRepository[BH]] = None, unpatched_repo: typing.Optional[git.GitRepository[BH]] = None, path: typing.Optional[linux.Path[BH]] = None, + rev: typing.Optional[str] = None, host: typing.Optional[BH] = None, lab: typing.Optional[linux.Lab] = None, ) -> git.GitRepository[BH]: @@ -366,6 +380,7 @@ def build( return UBootBuilder._build( self, clean=clean, + rev=rev, repo=repo, unpatched_repo=unpatched_repo, path=path,