Import dtc 1.5.1

This commit is contained in:
skrll 2019-12-22 12:34:02 +00:00
parent ae1eadec56
commit 1fb8aa2016
161 changed files with 7036 additions and 1894 deletions

32
external/gpl2/dtc/dist/BSD-2-Clause vendored Normal file
View File

@ -0,0 +1,32 @@
Valid-License-Identifier: BSD-2-Clause
SPDX-URL: https://spdx.org/licenses/BSD-2-Clause.html
Usage-Guide:
To use the BSD 2-clause "Simplified" License put the following SPDX
tag/value pair into a comment according to the placement guidelines in
the licensing rules documentation:
SPDX-License-Identifier: BSD-2-Clause
License-Text:
Copyright (c) <year> <owner> . All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@ -37,7 +37,7 @@ The upstream repository is here:
git://git.kernel.org/pub/scm/utils/dtc/dtc.git
https://git.kernel.org/pub/scm/utils/dtc/dtc.git
The gitweb interface for the upstream respository is:
The gitweb interface for the upstream repository is:
https://git.kernel.org/cgit/utils/dtc/dtc.git/
@ -78,6 +78,9 @@ The currently supported Output Formats are:
then simply be added to your Makefile. Additionally, the
assembly file exports some symbols that can be used.
- "yaml": DT encoded in YAML format. This representation is an
intermediate format used for validation tools.
3) Command Line
@ -231,7 +234,7 @@ For example:
"childnode at address". It in turn has a string property
called "childprop".
childnode@addresss {
childnode@address {
childprop = "hello\n";
};
@ -250,7 +253,7 @@ Labels may be applied to nodes or properties. Labels appear
before a node name, and are referenced using an ampersand: &label.
Absolute node path names are also allowed in node references.
In this exmaple, a node is labled "mpic" and then referenced:
In this example, a node is labeled "mpic" and then referenced:
mpic: interrupt-controller@40000 {
...
@ -261,7 +264,7 @@ In this exmaple, a node is labled "mpic" and then referenced:
...
};
And used in properties, lables may appear before or after any value:
And used in properties, labels may appear before or after any value:
randomnode {
prop: string = data: "mystring\n" data_end: ;
@ -415,7 +418,7 @@ value of r3.
among others, by kexec. If you are on an SMP system, this value
should match the content of the "reg" property of the CPU node in
the device-tree corresponding to the CPU calling the kernel entry
point (see further chapters for more informations on the required
point (see further chapters for more information on the required
device-tree contents)
- size_dt_strings
@ -581,7 +584,7 @@ looks like in practice.
This tree is almost a minimal tree. It pretty much contains the
minimal set of required nodes and properties to boot a linux kernel;
that is, some basic model informations at the root, the CPUs, and the
that is, some basic model information at the root, the CPUs, and the
physical memory layout. It also includes misc information passed
through /chosen, like in this example, the platform type (mandatory)
and the kernel command line arguments (optional).
@ -674,4 +677,86 @@ The fdtdump program prints a readable version of a flat device tree file.
The syntax of the fdtdump command line is:
fdtdump <DTB-file-name>
fdtdump [options] <DTB-file-name>
Where options are:
-d,--debug Dump debug information while decoding the file
-s,--scan Scan for an embedded fdt in given file
3) fdtoverlay -- Flat Device Tree overlay applicator
The fdtoverlay applies an arbitrary number of FDT overlays to a base FDT blob
to a given output file.
The syntax of the fdtoverlay command line is:
fdtoverlay -i <base-blob> -o <output-blob> <overlay-blob0> [<overlay-blob1> ...]
Where options are:
-i, --input Input base DT blob
-o, --output Output DT blob
-v, --verbose Verbose message output
4 ) fdtget -- Read properties from device tree
This command can be used to obtain individual values from the device tree in a
nicely formatted way. You can specify multiple nodes to display (when using -p)
or multiple node/property pairs (when not using -p). For the latter, each
property is displayed on its own line, with a space between each cell within
the property.
The syntax of the fdtget command is:
fdtget <options> <dt file> [<node> <property>]...
fdtget -p <options> <dt file> [<node> ]...
where options are:
<type> s=string, i=int, u=unsigned, x=hex
Optional modifier prefix:
hh or b=byte, h=2 byte, l=4 byte (default)
Options: -[t:pld:hV]
-t, --type <arg> Type of data
-p, --properties List properties for each node
-l, --list List subnodes for each node
-d, --default <arg> Default value to display when the property is missing
-h, --help Print this help and exit
-V, --version Print version and exit
If -t is not provided, fdtget will try to figure out the type, trying to detect
strings, string lists and the size of each value in the property. This is
similar to how fdtdump works, and uses the same heuristics.
5 ) fdtput - Write properties to a device tree
The syntax of the fdtput command is:
fdtput <options> <dt file> <node> <property> [<value>...]
fdtput -c <options> <dt file> [<node>...]
fdtput -r <options> <dt file> [<node>...]
fdtput -d <options> <dt file> <node> [<property>...]
Options are:
<type> s=string, i=int, u=unsigned, x=hex
Optional modifier prefix:
hh or b=byte, h=2 byte, l=4 byte (default)
-c, --create Create nodes if they don't already exist
-r, --remove Delete nodes (and any subnodes) if they already exist
-d, --delete Delete properties if they already exist
-p, --auto-path Automatically create nodes as needed for the node path
-t, --type <arg> Type of data
-v, --verbose Display each value decoded from command line
-h, --help Print this help and exit
-V, --version Print version and exit
The option determines which usage is selected and therefore the operation that
is performed. The first usage adds or updates properties; the rest are used to
create/delete nodes and delete properties.
For the first usage, the command line arguments are joined together into a
single value which is written to the property. The -t option is required so
that fdtput knows how to decode its arguments.

View File

@ -1,12 +1,12 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
@ -225,7 +225,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Device Tree Compiler
#
@ -9,8 +10,8 @@
# CONFIG_LOCALVERSION from some future config system.
#
VERSION = 1
PATCHLEVEL = 4
SUBLEVEL = 4
PATCHLEVEL = 5
SUBLEVEL = 0
EXTRAVERSION =
LOCAL_VERSION =
CONFIG_LOCALVERSION =
@ -18,12 +19,19 @@ CONFIG_LOCALVERSION =
CPPFLAGS = -I libfdt -I .
WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
CFLAGS = -g -Os -fPIC -Werror $(WARNINGS)
CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS) $(EXTRA_CFLAGS)
BISON = bison
LEX = flex
SWIG = swig
PKG_CONFIG ?= pkg-config
PYTHON ?= python3
INSTALL = /usr/bin/install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_LIB = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_SCRIPT = $(INSTALL)
DESTDIR =
PREFIX = $(HOME)
BINDIR = $(PREFIX)/bin
@ -31,14 +39,34 @@ LIBDIR = $(PREFIX)/lib
INCLUDEDIR = $(PREFIX)/include
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
sed -e 's/\(cygwin\).*/cygwin/')
sed -e 's/\(cygwin\|msys\).*/\1/')
NO_VALGRIND := $(shell $(PKG_CONFIG) --exists valgrind; echo $$?)
ifeq ($(NO_VALGRIND),1)
CFLAGS += -DNO_VALGRIND
else
CFLAGS += $(shell $(PKG_CONFIG) --cflags valgrind)
endif
NO_YAML := $(shell $(PKG_CONFIG) --exists yaml-0.1; echo $$?)
ifeq ($(NO_YAML),1)
CFLAGS += -DNO_YAML
else
LDLIBS_dtc += $(shell $(PKG_CONFIG) --libs yaml-0.1)
endif
ifeq ($(HOSTOS),darwin)
SHAREDLIB_EXT=dylib
SHAREDLIB_LINK_OPTIONS=-dynamiclib -Wl,-install_name -Wl,
SHAREDLIB_EXT = dylib
SHAREDLIB_CFLAGS = -fPIC
SHAREDLIB_LDFLAGS = -fPIC -dynamiclib -Wl,-install_name -Wl,
else ifeq ($(HOSTOS),$(filter $(HOSTOS),msys cygwin))
SHAREDLIB_EXT = so
SHAREDLIB_CFLAGS =
SHAREDLIB_LDFLAGS = -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
else
SHAREDLIB_EXT=so
SHAREDLIB_LINK_OPTIONS=-shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
SHAREDLIB_EXT = so
SHAREDLIB_CFLAGS = -fPIC
SHAREDLIB_LDFLAGS = -fPIC -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
endif
#
@ -112,11 +140,34 @@ BIN += dtc
BIN += fdtdump
BIN += fdtget
BIN += fdtput
BIN += fdtoverlay
SCRIPTS = dtdiff
all: $(BIN) libfdt
# We need both Python and swig to build/install pylibfdt.
# This builds the given make ${target} if those deps are found.
check_python_deps = \
if $(PKG_CONFIG) --cflags $(PYTHON) >/dev/null 2>&1; then \
if which swig >/dev/null 2>&1; then \
can_build=yes; \
fi; \
fi; \
if [ "$${can_build}" = "yes" ]; then \
$(MAKE) $${target}; \
else \
echo "\#\# Skipping pylibfdt (install python dev and swig to build)"; \
fi ;
.PHONY: maybe_pylibfdt
maybe_pylibfdt: FORCE
target=pylibfdt; $(check_python_deps)
ifeq ($(NO_PYTHON),)
all: maybe_pylibfdt
endif
ifneq ($(DEPTARGETS),)
-include $(DTC_OBJS:%.o=%.d)
@ -124,6 +175,7 @@ ifneq ($(DEPTARGETS),)
-include $(FDTDUMP_OBJS:%.o=%.d)
-include $(FDTGET_OBJS:%.o=%.d)
-include $(FDTPUT_OBJS:%.o=%.d)
-include $(FDTOVERLAY_OBJS:%.o=%.d)
endif
@ -131,28 +183,27 @@ endif
#
# Rules for libfdt
#
LIBFDT_objdir = libfdt
LIBFDT_srcdir = libfdt
LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
LIBFDT_dir = libfdt
LIBFDT_archive = $(LIBFDT_dir)/libfdt.a
LIBFDT_lib = $(LIBFDT_dir)/$(LIBFDT_LIB)
LIBFDT_include = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_INCLUDES))
LIBFDT_version = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_VERSION))
include $(LIBFDT_srcdir)/Makefile.libfdt
include $(LIBFDT_dir)/Makefile.libfdt
.PHONY: libfdt
libfdt: $(LIBFDT_archive) $(LIBFDT_lib)
$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
$(LIBFDT_lib): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
$(LIBFDT_archive): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
libfdt_clean:
@$(VECHO) CLEAN "(libfdt)"
rm -f $(addprefix $(LIBFDT_objdir)/,$(STD_CLEANFILES))
rm -f $(LIBFDT_objdir)/*.so
$(LIBFDT_lib): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS)) $(LIBFDT_version)
@$(VECHO) LD $@
$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) \
$(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
ln -sf $(LIBFDT_LIB) $(LIBFDT_dir)/$(LIBFDT_soname)
ifneq ($(DEPTARGETS),)
-include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d)
-include $(LIBFDT_OBJS:%.o=$(LIBFDT_dir)/%.d)
endif
# This stops make from generating the lex and bison output during
@ -163,23 +214,32 @@ endif
install-bin: all $(SCRIPTS)
@$(VECHO) INSTALL-BIN
$(INSTALL) -d $(DESTDIR)$(BINDIR)
$(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR)
$(INSTALL_PROGRAM) $(BIN) $(DESTDIR)$(BINDIR)
$(INSTALL_SCRIPT) $(SCRIPTS) $(DESTDIR)$(BINDIR)
install-lib: all
@$(VECHO) INSTALL-LIB
$(INSTALL) -d $(DESTDIR)$(LIBDIR)
$(INSTALL) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
$(INSTALL_LIB) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname)
ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT)
$(INSTALL) -m 644 $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
$(INSTALL_DATA) $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
install-includes:
@$(VECHO) INSTALL-INC
$(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)
$(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
$(INSTALL_DATA) $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
install: install-bin install-lib install-includes
.PHONY: maybe_install_pylibfdt
maybe_install_pylibfdt: FORCE
target=install_pylibfdt; $(check_python_deps)
ifeq ($(NO_PYTHON),)
install: maybe_install_pylibfdt
endif
$(VERSION_FILE): Makefile FORCE
$(call filechk,version)
@ -192,9 +252,11 @@ convert-dtsv0: $(CONVERT_OBJS)
fdtdump: $(FDTDUMP_OBJS)
fdtget: $(FDTGET_OBJS) $(LIBFDT_archive)
fdtget: $(FDTGET_OBJS) $(LIBFDT_lib)
fdtput: $(FDTPUT_OBJS) $(LIBFDT_archive)
fdtput: $(FDTPUT_OBJS) $(LIBFDT_lib)
fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_lib)
dist:
git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \
@ -202,6 +264,17 @@ dist:
cat ../dtc-$(dtc_version).tar | \
gzip -9 > ../dtc-$(dtc_version).tar.gz
#
# Rules for pylibfdt
#
PYLIBFDT_dir = pylibfdt
include $(PYLIBFDT_dir)/Makefile.pylibfdt
.PHONY: pylibfdt
pylibfdt: $(PYLIBFDT_dir)/_libfdt.so
#
# Release signing and uploading
# This is for maintainer convenience, don't try this at home.
@ -234,6 +307,10 @@ TESTS_BIN += convert-dtsv0
TESTS_BIN += fdtput
TESTS_BIN += fdtget
TESTS_BIN += fdtdump
TESTS_BIN += fdtoverlay
ifeq ($(NO_PYTHON),)
TESTS_PYLIBFDT += maybe_pylibfdt
endif
include tests/Makefile.tests
@ -243,7 +320,7 @@ include tests/Makefile.tests
STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \
*.tab.[ch] *.lex.c *.output
clean: libfdt_clean tests_clean
clean: libfdt_clean pylibfdt_clean tests_clean
@$(VECHO) CLEAN
rm -f $(STD_CLEANFILES)
rm -f $(VERSION_FILE)
@ -255,7 +332,7 @@ clean: libfdt_clean tests_clean
#
%: %.o
@$(VECHO) LD $@
$(LINK.c) -o $@ $^
$(LINK.c) -o $@ $^ $(LDLIBS_$*)
%.o: %.c
@$(VECHO) CC $@
@ -285,10 +362,6 @@ clean: libfdt_clean tests_clean
@$(VECHO) AR $@
$(AR) $(ARFLAGS) $@ $^
$(LIBFDT_lib):
@$(VECHO) LD $@
$(CC) $(LDFLAGS) -fPIC $(SHAREDLIB_LINK_OPTIONS)$(LIBFDT_soname) -o $(LIBFDT_lib) $^
%.lex.c: %.l
@$(VECHO) LEX $@
$(LEX) -o$@ $<

View File

@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This is not a complete Makefile of itself.
# Instead, it is designed to be easily embeddable

View File

@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Makefile.dtc
#
# This is not a complete Makefile of itself. Instead, it is designed to
@ -14,5 +15,9 @@ DTC_SRCS = \
treesource.c \
util.c
ifneq ($(NO_YAML),1)
DTC_SRCS += yamltree.c
endif
DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c
DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)

View File

@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This is not a complete Makefile of itself. Instead, it is designed to
# be easily embeddable into other systems of Makefiles.
@ -22,3 +23,9 @@ FDTPUT_SRCS = \
util.c
FDTPUT_OBJS = $(FDTPUT_SRCS:%.c=%.o)
FDTOVERLAY_SRCS = \
fdtoverlay.c \
util.c
FDTOVERLAY_OBJS = $(FDTOVERLAY_SRCS:%.c=%.o)

View File

@ -7,6 +7,81 @@ DTC and LIBFDT are maintained by:
David Gibson <david@gibson.dropbear.id.au>
Jon Loeliger <jdl@jdl.com>
Python library
--------------
A Python library is also available. To build this you will need to install
swig and Python development files. On Debian distributions:
sudo apt-get install swig python3-dev
The library provides an Fdt class which you can use like this:
$ PYTHONPATH=../pylibfdt python3
>>> import libfdt
>>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read())
>>> node = fdt.path_offset('/subnode@1')
>>> print(node)
124
>>> prop_offset = fdt.first_property_offset(node)
>>> prop = fdt.get_property_by_offset(prop_offset)
>>> print('%s=%s' % (prop.name, prop.as_str()))
compatible=subnode1
>>> node2 = fdt.path_offset('/')
>>> print(fdt.getprop(node2, 'compatible').as_str())
test_tree1
You will find tests in tests/pylibfdt_tests.py showing how to use each
method. Help is available using the Python help command, e.g.:
$ cd pylibfdt
$ python3 -c "import libfdt; help(libfdt)"
If you add new features, please check code coverage:
$ sudo apt-get install python3-coverage
$ cd tests
# It's just 'coverage' on most other distributions
$ python3-coverage run pylibfdt_tests.py
$ python3-coverage html
# Open 'htmlcov/index.html' in your browser
To install the library via the normal setup.py method, use:
./pylibfdt/setup.py install [--prefix=/path/to/install_dir]
If --prefix is not provided, the default prefix is used, typically '/usr'
or '/usr/local'. See Python's distutils documentation for details. You can
also install via the Makefile if you like, but the above is more common.
To install both libfdt and pylibfdt you can use:
make install [SETUP_PREFIX=/path/to/install_dir] \
[PREFIX=/path/to/install_dir]
To disable building the python library, even if swig and Python are available,
use:
make NO_PYTHON=1
More work remains to support all of libfdt, including access to numeric
values.
Tests
-----
Test files are kept in the tests/ directory. Use 'make check' to build and run
all tests.
If you want to adjust a test file, be aware that tree_tree1.dts is compiled
and checked against a binary tree from assembler macros in trees.S. So
if you change that file you must change tree.S also.
Mailing list
------------
The following list is for discussion about dtc and libfdt implementation

View File

@ -4,11 +4,11 @@ Licensing and contribution policy of dtc and libfdt
This dtc package contains two pieces of software: dtc itself, and
libfdt which comprises the files in the libfdt/ subdirectory. These
two pieces of software, although closely related, are quite distinct.
dtc does not incoporate or rely on libfdt for its operation, nor vice
dtc does not incorporate or rely on libfdt for its operation, nor vice
versa. It is important that these two pieces of software have
different license conditions.
As the copyright banners in each source file attest, dtc is licensed
As SPDX license tags in each source file attest, dtc is licensed
under the GNU GPL. The full text of the GPL can be found in the file
entitled 'GPL' which should be included in this package. dtc code,
therefore, may not be incorporated into works which do not have a GPL
@ -16,10 +16,10 @@ compatible license.
libfdt, however, is GPL/BSD dual-licensed. That is, it may be used
either under the terms of the GPL, or under the terms of the 2-clause
BSD license (aka the ISC license). The full terms of that license are
given in the copyright banners of each of the libfdt source files.
This is, in practice, equivalent to being BSD licensed, since the
terms of the BSD license are strictly more permissive than the GPL.
BSD license (aka the ISC license). The full terms of that license can
be found are in the file entitled 'BSD-2-Clause'. This is, in
practice, equivalent to being BSD licensed, since the terms of the BSD
license are strictly more permissive than the GPL.
I made the decision to license libfdt in this way because I want to
encourage widespread and correct usage of flattened device trees,
@ -33,7 +33,7 @@ back to the libfdt mainline. While I hope that doesn't happen, I
believe the goal of allowing libfdt to be widely used is more
important than avoiding that. libfdt is quite small, and hardly
rocket science; so the incentive for such impolite behaviour is small,
and the inconvenience caused therby is not dire.
and the inconvenience caused thereby is not dire.
Licenses such as the LGPL which would allow code to be used in non-GPL
software, but also require contributions to be returned were

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,8 @@
/* $NetBSD: convert-dtsv0-lexer.l,v 1.1.1.2 2017/06/08 15:59:15 skrll Exp $ */
/* $NetBSD: convert-dtsv0-lexer.l,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005, 2008.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%option noyywrap nounput noinput never-interactive

View File

@ -1,23 +1,8 @@
/* $NetBSD: data.c,v 1.1.1.2 2017/06/08 15:59:15 skrll Exp $ */
/* $NetBSD: data.c,v 1.1.1.3 2019/12/22 12:34:03 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "dtc.h"
@ -76,7 +61,8 @@ struct data data_copy_escape_string(const char *s, int len)
struct data d;
char *q;
d = data_grow_for(empty_data, len + 1);
d = data_add_marker(empty_data, TYPE_STRING, NULL);
d = data_grow_for(d, len + 1);
q = d.val;
while (i < len) {
@ -96,6 +82,7 @@ struct data data_copy_file(FILE *f, size_t maxlen)
{
struct data d = empty_data;
d = data_add_marker(d, TYPE_NONE, NULL);
while (!feof(f) && (d.len < maxlen)) {
size_t chunksize, ret;

View File

@ -1,23 +1,8 @@
/* $NetBSD: dtc-lexer.l,v 1.1.1.2 2017/06/08 15:59:15 skrll Exp $ */
/* $NetBSD: dtc-lexer.l,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%option noyywrap nounput noinput never-interactive
@ -155,6 +140,13 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
return DT_DEL_NODE;
}
<*>"/omit-if-no-ref/" {
DPRINT("Keyword: /omit-if-no-ref/\n");
DPRINT("<PROPNODENAME>\n");
BEGIN(PROPNODENAME);
return DT_OMIT_NO_REF;
}
<*>{LABEL}: {
DPRINT("Label: %s\n", yytext);
yylval.labelref = xstrdup(yytext);
@ -208,14 +200,14 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
<*>\&{LABEL} { /* label reference */
DPRINT("Ref: %s\n", yytext+1);
yylval.labelref = xstrdup(yytext+1);
return DT_REF;
return DT_LABEL_REF;
}
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
yytext[yyleng-1] = '\0';
DPRINT("Ref: %s\n", yytext+2);
yylval.labelref = xstrdup(yytext+2);
return DT_REF;
return DT_PATH_REF;
}
<BYTESTRING>[0-9a-fA-F]{2} {

View File

@ -1,23 +1,8 @@
/* $NetBSD: dtc-parser.y,v 1.1.1.2 2017/06/08 15:59:15 skrll Exp $ */
/* $NetBSD: dtc-parser.y,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%{
#include <stdio.h>
@ -65,13 +50,15 @@ extern bool treesource_error;
%token DT_BITS
%token DT_DEL_PROP
%token DT_DEL_NODE
%token DT_OMIT_NO_REF
%token <propnodename> DT_PROPNODENAME
%token <integer> DT_LITERAL
%token <integer> DT_CHAR_LITERAL
%token <byte> DT_BYTE
%token <data> DT_STRING
%token <labelref> DT_LABEL
%token <labelref> DT_REF
%token <labelref> DT_LABEL_REF
%token <labelref> DT_PATH_REF
%token DT_INCBIN
%type <data> propdata
@ -84,6 +71,7 @@ extern bool treesource_error;
%type <data> bytestring
%type <prop> propdef
%type <proplist> proplist
%type <labelref> dt_ref
%type <node> devicetree
%type <node> nodedef
@ -159,6 +147,8 @@ memreserve:
}
;
dt_ref: DT_LABEL_REF | DT_PATH_REF;
devicetree:
'/' nodedef
{
@ -168,8 +158,21 @@ devicetree:
{
$$ = merge_nodes($1, $3);
}
| devicetree DT_LABEL DT_REF nodedef
| dt_ref nodedef
{
/*
* We rely on the rule being always:
* versioninfo plugindecl memreserves devicetree
* so $-1 is what we want (plugindecl)
*/
if (!($<flags>-1 & DTSF_PLUGIN))
ERROR(&@2, "Label or path %s not found", $1);
$$ = add_orphan_node(
name_node(build_node(NULL, NULL, NULL),
""),
$2, $1);
}
| devicetree DT_LABEL dt_ref nodedef
{
struct node *target = get_node_by_ref($1, $3);
@ -180,17 +183,45 @@ devicetree:
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1;
}
| devicetree DT_REF nodedef
| devicetree DT_PATH_REF nodedef
{
/*
* We rely on the rule being always:
* versioninfo plugindecl memreserves devicetree
* so $-1 is what we want (plugindecl)
*/
if ($<flags>-1 & DTSF_PLUGIN) {
add_orphan_node($1, $3, $2);
} else {
struct node *target = get_node_by_ref($1, $2);
if (target)
merge_nodes(target, $3);
else
ERROR(&@2, "Label or path %s not found", $2);
}
$$ = $1;
}
| devicetree DT_LABEL_REF nodedef
{
struct node *target = get_node_by_ref($1, $2);
if (target)
if (target) {
merge_nodes(target, $3);
else
ERROR(&@2, "Label or path %s not found", $2);
} else {
/*
* We rely on the rule being always:
* versioninfo plugindecl memreserves devicetree
* so $-1 is what we want (plugindecl)
*/
if ($<flags>-1 & DTSF_PLUGIN)
add_orphan_node($1, $3, $2);
else
ERROR(&@2, "Label or path %s not found", $2);
}
$$ = $1;
}
| devicetree DT_DEL_NODE DT_REF ';'
| devicetree DT_DEL_NODE dt_ref ';'
{
struct node *target = get_node_by_ref($1, $3);
@ -200,6 +231,18 @@ devicetree:
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1;
}
| devicetree DT_OMIT_NO_REF dt_ref ';'
{
struct node *target = get_node_by_ref($1, $3);
if (target)
omit_node_if_unused(target);
else
ERROR(&@3, "Label or path %s not found", $3);
$$ = $1;
}
;
@ -207,7 +250,7 @@ devicetree:
nodedef:
'{' proplist subnodes '}' ';'
{
$$ = build_node($2, $3);
$$ = build_node($2, $3, &@$);
}
;
@ -225,11 +268,11 @@ proplist:
propdef:
DT_PROPNODENAME '=' propdata ';'
{
$$ = build_property($1, $3);
$$ = build_property($1, $3, &@$);
}
| DT_PROPNODENAME ';'
{
$$ = build_property($1, empty_data);
$$ = build_property($1, empty_data, &@$);
}
| DT_DEL_PROP DT_PROPNODENAME ';'
{
@ -255,8 +298,9 @@ propdata:
{
$$ = data_merge($1, $3);
}
| propdataprefix DT_REF
| propdataprefix dt_ref
{
$1 = data_add_marker($1, TYPE_STRING, $2);
$$ = data_add_marker($1, REF_PATH, $2);
}
| propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')'
@ -310,22 +354,27 @@ arrayprefix:
DT_BITS DT_LITERAL '<'
{
unsigned long long bits;
enum markertype type = TYPE_UINT32;
bits = $2;
if ((bits != 8) && (bits != 16) &&
(bits != 32) && (bits != 64)) {
switch (bits) {
case 8: type = TYPE_UINT8; break;
case 16: type = TYPE_UINT16; break;
case 32: type = TYPE_UINT32; break;
case 64: type = TYPE_UINT64; break;
default:
ERROR(&@2, "Array elements must be"
" 8, 16, 32 or 64-bits");
bits = 32;
}
$$.data = empty_data;
$$.data = data_add_marker(empty_data, type, NULL);
$$.bits = bits;
}
| '<'
{
$$.data = empty_data;
$$.data = data_add_marker(empty_data, TYPE_UINT32, NULL);
$$.bits = 32;
}
| arrayprefix integer_prim
@ -347,7 +396,7 @@ arrayprefix:
$$.data = data_append_integer($1.data, $2, $1.bits);
}
| arrayprefix DT_REF
| arrayprefix dt_ref
{
uint64_t val = ~0ULL >> (64 - $1.bits);
@ -469,7 +518,7 @@ integer_unary:
bytestring:
/* empty */
{
$$ = empty_data;
$$ = data_add_marker(empty_data, TYPE_UINT8, NULL);
}
| bytestring DT_BYTE
{
@ -504,7 +553,11 @@ subnode:
}
| DT_DEL_NODE DT_PROPNODENAME ';'
{
$$ = name_node(build_node_delete(), $2);
$$ = name_node(build_node_delete(&@$), $2);
}
| DT_OMIT_NO_REF subnode
{
$$ = omit_node_if_unused($2);
}
| DT_LABEL subnode
{

View File

@ -1,23 +1,8 @@
/* $NetBSD: dtc.c,v 1.1.1.2 2017/06/08 15:59:15 skrll Exp $ */
/* $NetBSD: dtc.c,v 1.1.1.3 2019/12/22 12:34:03 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <sys/stat.h>
@ -33,10 +18,12 @@ int reservenum; /* Number of memory reservation slots */
int minsize; /* Minimum blob size */
int padsize; /* Additional padding to blob */
int alignsize; /* Additional padding to blob accroding to the alignsize */
int phandle_format = PHANDLE_BOTH; /* Use linux,phandle or phandle properties */
int phandle_format = PHANDLE_EPAPR; /* Use linux,phandle or phandle properties */
int generate_symbols; /* enable symbols & fixup support */
int generate_fixups; /* suppress generation of fixups on symbol support */
int auto_label_aliases; /* auto generate labels -> aliases */
int annotate; /* Level of annotation: 1 for input source location
>1 for full input source location. */
static int is_power_of_2(int x)
{
@ -61,10 +48,8 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
}
/* Usage related data. */
#define FDT_VERSION(version) _FDT_VERSION(version)
#define _FDT_VERSION(version) #version
static const char usage_synopsis[] = "dtc [options] <input file>";
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv";
static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@AThv";
static struct option const usage_long_opts[] = {
{"quiet", no_argument, NULL, 'q'},
{"in-format", a_argument, NULL, 'I'},
@ -85,6 +70,7 @@ static struct option const usage_long_opts[] = {
{"error", a_argument, NULL, 'E'},
{"symbols", no_argument, NULL, '@'},
{"auto-alias", no_argument, NULL, 'A'},
{"annotate", no_argument, NULL, 'T'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{NULL, no_argument, NULL, 0x0},
@ -99,8 +85,11 @@ static const char * const usage_opts_help[] = {
"\n\tOutput formats are:\n"
"\t\tdts - device tree source text\n"
"\t\tdtb - device tree blob\n"
#ifndef NO_YAML
"\t\tyaml - device tree encoded as YAML\n"
#endif
"\t\tasm - assembler source",
"\n\tBlob version to produce, defaults to "FDT_VERSION(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
"\n\tBlob version to produce, defaults to "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)",
"\n\tOutput dependency file",
"\n\tMake space for <number> reserve map entries (for dtb and asm output)",
"\n\tMake the blob at least <bytes> long (extra space)",
@ -118,6 +107,7 @@ static const char * const usage_opts_help[] = {
"\n\tEnable/disable errors (prefix with \"no-\")",
"\n\tEnable generation of symbols",
"\n\tEnable auto-alias of labels",
"\n\tAnnotate output .dts with input source file and line (-T -T for more details)",
"\n\tPrint this help and exit",
"\n\tPrint version and exit",
NULL,
@ -132,6 +122,8 @@ static const char *guess_type_by_name(const char *fname, const char *fallback)
return fallback;
if (!strcasecmp(s, ".dts"))
return "dts";
if (!strcasecmp(s, ".yaml"))
return "yaml";
if (!strcasecmp(s, ".dtb"))
return "dtb";
return fallback;
@ -263,6 +255,9 @@ int main(int argc, char *argv[])
case 'A':
auto_label_aliases = 1;
break;
case 'T':
annotate++;
break;
case 'h':
usage(NULL);
@ -301,6 +296,8 @@ int main(int argc, char *argv[])
outform = "dts";
}
}
if (annotate && (!streq(inform, "dts") || !streq(outform, "dts")))
die("--annotate requires -I dts -O dts\n");
if (streq(inform, "dts"))
dti = dt_from_source(arg);
else if (streq(inform, "fs"))
@ -321,13 +318,14 @@ int main(int argc, char *argv[])
dti->boot_cpuid_phys = cmdline_boot_cpuid;
fill_fullpaths(dti->dt, "");
process_checks(force, dti);
/* on a plugin, generate by default */
if (dti->dtsflags & DTSF_PLUGIN) {
generate_fixups = 1;
}
process_checks(force, dti);
if (auto_label_aliases)
generate_label_tree(dti, "aliases", false);
@ -353,6 +351,12 @@ int main(int argc, char *argv[])
if (streq(outform, "dts")) {
dt_to_source(outf, dti);
#ifndef NO_YAML
} else if (streq(outform, "yaml")) {
if (!streq(inform, "dts"))
die("YAML output format requires dts input format\n");
dt_to_yaml(outf, dti);
#endif
} else if (streq(outform, "dtb")) {
dt_to_blob(outf, dti, outversion);
} else if (streq(outform, "asm")) {

View File

@ -1,26 +1,11 @@
/* $NetBSD: dtc.h,v 1.1.1.2 2017/06/08 15:59:15 skrll Exp $ */
/* $NetBSD: dtc.h,v 1.1.1.3 2019/12/22 12:34:03 skrll Exp $ */
#ifndef _DTC_H
#define _DTC_H
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef DTC_H
#define DTC_H
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <stdio.h>
@ -33,6 +18,7 @@
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <inttypes.h>
#include <libfdt_env.h>
#include <fdt.h>
@ -59,6 +45,7 @@ extern int phandle_format; /* Use linux,phandle or phandle properties */
extern int generate_symbols; /* generate symbols for nodes with labels */
extern int generate_fixups; /* generate fixups */
extern int auto_label_aliases; /* auto generate labels -> aliases */
extern int annotate; /* annotate .dts with input source location */
#define PHANDLE_LEGACY 0x1
#define PHANDLE_EPAPR 0x2
@ -68,16 +55,24 @@ typedef uint32_t cell_t;
#define streq(a, b) (strcmp((a), (b)) == 0)
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
#define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
#define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
/* Data blobs */
enum markertype {
TYPE_NONE,
REF_PHANDLE,
REF_PATH,
LABEL,
TYPE_UINT8,
TYPE_UINT16,
TYPE_UINT32,
TYPE_UINT64,
TYPE_STRING,
};
extern const char *markername(enum markertype markertype);
struct marker {
enum markertype type;
@ -101,6 +96,8 @@ struct data {
for_each_marker(m) \
if ((m)->type == (t))
size_t type_marker_length(struct marker *m);
void data_free(struct data d);
struct data data_grow_for(struct data d, int xlen);
@ -137,6 +134,10 @@ struct label {
struct label *next;
};
struct bus_type {
const char *name;
};
struct property {
bool deleted;
char *name;
@ -145,6 +146,7 @@ struct property {
struct property *next;
struct label *labels;
struct srcpos *srcpos;
};
struct node {
@ -163,6 +165,10 @@ struct node {
int addr_cells, size_cells;
struct label *labels;
const struct bus_type *bus;
struct srcpos *srcpos;
bool omit_if_unused, is_referenced;
};
#define for_each_label_withdel(l0, l) \
@ -189,16 +195,21 @@ struct node {
void add_label(struct label **labels, char *label);
void delete_labels(struct label **labels);
struct property *build_property(char *name, struct data val);
struct property *build_property(char *name, struct data val,
struct srcpos *srcpos);
struct property *build_property_delete(char *name);
struct property *chain_property(struct property *first, struct property *list);
struct property *reverse_properties(struct property *first);
struct node *build_node(struct property *proplist, struct node *children);
struct node *build_node_delete(void);
struct node *build_node(struct property *proplist, struct node *children,
struct srcpos *srcpos);
struct node *build_node_delete(struct srcpos *srcpos);
struct node *name_node(struct node *node, char *name);
struct node *omit_node_if_unused(struct node *node);
struct node *reference_node(struct node *node);
struct node *chain_node(struct node *first, struct node *list);
struct node *merge_nodes(struct node *old_node, struct node *new_node);
struct node *add_orphan_node(struct node *old_node, struct node *new_node, char *ref);
void add_property(struct node *node, struct property *prop);
void delete_property_by_name(struct node *node, char *name);
@ -207,11 +218,13 @@ void add_child(struct node *parent, struct node *child);
void delete_node_by_name(struct node *parent, char *name);
void delete_node(struct node *node);
void append_to_property(struct node *node,
char *name, const void *data, int len);
char *name, const void *data, int len,
enum markertype type);
const char *get_unitname(struct node *node);
struct property *get_property(struct node *node, const char *propname);
cell_t propval_cell(struct property *prop);
cell_t propval_cell_n(struct property *prop, int n);
struct property *get_property_by_label(struct node *tree, const char *label,
struct node **node);
struct marker *get_marker_label(struct node *tree, const char *label,
@ -279,8 +292,12 @@ struct dt_info *dt_from_blob(const char *fname);
void dt_to_source(FILE *f, struct dt_info *dti);
struct dt_info *dt_from_source(const char *f);
/* YAML source */
void dt_to_yaml(FILE *f, struct dt_info *dti);
/* FS trees */
struct dt_info *dt_from_fs(const char *dirname);
#endif /* _DTC_H */
#endif /* DTC_H */

View File

@ -1,4 +1,5 @@
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# This script uses the bash <(...) extension.
# If you want to change this to work with a generic /bin/sh, make sure

View File

@ -1,5 +1,6 @@
/* $NetBSD: fdtdump.c,v 1.1.1.2 2017/06/08 15:59:16 skrll Exp $ */
/* $NetBSD: fdtdump.c,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* fdtdump.c - Contributed by Pantelis Antoniou <pantelis.antoniou AT gmail.com>
*/
@ -10,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <libfdt.h>
#include <libfdt_env.h>
@ -67,23 +69,24 @@ static void dump_blob(void *blob, bool debug)
shift = 4;
printf("/dts-v1/;\n");
printf("// magic:\t\t0x%x\n", fdt32_to_cpu(bph->magic));
printf("// totalsize:\t\t0x%x (%d)\n", totalsize, totalsize);
printf("// off_dt_struct:\t0x%x\n", off_dt);
printf("// off_dt_strings:\t0x%x\n", off_str);
printf("// off_mem_rsvmap:\t0x%x\n", off_mem_rsvmap);
printf("// version:\t\t%d\n", version);
printf("// last_comp_version:\t%d\n",
printf("// magic:\t\t0x%"PRIx32"\n", fdt32_to_cpu(bph->magic));
printf("// totalsize:\t\t0x%"PRIx32" (%"PRIu32")\n",
totalsize, totalsize);
printf("// off_dt_struct:\t0x%"PRIx32"\n", off_dt);
printf("// off_dt_strings:\t0x%"PRIx32"\n", off_str);
printf("// off_mem_rsvmap:\t0x%"PRIx32"\n", off_mem_rsvmap);
printf("// version:\t\t%"PRIu32"\n", version);
printf("// last_comp_version:\t%"PRIu32"\n",
fdt32_to_cpu(bph->last_comp_version));
if (version >= 2)
printf("// boot_cpuid_phys:\t0x%x\n",
printf("// boot_cpuid_phys:\t0x%"PRIx32"\n",
fdt32_to_cpu(bph->boot_cpuid_phys));
if (version >= 3)
printf("// size_dt_strings:\t0x%x\n",
printf("// size_dt_strings:\t0x%"PRIx32"\n",
fdt32_to_cpu(bph->size_dt_strings));
if (version >= 17)
printf("// size_dt_struct:\t0x%x\n",
printf("// size_dt_struct:\t0x%"PRIx32"\n",
fdt32_to_cpu(bph->size_dt_struct));
printf("\n");
@ -93,14 +96,14 @@ static void dump_blob(void *blob, bool debug)
if (addr == 0 && size == 0)
break;
printf("/memreserve/ %#llx %#llx;\n",
(unsigned long long)addr, (unsigned long long)size);
printf("/memreserve/ %#"PRIx64" %#"PRIx64";\n",
addr, size);
}
p = p_struct;
while ((tag = fdt32_to_cpu(GET_CELL(p))) != FDT_END) {
dumpf("%04zx: tag: 0x%08x (%s)\n",
dumpf("%04"PRIxPTR": tag: 0x%08"PRIx32" (%s)\n",
(uintptr_t)p - blob_off - 4, tag, tagname(tag));
if (tag == FDT_BEGIN_NODE) {
@ -129,7 +132,7 @@ static void dump_blob(void *blob, bool debug)
}
if (tag != FDT_PROP) {
fprintf(stderr, "%*s ** Unknown tag 0x%08x\n", depth * shift, "", tag);
fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
break;
}
sz = fdt32_to_cpu(GET_CELL(p));
@ -140,8 +143,8 @@ static void dump_blob(void *blob, bool debug)
p = PALIGN(p + sz, 4);
dumpf("%04zx: string: %s\n", (uintptr_t)s - blob_off, s);
dumpf("%04zx: value\n", (uintptr_t)t - blob_off);
dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);
dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
printf("%*s%s", depth * shift, "", s);
utilfdt_print_data(t, sz);
printf(";\n");
@ -167,7 +170,7 @@ static bool valid_header(char *p, off_t len)
if (len < sizeof(struct fdt_header) ||
fdt_magic(p) != FDT_MAGIC ||
fdt_version(p) > MAX_VERSION ||
fdt_last_comp_version(p) >= MAX_VERSION ||
fdt_last_comp_version(p) > MAX_VERSION ||
fdt_totalsize(p) >= len ||
fdt_off_dt_struct(p) >= len ||
fdt_off_dt_strings(p) >= len)
@ -183,8 +186,13 @@ int main(int argc, char *argv[])
char *buf;
bool debug = false;
bool scan = false;
off_t len;
size_t len;
fprintf(stderr, "\n"
"**** fdtdump is a low-level debugging tool, not meant for general use.\n"
"**** If you want to decompile a dtb, you probably want\n"
"**** dtc -I dtb -O dts <filename>\n\n"
);
while ((opt = util_getopt_long()) != EOF) {
switch (opt) {
case_USAGE_COMMON_FLAGS
@ -201,7 +209,7 @@ int main(int argc, char *argv[])
usage("missing input filename");
file = argv[optind];
buf = utilfdt_read_len(file, &len);
buf = utilfdt_read(file, &len);
if (!buf)
die("could not read: %s\n", file);
@ -224,14 +232,14 @@ int main(int argc, char *argv[])
if (valid_header(p, this_len))
break;
if (debug)
printf("%s: skipping fdt magic at offset %#zx\n",
printf("%s: skipping fdt magic at offset %#tx\n",
file, p - buf);
}
++p;
}
if (!p || endp - p < sizeof(struct fdt_header))
die("%s: could not locate fdt magic\n", file);
printf("%s: found fdt at offset %#zx\n", file, p - buf);
printf("%s: found fdt at offset %#tx\n", file, p - buf);
buf = p;
} else if (!valid_header(buf, len))
die("%s: header is not valid\n", file);

View File

@ -1,5 +1,6 @@
/* $NetBSD: fdtget.c,v 1.1.1.2 2017/06/08 15:59:16 skrll Exp $ */
/* $NetBSD: fdtget.c,v 1.1.1.3 2019/12/22 12:34:03 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
*
@ -8,21 +9,6 @@
* Based on code written by:
* Pantelis Antoniou <pantelis.antoniou@gmail.com> and
* Matthew McClintock <msm@freescale.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <assert.h>
@ -55,6 +41,37 @@ static void report_error(const char *where, int err)
fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
}
/**
* Shows a list of cells in the requested format
*
* @param disp Display information / options
* @param data Data to display
* @param len Maximum length of buffer
* @param size Data size to use for display (e.g. 4 for 32-bit)
* @return 0 if ok, -1 on error
*/
static int show_cell_list(struct display_info *disp, const char *data, int len,
int size)
{
const uint8_t *p = (const uint8_t *)data;
char fmt[3];
int value;
int i;
fmt[0] = '%';
fmt[1] = disp->type ? disp->type : 'd';
fmt[2] = '\0';
for (i = 0; i < len; i += size, p += size) {
if (i)
printf(" ");
value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
size == 2 ? (*p << 8) | p[1] : *p;
printf(fmt, value);
}
return 0;
}
/**
* Displays data of a given length according to selected options
*
@ -68,12 +85,9 @@ static void report_error(const char *where, int err)
*/
static int show_data(struct display_info *disp, const char *data, int len)
{
int i, size;
const uint8_t *p = (const uint8_t *)data;
int size;
const char *s;
int value;
int is_string;
char fmt[3];
/* no data, don't print */
if (len == 0)
@ -101,17 +115,8 @@ static int show_data(struct display_info *disp, const char *data, int len)
"selected data size\n");
return -1;
}
fmt[0] = '%';
fmt[1] = disp->type ? disp->type : 'd';
fmt[2] = '\0';
for (i = 0; i < len; i += size, p += size) {
if (i)
printf(" ");
value = size == 4 ? fdt32_to_cpu(*(const fdt32_t *)p) :
size == 2 ? (*p << 8) | p[1] : *p;
printf(fmt, value);
}
return 0;
return show_cell_list(disp, data, len, size);
}
/**
@ -123,7 +128,6 @@ static int show_data(struct display_info *disp, const char *data, int len)
*/
static int list_properties(const void *blob, int node)
{
const struct fdt_property *data;
const char *name;
int prop;
@ -132,8 +136,7 @@ static int list_properties(const void *blob, int node)
/* Stop silently when there are no more properties */
if (prop < 0)
return prop == -FDT_ERR_NOTFOUND ? 0 : prop;
data = fdt_get_property_by_offset(blob, prop, NULL);
name = fdt_string(blob, fdt32_to_cpu(data->nameoff));
fdt_getprop_by_offset(blob, prop, &name, NULL);
if (name)
puts(name);
prop = fdt_next_property_offset(blob, prop);
@ -256,7 +259,7 @@ static int do_fdtget(struct display_info *disp, const char *filename,
const char *prop;
int i, node;
blob = utilfdt_read(filename);
blob = utilfdt_read(filename, NULL);
if (!blob)
return -1;

211
external/gpl2/dtc/dist/fdtoverlay.c vendored Normal file
View File

@ -0,0 +1,211 @@
/* $NetBSD: fdtoverlay.c,v 1.1.1.1 2019/12/22 12:34:03 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2017 Konsulko Group Inc. All rights reserved.
*
* Author:
* Pantelis Antoniou <pantelis.antoniou@konsulko.com>
*/
#include <assert.h>
#include <ctype.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <libfdt.h>
#include "util.h"
#define BUF_INCREMENT 65536
/* Usage related data. */
static const char usage_synopsis[] =
"apply a number of overlays to a base blob\n"
" fdtoverlay <options> [<overlay.dtbo> [<overlay.dtbo>]]\n"
"\n"
USAGE_TYPE_MSG;
static const char usage_short_opts[] = "i:o:v" USAGE_COMMON_SHORT_OPTS;
static struct option const usage_long_opts[] = {
{"input", required_argument, NULL, 'i'},
{"output", required_argument, NULL, 'o'},
{"verbose", no_argument, NULL, 'v'},
USAGE_COMMON_LONG_OPTS,
};
static const char * const usage_opts_help[] = {
"Input base DT blob",
"Output DT blob",
"Verbose messages",
USAGE_COMMON_OPTS_HELP
};
int verbose = 0;
static void *apply_one(char *base, const char *overlay, size_t *buf_len,
const char *name)
{
char *tmp = NULL;
char *tmpo;
int ret;
/*
* We take a copies first, because a a failed apply can trash
* both the base blob and the overlay
*/
tmpo = xmalloc(fdt_totalsize(overlay));
do {
tmp = xrealloc(tmp, *buf_len);
ret = fdt_open_into(base, tmp, *buf_len);
if (ret) {
fprintf(stderr,
"\nFailed to make temporary copy: %s\n",
fdt_strerror(ret));
goto fail;
}
memcpy(tmpo, overlay, fdt_totalsize(overlay));
ret = fdt_overlay_apply(tmp, tmpo);
if (ret == -FDT_ERR_NOSPACE) {
*buf_len += BUF_INCREMENT;
}
} while (ret == -FDT_ERR_NOSPACE);
if (ret) {
fprintf(stderr, "\nFailed to apply '%s': %s\n",
name, fdt_strerror(ret));
goto fail;
}
free(base);
free(tmpo);
return tmp;
fail:
free(tmpo);
if (tmp)
free(tmp);
return NULL;
}
static int do_fdtoverlay(const char *input_filename,
const char *output_filename,
int argc, char *argv[])
{
char *blob = NULL;
char **ovblob = NULL;
size_t buf_len;
int i, ret = -1;
blob = utilfdt_read(input_filename, &buf_len);
if (!blob) {
fprintf(stderr, "\nFailed to read '%s'\n", input_filename);
goto out_err;
}
if (fdt_totalsize(blob) > buf_len) {
fprintf(stderr,
"\nBase blob is incomplete (%lu / %" PRIu32 " bytes read)\n",
(unsigned long)buf_len, fdt_totalsize(blob));
goto out_err;
}
ret = 0;
/* allocate blob pointer array */
ovblob = xmalloc(sizeof(*ovblob) * argc);
memset(ovblob, 0, sizeof(*ovblob) * argc);
/* read and keep track of the overlay blobs */
for (i = 0; i < argc; i++) {
size_t ov_len;
ovblob[i] = utilfdt_read(argv[i], &ov_len);
if (!ovblob[i]) {
fprintf(stderr, "\nFailed to read '%s'\n", argv[i]);
goto out_err;
}
if (fdt_totalsize(ovblob[i]) > ov_len) {
fprintf(stderr,
"\nOverlay '%s' is incomplete (%lu / %" PRIu32 " bytes read)\n",
argv[i], (unsigned long)ov_len,
fdt_totalsize(ovblob[i]));
goto out_err;
}
}
buf_len = fdt_totalsize(blob);
/* apply the overlays in sequence */
for (i = 0; i < argc; i++) {
blob = apply_one(blob, ovblob[i], &buf_len, argv[i]);
if (!blob)
goto out_err;
}
fdt_pack(blob);
ret = utilfdt_write(output_filename, blob);
if (ret)
fprintf(stderr, "\nFailed to write '%s'\n",
output_filename);
out_err:
if (ovblob) {
for (i = 0; i < argc; i++) {
if (ovblob[i])
free(ovblob[i]);
}
free(ovblob);
}
free(blob);
return ret;
}
int main(int argc, char *argv[])
{
int opt, i;
char *input_filename = NULL;
char *output_filename = NULL;
while ((opt = util_getopt_long()) != EOF) {
switch (opt) {
case_USAGE_COMMON_FLAGS
case 'i':
input_filename = optarg;
break;
case 'o':
output_filename = optarg;
break;
case 'v':
verbose = 1;
break;
}
}
if (!input_filename)
usage("missing input file");
if (!output_filename)
usage("missing output file");
argv += optind;
argc -= optind;
if (argc <= 0)
usage("missing overlay file(s)");
if (verbose) {
printf("input = %s\n", input_filename);
printf("output = %s\n", output_filename);
for (i = 0; i < argc; i++)
printf("overlay[%d] = %s\n", i, argv[i]);
}
if (do_fdtoverlay(input_filename, output_filename, argc, argv))
return 1;
return 0;
}

View File

@ -1,22 +1,8 @@
/* $NetBSD: fdtput.c,v 1.1.1.2 2017/06/08 15:59:16 skrll Exp $ */
/* $NetBSD: fdtput.c,v 1.1.1.3 2019/12/22 12:34:02 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <assert.h>
@ -132,7 +118,7 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,
#define ALIGN(x) (((x) + (FDT_TAGSIZE) - 1) & ~((FDT_TAGSIZE) - 1))
static char *_realloc_fdt(char *fdt, int delta)
static char *realloc_fdt(char *fdt, int delta)
{
int new_sz = fdt_totalsize(fdt) + delta;
fdt = xrealloc(fdt, new_sz);
@ -146,7 +132,7 @@ static char *realloc_node(char *fdt, const char *name)
/* FDT_BEGIN_NODE, node name in off_struct and FDT_END_NODE */
delta = sizeof(struct fdt_node_header) + ALIGN(strlen(name) + 1)
+ FDT_TAGSIZE;
return _realloc_fdt(fdt, delta);
return realloc_fdt(fdt, delta);
}
static char *realloc_property(char *fdt, int nodeoffset,
@ -163,7 +149,7 @@ static char *realloc_property(char *fdt, int nodeoffset,
/* actual value in off_struct */
delta += ALIGN(newlen) - ALIGN(oldlen);
return _realloc_fdt(fdt, delta);
return realloc_fdt(fdt, delta);
}
static int store_key_value(char **blob, const char *node_name,
@ -335,7 +321,7 @@ static int do_fdtput(struct display_info *disp, const char *filename,
char *node;
int len, ret = 0;
blob = utilfdt_read(filename);
blob = utilfdt_read(filename, NULL);
if (!blob)
return -1;

View File

@ -1,23 +1,8 @@
/* $NetBSD: flattree.c,v 1.1.1.2 2017/06/08 15:59:18 skrll Exp $ */
/* $NetBSD: flattree.c,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "dtc.h"
@ -395,7 +380,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
padlen = 0;
if (quiet < 1)
fprintf(stderr,
"Warning: blob size %d >= minimum size %d\n",
"Warning: blob size %"PRIu32" >= minimum size %d\n",
fdt32_to_cpu(fdt.totalsize), minsize);
}
}
@ -527,7 +512,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
fprintf(f, "/* Memory reserve map from source file */\n");
/*
* Use .long on high and low halfs of u64s to avoid .quad
* Use .long on high and low halves of u64s to avoid .quad
* as it appears .quad isn't available in some assemblers.
*/
for (re = dti->reservelist; re; re = re->next) {
@ -694,7 +679,7 @@ static struct property *flat_read_property(struct inbuf *dtbuf,
val = flat_read_data(dtbuf, proplen);
return build_property(name, val);
return build_property(name, val, NULL);
}
@ -733,7 +718,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
plen = strlen(ppath);
if (!strneq(ppath, cpath, plen))
if (!strstarts(cpath, ppath))
die("Path \"%s\" is not valid as a child of \"%s\"\n",
cpath, ppath);
@ -752,7 +737,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
char *flatname;
uint32_t val;
node = build_node(NULL, NULL);
node = build_node(NULL, NULL, NULL);
flatname = flat_read_string(dtbuf);

View File

@ -1,23 +1,8 @@
/* $NetBSD: fstree.c,v 1.1.1.2 2017/06/08 15:59:18 skrll Exp $ */
/* $NetBSD: fstree.c,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "dtc.h"
@ -36,7 +21,7 @@ static struct node *read_fstree(const char *dirname)
if (!d)
die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
tree = build_node(NULL, NULL);
tree = build_node(NULL, NULL, NULL);
while ((de = readdir(d)) != NULL) {
char *tmpname;
@ -62,7 +47,8 @@ static struct node *read_fstree(const char *dirname)
} else {
prop = build_property(xstrdup(de->d_name),
data_copy_file(pfile,
st.st_size));
st.st_size),
NULL);
add_property(tree, prop);
fclose(pfile);
}

View File

@ -1,26 +1,12 @@
/* $NetBSD: livetree.c,v 1.1.1.2 2017/06/08 15:59:21 skrll Exp $ */
/* $NetBSD: livetree.c,v 1.1.1.3 2019/12/22 12:34:03 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "dtc.h"
#include "srcpos.h"
/*
* Tree building functions
@ -52,7 +38,8 @@ void delete_labels(struct label **labels)
label->deleted = 1;
}
struct property *build_property(char *name, struct data val)
struct property *build_property(char *name, struct data val,
struct srcpos *srcpos)
{
struct property *new = xmalloc(sizeof(*new));
@ -60,6 +47,7 @@ struct property *build_property(char *name, struct data val)
new->name = name;
new->val = val;
new->srcpos = srcpos_copy(srcpos);
return new;
}
@ -99,7 +87,8 @@ struct property *reverse_properties(struct property *first)
return head;
}
struct node *build_node(struct property *proplist, struct node *children)
struct node *build_node(struct property *proplist, struct node *children,
struct srcpos *srcpos)
{
struct node *new = xmalloc(sizeof(*new));
struct node *child;
@ -108,6 +97,7 @@ struct node *build_node(struct property *proplist, struct node *children)
new->proplist = reverse_properties(proplist);
new->children = children;
new->srcpos = srcpos_copy(srcpos);
for_each_child(new, child) {
child->parent = new;
@ -116,13 +106,14 @@ struct node *build_node(struct property *proplist, struct node *children)
return new;
}
struct node *build_node_delete(void)
struct node *build_node_delete(struct srcpos *srcpos)
{
struct node *new = xmalloc(sizeof(*new));
memset(new, 0, sizeof(*new));
new->deleted = 1;
new->srcpos = srcpos_copy(srcpos);
return new;
}
@ -136,6 +127,20 @@ struct node *name_node(struct node *node, char *name)
return node;
}
struct node *omit_node_if_unused(struct node *node)
{
node->omit_if_unused = 1;
return node;
}
struct node *reference_node(struct node *node)
{
node->is_referenced = 1;
return node;
}
struct node *merge_nodes(struct node *old_node, struct node *new_node)
{
struct property *new_prop, *old_prop;
@ -171,6 +176,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
old_prop->val = new_prop->val;
old_prop->deleted = 0;
free(old_prop->srcpos);
old_prop->srcpos = new_prop->srcpos;
free(new_prop);
new_prop = NULL;
break;
@ -211,6 +218,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
add_child(old_node, new_child);
}
old_node->srcpos = srcpos_extend(old_node->srcpos, new_node->srcpos);
/* The new node contents are now merged into the old node. Free
* the new node. */
free(new_node);
@ -218,6 +227,36 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
return old_node;
}
struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
{
static unsigned int next_orphan_fragment = 0;
struct node *node;
struct property *p;
struct data d = empty_data;
char *name;
if (ref[0] == '/') {
d = data_add_marker(d, TYPE_STRING, ref);
d = data_append_data(d, ref, strlen(ref) + 1);
p = build_property("target-path", d, NULL);
} else {
d = data_add_marker(d, REF_PHANDLE, ref);
d = data_append_integer(d, 0xffffffff, 32);
p = build_property("target", d, NULL);
}
xasprintf(&name, "fragment@%u",
next_orphan_fragment++);
name_node(new_node, "__overlay__");
node = build_node(p, new_node, NULL);
name_node(node, name);
add_child(dt, node);
return dt;
}
struct node *chain_node(struct node *first, struct node *list)
{
assert(first->next_sibling == NULL);
@ -299,18 +338,21 @@ void delete_node(struct node *node)
}
void append_to_property(struct node *node,
char *name, const void *data, int len)
char *name, const void *data, int len,
enum markertype type)
{
struct data d;
struct property *p;
p = get_property(node, name);
if (p) {
d = data_append_data(p->val, data, len);
d = data_add_marker(p->val, type, name);
d = data_append_data(d, data, len);
p->val = d;
} else {
d = data_append_data(empty_data, data, len);
p = build_property(name, d);
d = data_add_marker(empty_data, type, name);
d = data_append_data(d, data, len);
p = build_property(name, d, NULL);
add_property(node, p);
}
}
@ -398,6 +440,12 @@ cell_t propval_cell(struct property *prop)
return fdt32_to_cpu(*((fdt32_t *)prop->val.val));
}
cell_t propval_cell_n(struct property *prop, int n)
{
assert(prop->val.len / sizeof(cell_t) >= n);
return fdt32_to_cpu(*((fdt32_t *)prop->val.val + n));
}
struct property *get_property_by_label(struct node *tree, const char *label,
struct node **node)
{
@ -480,7 +528,7 @@ struct node *get_node_by_path(struct node *tree, const char *path)
p = strchr(path, '/');
for_each_child(tree, child) {
if (p && strneq(path, child->name, p-path))
if (p && strprefixeq(path, p - path, child->name))
return get_node_by_path(child, p+1);
else if (!p && streq(path, child->name))
return child;
@ -513,7 +561,10 @@ struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
{
struct node *child, *node;
assert((phandle != 0) && (phandle != -1));
if ((phandle == 0) || (phandle == -1)) {
assert(generate_fixups);
return NULL;
}
if (tree->phandle == phandle) {
if (tree->deleted)
@ -543,6 +594,7 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
cell_t get_node_phandle(struct node *root, struct node *node)
{
static cell_t phandle = 1; /* FIXME: ick, static local */
struct data d = empty_data;
if ((node->phandle != 0) && (node->phandle != -1))
return node->phandle;
@ -552,17 +604,16 @@ cell_t get_node_phandle(struct node *root, struct node *node)
node->phandle = phandle;
d = data_add_marker(d, TYPE_UINT32, NULL);
d = data_append_cell(d, phandle);
if (!get_property(node, "linux,phandle")
&& (phandle_format & PHANDLE_LEGACY))
add_property(node,
build_property("linux,phandle",
data_append_cell(empty_data, phandle)));
add_property(node, build_property("linux,phandle", d, NULL));
if (!get_property(node, "phandle")
&& (phandle_format & PHANDLE_EPAPR))
add_property(node,
build_property("phandle",
data_append_cell(empty_data, phandle)));
add_property(node, build_property("phandle", d, NULL));
/* If the node *does* have a phandle property, we must
* be dealing with a self-referencing phandle, which will be
@ -736,7 +787,7 @@ static struct node *build_and_name_child_node(struct node *parent, char *name)
{
struct node *node;
node = build_node(NULL, NULL);
node = build_node(NULL, NULL, NULL);
name_node(node, xstrdup(name));
add_child(parent, node);
@ -797,8 +848,9 @@ static void generate_label_tree_internal(struct dt_info *dti,
/* insert it */
p = build_property(l->label,
data_copy_mem(node->fullpath,
strlen(node->fullpath) + 1));
data_copy_escape_string(node->fullpath,
strlen(node->fullpath)),
NULL);
add_property(an, p);
}
@ -848,7 +900,7 @@ static void add_fixup_entry(struct dt_info *dti, struct node *fn,
xasprintf(&entry, "%s:%s:%u",
node->fullpath, prop->name, m->offset);
append_to_property(fn, m->ref, entry, strlen(entry) + 1);
append_to_property(fn, m->ref, entry, strlen(entry) + 1, TYPE_STRING);
free(entry);
}
@ -908,7 +960,7 @@ static void add_local_fixup_entry(struct dt_info *dti,
char **compp;
int i, depth;
/* walk back retreiving depth */
/* walk back retrieving depth */
depth = 0;
for (wn = node; wn; wn = wn->parent)
depth++;
@ -931,7 +983,7 @@ static void add_local_fixup_entry(struct dt_info *dti,
free(compp);
value_32 = cpu_to_fdt32(m->offset);
append_to_property(wn, prop->name, &value_32, sizeof(value_32));
append_to_property(wn, prop->name, &value_32, sizeof(value_32), TYPE_UINT32);
}
static void generate_local_fixups_tree_internal(struct dt_info *dti,

View File

@ -0,0 +1,3 @@
libfdt.py
*.pyc
libfdt_wrap.c

View File

@ -0,0 +1,30 @@
# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
# Makefile.pylibfdt
#
PYLIBFDT_srcs = $(PYLIBFDT_dir)/libfdt.i
PYMODULE = $(PYLIBFDT_dir)/_libfdt.so
PYLIBFDT_CLEANFILES_L = libfdt_wrap.c libfdt.py *.pyc *.so
PYLIBFDT_CLEANFILES = $(PYLIBFDT_CLEANFILES_L:%=$(PYLIBFDT_dir)/%)
PYLIBFDT_CLEANDIRS_L = build __pycache__
PYLIBFDT_CLEANDIRS = $(PYLIBFDT_CLEANDIRS_L:%=$(PYLIBFDT_dir)/%)
SETUP = $(PYLIBFDT_dir)/setup.py
SETUPFLAGS =
ifndef V
SETUPFLAGS += --quiet
endif
$(PYMODULE): $(PYLIBFDT_srcs) $(LIBFDT_archive) $(SETUP) $(VERSION_FILE)
@$(VECHO) PYMOD $@
$(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext --build-lib=../$(PYLIBFDT_dir)
install_pylibfdt: $(PYMODULE)
@$(VECHO) INSTALL-PYLIB
$(PYTHON) $(SETUP) $(SETUPFLAGS) install --prefix=$(PREFIX)
pylibfdt_clean:
@$(VECHO) CLEAN "(pylibfdt)"
rm -f $(PYLIBFDT_CLEANFILES)
rm -rf $(PYLIBFDT_CLEANDIRS)

1118
external/gpl2/dtc/dist/pylibfdt/libfdt.i vendored Normal file

File diff suppressed because it is too large Load Diff

45
external/gpl2/dtc/dist/pylibfdt/setup.py vendored Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python2
# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
"""
setup.py file for SWIG libfdt
Copyright (C) 2017 Google, Inc.
Written by Simon Glass <sjg@chromium.org>
"""
from distutils.core import setup, Extension
import os
import re
import sys
VERSION_PATTERN = '^#define DTC_VERSION "DTC ([^"]*)"$'
def get_version():
version_file = "../version_gen.h"
f = open(version_file, 'rt')
m = re.match(VERSION_PATTERN, f.readline())
return m.group(1)
setupdir = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir(setupdir)
libfdt_module = Extension(
'_libfdt',
sources=['libfdt.i'],
include_dirs=['../libfdt'],
libraries=['fdt'],
library_dirs=['../libfdt'],
swig_opts=['-I../libfdt'],
)
setup(
name='libfdt',
version=get_version(),
author='Simon Glass <sjg@chromium.org>',
description='Python binding for libfdt',
ext_modules=[libfdt_module],
py_modules=['libfdt'],
)

View File

@ -1,4 +1,5 @@
#! /bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
REMOTE_GIT=/pub/scm/utils/dtc/dtc.git
REMOTE_PATH=/pub/software/utils/dtc

View File

@ -1,4 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Print additional version information for non-release trees.
usage() {

View File

@ -1,22 +1,8 @@
/* $NetBSD: srcpos.c,v 1.1.1.2 2017/06/08 15:59:21 skrll Exp $ */
/* $NetBSD: srcpos.c,v 1.1.1.3 2019/12/22 12:34:03 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#define _GNU_SOURCE
@ -35,6 +21,9 @@ struct search_path {
/* This is the list of directories that we search for source files */
static struct search_path *search_path_head, **search_path_tail;
/* Detect infinite include recursion. */
#define MAX_SRCFILE_DEPTH (100)
static int srcfile_depth; /* = 0 */
static char *get_dirname(const char *path)
{
@ -53,11 +42,51 @@ static char *get_dirname(const char *path)
FILE *depfile; /* = NULL */
struct srcfile_state *current_srcfile; /* = NULL */
static char *initial_path; /* = NULL */
static int initial_pathlen; /* = 0 */
static bool initial_cpp = true;
/* Detect infinite include recursion. */
#define MAX_SRCFILE_DEPTH (100)
static int srcfile_depth; /* = 0 */
static void set_initial_path(char *fname)
{
int i, len = strlen(fname);
xasprintf(&initial_path, "%s", fname);
initial_pathlen = 0;
for (i = 0; i != len; i++)
if (initial_path[i] == '/')
initial_pathlen++;
}
static char *shorten_to_initial_path(char *fname)
{
char *p1, *p2, *prevslash1 = NULL;
int slashes = 0;
for (p1 = fname, p2 = initial_path; *p1 && *p2; p1++, p2++) {
if (*p1 != *p2)
break;
if (*p1 == '/') {
prevslash1 = p1;
slashes++;
}
}
p1 = prevslash1 + 1;
if (prevslash1) {
int diff = initial_pathlen - slashes, i, j;
int restlen = strlen(fname) - (p1 - fname);
char *res;
res = xmalloc((3 * diff) + restlen + 1);
for (i = 0, j = 0; i != diff; i++) {
res[j++] = '.';
res[j++] = '.';
res[j++] = '/';
}
strcpy(res + j, p1);
return res;
}
return NULL;
}
/**
* Try to open a file in a given directory.
@ -159,6 +188,9 @@ void srcfile_push(const char *fname)
srcfile->colno = 1;
current_srcfile = srcfile;
if (srcfile_depth == 1)
set_initial_path(srcfile->name);
}
bool srcfile_pop(void)
@ -199,20 +231,6 @@ void srcfile_add_search_path(const char *dirname)
search_path_tail = &node->next;
}
/*
* The empty source position.
*/
struct srcpos srcpos_empty = {
.first_line = 0,
.first_column = 0,
.last_line = 0,
.last_column = 0,
.file = NULL,
};
#define TAB_SIZE 8
void srcpos_update(struct srcpos *pos, const char *text, int len)
{
int i;
@ -226,9 +244,6 @@ void srcpos_update(struct srcpos *pos, const char *text, int len)
if (text[i] == '\n') {
current_srcfile->lineno++;
current_srcfile->colno = 1;
} else if (text[i] == '\t') {
current_srcfile->colno =
ALIGN(current_srcfile->colno, TAB_SIZE);
} else {
current_srcfile->colno++;
}
@ -241,13 +256,35 @@ struct srcpos *
srcpos_copy(struct srcpos *pos)
{
struct srcpos *pos_new;
struct srcfile_state *srcfile_state;
if (!pos)
return NULL;
pos_new = xmalloc(sizeof(struct srcpos));
assert(pos->next == NULL);
memcpy(pos_new, pos, sizeof(struct srcpos));
/* allocate without free */
srcfile_state = xmalloc(sizeof(struct srcfile_state));
memcpy(srcfile_state, pos->file, sizeof(struct srcfile_state));
pos_new->file = srcfile_state;
return pos_new;
}
struct srcpos *srcpos_extend(struct srcpos *pos, struct srcpos *newtail)
{
struct srcpos *p;
if (!pos)
return newtail;
for (p = pos; p->next != NULL; p = p->next);
p->next = newtail;
return pos;
}
char *
srcpos_string(struct srcpos *pos)
{
@ -273,6 +310,68 @@ srcpos_string(struct srcpos *pos)
return pos_str;
}
static char *
srcpos_string_comment(struct srcpos *pos, bool first_line, int level)
{
char *pos_str, *fname, *first, *rest;
bool fresh_fname = false;
if (!pos) {
if (level > 1) {
xasprintf(&pos_str, "<no-file>:<no-line>");
return pos_str;
} else {
return NULL;
}
}
if (!pos->file)
fname = "<no-file>";
else if (!pos->file->name)
fname = "<no-filename>";
else if (level > 1)
fname = pos->file->name;
else {
fname = shorten_to_initial_path(pos->file->name);
if (fname)
fresh_fname = true;
else
fname = pos->file->name;
}
if (level > 1)
xasprintf(&first, "%s:%d:%d-%d:%d", fname,
pos->first_line, pos->first_column,
pos->last_line, pos->last_column);
else
xasprintf(&first, "%s:%d", fname,
first_line ? pos->first_line : pos->last_line);
if (fresh_fname)
free(fname);
if (pos->next != NULL) {
rest = srcpos_string_comment(pos->next, first_line, level);
xasprintf(&pos_str, "%s, %s", first, rest);
free(first);
free(rest);
} else {
pos_str = first;
}
return pos_str;
}
char *srcpos_string_first(struct srcpos *pos, int level)
{
return srcpos_string_comment(pos, true, level);
}
char *srcpos_string_last(struct srcpos *pos, int level)
{
return srcpos_string_comment(pos, false, level);
}
void srcpos_verror(struct srcpos *pos, const char *prefix,
const char *fmt, va_list va)
{
@ -301,4 +400,9 @@ void srcpos_set_line(char *f, int l)
{
current_srcfile->name = f;
current_srcfile->lineno = l;
if (initial_cpp) {
initial_cpp = false;
set_initial_path(f);
}
}

View File

@ -1,26 +1,12 @@
/* $NetBSD: srcpos.h,v 1.1.1.2 2017/06/08 15:59:21 skrll Exp $ */
/* $NetBSD: srcpos.h,v 1.1.1.3 2019/12/22 12:34:04 skrll Exp $ */
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#ifndef _SRCPOS_H_
#define _SRCPOS_H_
#ifndef SRCPOS_H
#define SRCPOS_H
#include <stdio.h>
#include <stdbool.h>
@ -76,6 +62,7 @@ struct srcpos {
int last_line;
int last_column;
struct srcfile_state *file;
struct srcpos *next;
};
#define YYLTYPE struct srcpos
@ -95,19 +82,18 @@ struct srcpos {
YYRHSLOC(Rhs, 0).last_column; \
(Current).file = YYRHSLOC (Rhs, 0).file; \
} \
(Current).next = NULL; \
} while (0)
/*
* Fictional source position used for IR nodes that are
* created without otherwise knowing a true source position.
* For example,constant definitions from the command line.
*/
extern struct srcpos srcpos_empty;
extern void srcpos_update(struct srcpos *pos, const char *text, int len);
extern struct srcpos *srcpos_copy(struct srcpos *pos);
extern struct srcpos *srcpos_extend(struct srcpos *new_srcpos,
struct srcpos *old_srcpos);
extern char *srcpos_string(struct srcpos *pos);
extern char *srcpos_string_first(struct srcpos *pos, int level);
extern char *srcpos_string_last(struct srcpos *pos, int level);
extern void PRINTF(3, 0) srcpos_verror(struct srcpos *pos, const char *prefix,
const char *fmt, va_list va);
@ -116,4 +102,4 @@ extern void PRINTF(3, 4) srcpos_error(struct srcpos *pos, const char *prefix,
extern void srcpos_set_line(char *f, int l);
#endif /* _SRCPOS_H_ */
#endif /* SRCPOS_H */

View File

@ -1,13 +1,19 @@
*.dtb
*.dts.test.s
*.test.dts
*.test.dt.yaml
tmp.*
/fs/
/add_subnode_with_nops
/addr_size_cells
/addr_size_cells2
/appendprop[12]
/appendprop_addrrange
/asm_tree_dump
/boot-cpuid
/char_literal
/check_full
/check_header
/check_path
/del_node
/del_property
@ -23,8 +29,10 @@ tmp.*
/get_path
/get_phandle
/getprop
/get_prop_offset
/incbin
/integer-expressions
/fs_tree1
/mangle-layout
/move_and_save
/node_check_compatible
@ -48,6 +56,7 @@ tmp.*
/references
/root_node
/rw_tree1
/rw_oom
/set_name
/setprop
/setprop_inplace
@ -58,6 +67,9 @@ tmp.*
/subnode_offset
/supernode_atdepth_offset
/sw_tree1
/sw_states
/truncated_property
/truncated_string
/truncated_memrsv
/utilfdt_test
/value-labels

View File

@ -1,6 +1,6 @@
LIB_TESTS_L = get_mem_rsv \
root_node find_property subnode_offset path_offset \
get_name getprop get_phandle \
get_name getprop get_prop_offset get_phandle \
get_path supernode_atdepth_offset parent_offset \
node_offset_by_prop_value node_offset_by_phandle \
node_check_compatible node_offset_by_compatible \
@ -9,11 +9,13 @@ LIB_TESTS_L = get_mem_rsv \
sized_cells \
notfound \
addr_size_cells \
addr_size_cells2 \
appendprop_addrrange \
stringlist \
setprop_inplace nop_property nop_node \
sw_tree1 \
sw_tree1 sw_states \
move_and_save mangle-layout nopulate \
open_pack rw_tree1 set_name setprop del_property del_node \
open_pack rw_tree1 rw_oom set_name setprop del_property del_node \
appendprop1 appendprop2 propname_escapes \
string_escapes references path-references phandle_format \
boot-cpuid incbin \
@ -26,10 +28,11 @@ LIB_TESTS_L = get_mem_rsv \
property_iterate \
subnode_iterate \
overlay overlay_bad_fixup \
check_path
check_path check_header check_full \
fs_tree1
LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
LIBTREE_TESTS_L = truncated_property
LIBTREE_TESTS_L = truncated_property truncated_string truncated_memrsv
LIBTREE_TESTS = $(LIBTREE_TESTS_L:%=$(TESTS_PREFIX)%)
DL_LIB_TESTS_L = asm_tree_dump value-labels
@ -45,21 +48,27 @@ TESTS_TARGETS = $(TESTS) $(TESTS_TREES)
TESTS_DEPFILES = $(TESTS:%=%.d) \
$(addprefix $(TESTS_PREFIX),testutils.d trees.d dumptrees.d)
TESTS_CLEANFILES_L = *.output vglog.* vgcore.* *.dtb *.test.dts *.dtsv1 tmp.*
TESTS_CLEANFILES_L += dumptrees
TESTS_CLEANFILES_L = $(STD_CLEANFILES) \
*.dtb *.test.dts *.test.dt.yaml *.dtsv1 tmp.* \
dumptrees
TESTS_CLEANFILES = $(TESTS) $(TESTS_CLEANFILES_L:%=$(TESTS_PREFIX)%)
TESTS_CLEANDIRS_L = fs
TESTS_CLEANDIRS = $(TESTS_CLEANDIRS_L:%=$(TESTS_PREFIX)%)
.PHONY: tests
tests: $(TESTS) $(TESTS_TREES)
$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive)
$(LIB_TESTS): %: $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_lib)
$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_archive)
# Not necessary on all platforms; allow -ldl to be excluded instead of forcing
# other platforms to patch it out.
LIBDL = -ldl
$(DL_LIB_TESTS): %: %.o $(TESTS_PREFIX)testutils.o util.o $(LIBFDT_lib)
@$(VECHO) LD [libdl] $@
$(LINK.c) -o $@ $^ -ldl
$(LINK.c) -o $@ $^ $(LIBDL)
$(LIBTREE_TESTS): %: $(TESTS_PREFIX)testutils.o $(TESTS_PREFIX)trees.o \
util.o $(LIBFDT_archive)
util.o $(LIBFDT_lib)
$(TESTS_PREFIX)dumptrees: $(TESTS_PREFIX)trees.o
@ -69,19 +78,23 @@ $(TESTS_TREES): $(TESTS_PREFIX)dumptrees
tests_clean:
@$(VECHO) CLEAN "(tests)"
rm -f $(STD_CLEANFILES:%=$(TESTS_PREFIX)%)
rm -f $(TESTS_CLEANFILES)
rm -rf $(TESTS_CLEANDIRS)
check: tests ${TESTS_BIN}
cd $(TESTS_PREFIX); ./run_tests.sh
check: tests ${TESTS_BIN} $(TESTS_PYLIBFDT)
cd $(TESTS_PREFIX); PYTHON=$(PYTHON) ./run_tests.sh
checkm: tests ${TESTS_BIN}
cd $(TESTS_PREFIX); ./run_tests.sh -m 2>&1 | tee vglog.$$$$
ifeq ($(NO_VALGRIND),1)
checkm:
@echo "make checkm requires valgrind, but NO_VALGRIND=1"
else
checkm: tests ${TESTS_BIN} $(TESTS_PYLIBFDT)
cd $(TESTS_PREFIX); PYTHON=$(PYTHON) ./run_tests.sh -m
endif
checkv: tests ${TESTS_BIN}
cd $(TESTS_PREFIX); ./run_tests.sh -v
checkv: tests ${TESTS_BIN} $(TESTS_PYLIBFDT)
cd $(TESTS_PREFIX); PYTHON=$(PYTHON) ./run_tests.sh -v
ifneq ($(DEPTARGETS),)
-include $(TESTS_DEPFILES)
endif

View File

@ -1,23 +1,10 @@
/* $NetBSD: add_subnode_with_nops.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: add_subnode_with_nops.c,v 1.1.1.3 2019/12/22 12:34:05 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_nop_node()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: addr_size_cells.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: addr_size_cells.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for #address-cells and #size-cells handling
* Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>
@ -60,7 +47,12 @@ int main(int argc, char *argv[])
fdt = load_blob(argv[1]);
check_node(fdt, "/", 2, 2);
check_node(fdt, "/identity-bus@0", 2, 2);
check_node(fdt, "/identity-bus@0", 2, 1);
check_node(fdt, "/simple-bus@1000000", 2, 1);
check_node(fdt, "/discrete-bus@2000000", 1, 0);
check_node(fdt, "/c0", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
check_node(fdt, "/c1", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
check_node(fdt, "/c2", -FDT_ERR_BADNCELLS, -FDT_ERR_BADNCELLS);
check_node(fdt, "/c3", -FDT_ERR_BADNCELLS, 0);
PASS();
}

View File

@ -0,0 +1,51 @@
/* $NetBSD: addr_size_cells2.c,v 1.1.1.1 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for #address-cells and #size-cells handling
* Copyright (C) 2014 David Gibson, <david@gibson.dropbear.id.au>
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <libfdt.h>
#include "tests.h"
#include "testdata.h"
static void check_node(const void *fdt, const char *path, int ac, int sc)
{
int offset;
int xac, xsc;
offset = fdt_path_offset(fdt, path);
if (offset < 0)
FAIL("Couldn't find path %s", path);
xac = fdt_address_cells(fdt, offset);
xsc = fdt_size_cells(fdt, offset);
if (xac != ac)
FAIL("Address cells for %s is %d instead of %d\n",
path, xac, ac);
if (xsc != sc)
FAIL("Size cells for %s is %d instead of %d\n",
path, xsc, sc);
}
int main(int argc, char *argv[])
{
void *fdt;
if (argc != 2)
CONFIG("Usage: %s <dtb file>\n", argv[0]);
test_init(argc, argv);
fdt = load_blob(argv[1]);
check_node(fdt, "/", 2, 1);
PASS();
}

View File

@ -12,4 +12,29 @@
#address-cells = <2>;
#size-cells = <1>;
};
discrete-bus@2000000 {
#address-cells = <1>;
#size-cells = <0>;
};
c0@0 {
#address-cells = <1 1>;
#size-cells = <1 1>;
};
c1@0 {
#address-cells = <0x80000000>;
#size-cells = <0x80000000>;
};
c2@0 {
#address-cells = <5>;
#size-cells = <5>;
};
c3@0 {
#address-cells = <0>;
#size-cells = <0>;
};
};

View File

@ -1,23 +1,10 @@
/* $NetBSD: appendprop1.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: appendprop1.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_appendprop()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: appendprop2.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: appendprop2.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_appendprop()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -0,0 +1,97 @@
/* $NetBSD: appendprop_addrrange.c,v 1.1.1.1 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_appendprop_addrrange()
* Copyright (C) 2018 AKASHI Takahiro, Linaro Limited
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <libfdt.h>
#include "tests.h"
#include "testdata.h"
int main(int argc, char *argv[])
{
void *fdt, *buf;
int offset, xac, xsc, num, i, err;
uint64_t addr, size;
if (argc != 5)
CONFIG("Usage: %s <dtb file> <address-cells> <size-cells> <num>\n",
argv[0]);
test_init(argc, argv);
fdt = load_blob(argv[1]);
xac = strtol(argv[2], NULL, 10);
xsc = strtol(argv[3], NULL, 10);
num = strtol(argv[4], NULL, 10);
buf = xmalloc(0x1000);
if (!buf)
FAIL("Couldn't allocate temporary buffer");
err = fdt_open_into(fdt, buf, 0x1000);
if (err)
FAIL("fdt_open_into(): %s", fdt_strerror(err));
fdt = buf;
/* Set up */
err = fdt_setprop_cell(fdt, 0, "#address-cells", xac);
if (err)
FAIL("fdt_setprop_cell(\"#address-cells\"): %s",
fdt_strerror(err));
err = fdt_setprop_cell(fdt, 0, "#size-cells", xsc);
if (err)
FAIL("fdt_setprop_cell(\"#size-cells\"): %s",
fdt_strerror(err));
offset = fdt_path_offset(fdt, "/node@1");
if (offset < 0)
FAIL("Couldn't find path %s", "/node@1");
addr = TEST_MEMREGION_ADDR;
if (xac > 1)
addr += TEST_MEMREGION_ADDR_HI;
size = TEST_MEMREGION_SIZE;
if (xsc > 1)
size += TEST_MEMREGION_SIZE_HI;
/*
* Do test
*/
/* 1. repeat append's */
for (i = 0; i < num; i++) {
err = fdt_appendprop_addrrange(fdt, 0, offset,
"prop-memregion", addr, size);
if (err)
FAIL("Failed to append[%d] \"prop-memregion\": %s",
i, fdt_strerror(err));
check_getprop_addrrange(fdt, 0, offset, "prop-memregion",
i + 1);
addr += size;
size += TEST_MEMREGION_SIZE_INC;
}
/* 2. default property name */
addr = TEST_MEMREGION_ADDR;
if (xac > 1)
addr += TEST_MEMREGION_ADDR_HI;
size = TEST_MEMREGION_SIZE;
if (xsc > 1)
size += TEST_MEMREGION_SIZE_HI;
err = fdt_appendprop_addrrange(fdt, 0, offset, "reg", addr, size);
if (err)
FAIL("Failed to set \"reg\": %s", fdt_strerror(err));
check_getprop_addrrange(fdt, 0, offset, "reg", 1);
PASS();
}

View File

@ -1,23 +1,10 @@
/* $NetBSD: asm_tree_dump.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: asm_tree_dump.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Tests if an asm tree built into a shared object matches a given dtb
* Copyright (C) 2008 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -0,0 +1,10 @@
/dts-v1/;
/ {
node2 {
chosen {
bootargs = <0xdeadbeef>;
stdout-path = <1>;
};
};
};

View File

@ -0,0 +1,13 @@
/dts-v1/;
/ {
gpio: gpio-controller {
#gpio-cells = <3>;
};
node {
nr-gpios = <1>;
foo-gpios = <&gpio>;
bar-gpio = <&gpio 1 2 3>;
};
};

View File

@ -0,0 +1,24 @@
/dts-v1/;
/ {
ports {
#address-cells = <1>;
#size-cells = <0>;
bad_endpoint: port-a@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <0>;
endpoint@d0 {
reg = <0>;
remote-endpoint = <0xdeadbeef>;
};
};
port@1 {
reg = <0>;
};
};
};

View File

@ -0,0 +1,12 @@
/dts-v1/;
/ {
interrupt-parent = <&intc>;
intc: interrupt-controller {
#interrupt-cells = <3>;
};
node {
interrupts = <1>;
};
};

View File

@ -0,0 +1,11 @@
/dts-v1/;
/ {
intc: interrupt-controller {
#interrupt-cells = <3>;
};
node {
interrupts-extended = <&intc>;
};
};

View File

@ -4,4 +4,11 @@
device_type = <0xdeadbeef>;
model = <0xdeadbeef>;
status = <0xdeadbeef>;
label = <0xdeadbeef>;
foobar-names = "foo", <1>;
node {
compatible = "good", <0xdeadbeef>;
};
};

View File

@ -1,21 +1,8 @@
/* $NetBSD: boot-cpuid.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: boot-cpuid.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* Copyright (C) 2008 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,24 +1,11 @@
/* $NetBSD: char_literal.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: char_literal.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for character literals in dtc
* Copyright (C) 2006 David Gibson, IBM Corporation.
* Copyright (C) 2011 The Chromium Authors. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -0,0 +1,52 @@
/* $NetBSD: check_full.c,v 1.1.1.1 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Tests if two given dtbs are structurally equal (including order)
* Copyright (C) 2007 David Gibson, IBM Corporation.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <libfdt.h>
#include "tests.h"
#include "testdata.h"
static int expect_bad; /* = 0 */
int main(int argc, char *argv[])
{
const char *filename;
char *fdt;
size_t len;
int err;
test_init(argc, argv);
if ((argc != 2)
&& ((argc != 3) || !streq(argv[1], "-n")))
CONFIG("Usage: %s [-n] <dtb file>", argv[0]);
if (argc == 3)
expect_bad = 1;
filename = argv[argc-1];
err = utilfdt_read_err(filename, &fdt, &len);
if (err)
CONFIG("Couldn't open blob from \"%s\": %s",
filename, strerror(err));
vg_prepare_blob(fdt, len);
err = fdt_check_full(fdt, len);
if (expect_bad && (err == 0))
FAIL("fdt_check_full() succeeded unexpectedly");
else if (!expect_bad && (err != 0))
FAIL("fdt_check_full() failed: %s", fdt_strerror(err));
PASS();
}

View File

@ -0,0 +1,117 @@
/* $NetBSD: check_header.c,v 1.1.1.1 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_check_header
* Copyright (C) 2018 David Gibson
*/
#include <stdio.h>
#include <libfdt.h>
#include "tests.h"
static void *dtdup(void *dt)
{
size_t bufsize = fdt_totalsize(dt);
void *buf = xmalloc(bufsize);
fdt_move(dt, buf, bufsize);
return buf;
}
#define CHECK_MANGLE(exerr, code) \
do { \
void *fdt = dtdup(template); \
{ code } \
err = fdt_check_header(fdt); \
verbose_printf("\"%s\" => %s\n", #code, fdt_strerror(err)); \
if (err != (exerr)) \
FAIL("fdt_check_header() didn't catch mangle %s", \
#code); \
free(fdt); \
} while (0)
int main(int argc, char *argv[])
{
void *template;
int err;
test_init(argc, argv);
template = load_blob(argv[1]);
/* Check that the base dt is valid before mangling it */
err = fdt_check_header(template);
if (err != 0)
FAIL("Base tree fails: %s", fdt_strerror(err));
/* Check a no-op mangle doesn't break things */
CHECK_MANGLE(0, ; );
/* Mess up the magic number */
CHECK_MANGLE(-FDT_ERR_BADMAGIC,
fdt_set_magic(fdt, fdt_magic(fdt) ^ 0x1);
);
CHECK_MANGLE(-FDT_ERR_BADMAGIC,
fdt_set_magic(fdt, fdt_magic(fdt) ^ 0x80000000);
);
/* Mess up the version */
CHECK_MANGLE(-FDT_ERR_BADVERSION,
fdt_set_version(fdt, FDT_FIRST_SUPPORTED_VERSION - 1);
fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION - 1);
);
CHECK_MANGLE(-FDT_ERR_BADVERSION,
fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION + 1);
fdt_set_last_comp_version(fdt, FDT_LAST_SUPPORTED_VERSION + 1);
);
CHECK_MANGLE(-FDT_ERR_BADVERSION,
fdt_set_version(fdt, FDT_FIRST_SUPPORTED_VERSION);
fdt_set_last_comp_version(fdt, FDT_LAST_SUPPORTED_VERSION);
);
/* Out of bounds sizes */
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, FDT_V1_SIZE - 1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, (uint32_t)INT_MAX + 1);
);
/* Truncate within various blocks */
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, fdt_off_dt_struct(fdt) - 1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, fdt_off_dt_strings(fdt) - 1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, fdt_off_mem_rsvmap(fdt) - 1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, fdt_off_dt_struct(fdt) + 1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, fdt_off_dt_strings(fdt) + 1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_totalsize(fdt, fdt_off_mem_rsvmap(fdt) + 1);
);
/* Negative block sizes */
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_size_dt_struct(fdt, (uint32_t)-1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_size_dt_strings(fdt, (uint32_t)-1);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_size_dt_struct(fdt, (uint32_t)INT_MIN);
);
CHECK_MANGLE(-FDT_ERR_TRUNCATED,
fdt_set_size_dt_strings(fdt, (uint32_t)INT_MIN);
);
PASS();
}

View File

@ -1,23 +1,10 @@
/* $NetBSD: check_path.c,v 1.1.1.1 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: check_path.c,v 1.1.1.2 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for node existence
* Copyright (C) 2016 Konsulko Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: del_node.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: del_node.c,v 1.1.1.3 2019/12/22 12:34:05 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_nop_node()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: del_property.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: del_property.c,v 1.1.1.3 2019/12/22 12:34:05 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_delprop()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: dtb_reverse.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: dtb_reverse.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Tests if two given dtbs are structurally equal (including order)
* Copyright (C) 2010 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: dtbs_equal_ordered.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: dtbs_equal_ordered.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Tests if two given dtbs are structurally equal (including order)
* Copyright (C) 2007 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: dtbs_equal_unordered.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: dtbs_equal_unordered.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Tests if two given dtbs are structurally equal (including order)
* Copyright (C) 2007 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@ -32,6 +19,7 @@
#include "testdata.h"
static int notequal; /* = 0 */
static int ignore_memrsv; /* = 0 */
#define MISMATCH(fmt, ...) \
do { \
@ -197,22 +185,41 @@ static void compare_node(const void *fdt1, int offset1,
compare_subnodes(fdt2, offset2, fdt1, offset1, 0);
}
static void badargs(char **argv)
{
CONFIG("Usage: %s [-n] [-m] <dtb file> <dtb file>", argv[0]);
}
int main(int argc, char *argv[])
{
void *fdt1, *fdt2;
uint32_t cpuid1, cpuid2;
char **args;
int argsleft;
test_init(argc, argv);
if ((argc != 3)
&& ((argc != 4) || !streq(argv[1], "-n")))
CONFIG("Usage: %s [-n] <dtb file> <dtb file>", argv[0]);
if (argc == 4)
notequal = 1;
fdt1 = load_blob(argv[argc-2]);
fdt2 = load_blob(argv[argc-1]);
args = &argv[1];
argsleft = argc - 1;
compare_mem_rsv(fdt1, fdt2);
while (argsleft > 2) {
if (streq(args[0], "-n"))
notequal = 1;
else if (streq(args[0], "-m"))
ignore_memrsv = 1;
else
badargs(argv);
args++;
argsleft--;
}
if (argsleft != 2)
badargs(argv);
fdt1 = load_blob(args[0]);
fdt2 = load_blob(args[1]);
if (!ignore_memrsv)
compare_mem_rsv(fdt1, fdt2);
compare_node(fdt1, 0, fdt2, 0);
cpuid1 = fdt_boot_cpuid_phys(fdt1);

View File

@ -1,6 +1,6 @@
#! /bin/sh
. ./tests.sh
. ./testutils.sh
for x; do
shift
@ -30,13 +30,13 @@ ret="$?"
FAIL_IF_SIGNAL $ret
for c in $YESCHECKS; do
if ! grep -E "^(ERROR)|(Warning) \($c\):" $LOG > /dev/null; then
if ! grep -E "(ERROR|Warning) \($c\):" $LOG > /dev/null; then
FAIL "Failed to trigger check \"$c\""
fi
done
for c in $NOCHECKS; do
if grep -E "^(ERROR)|(Warning) \($c\):" $LOG > /dev/null; then
if grep -E "(ERROR|Warning) \($c\):" $LOG > /dev/null; then
FAIL "Incorrectly triggered check \"$c\""
fi
done

View File

@ -1,6 +1,6 @@
#! /bin/sh
. ./tests.sh
. ./testutils.sh
if [ "$1" = "-n" ]; then
NEG="$1"

View File

@ -1,6 +1,6 @@
#! /bin/sh
. ./tests.sh
. ./testutils.sh
verbose_run $VALGRIND "$DTC" -o/dev/null "$@"
ret="$?"

View File

@ -1,25 +1,10 @@
/* $NetBSD: dumptrees.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: dumptrees.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* dumptrees - utility for libfdt testing
*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2006.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include <stdio.h>
#include <stdlib.h>
@ -35,10 +20,12 @@ static struct {
void *blob;
const char *filename;
} trees[] = {
#define TREE(name) { &_##name, #name ".dtb" }
#define TREE(name) { &name, #name ".dtb" }
TREE(test_tree1),
TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char),
TREE(ovf_size_strings),
TREE(truncated_property), TREE(truncated_string),
TREE(truncated_memrsv),
};
#define NUM_TREES (sizeof(trees) / sizeof(trees[0]))

View File

@ -1,23 +1,10 @@
/* $NetBSD: extra-terminating-null.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: extra-terminating-null.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for properties with more than one terminating null
* Copyright (C) 2009 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -4,7 +4,7 @@
# $1 - source file to compile and compare with fdtdump output of the
# compiled file.
. ./tests.sh
. ./testutils.sh
dts="$1"
dtb="${dts}.dtb"

View File

@ -1,6 +1,6 @@
#! /bin/sh
. ./tests.sh
. ./testutils.sh
LOG=tmp.log.$$
EXPECT=tmp.expect.$$

View File

@ -0,0 +1,40 @@
#! /bin/sh
# Run script for fdtoverlay tests
# We run fdtoverlay to generate a target device tree, then fdtget to check it
# Usage
# fdtoverlay-runtest.sh name expected_output dtb_file node property flags value
. ./testutils.sh
LOG=tmp.log.$$
EXPECT=tmp.expect.$$
rm -f $LOG $EXPECT
trap "rm -f $LOG $EXPECT" 0
expect="$1"
echo $expect >$EXPECT
node="$2"
property="$3"
flags="$4"
basedtb="$5"
targetdtb="$6"
shift 6
overlays="$@"
# First run fdtoverlay
verbose_run_check $VALGRIND "$FDTOVERLAY" -i "$basedtb" -o "$targetdtb" $overlays
# Now fdtget to read the value
verbose_run_log_check "$LOG" $VALGRIND "$DTGET" "$targetdtb" "$node" "$property" $flags
if cmp $EXPECT $LOG >/dev/null; then
PASS
else
if [ -z "$QUIET_TEST" ]; then
echo "EXPECTED :-:"
cat $EXPECT
fi
FAIL "Results differ from expected"
fi

View File

@ -1,12 +1,12 @@
#! /bin/sh
# Run script for fdtput tests
# We run fdtput to update the device tree, thn fdtget to check it
# We run fdtput to update the device tree, then fdtget to check it
# Usage
# fdtput-runtest.sh name expected_output dtb_file node property flags value
. ./tests.sh
. ./testutils.sh
LOG=tmp.log.$$
EXPECT=tmp.expect.$$

View File

@ -1,23 +1,10 @@
/* $NetBSD: find_property.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: find_property.c,v 1.1.1.3 2019/12/22 12:34:05 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_property_offset()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

157
external/gpl2/dtc/dist/tests/fs_tree1.c vendored Normal file
View File

@ -0,0 +1,157 @@
/* $NetBSD: fs_tree1.c,v 1.1.1.1 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase/tool constructing an fs tree for further test
* Copyright (C) 2018 David Gibson, Red Hat Inc.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdint.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <libfdt.h>
#include "tests.h"
#include "testdata.h"
static void start_dir(const char *name)
{
int rc;
rc = mkdir(name, 0777);
if (rc != 0)
FAIL("mkdir(\"%s\"): %s", name, strerror(errno));
rc = chdir(name);
if (rc != 0)
FAIL("chdir(\"%s\"): %s", name, strerror(errno));
}
static void end_dir(void)
{
int rc;
rc = chdir("..");
if (rc != 0)
FAIL("chdir(..): %s", strerror(errno));
}
static void mkfile(const char *name, void *data, size_t len)
{
int fd;
int rc;
fd = open(name, O_WRONLY|O_CREAT, 0666);
if (fd < 0)
FAIL("open(\"%s\"): %s", name, strerror(errno));
rc = write(fd, data, len);
if (rc < 0)
FAIL("write(\"%s\"): %s", name, strerror(errno));
if (rc != len)
FAIL("write(\"%s\"): short write", name);
rc = close(fd);
if (rc != 0)
FAIL("close(\"%s\"): %s", name, strerror(errno));
}
#define mkfile_str(name, s) \
do { \
char str[] = s; \
mkfile((name), str, sizeof(str)); \
} while (0)
static void mkfile_u32(const char *name, uint32_t val)
{
val = cpu_to_fdt32(val);
mkfile(name, &val, sizeof(val));
}
static void mkfile_u64(const char *name, uint64_t val)
{
val = cpu_to_fdt64(val);
mkfile(name, &val, sizeof(val));
}
int main(int argc, char *argv[])
{
const char *base;
test_init(argc, argv);
if (argc != 2)
CONFIG("Usage: %s <path>", argv[0]);
base = argv[1];
start_dir(base);
mkfile_str("compatible", "test_tree1");
mkfile_u32("prop-int", TEST_VALUE_1);
mkfile_u64("prop-int64", 0xdeadbeef01abcdefULL);
mkfile_str("prop-str", "hello world");
mkfile_u32("#address-cells", 1);
mkfile_u32("#size-cells", 0);
{
start_dir("subnode@1");
mkfile_str("compatible", "subnode1");
mkfile_u32("reg", 1);
mkfile_u32("prop-int", TEST_VALUE_1);
{
start_dir("subsubnode");
mkfile_str("compatible", "subsubnode1\0subsubnode");
mkfile_str("placeholder", "this is a placeholder string\0string2");
mkfile_u32("prop-int", TEST_VALUE_1);
end_dir();
}
{
start_dir("ss1");
end_dir();
}
end_dir();
}
{
start_dir("subnode@2");
mkfile_u32("reg", 2);
mkfile_u32("linux,phandle", 0x2000);
mkfile_u32("prop-int", TEST_VALUE_2);
mkfile_u32("#address-cells", 1);
mkfile_u32("#size-cells", 0);
{
start_dir("subsubnode@0");
mkfile_u32("reg", 0);
mkfile_u32("phandle", 0x2001);
mkfile_str("compatible", "subsubnode2\0subsubnode");
mkfile_u32("prop-int", TEST_VALUE_2);
end_dir();
}
{
start_dir("ss2");
end_dir();
}
end_dir();
}
PASS();
}

View File

@ -1,23 +1,10 @@
/* $NetBSD: get_alias.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: get_alias.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_get_alias()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: get_mem_rsv.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: get_mem_rsv.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_get_mem_rsv() and fdt_num_mem_rsv()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: get_name.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: get_name.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_get_name()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: get_path.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: get_path.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_get_path()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>
@ -44,7 +31,8 @@ static void check_path_buf(void *fdt, const char *path, int pathlen, int buflen)
memset(buf, POISON, sizeof(buf)); /* poison the buffer */
len = fdt_get_path(fdt, offset, buf, buflen);
verbose_printf("get_path() %s -> %d -> %s\n", path, offset, buf);
verbose_printf("get_path() %s -> %d -> %s\n", path, offset,
len >= 0 ? buf : "<error>");
if (buflen <= pathlen) {
if (len != -FDT_ERR_NOSPACE)

View File

@ -1,24 +1,12 @@
/* $NetBSD: get_phandle.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: get_phandle.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_get_phandle()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -44,10 +32,32 @@ static void check_phandle(void *fdt, const char *path, uint32_t checkhandle)
path, phandle, checkhandle);
}
static void check_phandle_unique(const void *fdt, uint32_t checkhandle)
{
uint32_t phandle;
int offset = -1;
while (true) {
offset = fdt_next_node(fdt, offset, NULL);
if (offset < 0) {
if (offset == -FDT_ERR_NOTFOUND)
break;
FAIL("error looking for phandle %#x", checkhandle);
}
phandle = fdt_get_phandle(fdt, offset);
if (phandle == checkhandle)
FAIL("generated phandle already exists");
}
}
int main(int argc, char *argv[])
{
uint32_t max;
uint32_t max, phandle;
void *fdt;
int err;
test_init(argc, argv);
fdt = load_blob_arg(argc, argv);
@ -56,10 +66,24 @@ int main(int argc, char *argv[])
check_phandle(fdt, "/subnode@2", PHANDLE_1);
check_phandle(fdt, "/subnode@2/subsubnode@0", PHANDLE_2);
err = fdt_find_max_phandle(fdt, &max);
if (err < 0)
FAIL("fdt_find_max_phandle returned %d instead of 0\n", err);
if (max != PHANDLE_2)
FAIL("fdt_find_max_phandle found 0x%x instead of 0x%x", max,
PHANDLE_2);
max = fdt_get_max_phandle(fdt);
if (max != PHANDLE_2)
FAIL("fdt_get_max_phandle returned 0x%x instead of 0x%x\n",
max, PHANDLE_2);
err = fdt_generate_phandle(fdt, &phandle);
if (err < 0)
FAIL("failed to generate phandle: %d", err);
check_phandle_unique(fdt, phandle);
PASS();
}

View File

@ -0,0 +1,45 @@
/* $NetBSD: get_prop_offset.c,v 1.1.1.1 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_getprop_by_offset()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <libfdt.h>
#include "tests.h"
#include "testdata.h"
int main(int argc, char *argv[])
{
bool found_prop_int = false;
bool found_prop_str = false;
int poffset;
void *fdt;
test_init(argc, argv);
fdt = load_blob_arg(argc, argv);
fdt_for_each_property_offset(poffset, fdt, 0) {
if (check_get_prop_offset_cell(fdt, poffset, "prop-int",
TEST_VALUE_1))
found_prop_int = true;
if (check_get_prop_offset(fdt, poffset, "prop-str",
strlen(TEST_STRING_1) + 1,
TEST_STRING_1))
found_prop_str = true;
}
if (!found_prop_int)
FAIL("Property 'prop-int' not found");
if (!found_prop_str)
FAIL("Property 'prop-str' not found");
PASS();
}

View File

@ -1,23 +1,10 @@
/* $NetBSD: getprop.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: getprop.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_getprop()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: incbin.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $ */
/* $NetBSD: incbin.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for string escapes in dtc
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -5,6 +5,7 @@
subsubnode {
compatible = "subsubnode1", "subsubnode";
placeholder = "this is a placeholder string", "string2";
prop-int = <0xdeadbeef>;
};

View File

@ -1,23 +1,10 @@
/* $NetBSD: integer-expressions.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: integer-expressions.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* Testcase for dtc expression support
*
* Copyright (C) 2008 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@ -99,7 +86,7 @@ int main(int argc, char *argv[])
res = fdt_getprop(fdt, 0, "expressions", &reslen);
if (!res)
FAIL("Error retreiving expression results: %s\n",
FAIL("Error retrieving expression results: %s\n",
fdt_strerror(reslen));
if (reslen != (ARRAY_SIZE(expr_table) * sizeof(uint32_t)))

View File

@ -1,23 +1,10 @@
/* $NetBSD: mangle-layout.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: mangle-layout.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase/tool for rearranging blocks of a dtb
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@ -46,13 +33,9 @@ static void expand_buf(struct bufstate *buf, int newsize)
static void new_header(struct bufstate *buf, int version, const void *fdt)
{
int hdrsize;
int hdrsize = fdt_header_size_(version);
if (version == 16)
hdrsize = FDT_V16_SIZE;
else if (version == 17)
hdrsize = FDT_V17_SIZE;
else
if ((version != 16) && (version != 17))
CONFIG("Bad version %d", version);
expand_buf(buf, hdrsize);

View File

@ -1,23 +1,10 @@
/* $NetBSD: move_and_save.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: move_and_save.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Basic testcase for read-only access
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -41,4 +41,9 @@ m1: mq: /memreserve/ 0 0x1000;
n2 = &n2;
n3 = &n3;
};
node6 {
linux,phandle = <0xfffffffe>;
phandle = <0xfffffffe>;
};
};

View File

@ -39,6 +39,11 @@ m1: mq: /memreserve/ 0 0x1000;
n2 = &n2;
n3 = &n3;
};
node6 {
linux,phandle = <0xfffffffe>;
phandle = <0xfffffffe>;
};
};
/ {

View File

@ -1,23 +1,10 @@
/* $NetBSD: node_check_compatible.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: node_check_compatible.c,v 1.1.1.3 2019/12/22 12:34:05 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_node_check_compatible()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
@ -47,6 +34,23 @@ static void check_compatible(const void *fdt, const char *path,
FAIL("%s is not compatible with \"%s\"", path, compat);
}
static void check_not_compatible(const void *fdt, const char *path,
const char *compat)
{
int offset, err;
offset = fdt_path_offset(fdt, path);
if (offset < 0)
FAIL("fdt_path_offset(%s): %s", path, fdt_strerror(offset));
err = fdt_node_check_compatible(fdt, offset, compat);
if (err < 0)
FAIL("fdt_node_check_compatible(%s): %s", path,
fdt_strerror(err));
if (err == 0)
FAIL("%s is incorrectly compatible with \"%s\"", path, compat);
}
int main(int argc, char *argv[])
{
void *fdt;
@ -57,8 +61,10 @@ int main(int argc, char *argv[])
check_compatible(fdt, "/", "test_tree1");
check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode1");
check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode");
check_not_compatible(fdt, "/subnode@1/subsubnode", "subsubnode2");
check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode2");
check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode");
check_not_compatible(fdt, "/subnode@2/subsubnode", "subsubnode1");
PASS();
}

View File

@ -1,23 +1,10 @@
/* $NetBSD: node_offset_by_compatible.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: node_offset_by_compatible.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_node_offset_by_compatible()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: node_offset_by_phandle.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: node_offset_by_phandle.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_node_offset_by_phandle()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: node_offset_by_prop_value.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: node_offset_by_prop_value.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_path_offset()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: nop_node.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: nop_node.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_nop_node()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: nop_property.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: nop_property.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for fdt_nop_property()
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: nopulate.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: nopulate.c,v 1.1.1.3 2019/12/22 12:34:05 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase/tool for rearranging blocks of a dtb
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,23 +1,10 @@
/* $NetBSD: notfound.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: notfound.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for behaviour on searching for a non-existent node
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <stdio.h>

View File

@ -0,0 +1,26 @@
/dts-v1/;
/ {
test-phandle = <&node3>;
test-path = &node4;
/omit-if-no-ref/ node1: node1 {
bar = <0xdeadbeef>;
};
node2: node2 {
foo = <0x42>;
};
node3: node3 {
test = "test";
};
node4: node4 {
test;
};
};
/omit-if-no-ref/ &node2;
/omit-if-no-ref/ &node3;
/omit-if-no-ref/ &node4;

View File

@ -1,23 +1,10 @@
/* $NetBSD: open_pack.c,v 1.1.1.2 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: open_pack.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Basic testcase for read-only access
* Copyright (C) 2006 David Gibson, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>

View File

@ -1,24 +1,11 @@
/* $NetBSD: overlay.c,v 1.1.1.1 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: overlay.c,v 1.1.1.2 2019/12/22 12:34:07 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for DT overlays()
* Copyright (C) 2016 Free Electrons
* Copyright (C) 2016 NextThing Co.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>

View File

@ -1,24 +1,11 @@
/* $NetBSD: overlay_bad_fixup.c,v 1.1.1.1 2017/06/08 15:59:27 skrll Exp $ */
/* $NetBSD: overlay_bad_fixup.c,v 1.1.1.2 2019/12/22 12:34:06 skrll Exp $ */
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for DT overlays()
* Copyright (C) 2016 Free Electrons
* Copyright (C) 2016 NextThing Co.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>

View File

@ -14,6 +14,10 @@
subtest: sub-test-node {
sub-test-property;
subtest_with_long_path: sub-test-node-with-very-long-target-path {
long-test-path-property;
};
};
};
};

View File

@ -9,78 +9,44 @@
/dts-v1/;
/plugin/;
/ {
/* Test that we can change an int by another */
fragment@0 {
target = <&test>;
/* Test that we can change an int by another */
&test {
test-int-property = <43>;
};
__overlay__ {
test-int-property = <43>;
};
};
/* Test that we can replace a string by a longer one */
&test {
test-str-property = "foobar";
};
/* Test that we can replace a string by a longer one */
fragment@1 {
target = <&test>;
/* Test that we add a new property */
&test {
test-str-property-2 = "foobar2";
};
__overlay__ {
test-str-property = "foobar";
};
};
/* Test that we add a new property */
fragment@2 {
target = <&test>;
__overlay__ {
test-str-property-2 = "foobar2";
};
};
/* Test that we add a new node (by phandle) */
fragment@3 {
target = <&test>;
__overlay__ {
new-node {
new-property;
};
};
};
fragment@5 {
target = <&test>;
__overlay__ {
local: new-local-node {
new-property;
};
};
};
fragment@6 {
target = <&test>;
__overlay__ {
test-phandle = <&test>, <&local>;
};
};
fragment@7 {
target = <&test>;
__overlay__ {
test-several-phandle = <&local>, <&local>;
};
};
fragment@8 {
target = <&test>;
__overlay__ {
sub-test-node {
new-sub-test-property;
};
};
/* Test that we add a new node (by phandle) */
&test {
new-node {
new-property;
};
};
&test {
local: new-local-node {
new-property;
};
};
&test {
test-phandle = <&test>, <&local>;
};
&test {
test-several-phandle = <&local>, <&local>;
};
&test {
sub-test-node {
new-sub-test-property;
};
};

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2016 NextThing Co
* Copyright (c) 2016 Free Electrons
* Copyright (c) 2016 Konsulko Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
/dts-v1/;
/plugin/;
/* Test that we can change an int by another */
&{/test-node} {
test-int-property = <43>;
};
/* Test that we can replace a string by a longer one */
&{/test-node} {
test-str-property = "foobar";
};
/* Test that we add a new property */
&{/test-node} {
test-str-property-2 = "foobar2";
};
/* Test that we add a new node (by phandle) */
&{/test-node} {
new-node {
new-property;
};
};
&{/} {
local: new-local-node {
new-property;
};
};
&{/} {
test-several-phandle = <&local>, <&local>;
};
&{/test-node} {
sub-test-node {
new-sub-test-property;
};
};

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2016 NextThing Co
* Copyright (c) 2016 Free Electrons
* Copyright (c) 2016 Konsulko Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
/dts-v1/;
/plugin/;
&test {
parent: new-node {
parent-property;
};
};
&parent {
new-merged-property;
new-merged-node {
new-property;
};
};
&{/} {
new-root-node {
new-root-node-property;
};
};

View File

@ -0,0 +1,32 @@
/dts-v1/;
/plugin/;
&subtest_with_long_path {
lpath_0: test-0 {
prop = "lpath";
};
lpath_1: test-1 {
prop = "lpath";
};
lpath_2: test-2 {
prop = "lpath";
};
lpath_3: test-3 {
prop = "lpath";
};
lpath_4: test-4 {
prop = "lpath";
};
lpath_5: test-5 {
prop = "lpath";
};
lpath_6: test-6 {
prop = "lpath";
};
};

Some files were not shown because too many files have changed in this diff Show More