Skip to content

Commit eb89445

Browse files
committed
doc: Add documentation for U-Boot integration [v2]
Cover the drivers, scripts, pytest and the Gitlab information. Note: This implementation is the result of working through what is needed in Labgrid to support U-Boot labs. I did initially file quite a few issues[1] but there has not been a lot of traction and I got feedback that I have overwhelmed people with too many. So I have stopped filing issues on the things I hit along the way. I have carried on with the implementation in the hope that this can be a better basis for discussion. Note that all of these patches are work-in-progress. Feedback on any or all may change the implementation and documentation substantially. Changes in v5: - Rebase on latest grpc branch - Fix pylint errors and warnings Changes in v4: - Support for Beagleplay, which needs files from two separate U-Boot builds - Support for a 'recovery' button needed to boot the image - Tidy up the internal-console support - Fix pytest behaviour with an unpatched U-Boot (that doesn't have lab mode) Changes in v3: - Rebase on top of grpc branch - Don't mess with terminal setting unless stdin is a terminal - Don't show an error if there are no resources when auto-acquiring - Support QEMU in UBootWriter Some changes in v2: - Rationalise the flags for the U-Boot scripts - Support tracing with em100 - Support an internal terminal instead of microcom - Add a -D flag for debugging - Support send-only boards - Add a way to build the U-Boot config - Add a control for buildman's process-limit - allow the build-dir to be specified in a variable - add documentation about U-Boot-pytest integration - add source_dir and config_file to UBootProviderDriver - add an internal terminal - expand the U-Boot scripts - significantly improve the U-Boot-pytest integration The approximate diffstat is: contrib/sync-places.py | 23 +- contrib/u-boot/.gitignore | 1 + contrib/u-boot/_ub-bisect-try | 47 ++ contrib/u-boot/conftest.py | 21 + contrib/u-boot/get_args.sh | 128 +++++ contrib/u-boot/index.rst | 232 +++++++++ contrib/u-boot/lg-client | 11 + contrib/u-boot/lg-env | 10 + contrib/u-boot/test_smoke.py | 3 + contrib/u-boot/ub-bisect | 44 ++ contrib/u-boot/ub-cli | 39 ++ contrib/u-boot/ub-int | 41 ++ contrib/u-boot/ub-pyt | 69 +++ contrib/u-boot/ub-smoke | 48 ++ doc/configuration.rst | 611 ++++++++++++++++++++++- doc/usage.rst | 288 +++++++++++ labgrid/driver/__init__.py | 10 +- labgrid/driver/common.py | 11 + labgrid/driver/consoleexpectmixin.py | 7 + labgrid/driver/powerdriver.py | 29 ++ labgrid/driver/qemudriver.py | 84 ++-- labgrid/driver/recoverydriver.py | 25 + labgrid/driver/resetdriver.py | 7 + labgrid/driver/servodriver.py | 157 ++++++ labgrid/driver/sfemulatordriver.py | 102 ++++ labgrid/driver/ubootdriver.py | 27 +- labgrid/driver/ubootproviderdriver.py | 323 ++++++++++++ labgrid/driver/ubootwriterdriver.py | 160 ++++++ labgrid/driver/usbhidrelay.py | 7 +- labgrid/driver/usbloader.py | 170 ++++++- labgrid/driver/usbstoragedriver.py | 18 +- labgrid/factory.py | 4 +- labgrid/protocol/__init__.py | 1 + labgrid/protocol/bootstrapprotocol.py | 8 +- labgrid/protocol/recoveryprotocol.py | 14 + labgrid/protocol/resetprotocol.py | 12 + labgrid/pytestplugin/fixtures.py | 21 +- labgrid/pytestplugin/hooks.py | 8 + labgrid/remote/client.py | 351 ++++++++----- labgrid/remote/config.py | 7 +- labgrid/remote/exporter.py | 122 ++++- labgrid/resource/__init__.py | 6 + labgrid/resource/remote.py | 24 + labgrid/resource/servo.py | 485 ++++++++++++++++++ labgrid/resource/sfemulator.py | 33 ++ labgrid/resource/suggest.py | 6 + labgrid/resource/udev.py | 33 ++ labgrid/strategy/ubootstrategy.py | 151 +++++- labgrid/target.py | 120 ++++- labgrid/util/helper.py | 220 ++++---- labgrid/util/ssh.py | 3 +- labgrid/util/term.py | 184 +++++++ labgrid/var_dict.py | 8 + man/labgrid-client.1 | 6 + man/labgrid-client.rst | 4 + man/labgrid-device-config.5 | 4 + 56 files changed, 4267 insertions(+), 321 deletions(-) [1] https://github.com/labgrid-project/labgrid/issues/created_by/sjg20 Signed-off-by: Simon Glass <sjg@chromium.org>
1 parent d5bbfd7 commit eb89445

2 files changed

Lines changed: 288 additions & 0 deletions

File tree

doc/configuration.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,8 @@ Arguments:
20212021
- login_timeout (int, default=60): timeout for password/login prompt detection
20222022
- for other arguments, see `UBootDriver`_
20232023

2024+
.. _UBootProviderInfo:
2025+
20242026
UBootProviderDriver
20252027
~~~~~~~~~~~~~~~~~~~
20262028

@@ -2064,6 +2066,11 @@ Variables:
20642066
specified in the environment file
20652067
- do-clean (str): If set to "1" this cleans the build before starting,
20662068
otherwise it does an incremental build
2069+
- build-dir (str): If set, this is used as the build directory for U-Boot
2070+
- process-limit (int): Limits the number of buildman processes which can
2071+
be running jobs at once. Set this to 1 to avoid over-taxing your
2072+
CPU. Buildman does its own multithreading, so each process will use
2073+
all available CPUs anyway.
20672074

20682075
Environment variables:
20692076
- U_BOOT_BUILD_DIR (str): If present, this is used as the build directory for
@@ -2115,6 +2122,8 @@ Tools:
21152122
tools:
21162123
buildman: "buildman.stable"
21172124
2125+
.. _UBootWriterInfo:
2126+
21182127
UBootWriterDriver
21192128
~~~~~~~~~~~~~~~~~
21202129

@@ -3875,6 +3884,8 @@ the "shell" state:
38753884
This command would transition directly into a Linux shell and
38763885
activate the `ShellDriver`_.
38773886

3887+
.. _UBootStrategyInfo:
3888+
38783889
UBootStrategy
38793890
~~~~~~~~~~~~~
38803891
A :any:`UBootStrategy` has five states:

doc/usage.rst

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,280 @@ like this:
883883
$ labgrid-client -p example allow sirius/john
884884
885885
To remove the allow it is currently necessary to unlock and lock the place.
886+
887+
U-Boot Integration
888+
------------------
889+
890+
.. note::
891+
See status_ for current status and development branches.
892+
893+
Most ARM boards (and some others) use U-Boot as their bootloader. Labgrid
894+
provides various features to help with development and testing on these boards.
895+
Together these features allow interactive use of Labgrid to build U-Boot from
896+
source, write it to a board and boot it. Support is provided for U-Boot's pytest
897+
and Gitlab setup.
898+
899+
This section describes the various features which contribute to the overall
900+
functionality. The names of contributed scripts (in *contrib/u-boot*) are shown
901+
in brackets.
902+
903+
Interactive use
904+
~~~~~~~~~~~~~~~
905+
906+
Labgrid provides a 'console' command which can be used to connect to a board.
907+
The :ref:`UBootStrategyInfo` driver provides a way to power cycle (or reset)
908+
the board so that U-Boot starts. It also provides two useful states:
909+
910+
- `start` which starts up U-Boot and lets it boot (*ub-int*)
911+
- `uboot` which starts up U-Boot and stops it at the CLI prompt (*ub-cli*)
912+
913+
Both of these are useful in development.
914+
915+
Building U-Boot
916+
~~~~~~~~~~~~~~~
917+
918+
Labgrid intentionally
919+
`doesn't include <https://github.com/labgrid-project/labgrid/issues/1068>`_
920+
build functionality as usually the software-under-test already comes with a
921+
build system and it wants to test the artifacts as built by the "real" build
922+
system.
923+
924+
U-Boot is no exception and it provides the
925+
`buildman <https://docs.u-boot.org/en/latest/build/buildman.html>`_ for this
926+
purpose.
927+
928+
Still, for interactive use some sort of build is needed. The
929+
:ref:`UBootProviderInfo` provides an interface to buildman and a way of dealing
930+
with board-specific binary blobs. The buildman tool works automatically provided
931+
that you have set it up with suitable toolchains. See
932+
`buildman <https://docs.u-boot.org/en/latest/build/buildman.html>`_ for more
933+
information.
934+
935+
Writing U-Boot
936+
~~~~~~~~~~~~~~
937+
938+
Writing U-Boot to a board can be complicated, because each SoC uses its own
939+
means of booting. The other problem is that special lab hardware is generally
940+
needed to update the boot device, e.g.
941+
`SD-wire <https://wiki.tizen.org/SD_MUX>`_.
942+
943+
Fortunately Labgrid provides the means for manipulating the lab hardware. All
944+
that is needed is a driver which understands where to write images, which files
945+
to use and the sequence to use in each case. The :ref:`UBootWriterInfo` driver
946+
handles this. It picks out the necessary files from a build directory and writes
947+
them to the selected boot media, or sends them using the SoC-specific bootrom.
948+
Combined with :ref:`UBootStrategyInfo` it provides automated updating of U-Boot
949+
on suported SoCs regardless of the lab setup.
950+
951+
Run labgrid tests
952+
~~~~~~~~~~~~~~~~~
953+
954+
Labgrid provides integration with pytest. As part of the U-Boot integration, a
955+
conftest.py file is provided which can build and smoke-test U-Boot on a board
956+
(*ub-smoke*).
957+
958+
Run U-Boot tests
959+
~~~~~~~~~~~~~~~~~
960+
961+
It is also possible to run the U-Boot tests (*ub-pyt*). To do this you will need
962+
to set up Labgrid integration with the
963+
`U-Boot test hooks <https://source.denx.de/u-boot/u-boot-test-hooks>`_.
964+
To do this, create the directory `u-boot-test-hooks/bin/$hostname` and add an
965+
executable file called `common.labgrid` which sets the crossbar and environment
966+
information:
967+
968+
.. code-block:: bash
969+
970+
export LG_CROSSBAR="ws://kea:20408/ws"
971+
export LG_ENV="/path/to/env.cfg"
972+
973+
flash_impl=none
974+
reset_impl=none
975+
console_impl=labgrid
976+
release_impl=labgrid
977+
978+
The last four lines tell the hooks to use labgrid.
979+
980+
Then create another executable file (in the same directory) called 'conf.all',
981+
containing:
982+
983+
.. code-block:: bash
984+
985+
. "${bin_dir}/${hostname}/common-labgrid"
986+
987+
Bisecting
988+
~~~~~~~~~
989+
990+
It is possible to use the *ub-pyt* or *ub-smoke* scripts with `git bisect run`
991+
to bisect a problem on a particular board. However there is a slightly more
992+
powerful script which supports applying a commit each time (*ub-bisect*).
993+
994+
Setting up pytest
995+
~~~~~~~~~~~~~~~~~
996+
997+
To set up the U-Boot pytest integration:
998+
999+
#. Copy the `contrib/u-boot` directory to somewhere suitable and add it to your
1000+
path. For example:
1001+
1002+
.. code-block:: bash
1003+
1004+
cp -a contrib/u-boot ~/bin/u-boot
1005+
echo 'PATH="$PATH:~/bin/u-boot"' >> ~/.bashrc
1006+
1007+
#. Edit the `lg-env` file to set the lab parameters according to your setup.
1008+
#. Start a new terminal, or login again, so the path updates. You can now use
1009+
the scripts as documented below.
1010+
1011+
Gitlab Integration
1012+
~~~~~~~~~~~~~~~~~~
1013+
1014+
U-Boot uses `Gitlab <https://gitlab.com>`_ as the basis for its Continuous
1015+
Integration (CI) system (`U-Boot instance <https://source.denx.de/u-boot>`_).
1016+
It is possible to set up your own lab which integrates with Gitlab, with your
1017+
own Git lab 'runner' which can control Labgrid. This allows pushing branches to
1018+
Gitlab and running tests on real hardware, similarly to how QEMU is used in
1019+
Gitlab.
1020+
1021+
To set this up:
1022+
1023+
#. Install `gitlab-runner` using these
1024+
`instructions <https://docs.gitlab.com/runner/install/linux-repository.html>`_.
1025+
1026+
#. Register a
1027+
`new runner <https://docs.gitlab.com/ee/tutorials/create_register_first_runner>`_
1028+
following the instructions using your custodian CI settings (i.e. do this at
1029+
`https://source.denx.de`).
1030+
1031+
Select Linux and with tags set to `lab`. Click `Create runner` and use the
1032+
command line to register the runner. Use `<hostname>-lab` (for example
1033+
`kea-lab`) as your host name and select `shell` as the executor:
1034+
1035+
.. code-block:: console
1036+
1037+
$ gitlab-runner register --url https://source.denx.de --token glrt-xxx
1038+
Enter the GitLab instance URL (for example, https://gitlab.com/):
1039+
[https://source.denx.de]:
1040+
Verifying runner... is valid runner=yyy
1041+
Enter a name for the runner. This is stored only in the local config.toml file:
1042+
[<hostname>]: <hostname>-lab
1043+
Enter an executor: ssh, parallels, docker-windows, docker+machine, kubernetes, instance, custom, shell, virtualbox, docker, docker-autoscaler:
1044+
shell
1045+
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
1046+
1047+
#. Edit the resulting `/etc/gitlab-runner/config.toml` file to allow more than
1048+
one job at a time by adding 'concurrent = x' where x is the number of jobs.
1049+
Here we use concurrent = 8 (this is just an example; don't replace your file
1050+
with this):
1051+
1052+
.. code-block:: toml
1053+
1054+
concurrent = 8
1055+
check_interval = 0
1056+
shutdown_timeout = 0
1057+
1058+
[session_server]
1059+
session_timeout = 1800
1060+
1061+
[[runners]]
1062+
name = "ellesmere-lab"
1063+
url = "https://source.denx.de"
1064+
id = 130
1065+
token = "..."
1066+
token_obtained_at = 2024-05-15T20:41:29Z
1067+
token_expires_at = 0001-01-01T00:00:00Z
1068+
executor = "shell"
1069+
[runners.custom_build_dir]
1070+
1071+
#. Gitlab will run tests as the 'gitlab-runner' user. Make sure your labgrid
1072+
installation is installed such that it is visible to that user. One way is:
1073+
1074+
.. code-block:: bash
1075+
1076+
sudo su - gitlab-runner
1077+
cd /path/to/labgrid
1078+
pip install .
1079+
1080+
#. Add the following to U-Boot's `.gitlab-ci.yml`, adjusting the variables as
1081+
needed. For trying it out initially you might want to disable all the other
1082+
rules by changing `when: always` to `when: never`:
1083+
1084+
.. code-block:: yaml
1085+
1086+
.lab_template: &lab_dfn
1087+
stage: lab
1088+
tags: [ 'lab' ]
1089+
script:
1090+
# Environment:
1091+
# SRC - source tree
1092+
# ROOT - directory above that
1093+
# OUT - output directory for builds
1094+
- export SRC="$(pwd)"
1095+
- ROOT="$(dirname ${SRC})"
1096+
- export OUT="${ROOT}/out"
1097+
- export PATH=$PATH:~/bin
1098+
- export PATH=$PATH:/vid/software/devel/ubtest/u-boot-test-hooks/bin
1099+
1100+
# Load it on the device
1101+
- ret=0
1102+
- echo "board ${BOARD} id ${ID}"
1103+
- ${SRC}/test/py/test.py -B "${BOARD}" --id ${ID} --configure
1104+
--build-dir "${OUT}/current/${BOARD}" -k "not bootstd"|| ret=$?
1105+
- if [[ $ret -ne 0 ]]; then
1106+
exit $ret;
1107+
fi
1108+
1109+
rpi3:
1110+
variables:
1111+
BOARD: rpi_3_32b ## This is a U-Boot board name
1112+
ID: rpi3 ## This is the corresponding role/target
1113+
<<: *lab_dfn
1114+
1115+
#. Commit your changes and push to your custodian tree. This example shows the
1116+
driver model tree at a remote called 'dm':
1117+
1118+
.. code-block:: bash
1119+
1120+
$ git remote -v |grep dm
1121+
dm git@source.denx.de:u-boot/custodians/u-boot-dm.git (fetch)
1122+
dm git@source.denx.de:u-boot/custodians/u-boot-dm.git (push)
1123+
$ git push dm HEAD:try
1124+
1125+
#. Navigate to the pipelines and you should see your tests running. You can
1126+
debug things from there, e.g. using the `ub-int` or `ub-pyt` scripts on an
1127+
individual board. An example may be visible
1128+
`here <https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/20769>`_.
1129+
1130+
Scripts
1131+
~~~~~~~
1132+
1133+
Various scripts are provided in the `contrib/` directory, specifically targeted
1134+
at U-Boot testing and development.
1135+
1136+
.. include:: ../contrib/u-boot/index.rst
1137+
1138+
1139+
.. _status:
1140+
1141+
U-Boot Integration Status
1142+
~~~~~~~~~~~~~~~~~~~~~~~~~
1143+
1144+
Date: May '24
1145+
Overall status: Ready for early testing
1146+
1147+
Required pieces:
1148+
1149+
- `Labgrid WIP PR <https://github.com/sjg20/labgrid/tree/u-boot-integration>`_
1150+
- `U-Boot test hooks branch <https://github.com/sjg20/uboot-test-hooks/tree/labgrid>`_
1151+
- `U-Boot branch <https://github.com/sjg20/u-boot/tree/labgrid>`_ (needed for
1152+
U-Boot pytest integration)
1153+
1154+
Testing has been very limited, basically a set of 21 boards, including sunxi,
1155+
rpi, RK3399, ODroid-C4, pine64, Orange Pi PC, various Chromebooks and Intel
1156+
Minnowboard Max.
1157+
1158+
Some U-Boot pytests fails on some hardware:
1159+
- TPM tests fail on boards with a TPM
1160+
- test_log_format fails on several (perhaps all?) boards
1161+
1162+
There are likely many other problems.

0 commit comments

Comments
 (0)