Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
65 changes: 65 additions & 0 deletions contrib/ub-try-int
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -e

lab=kea.py
V=
clean=False

usage() {
echo Error: $1

echo "Usage: [-cv] $0 <board> [<commit>]"
echo
echo " -c - clean before building"
echo " -v - use verbose output"
echo
echo "<commit> is a branch/commit on the tree used by tbot"
echo "If <commit> 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
64 changes: 64 additions & 0 deletions contrib/uboot_flash.py
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 38 additions & 0 deletions contrib/uboot_send.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion tbot/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tbot/machine/board/uboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 - (
Expand Down
16 changes: 9 additions & 7 deletions tbot/tc/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down
33 changes: 24 additions & 9 deletions tbot/tc/uboot/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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]:
Expand Down Expand Up @@ -314,17 +324,17 @@ 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)

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)
Expand All @@ -338,15 +348,18 @@ 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]:
"""
Just checkout and patch a version of U-Boot without attempting to build it.

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,
Expand All @@ -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]:
Expand All @@ -366,6 +380,7 @@ def build(
return UBootBuilder._build(
self,
clean=clean,
rev=rev,
repo=repo,
unpatched_repo=unpatched_repo,
path=path,
Expand Down