Commit graph

670 commits

Author SHA1 Message Date
Rob Herring
b3bbac02d5 checks: add phandle with arg property checks
Many common bindings follow the same pattern of client properties
containing a phandle and N arg cells where N is defined in the provider
with a '#<specifier>-cells' property such as:

	intc0: interrupt-controller@0 {
		#interrupt-cells = <3>;
	};
	intc1: interrupt-controller@1 {
		#interrupt-cells = <2>;
	};

	node {
		interrupts-extended = <&intc0 1 2 3>, <&intc1 4 5>;
	};

Add checks for properties following this pattern.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-09-22 21:14:10 +10:00
Simon Glass
fe50bd1ecc fdtget: Split out cell list display into a new function
The show_data() function is quite long. Split out the part that loops
through the values. This makes it easier to add new features.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:29:48 +10:00
Simon Glass
62d812308d README: Add a note about test_tree1.dts
Add a little note in the README about something which confused me.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:18:25 +10:00
Simon Glass
5bed86aee9 pylibfdt: Add support for fdt_subnode_offset()
Add this into the class to simplify use of this function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:17:57 +10:00
Simon Glass
46f31b65b3 pylibfdt: Add support for fdt_node_offset_by_phandle()
Add this into the class to simplify use of this function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:00:44 +10:00
Simon Glass
a3ae437236 pylibfdt: Add support for fdt_parent_offset()
Add this into the class to simplify use of this function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:00:44 +10:00
Simon Glass
a198af8034 pylibfdt: Add support for fdt_get_phandle()
Add this into the class to simplify use of this function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:00:44 +10:00
Simon Glass
b9eba92ea5 tests: Return a failure code when any tests fail
At present 'make check' succeeds even if some tests fail. Adjust this so
that we can use things like 'git bisect run make check' to find a failure.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:00:44 +10:00
Simon Glass
155faf6cc2 pylibfdt: Use local pylibfdt module
Some systems may have the Python libfdt.py library installed. Adjust the
tests to prepend the local libfdt path so that we test the local version
instead of the system version.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:00:44 +10:00
Simon Glass
50e5cd07f3 pylibfdt: Add a test for use of uint32_t
Using the libfdt function without going through the Python Fdt class
requires use of the uint32_t type. Add a test that this works correctly.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21 10:00:44 +10:00
Simon Glass
ab78860f09 pylibfdt: Add stdint include to fix uint32_t
Some types used by libfdt.h are not understood the Python module since
they are defined outside it. An example is an attempt to do this:

   import libfdt
   result = libfdt.fdt_node_offset_by_phandle(fdt, phandle)

This results in:

TypeError: in method 'fdt_node_offset_by_phandle', argument 2 of
	type 'uint32_t'

Include the standard integer header file to fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-15 13:47:24 +10:00
Pantelis Antoniou
36f511fb11 tests: Add stacked overlay tests on fdtoverlay
Add a stacked overlay unit test, piggybacking on fdtoverlay.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-09 17:18:47 +10:00
Pantelis Antoniou
1bb00655d3 fdt: Allow stacked overlays phandle references
This patch enables an overlay to refer to a previous overlay's
labels by performing a merge of symbol information at application
time.

In a nutshell it allows an overlay to refer to a symbol that a previous
overlay has defined. It requires both the base and all the overlays
to be compiled with the -@ command line switch so that symbol
information is included.

base.dts
--------

	/dts-v1/;
	/ {
		foo: foonode {
			foo-property;
		};
	};

	$ dtc -@ -I dts -O dtb -o base.dtb base.dts

bar.dts
-------

	/dts-v1/;
	/plugin/;
	/ {
		fragment@1 {
			target = <&foo>;
			__overlay__ {
				overlay-1-property;
				bar: barnode {
					bar-property;
				};
			};
		};
	};

	$ dtc -@ -I dts -O dtb -o bar.dtb bar.dts

baz.dts
-------

	/dts-v1/;
	/plugin/;
	/ {
		fragment@1 {
			target = <&bar>;
			__overlay__ {
				overlay-2-property;
				baz: baznode {
					baz-property;
				};
			};
		};
	};

	$ dtc -@ -I dts -O dtb -o baz.dtb baz.dts

Applying the overlays:

	$ fdtoverlay -i base.dtb -o target.dtb bar.dtb baz.dtb

Dumping:

	$ fdtdump target.dtb
	/ {
            foonode {
                overlay-1-property;
                foo-property;
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
                barnode {
                    overlay-2-property;
                    phandle = <0x00000002>;
                    linux,phandle = <0x00000002>;
                    bar-property;
                    baznode {
                        phandle = <0x00000003>;
                        linux,phandle = <0x00000003>;
                        baz-property;
                    };
                };
            };
            __symbols__ {
                baz = "/foonode/barnode/baznode";
                bar = "/foonode/barnode";
                foo = "/foonode";
            };
	};

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-09 17:18:47 +10:00
Pantelis Antoniou
a33c2247ac Introduce fdt_setprop_placeholder() method
In some cases you need to add a property but the contents of it
are not known at creation time, merely the extend of it.

This method allows you to create a property of a given size (filled
with garbage) while a pointer to the property data will be provided.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
[dwg: Corrected commit message]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-07-28 14:34:36 +10:00
Rob Herring
0016f8c2aa dtc: change default phandles to ePAPR style instead of both
Currently, both legacy (linux,phandle) and ePAPR (phandle) properties
are inserted into dtbs by default. The newer ePAPR style has been
supported in dtc and Linux kernel for 7 years. That should be a long
enough transition period. We can save a little space by not putting both
into the dtb.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-07-13 10:21:42 +10:00
Pantelis Antoniou
e3b9a9588a tests: fdtoverlay unit test
Add an fdtoverlay unit test. Applies applies overlay(s) and then
retrieves an inserted property to verify.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-06-15 15:37:07 +08:00
Pantelis Antoniou
42409146f2 fdtoverlay: A tool that applies overlays
Since libfdt support overlay application on FDT blobs, provide
a command line tool that applies an arbitrary number of
overlays, one after another to a base fdt blob and output
the result in the given file.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-06-15 15:37:07 +08:00
Pantelis Antoniou
aae22722fc manual: Document missing options
The -d and -s options were undocumented. Add an entry in the manual.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-06-14 23:04:48 +08:00
David Gibson
13ce6e1c2f dtc: fix sprintf() format string error, again
2a42b14 "dtc: check.c fix compile error" changed a format string using
%lx which wasn't correct for all platforms.  Unfortunately it changed it to
%zx, which is wrong for a different set of platforms (and only right on
the others by accident).  The parameter we're formatting here is uint64_t,
not size_t, so we need to use the PRIx64 macro from <inttypes.h> to get
this right.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-06-08 14:35:16 +10:00
Cufi, Carles
d990b80138 Makefile: Fix build on MSYS2 and Cygwin
The host compiler on MSYS2 and Cygwin does not allow the -fPIC option,
issuing a warning that is treated as an error and stops the build.
Detect whether we're running under MSYS2 or Cygwin and avoid adding
-fPIC to prevent the error from happening.

Tested on Linux, MSYS2 and Cygwin.

Signed-off-by: Carles Cufi <carles.cufi@gmail.com>
[dwg: Added explicit empty CFLAGS for clarity]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-05-20 16:17:41 +10:00
David Gibson
51f56dedf8 Clean up shared library compile/link options
- Allow overriding of shared library compile time flags for platforms whic
  need it
- Include -fPIC in the link flags variable instead of including it raw
  in the target rule
- Cosmetic formatting tweaks

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-05-19 16:11:48 +10:00
David Gibson
21a2bc896e Suppress expected error message in fdtdump test
Since 548aea2 "fdtdump: Discourage use of fdtdump", fdtdump unconditionally
prints a message discouraging its own use except for debugging purposes.
This shows up messily in the "make check" output, so suppress it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-05-17 12:15:26 +10:00
Shuah Khan
2a42b14d0d dtc: check.c fix compile error
Fix the following compile error found on odroid-xu4:

checks.c: In function ‘check_simple_bus_reg’:
checks.c:876:41: error: format ‘%lx’ expects argument of type
‘long unsigned int’, but argument 4 has type
‘uint64_t{aka long long unsigned int}’ [-Werror=format=]
  snprintf(unit_addr, sizeof(unit_addr), "%lx", reg);
                                         ^
checks.c:876:41: error: format ‘%lx’ expects argument of type
‘long unsigned int’, but argument 4 has type
‘uint64_t {aka long long unsigned int}’ [-Werror=format=]
cc1: all warnings being treated as errors
Makefile:304: recipe for target 'checks.o' failed
make: *** [checks.o] Error 1

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
[dwg: Correct new format to be correct in general]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-05-17 12:10:51 +10:00
Tim Montague
a10cb3c818 Fix get_node_by_path string equality check
When determining if to recurse into a node, get_node_by_path does not
check if the length of each node name is equal.  If searching for
/foo/baz, this can result in recursing into /foobar because
strneq("foo", "foobar", 3) is true.

This can result in a reference to /foo/baz to be incorrectly set to
/foobar/baz.  A test for this was added.

Signed-off-by: Tim Montague <tmontague@ghs.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-19 11:25:32 +10:00
David Gibson
548aea2c43 fdtdump: Discourage use of fdtdump
fdtdump is, and always has been, a quick-and-dirty debugging tool.  However
I keep getting reports of people using it for real work.  For production
decompiling of a dtb, dtc in -I dtb -O dts mode is the right tool. In the
hopes of getting that message out there, add a warning message to fdtdump
to discourage its use.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-18 13:05:08 +10:00
David Gibson
c2258841a7 fdtdump: Fix over-zealous version check
It's perfectly valid for a dtb to have version and last compat version set
to the same value, and that value can be 17 (the latest defined version).
However, since 0931cea "dtc: fdtdump: check fdt if not in scanning mode"
fdtdump will refuse to process such a dtb.  We get away with this in many
cases because dtc's typical output has last compat version equal to 16,
rather than 17, but it's still a bug.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-18 12:52:08 +10:00
Simon Glass
9067ee4be0 Fix a few whitespace and style nits
These were noticed when synching with U-Boot's downstream tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-09 20:56:37 +10:00
Simon Glass
e56f2b07be pylibfdt: Use setup.py to build the swig file
Since we are using the standard .i extension for the swig file, we can use
setup.py to build the wrapper. Drop the existing build code since it is
not needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
Simon Glass
896f1c1332 pylibfdt: Use Makefile constructs to implement NO_PYTHON
The current mechanism uses a shell construct, but it seems better to use
a Makefile approach.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
Simon Glass
90db6d9989 pylibfdt: Allow setup.py to operate stand-alone
At present we require that setup.py is executed from the Makefile, which
sets up various important things like the list of files to build and the
version number.

However many installation systems expect to be able to change to the
directory containing setup.py and run it. This allows them to support (for
example) building/installing for multiple Python versions, varying
installation paths, particular C flags, etc.

The problem in implementing this is that we don't want to duplicate the
information in the Makefile. A common solution (so I am told) is to parse
the Makefile to obtain the required information.

Update the setup.py script to read a few Makefiles when it does not see
the required information in its environment. This allows installation
using:

   ./pylibfdt/setup.py install

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08 11:54:07 +10:00
David Gibson
e20d9658cd Add Coverity Scan support
I've recently signed up dtc for Coverity Scan coverage.  This adds magic
to the .travis.yml file to submit builds to Coverity for analysis.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:55:16 +10:00
Simon Glass
b04a2cf088 pylibfdt: Fix code style in setup.py
We should follow PEP8 even for our setup() call.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:43:34 +10:00
Simon Glass
1c5170d3a4 pylibfdt: Rename libfdt.swig to libfdt.i
The .i extension allows Python distutils to automatically handle the swig
file. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-07 15:43:34 +10:00
Simon Glass
580a9f6c28 Add a libfdt function to write a property placeholder
The existing function to add a new property to a tree being built requires
that the entire contents of the new property be passed in. For some
applications it is more convenient to be able to add the property contents
later, perhaps by reading from a file. This avoids double-buffering of the
contents.

Add a new function to support this and adjust the existing fdt_property() to
use it.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-02 13:38:46 +10:00
Simon Glass
ab15256d8d pylibfdt: Use the call function to simplify the Makefile
This is in a separate patch since I not sure if GNU make features
are permitted in the Makefile.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
9f2e3a3a1f pylibfdt: Use the correct libfdt version in the module
Use the same version number in the module as with the rest of libfdt. This
can be examined with:

   import pkg_resources
   print pkg_resources.require('libfdt')[0].version

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
e91c652af2 pylibfdt: Enable installation of Python module
Adjust the setup script to support installation, and call it from the
Makefile if enabled. It will be disabled if we were unable to build the
module (e.g. due to swig being missing), or the NO_PYTHON environment
variable is set.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
Simon Glass
8a892fd85d pylibfdt: Allow building to be disabled
Some build systems want to build python libraries separately from the
rest of the build.

Add a NO_PYTHON option to enable this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-29 16:13:58 +11:00
David Gibson
741cdff85d .travis.yml: Add builds with and without Python library prerequisites
To make sure the Makefile behaves in both cases, make Travis matrix builds
with and without swig installed.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 16:30:27 +11:00
Simon Glass
14c4171f4f pylibfdt: Use package_dir to set the package directory
At present we manually move _libfdt.so into the correct place. Provide a
package directory so we can avoid needing to do this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:33:25 +11:00
Simon Glass
89a5062ab2 pylibfdt: Use environment to pass C flags and files
At present setup.py adjusts its command line when running, so that the
C flags and file list can be passed as arguments. Pass them in environment
variables instead, so we can avoid this messiness. It also allows us to
support the 'install' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:33:25 +11:00
Simon Glass
4e0e0d0497 pylibfdt: Allow pkg-config to be supplied in the environment
Some build systems have their own version of the pkg-config tool.
Use a variable for this instead of hard-coding it, to allow for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Mike Frysinger <vapier@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-27 15:27:21 +11:00
David Gibson
6afd7d9688 Correct typo: s/pylibgfdt/pylibfdt/
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-22 16:34:39 +11:00
Simon Glass
756ffc4f52 Build pylibfdt as part of the normal build process
If swig and the Python are available, build pylibfdt automatically.
Adjust the tests to run Python tests too in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
[dwg: Make error message clearer that missing swig or python-dev isn't
 fatal to the whole build]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:31:13 +11:00
Simon Glass
8cb3896358 Adjust libfdt.h to work with swig
There are a few places where libfdt.h cannot be used as is with swig:

- macros like fdt_totalsize() have to be defined as C declarations
- fdt_offset_ptr() and fdt_getprop_namelen() need special treatment due to
    a TODO in the wrapper for fdt_getprop(). However they are not useful to
    Python so can be removed

Add #ifdefs to work around these problem.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Simon Glass
b40aa8359a Mention pylibfdt in the documentation
Add a note about pylibfdt in the README.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Simon Glass
12cfb740cc Add tests for pylibfdt
Add a set of tests to cover the functionality in pylibfdt.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Simon Glass
50f2507016 Add an initial Python library for libfdt
Add Python bindings for a bare-bones set of libfdt functions. These allow
navigating the tree and reading node names and properties.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 16:21:58 +11:00
Rob Herring
cdbb2b6c7a checks: Warn on node name unit-addresses with '0x' or leading 0s
Node name unit-addresses should generally never begin with 0x or leading
0s. Add warnings to check for these cases, but only for nodes without a
known bus type as there should be better bus specific checks of the
unit address in those cases. Any unit addresses that don't follow the
general rule will need to add a new bus type. There aren't any known
ones ATM.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 14:49:04 +11:00
Rob Herring
4c15d5da17 checks: Add bus checks for simple-bus buses
Add checks to identify simple-bus bus types and checks for child
devices. Simple-bus type is generally identified by "simple-bus"
compatible string. We also treat the root as a simple-bus, but only for
child nodes with reg property.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21 14:49:04 +11:00