Commit Graph

148 Commits

Author SHA1 Message Date
Alper Nebi Yasak
1e4687aa47 binman: Use target-specific tools when cross-compiling
Currently, binman always runs the compile tools like cc, objcopy, strip,
etc. using their literal name. Instead, this patch makes it use the
target-specific versions by default, derived from the tool-specific
environment variables (CC, OBJCOPY, STRIP, etc.) or from the
CROSS_COMPILE environment variable.

For example, the u-boot-elf etype directly uses 'strip'. Trying to run
the tests with 'CROSS_COMPILE=i686-linux-gnu- binman test' on an arm64
host results in the '097_elf_strip.dts' test to fail as the arm64
version of 'strip' can't understand the format of the x86 ELF file.

This also adjusts some command.Output() calls that caused test errors or
failures to use the target versions of the tools they call. After this,
patch, an arm64 host can run all tests with no errors or failures using
a correct CROSS_COMPILE value.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-09-22 12:54:13 -06:00
Simon Glass
946ec85037 dtoc: Add a setup script for Python
Allow dtoc to be installed by adding a suitable setup.py script.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-08-22 08:53:38 -06:00
Walter Lozano
e9ab331ca6 dtoc: remove compatible string aliases support
After latest improvements in dtoc, compatible strings are checked
against driver and driver alias list to get a valid driver name. With
this new feature the list of compatible string aliases seems not
useful any more.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-28 19:30:39 -06:00
Walter Lozano
dcb3ed642b dtoc: look for compatible string aliases in driver list
Currently dtoc checks if the first compatible string in a dtb node
matches either a driver o driver alias name, without taking into account
any other compatible string in the list. In the case that no driver matches
the first compatible string a warning is printed and the U_BOOT_DEVICE is
not being declared correctly.

This patch adds dtoc's support for try all the compatible strings in the
dtb node, in an effort to find the correct driver.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-28 19:30:39 -06:00
Walter Lozano
6c74d1b832 dtoc: add coverage test for unicode error
Add an additional test to dtoc in order improve the coverage,
specifically to take into account the case of unicode error when
scanning drivers.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
2020-07-28 19:30:39 -06:00
Simon Glass
c063917906 dtoc: Allow adding variable-sized data to a dtb
Add a method for adding a property containing arbitrary bytes. Make sure
that the tree can expand as needed in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-25 14:46:57 -06:00
Tom Rini
7208396bbf Revert "Merge tag 'dm-pull-20jul20' of git://git.denx.de/u-boot-dm"
This reverts commit 5d3a21df66, reversing
changes made to 56d37f1c56.

Unfortunately this is causing CI failures:
https://travis-ci.org/github/trini/u-boot/jobs/711313649

Signed-off-by: Tom Rini <trini@konsulko.com>
2020-07-24 08:42:06 -04:00
Simon Glass
1f238bd5bd dtoc: Allow adding variable-sized data to a dtb
Add a method for adding a property containing arbitrary bytes. Make sure
that the tree can expand as needed in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-20 11:37:47 -06:00
Simon Glass
f02d0eb3fa dtoc: Support ACPI paths in of-platdata
The start of an ACPI path typically has backslashes in it. These are not
preserved during the translation from device tree to C code, since dtc
(correctly) uses the first backslash as an escape character, and dtoc
therefore leaves it out of the C string.

Fix this with special-case handling.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-17 14:32:24 +08:00
Walter Lozano
6c3fc50ee5 dtoc: add test for cd-gpios
Add a test for dtoc taking into account the cd-gpios property.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-09 22:00:29 -06:00
Walter Lozano
ad34017c8c dtoc: update dtb_platdata to support cd-gpios
Currently dtoc does not support the property cd-gpios used to declare
the gpios for card detect in mmc.

This patch adds support to cd-gpios property.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-09 22:00:29 -06:00
Walter Lozano
51f1263d89 dtoc: extend dtoc to use struct driver_info when linking nodes
In the current implementation, when dtoc parses a dtb to generate a struct
platdata it converts the information related to linked nodes as pointers
to struct platdata of destination nodes. By doing this, it makes
difficult to get pointer to udevices created based on these
information.

This patch extends dtoc to use struct driver_info when populating
information about linked nodes, which makes it easier to later get
the devices created. In this context, reimplement functions like
clk_get_by_index_platdata() which made use of the previous approach.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-09 22:00:29 -06:00
Walter Lozano
361e733596 dtoc: add option to disable warnings
As dtoc now performs checks for valid driver names, when running dtoc
tests several warnings arise as these tests don't use valid driver
names.

This patch adds an option to disable those warning, which is only
intended for running tests.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-09 22:00:29 -06:00
Walter Lozano
dac8228df9 dtoc: add support to scan drivers
Currently dtoc scans dtbs to convert them to struct platdata and
to generate U_BOOT_DEVICE entries. These entries need to be filled
with the driver name, but at this moment the information used is the
compatible name present in the dtb. This causes that only nodes with
a compatible name that matches a driver name generate a working
entry.

In order to improve this behaviour, this patch adds to dtoc the
capability of scan drivers source code to generate a list of valid driver
names and aliases. This allows to generate U_BOOT_DEVICE entries using
valid driver names and rise a warning in the case a name is not valid.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Open files in utf-8 mode:
Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-09 22:00:15 -06:00
Walter Lozano
ace16e88d9 dtoc: add missing code comments
Add missing information about internal class members in order to make
the code easier to follow.

Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-07-09 18:57:22 -06:00
Simon Glass
b4fa94959d patman: Tidy up sys.path changes
Now that we are using absolute paths we can remove some of the sys.path
mangling that appears in the tools.

We only need to add the path to 'tools/' so that everything can find
modules relative to that directory.

The special paths for finding pylibfdt remain.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-26 14:25:21 -06:00
Simon Glass
bf776679a7 patman: Move to absolute imports
At present patman sets the python path on startup so that it can access
the libraries it needs. If we convert to use absolute imports this is not
necessary.

Move patman to use absolute imports. This requires changes in tools which
use the patman libraries (which is most of them).

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-26 14:25:21 -06:00
Simon Glass
4d25fe2d95 dtoc: Rename the main module
Python does not like the module name being the same as the module
directory. To allow dtoc modules to be used from other tools, rename
it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-26 14:25:21 -06:00
Simon Glass
83a4518771 patman: Drop references to __future__
We don't need these now that the tools using Python 3. Drop them.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-26 14:25:21 -06:00
Heinrich Schuchardt
2799a69ee8 doc: fix references to driver-model
Fix some errors pointed out by 'make refcheckdocs'.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
2020-04-17 12:32:36 -04:00
Simon Glass
a90df2b172 dtoc: Convert fdt.py to Python 3
Drop the now-unused Python 2 code to keep code coverage at 100%.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-11-04 18:15:32 -07:00
Simon Glass
3c19dc8b68 test_dtoc: Move to use Python 3
Update this test to use Python 3 to meet the 2020 deadline.

Also make it executable while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-11-04 18:15:32 -07:00
Simon Glass
f7ba5f0db2 test_fdt: Move to use Python 3
Update this test to use Python 3 to meet the 2020 deadline.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-11-04 18:15:32 -07:00
Simon Glass
f6e02497ae binman: Update state when replacing device-tree entries
Since the state module holds references to all the device trees used by
binman, it must be updated when the device trees are updated. Add support
for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29 09:38:06 -06:00
Simon Glass
a004f29464 binman: Tidy up _SetupDtb() to use its own temporary file
At present EnsureCompiled() uses an file from the 'output' directory (in
the tools module) when compiling the device tree. This is fine in most
cases, allowing useful inspection of the output files from binman.

However in functional tests, _SetupDtb() creates an output directory and
immediately removes it afterwards. This serves no benefit and just
confuses things, since the 'official' output directory is supposed to be
created and destroyed in control.Binman().

Add a new parameter for the optional temporary directory to use, and use a
separate temporary directory in _SetupDtb().

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29 09:38:06 -06:00
Simon Glass
e44bc831e2 dtoc: Update Fdt.GetNode() to handle the root node
This function currently fails if the root node is requested. Requesting
the root node is sometimes useful, so fix the bug.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29 09:38:05 -06:00
Simon Glass
880e9ee650 dtoc: Update Fdt.FromData() to allow a name
It is confusing when something goes wrong with a device tree which was
created from data rather than a file, since there is no identifying
filename. Add an option to provide this. Use the filename as the name,
where available

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29 09:38:05 -06:00
Simon Glass
d9dad10e3c binman: Show a helpful error when a DT property is missing
At present a Python exception is raised which does not show the node
information. Add a more helpful exception in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29 09:38:05 -06:00
Simon Glass
1000096b06 dtoc: Return a non-zero exit code when tests fail
At present 'dtoc -t' return a success code even if some of the tests fail.
Fix this by checking the test result and setting the exit code. This
allows 'make qcheck' to function as expected.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-29 09:38:05 -06:00
Simon Glass
9b044f7e3d dtoc: Update dtb_platdata to support Python 3
The only change needed is to update get_value() to support the 'bytes'
type correctly with Python 3.

With this the dtoc unit tests pass with both Python 2 and 3:

PYTHONPATH=/tmp/b/sandbox_spl/scripts/dtc/pylibfdt python \
	./tools/dtoc/dtoc -t

PYTHONPATH=~/cosarm/dtc/pylibfdt:tools/patman python3 \
	./tools/dtoc/dtoc -t

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
209a55976b dtoc: Update fdt_util for Python 3
Since we are now using the bytes type in Python 3, the conversion in
fdt32_to_cpu() is not necessary, so drop it.

Also use 'int' instead of 'long' to convert the integer value, since
'long' is not present in Python 3.

With this, test_fdt passes with both Python 2 and 3:

PYTHONPATH=/tmp/b/sandbox_spl/scripts/dtc/pylibfdt python \
	./tools/dtoc/test_fdt -t

PYTHONPATH=~/cosarm/dtc/pylibfdt:tools/patman python3 \
	./tools/dtoc/test_fdt -t

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
b5f0dafd4b dtoc: Add a unit test for BytesToValue()
Add a simple unit test for one of the cases of this function, so that any
fault can be seen directly, rather than appearing through the failure of
another test.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
e66d318fef dtoc: Test full 64-bit properties with FdtCellsToCpu()
At present this test does not check the upper 32 bits of the returned
value. Add some additional tests to cover this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
2ab6e13e01 dtoc: Use binary mode for reading files
The .dtb files are binary so we should open them as binary files. This
allows Python 3 to use the correct 'bytes' type.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
635180538e dtoc: Convert the Fdt.Node class to Python 3
Update this class to work correctly on Python 3 and to pass its unit
tests. The only required change is to deal with a difference in the
behaviour of sorting with a None value.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
928527f686 dtoc: Convert the Fdt.Prop class to Python 3
Update this class to work correctly on Python 3 and to pass its unit
tests.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
f6b64815dd dtoc: Use byte type instead of str in fdt
In Python 3 bytes and str are separate types. Use bytes to ensure that
the code functions correctly with Python 3.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
2b6ed5e92e dtoc: Updates BytesToValue() for Python 3
The difference between the bytes and str types in Python 3 requires a
number of minor changes to this function. Update it to handle the input
data using the 'bytes' type. Create two useful helper functions which can
be used by other modules too.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
7e6952df36 dtoc: Move BytesToValue() out of the Prop class
This method does not actually use any members of the Prop class. Move it
out of the class so that it is easier to add unit tests.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
194b8d5e71 dtoc: Use GetBytes() to obtain repeating bytes
Use this helper function which works on both Python 2 and Python 3.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
1953ce7531 dtoc: Sort platdata output from dtoc
At present the order of struct field emitted by this tool depends on the
internal workings of a Python dictionary. Sort the fields to remove this
uncertainty, so that tests are deterministic.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
90a8132f4d dtoc: Adjust code for Python 3
Update a few things in this tool so that they support Python 3:
- print statements
- iteritems()
- xrange()

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:58 -06:00
Simon Glass
3e4b51e8d6 tools: dtoc: Open all binary files in binary mode
Fix an open() statement to use binary mode, so that it works as expected
with Python 3.

Signed-off-by: Simon Glass <sjg@chromium.org>
2019-07-10 16:52:45 -06:00
Heiko Schocher
e9cde87ec1 dtb_platdata.py: prevent define generation of alias
generate define for an alias only if the struct is not
created already.

This prevents compilerwarning:
  PLAT    spl/dts/dt-platdata.o
spl/dts/dt-platdata.c:11:46: error: missing braces around initializer [-Werror=missing-braces]
 static const struct dtd_simple_bus dtv_ahb = {
                                              ^
spl/dts/dt-platdata.c:20:46: error: missing braces around initializer [-Werror=missing-braces]
 static const struct dtd_simple_bus dtv_apb = {
                                              ^
cc1: all warnings being treated as errors

on the at91 based taurus board. Reason is in at91sam9260.dtsi
is defined:

ahb {
        compatible = "simple-bus";
        ranges;

and later:

pinctrl: pinctrl@fffff400 {
        compatible = "atmel,at91rm9200-pinctrl", "simple-bus";
        ranges = <0xfffff400 0xfffff400 0x600>;

without this patch dtoc generates:

struct dtd_atmel_at91rm9200_pinctrl {
	fdt32_t		atmel_mux_mask[6];
	fdt32_t		ranges[3];
	fdt32_t		reg[6];
};

struct dtd_simple_bus {
        bool            ranges;
};

"#define dtd_simple_bus dtd_atmel_at91rm9200_pinctrl"

and the line with "define dtd_simple_bus..." introduces
the warning. This define is not needed.

Signed-off-by: Heiko Schocher <hs@denx.de>
2019-04-26 18:58:20 -04:00
Simon Goldschmidt
e4478d9ac8 tests: dtoc: adapt tests to changed dtoc output
The dtoc tests need to be adapted to dtoc being changed to output platdata
structs as const, which has been introduced in commit 7d05d3a8e3 ("dtoc:
make generated platdata structs const").

Fixes: 7d05d3a8e3 ("dtoc: make generated platdata structs const")
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
2019-01-26 08:13:56 -05:00
Simon Goldschmidt
7d05d3a8e3 dtoc: make generated platdata structs const
The platdata initialization structs are currently generated into .rwdata.
Make sure the are put into .rodata by generating them as const.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2019-01-15 15:28:45 -05:00
Simon Glass
41b781ddf1 dtoc: Fix the value of SetInt()
This does not set the correct value at present. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2018-10-09 04:40:27 -06:00
Simon Glass
11ae93eef4 binman: Run tests concurrently
At present the tests run one after the other using a single CPU. This is
not very efficient. Bring in the concurrencytest module and run the tests
concurrently, using one process for each CPU by default. A -P option
allows this to be overridden, which is necessary for code-coverage to
function correctly.

This requires fixing a few tests which are currently not fully
independent.

At some point we might consider doing this across all pytests in U-Boot.
There is a pytest version that supports specifying the number of processes
to use, but it did not work for me.

Signed-off-by: Simon Glass <sjg@chromium.org>
2018-10-08 07:34:34 -06:00
Simon Glass
4b4bc06ef4 buildman: dtoc: Suppress unwanted output from test
There are a few test cases which print output. Suppress this so that tests
can run silently in the normal case.

Signed-off-by: Simon Glass <sjg@chromium.org>
2018-10-08 07:34:34 -06:00
Simon Glass
e0e6275f4c binman: Fix up removal of temporary directories
At present 'make check' leaves some temporary directories around. Part of
this is because we call tools.PrepareOutputDir() twice in some cases,
without calling tools.FinaliseOutputDir() in between.

Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2018-10-08 07:34:34 -06:00