aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2023-09-15pylibfdt: Support boolean propertiesHEADmastermainSimon Glass2-0/+34
Boolean properties are unusual in that their presense or absence indicates the value of the property. This makes them a little painful to support using the existing getprop() support. Add new methods to deal with booleans specifically. Signed-off-by: Simon Glass <sjg@chromium.org> Message-ID: <20230912182716.248253-1-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-04tests: generate dtbs in Meson build directoryBrandon Maier1-2/+3
When running under Meson, check_tests() is generating dtb build files in the source directory. This is because dtb is named by appending ".test.dtb" to the full source file name. Use basename to extract just the source filename and write it to the working directory which is the build directory. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-08-03tests: fix use of deprecated meson methodsBrandon Maier1-2/+2
Fixes the following warnings > tests/meson.build:123: WARNING: Project targets '>=0.56.0' but uses feature deprecated since '0.55.0': ExternalProgram.path. use ExternalProgram.full_path() instead > tests/meson.build:124: WARNING: Project targets '>=0.56.0' but uses feature deprecated since '0.56.0': meson.source_root. use meson.project_source_root() or meson.global_source_root() instead. Signed-off-by: Brandon Maier <brandon.maier@collins.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14dtc: Correct invalid dts output with mixed phandles and integersDavid Gibson2-0/+2
The handling of "type preservation" dts output is based on the idea of "phandles with arguments" in properties, which isn't really a thing, other than a fairly common convention about how bindings are written. There's nothing preventing a binding which freely mixes phandles and other integers in an array of cells. Currently write_propval() handles this incorrectly: specifically the case of a phandle which follows a regular integer in a 32-bit cell array, but without a new '< >' delimited causing an extra TYPE_UINT32 marker to be inserted. In this case it omits the necessary space between the integer and the phandle reference, leading to output which can't be sent back into dtc and parsed. Correct this, and update tests to match. I think this is more or less correct for now, but really write_propval() is a big mess :(. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14tests: Add additional tests for device graph checksJohannes Beisswenger3-0/+61
* bad-graph-child-address.dts: additional child address test since the one in bad-graph.dts is now shadowed by its prerequisites also failing. * bad-graph-reg-cells.dts: test warnings produced by check_graph_reg(). Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-05-14yaml: Depend on libyaml >= 0.2.3Uwe Kleine-König1-1/+1
libyaml before 0.2.3 expects non-const string parameters. Supporting both variants would require either cpp magic or ignoring "discarded-qualifiers" compiler warnings. For the sake of simplicity just support libyaml 0.2.3 and newer. Note that NO_YAML can be overwritten on the make command line. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
2023-05-07tests: Add test cases for bad endpoint node and remote-endpoint prop checksJohannes Beisswenger5-0/+46
Signed-off-by: Johannes Beisswenger <johannes.beisswenger@cetitec.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01tests: fix leaks spotted by ASANMarc-André Lureau10-21/+25
Always allocate from open_blob_rw(), to simplify memory management. The fixes are not exhaustive. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-03-01tests: fix -Wwrite-stringsMarc-André Lureau2-3/+3
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-28meson: Fix cell overflow tests when running from mesonDavid Gibson1-2/+2
Because meson always builds out-of-tree we need to reference things in the original source tree via $SRCDIR from run_tests.sh. We forgot a couple of cases for the cell overflow tests. Fix them. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2023-02-27Use #ifdef NO_VALGRINDMarc-André Lureau1-1/+1
Using simply #if will fail when NO_VALGRIND is undefined. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-02-27Do not redefine _GNU_SOURCE if already setMarc-André Lureau1-0/+2
Or else, compilation will fail. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-02-05pylibfdt: add size_hint parameter for get_pathLuca Weiss1-0/+1
This also enables us to test the -NOSPACE condition by adding a test setting size_hint=1 so this path is taken. Message-Id: <20230201181112.1644842-1-luca@z3ntu.xyz> Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-11-21dtc: Warning rather than error on possible truncation of cell valuesDavid Gibson3-0/+19
We always evaluate integer values in cell arrays as 64-bit quantities, then truncate to the size of the array cells (32-bit by default). However to detect accidental truncation of meaningful values, we give an error if the truncated portion isn't either all 0 or all 1 bits. However, this can still give counterintuitive errors. For if the user is thinking in 2's complement 32-bit arithmetic (which would be quite natural), then they'd expect the expression (-0xffffffff-2) to evaluate to -1 (0xffffffff). However in 64-bit it evaluates to 0xfffffffeffffffff which does truncate to the expected value but trips this error message. Because of this reduce the error to only a warnings, with a somewhat more helpful message. Fixes: https://github.com/dgibson/dtc/issues/74 Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-10-12libfdt: tests: add get_next_tag_invalid_prop_lenTadeusz Struk5-1/+104
Add a new test get_next_tag_invalid_prop_len, which covers fdt_next_tag(), when it is passed an corrupted blob, with invalid property len values. The test runs twice, on a blob in sw and finished state. Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org> Message-Id: <20221011182611.116011-2-tadeusz.struk@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-31Don't generate erroneous fixups from reference to pathDavid Gibson2-0/+7
The dtb overlay format only permits (non local) fixups to reference labels, not paths. That's because the fixup target goes into the property name in the overlay, and property names aren't permitted to include '/' characters. Stop erroneously generating such fixups, because we didn't check for this case. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-27Allow static building with mesonTero Tervala1-2/+7
Added "static-build" option in the meson_options.txt. Setting it to "true" allows static building. Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220629163557.932298-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-27Allow static building with makeTero Tervala2-8/+14
Set STATIC_BUILD=1 environment variable to enable static building when using makefiles. Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220629163531.932281-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-26Fix test script to run also on dash shellTero Tervala1-2/+2
/bin/sh points to dash instead of bash in some linux distros. One test would fail if dash was used, this fix will allow all tests to run properly on dash too. dash built-in printf does not support "\xNN" -hex escape format. "\NNN" -octal escape format is supported by both bash and dash printf. Replaced "$(echo "$expect")" because this actually runs /bin/echo instead of shell internal echo and in some cases causes "\NNN" escapes to be printed as the actual characters they represent instead of the escape sequence itself. Cosmetic quotes added to make printout a bit clearer. Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220704073722.1075849-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-07-02Add missing relref_merge test to meson test listTero Tervala1-0/+1
Will remove one "Strange test result" when running tests with meson Signed-off-by: Tero Tervala <tero.tervala@unikie.com> Message-Id: <20220629163114.932175-1-tero.tervala@unikie.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-04-20pylibfdt: add FdtRo.get_path()Luca Weiss1-0/+13
Add a new Python method wrapping fdt_get_path() from the C API. Also add a test for the new method. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20220419194537.63170-1-luca@z3ntu.xyz> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2022-01-25tests: add test cases for label-relative path referencesAhmad Fatoum7-2/+112
Newly added &{label/path} feature doesn't yet have any tests. Add some. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
2021-12-29Handle integer overflow in check_property_phandle_args()David Gibson2-0/+21
If the corresponding '#xxx-cells' value is much too large, an integer overflow can prevent the checks in check_property_phandle_args() from correctly determining that the checked property is too short for the given cells value. This leads to an infinite loops. This patch fixes the bug, and adds a testcase for it. Further information in https://github.com/dgibson/dtc/issues/64 Reported-by: Anciety <anciety@pku.edu.cn> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28tests: setprop_inplace: use xstrdup instead of unchecked strdupAhmad Fatoum1-1/+1
This is the only strdup instance we have, all others are xstrdup. As strdup is _POSIX_C_SOURCE >= v200809L, which we don't require and we don't check strdup error return here, switch to xstrdup instead. This aligns the test with others that call xfuncs, mainly xmalloc(). Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28pylibfdt: add Property.as_*int*_array()Luca Weiss2-0/+15
Add new methods to handle decoding of int32, uint32, int64 and uint64 arrays. Also add tests for the new methods. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211225132558.167123-3-luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-28pylibfdt: add Property.as_stringlist()Luca Weiss1-0/+8
Add a new method for decoding a string list property, useful for e.g. the "reg-names" property. Also add a test for the new method. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Message-Id: <20211225132558.167123-2-luca@z3ntu.xyz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-12-09Support 'r' format for printing raw bytes with fdtgetRafał Miłecki2-1/+6
FT is sometimes used for storing raw data. That is quite common for U-Boot FIT images. Extracting such data is not trivial currently. Using type 's' (string) will replace every 0x00 (NUL) with 0x20 (space). Using type 'x' will print bytes but in xxd incompatible format. This commit adds support for 'r' (raw) format. Example usage: fdtget -t r firmware.itb /images/foo data > image.raw Support for encoding isn't added as there isn't any clean way of passing binary data as command line argument. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Message-Id: <20211209061420.29466-1-zajec5@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-10-21checks: Add an interrupt-map checkRob Herring4-0/+59
Add a check for parsing 'interrupt-map' properties. The check primarily tests parsing 'interrupt-map' properties which depends on and the parent interrupt controller (or another map) node. Note that this does not require '#address-cells' in the interrupt-map parent, but treats missing '#address-cells' as 0 which is how the Linux kernel parses it. There's numerous cases that expect this behavior. Cc: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20211015213527.2237774-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-10-11treesource: Maintain phandle label/path on outputRob Herring2-0/+6
The dts output will just output phandle integer values, but often the necessary markers are present with path or label references. Improve the output and maintain phandle label or path references when present in dts output. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210727183023.3212077-6-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-09-27asm: Use assembler macros instead of cpp macrosDavid Gibson1-194/+207
tests/trees.S is a weird thing: a portable aseembler file, used to produce a specific binary output. Currently it uses CPP macros quite heavily to construct the dtbs we want (including some partial and broken trees). Using cpp has the side effect that we need to use ; separators between instructions (or, rather, pseudo-ops), because cpp won't expand newlines. However, it turns out that while ; is a suitable separator on most targets, it doesn't work for all of them (e.g. HP PA-RISC). Switch to using the assembler's inbuilt macros rather than CPP, so that we can use genuine newlines. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-09-25asm: Use .asciz and .ascii instead of .stringRob Herring3-51/+49
We use the .string pseudo-op both in some of our test assembly files and in our -Oasm output. We expect this to emit a \0 terminated string into the .o file. However for certain targets (e.g. HP PA-RISC) it doesn't include the \0. Use .asciz instead, which explicitly does what we want. There's also one place we can use .ascii (which explicitly emits a string *without* \0 termination) instead of multiple .byte directives. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-21tests: Fix signedness comparisons warningsAndre Przywara13-16/+35
With -Wsign-compare, compilers warn about a mismatching signedness in comparisons in various files in the tests/ directory. For about half of the cases we can simply change the signed variable to be of an unsigned type, because they will never need to store negative values (which is the best fix of the problem). In the remaining cases we can cast the signed variable to an unsigned type, provided we know for sure it is not negative. We see two different scenarios here: - We either just explicitly checked for this variable to be positive (if (rc < 0) FAIL();), or - We rely on a function returning only positive values in the "length" pointer if the function returned successfully: which we just checked. At two occassions we compare with a constant "-1" (even though the variable is unsigned), so we just change this to ~0U to create an unsigned comparison value. Since this is about the tests, let's also add explicit tests for those values really not being negative. This fixes "make tests" (but not "make check" yet), when compiled with -Wsign-compare. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20210618172030.9684-2-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-06-08checks: Drop interrupt_cells_is_cell checkRob Herring1-2/+2
With the prior commit, this check is now redundant. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210526010335.860787-4-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-05-04tests: add a positive gpio test caseIlya Lipnitskiy2-0/+14
Ensure that properly named properties don't trigger warnings Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com> Message-Id: <20210504035944.8453-5-ilya.lipnitskiy@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-23libfdt: Check that the root-node name is emptySimon Glass5-3/+20
The root node is supposed to have an empty name, but at present this is not checked. The behaviour of such a tree is not well defined. Most software rightly assumes that the root node is at offset 0 and does not check the name. This oddity was discovered as part of a security investigation into U-Boot verified boot. Add a check for this to fdt_check_full(). Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Arie Haenel <arie.haenel@intel.com> Reported-by: Julien Lenoir <julien.lenoir@intel.com> Message-Id: <20210323010410.3222701-2-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2021-03-23libfdt: Check that there is only one root nodeSimon Glass5-2/+25
At present it is possible to have two root nodes and even access nodes in the 'second' root. Such trees should not be considered valid. This was discovered as part of a security investigation into U-Boot verified boot. Add a check for this to fdt_check_full(). Signed-off-by: Simon Glass <sjg@chromium.org> Reported-by: Arie Haenel <arie.haenel@intel.com> Reported-by: Julien Lenoir <julien.lenoir@intel.com> Message-Id: <20210323000926.3210733-1-sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-22tests: Fix overlay_overlay_nosugar test casePaul Barker2-5/+5
This test was accidentally skipped as the wrong test dts file was built. The fragment numbering in this sugar-free test case needed adjusting to match the numbering generated by dtc for overlay_overlay.dts. Signed-off-by: Paul Barker <pbarker@konsulko.com> Message-Id: <20201219143521.2118-1-pbarker@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-08meson: increase default timeout for testsMarc-André Lureau1-0/+1
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201207130055.462734-4-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-12-08meson: do not assume python is installed, skip testsMarc-André Lureau1-6/+6
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201207130055.462734-3-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-10-21build-sys: add meson buildMarc-André Lureau1-0/+130
The meson build system allows projects to "vendor" dtc easily, thanks to subproject(). QEMU has recently switched to meson, and adding meson support to dtc will help to handle the QEMU submodule. meson rules are arguably simpler to write and maintain than the hand-crafted/custom Makefile. meson support various backends, and default build options (including coverage, sanitizer, debug/release etc, see: https://mesonbuild.com/Builtin-options.html) Compare to the Makefiles, the same build targets should be built and installed and the same tests should be run ("meson test" can be provided extra test arguments for running the equivalent of checkm/checkv). There is no support EXTRAVERSION/LOCAL_VERSION/CONFIG_LOCALVERSION, instead the version is simply set with project(), and vcs_tag() is used for git/dirty version reporting (This is most common and is hopefully enough. If necessary, configure-time options could be added for extra versioning.). libfdt shared library is build following regular naming conventions: instead of libfdt.so.1 -> libfdt-1.6.0.so (with current build-sys), libfdt.so.1 -> libfdt.so.1.6.0. I am not sure why the current build system use an uncommon naming pattern. I also included a libfdt.pc pkg-config file, as convenience. Both Linux native build and mingw cross-build pass. CI pass. Tests are only run on native build. The current Makefiles are left in-tree, and make/check still work. Eventually, the Makefiles could be marked as deprecated, to start a transition period and avoid having to maintain 2 build systems in the near future. (run_tests.sh could eventually be replaced by the meson test runner, which would have several advantages in term of flexibility/features, but this is left for another day) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201012073405.1682782-3-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-05-18checks: Add interrupt provider testAndre Przywara2-0/+8
An interrupt provider (an actual interrupt-controller node or an interrupt nexus) should have both #address-cells and #interrupt-cells properties explicitly defined. Add an extra test for this. We check for the #interrupt-cells property already, but this does not cover every controller so far, only those that get referenced by an interrupts property in some node. Also we miss interrupt nexus nodes. A missing #address-cells property is less critical, but creates ambiguities when used in interrupt-map properties, so warn about this as well now. This removes the now redundant warning in the existing interrupts test. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Message-Id: <20200515141827.27957-2-andre.przywara@arm.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04tests: Allow running the testsuite on already installed binary / librariesDavid Gibson2-6/+13
Currently the test runner script always expects to be run from within the tests/ subdirectory of a dtc source tree: it looks for dtc and other binaries in the parent of the current directory and for the libfdt shared library in ../libfdt. That works great with make check and for testing a build you've just made. However, sometimes it's useful to test a dtc & libfdt which have already been installed on the system, or which for whatever reason are located somewhere else. This patch allows the test runner script to do this when TEST_BINDIR and/or TEST_LIBDIR environment variables are set. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04tests: Honour NO_YAML make variableDavid Gibson1-1/+15
Support for YAML output in dtc is optional (to cover systems that don't have libyaml). Currently the tests for yaml output test if the libyaml package is locally installed. That duplicates similar logic in the Makefile, and worse it will cause failed tests if the user explicitly disables YAML support, rather than simply not having libyaml installed. Fix this by having the test script use the NO_YAML variable exported by make. Fall back to the current test if the variable isn't set, such as when running the script manually. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04tests: Properly clean up .bak file from testsDavid Gibson1-1/+1
One of our testcases creates a .bak file from invoking sed. Fix that to be removed by make clean, and also ignore it in git to avoid clutter. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04tests: Honour $(NO_PYTHON) flag from Makefile in run_tests.shDavid Gibson1-1/+15
Currently the test script bases whether to run the Python tests on whether it can see a built Python module. That can easily be fooled if there is a stale module there. Instead, have it actually look at the NO_PYTHON variable exported from the Makefile. If the variable doesn't exist (such as if we're running the script manually) fall back on the old logic. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04tests: No need to explicitly pass $PYTHON from Make to run_tests.shDavid Gibson1-3/+3
Make automatically passes its variables through the environment, so we don't need to explicitly copy this one into the test script. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04tests: Let run_tests.sh run Python tests without Makefile assistanceDavid Gibson1-0/+4
Currently run_tests.sh needs the $PYTHON environment variable set to correctly run pylibfdt tests. The Makefile does this for make check, but it breaks if the script is run manually. Add a fallback to handle that case. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2020-03-04checks: Add 'dma-ranges' checkRob Herring2-0/+13
Generalize the existing 'ranges' check to also work for 'dma-ranges' which has the same parsing requirements. Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20200303193931.1653-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-16tests: default to 'cc' if CC not setEd Maste1-1/+1
By default FreeBSD does not have 'gcc' in the PATH (on common platforms). As on Linux 'cc' is available as a link to the default compiler (Clang or GCC), so just use 'cc'. Signed-off-by: Ed Maste <emaste@freebsd.org> Message-Id: <20191115155108.39488-1-emaste@freefall.freebsd.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-11-15Add test-case for trailing zeroStefan Mavrodiev1-0/+4
If there is trailing zero, fdtget adds extra chacarter to the property value. Thus comparing the expected with the actual value, an error is emitted. Signed-off-by: Stefan Mavrodiev <stefan@olimex.com> Message-Id: <20191111080444.9819-3-stefan@olimex.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>