aboutsummaryrefslogtreecommitdiff
path: root/pylibfdt
AgeCommit message (Collapse)AuthorFilesLines
2019-02-19pylibfdt: Test fdt.setprop take bytes on Python 3, add error handlingPetr Viktorin1-0/+4
Signed-off-by: Petr Viktorin <pviktori@redhat.com> Message-Id: <20190218164856.23861-3-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-02-19pylibfdt: check_err accepts only integer as a first argument.Lumir Balhar1-1/+1
A list passed as an argument to check_err() means that there is no error code to check and therefore it should be returned back. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Message-Id: <20190218164856.23861-2-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-02-19pylibfdt: Proper handling of bytes/unicode strings and octal literalsLumir Balhar1-3/+11
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Message-Id: <20190218164856.23861-1-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23PEP8 / Flake8 cleanups for setup.pyDavid Gibson1-6/+7
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23Remove broken objdir / srcdir supportDavid Gibson1-6/+6
The dtc makefiles have support for building into a separate directory from the sources... except that it's broken and probably always has been. Remove the pretense. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23pylibfdt: Use common PREFIX variableDavid Gibson1-1/+1
For no particularly good reason, the install target for the Python library uses a different PREFIX variable to give the installation destination to the rest of dtc & libfdt. Make it use the same one. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23Refine pylibfdt_clean targetDavid Gibson1-1/+8
Move it to the subdir Makefile, generalize some of the patterns, remove the 'build' directory made by setup.py and __pycache__ directory made by Python3. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23pylibfdt: Allow switch to Python 3 via environment variable PYTHONLumir Balhar1-2/+2
Python 2 is still the default but it can be changed by setting environment variable PYTHON before build/test. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-25pylibfdt: Don't have setup.py depend on where it's invoked fromDavid Gibson3-8/+11
Currently setup.py depends on being invoked from the right directory (specifically it needs to be run from the root of the project). That's a bit confusing. This updates setup.py to no longer depend on the invoking directory by instead having it change directory to the location of the script itself, then using internal paths relative to that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Eliminate run_setup make functionDavid Gibson1-7/+3
This function no longer does anything useful, so get rid of it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Improved version extractionDavid Gibson2-73/+8
Currently setup.py expects the library version in a VERSION environment variable, or it exctracts the version from the Makefile. The latter is for the case where the script is run standalone, rather than from make. But parsing the Makefile is ugly and fragile, and won't always get the same version we put into the C code. This changes to instead extracting the version from the trivial .h file we already generate to put the version into C code. It's still slightly ugly, but it's simpler and since we can control the precise format of that .h, not as fragile. This lets us remove the remains of the makefile parsing code from setup.py. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Don't silence setup.py when V=1David Gibson1-1/+6
At the moment we unconditionally pass --quiet to setup.py. Change that to get more debugging output from it when V=1 is passed to make. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Make SETUP make variableDavid Gibson1-2/+4
This points to the Python setup script, since we reference it in a couple of places. While we're there correct two small problems: 1) setup.py is part of the checked in sources and so lives in $(PYLIBFDT_srcdir) not $(PYLIBFDT_objdir) [this only worked because those are the same by default] 2) The module itself should depend on the setup script so it is rebuilt if the script is changed Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Simpler CFLAGS handlingDavid Gibson2-8/+5
At the moment we have some fiddly code to either pass in make's CPPFLAGS to setup.py, or have setup.py extract them from the Makefile. But really the only thing we need from here is the include paths. We already know what include paths we need (libfdt/) so we can just set that directly in setup.py. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Link extension module with libfdt rather than rebuildingDavid Gibson2-19/+12
Currently we build the Python extension module from all the libfdt source files as well as the swig wrapper file. This is a bit silly, since we've already compiled libfdt itself. This changes the build to instead build the extension module from just the swig wrapper, linking it against the libfdt.a we've already build. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: Correctly set build output directoryDavid Gibson2-12/+5
Our Makefile currently passes PYLIBFDT_objdir into setup.py in an attempt to set the correct place to put the Python extension module output. But that gets passed in the 'package_dir' map in distutils. But that's basically not what package_dir controls. What actually makes us find the module in the right place is the --inplace passed to setup.py (causing the module to go into the current directory), and the following 'mv' in the Makefile to move it into the right final location. We can simplify setup.py by dropping the useless objdir stuff, and get the module put in the right place straight way by instead using the --build-lib setup.py option. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-25pylibfdt: We don't need include files from the base directoryDavid Gibson1-7/+3
pylibfdt/setup.py currently adds include flags to the extension module build to allow include files in the base dtc directory. But pylibfdt doesn't rely on any headers there, only on headers in libfdt/ - it also shouldn't rely on dtc headers at any future time. So, remove that from the include list, allowing some simplifications to setup.py. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-13pylibfdt: Add a means to add and delete notesSimon Glass1-0/+29
These methods are needed to permit larger changes to the device tree blob. Add two new methods and an associate test. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-13pylibfdt: Allow delprop() to return errorsSimon Glass1-2/+6
At present this method always raised an exception when an error occurs. Add a 'quiet' argument so it matches the other methods. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-02pylibfdt: fdt_get_mem_rsv returns 2 uint64_t valuesDan Horák1-1/+1
Fix typemap for fdt_get_mem_rsv so it returns 64-bit values. Fixes https://github.com/dgibson/dtc/issues/15. Signed-off-by: Dan Horák <dan@danny.cz> [dwg: Adjusted commit message for typo and context] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-08-31pylibfdt: Don't incorrectly / unnecessarily override uint64_t typemapDavid Gibson1-5/+0
In libfdt.i we set the handling of uint64_t parameters to use PyLong_AsUnsignedLong. But for 32-bit platforms, where an unsigned long is 32-bits, this will truncate the value we need. It turns out swig's default typemapping for uint64_t correctly handles conversions both to python ints and python longs, so we don't need this typemap at all. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-11pylibfdt: Support the sequential-write interfaceSimon Glass1-77/+383
It is useful to be able to create a device tree from scratch using software. This is supported in libfdt but not currently available in the Python bindings. Add a new FdtSw class to handle this, with various methods corresponding to the libfdt functions. When the tree is complete, calling AsFdt() will return the completed device-tree object. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-14pylibfdt: Support setting the name of a nodeSimon Glass1-0/+17
Add a method to call fdt_set_name(). Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-14pylibfdt: Add functions to set and get properties as stringsSimon Glass1-0/+30
It is common to want to set a property to a nul-terminated string in a device tree. Add python methods to handle this. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-13pylibfdt: Update the bytearray size with pack()Simon Glass1-1/+8
At present pack() calls fdt_pack() which may well reduce the size of the device-tree data. However this does not currently update the size of the bytearray to take account of any reduction. This means that there may be unused data at the end of the bytearray and any users of as_bytearray() will see this extra data. Fix this by resizing the bytearray after packing. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-13pylibfdt: Allow reading integer values from propertiesSimon Glass1-3/+19
Extend the Properties class with some functions to read a single integer property. Add a new getprop_obj() function to return a Property object instead of the raw data. This suggested approach can be extended to handle other types, as well as arrays. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-13pylibfdt: Use an unsigned type for fdt32_tSimon Glass1-13/+16
The members of struct fdt_header are declared as fdt32_t which is a 32-bit, big-endian, unsigned integer. These fields are accessed by macros in libfdt.h so no return type is declared. But the correct return type is uint32_t, not fdt32_t, since the endianness conversion is done within the macro before returning the value. The macros are re-declared as normal functions in pylibfdt since swig does not support macros. The return type is currently int. Change it to uint32_t, which allows us to drop the work-around mask in Fdt.magic(). Also change the typedef for fdt32_t to uint32_t. The currently has no obvious effect, since use of big-endian values should always be internal to pylibfdt, but it is more correct. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-12pylibfdt: Add functions to update propertiesSimon Glass1-0/+59
Allow updating and creating properties, including special methods for integers. 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>
2018-06-09pylibfdt: Support device-tree creation/expansionSimon Glass1-0/+33
Add support for fdt_open_into() and fdt_create_empty_tree() from the Python library. The former is named resize() since it better fits with what the Python binding actually does. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-09pylibfdt: Add support for reading the memory reserve mapSimon Glass1-0/+34
Add a way to access this information from Python. 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>
2018-06-09pylibfdt: Add support for the rest of the header functionsSimon Glass1-3/+68
Export all of these through Python. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-08pylibfdt: Add support for fdt_next_node()Simon Glass1-0/+33
This function requires a bit of typemap effort to get the depth parameter to work correctly. Add support for it, along with a test. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-08pylibfdt: Reorder functions to match libfdt.hSimon Glass1-72/+72
The ordering of the Python functions loosely matches the corresponding function in the C header file, but not exactly. As we add more functions it is easier to track what is missing if they are in the same order. Move some functions around to achieve this. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-08pylibfdt: Return string instead of bytearray from getprop()Simon Glass1-2/+3
The return value is not actually mutable, so it seems more correct to return bytes rather than a bytearray. Suggested-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-04Make Property a subclass of bytearraySimon Glass1-3/+4
It is annoying to have to add .value when we want the value of a Property. Make Property a subclass of bytearray so that it can be used directly when the value is required. Fix the Property class comment while we are here. Suggested-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-04pylibfdt: Add a method to access the device tree directlySimon Glass1-0/+11
When calling libfdt functions which are not supported by the Fdt class it is necessary to get direct access to the device tree data. At present this requries using the internal _fdt member. Add a new method to provide public access to this, without allowing the data to be changed. Note that a bytearray type is returned rather than str, since the swig types are set up for bytearray to map correctly to const void *. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-09-27pylibfdt: Use Python2 explicitlyDavid Gibson1-1/+1
The pylibfdt code is written for Python2, not Python3. So, it's safer to explicitly request Python2 in our scripts and when checking pkg-config. On Arch Linux at least, there isn't actually a plain "python" link, just "python2" and "python3", so the current setup won't work at all. According to https://www.python.org/dev/peps/pep-0394/ using "python2" should work, and is preferred. Updating pylibfdt to work with Python3 would be nice, but is a problem for another day. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-08-21pylibfdt: Add support for fdt_subnode_offset()Simon Glass1-0/+17
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-21pylibfdt: Add support for fdt_node_offset_by_phandle()Simon Glass1-0/+14
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-21pylibfdt: Add support for fdt_parent_offset()Simon Glass1-0/+15
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-21pylibfdt: Add support for fdt_get_phandle()Simon Glass1-0/+12
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-15pylibfdt: Add stdint include to fix uint32_tSimon Glass1-0/+2
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-04-08pylibfdt: Use setup.py to build the swig fileSimon Glass1-9/+5
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-08pylibfdt: Use Makefile constructs to implement NO_PYTHONSimon Glass1-7/+0
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-08pylibfdt: Allow setup.py to operate stand-aloneSimon Glass2-9/+98
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-07pylibfdt: Fix code style in setup.pySimon Glass1-8/+9
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-07pylibfdt: Rename libfdt.swig to libfdt.iSimon Glass2-1/+1
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-03-29pylibfdt: Use the call function to simplify the MakefileSimon Glass1-7/+7
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-29pylibfdt: Use the correct libfdt version in the moduleSimon Glass2-2/+4
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-29pylibfdt: Enable installation of Python moduleSimon Glass1-0/+14
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>