Commit Graph

16 Commits

Author SHA1 Message Date
Samuel Dionne-Riel ac549ac82d tools: fdtgrep: Use unsigned chars for arrays
Otherwise, values over 127 end up prefixed with ffffff.

Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
Cc: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2021-03-22 19:23:26 +13:00
Heinrich Schuchardt b606a6cfa6 tools: ftdgrep: use /* fallthrough */ as needed
GCC recognizes /* fallthrough */ if -Wimplicit-fallthrough=3 is enabled.
Let's use it consistently.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-05-15 14:47:35 -04:00
Masahiro Yamada 64045a6a17 libfdt: split fdt_region declarations out to <fdt_region.h>
fdt_region APIs are not part of libfdt. They are U-Boot extension
for the verified boot. Split the declarations related to fdt_region
out of <fdt_region.h>. This allows <linux/libfdt.h> to become a
simple wrapper file, like Linux does.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2020-04-26 14:24:08 -06:00
Patrick Delaunay dae188e683 tools: ftdgrep: correct the find regions loop in do_fdtgrep
Use realloc and update the loop executed in do_fdtgrep to find all
the regions: only test count > max_region after the second pass.

This patch solve an issue if the number of region found (count)
is greater then the default value (max_region = count = 100):
the second pass is never executed, because the loop stops after
the first pass (i = 0, count > 100, max_regions = 100)
with error -1 and the error message
"Internal error with fdtgrep_find_region".

I also update the error message.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
2020-01-24 12:33:08 -05:00
Simon Glass dd0ee9ea85 fdtgrep: Separate out checking of two allocations
The current code might succeed on the first allocation and fail on the
second. Separate the checks to avoid this problem.

Of course, free() will never fail and the chances that (when allocating
two small areas) one will succeed and one will fail are just as remote.
But this keeps coverity happy.

Reported-by: Coverity (CID: 131226)

Signed-off-by: Simon Glass <sjg@chromium.org>
2018-06-19 07:31:44 -04:00
Simon Glass e178db1d77 fdtgrep: Fix logic of free() in do_fdtgrep()
This loop never actually exits, but the way the code is written this is
not obvious. Add an explicit error check.

Reported-by: Coverity (CID: 131280)
Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Add explicit init of region to NULL per LLVM warning]
Signed-off-by: Tom Rini <trini@konsulko.com>
2018-06-19 07:31:43 -04:00
Tom Rini 83d290c56f SPDX: Convert all of our single license tags to Linux Kernel style
When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from.  So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry.  Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents.  There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>
2018-05-07 09:34:12 -04:00
Masahiro Yamada d2bf1152c0 tools: include necessary headers explicitly
Several host-tools use "bool" type without including <stdbool.h>.
This relies on the crappy header inclusion chain.

tools/Makefile has the following line:

  HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \

All host-tools are forced to include libfdt_env.h even if they are
totally unrelated to FDT.  Then, <stdbool.h> is indirectly included
as follows:

     include/libfdt_env.h
  -> include/linux/types.h
  -> <stdbool.h>

I am fixing this horrible crap.  In advance, I need to add necessary
include directives explicitly.  tools/fdtgrep.c needs more; <fctl.h>
for open() and <errno.h> for errno.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-01-28 12:27:31 -05:00
Masahiro Yamada ae9ace7089 libfdt: migrate fdt_rw.c to a wrapper of scripts/dtc/libfdt/fdt_rw.c
The only difference between scripts/dtc/libfdt/fdt_rw.c and
lib/libfdt/fdt_rw.c is fdt_remove_unused_strings().

It is only used by fdtgrep, so we do not need to compile it for U-Boot
image.  Move it to tools/libfdt/fdw_rw.c so that lib/libfdt/fdt_rw.c
can be a wrapper of scripts/dtc/libfdt/fdt_rw.c.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-01-28 12:27:30 -05:00
Jan Kundrát b95a5190ba Do not attempt to use the systemwide libfdt
U-Boot bundles a patched copy of libfdt, so it's wrong to attempt to
include it <like/this>. This breaks the build for me when I have dtc
fully installed in my host -- as happened earlier tonight with
Buildroot, for example.

There are several other occurrences throughout the code where '<libfdt'
matches. I'm not modifying these because I have no clue why the
<systemwide> include style is being used -- IMHO wrongly.

Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
2017-11-06 09:59:02 -05:00
Simon Glass 9672515319 fdtgrep: Deal with NULL data passed to check_type_include()
Since the parameter can be NULL we must be careful not to dereference it
in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 163250)
Fixes: 1043d0a0 (fdt: Add fdtgrep tool)
2017-06-12 08:38:07 -04:00
Simon Glass c47a38b477 fdtgrep: Cope with the /aliases node being last
With skeleton.dtsi being dropped it is more likely that the /aliases node
will be last in the device tree. Update fdtgrep to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-04-13 14:43:31 -06:00
Robert P. J. Day fc0b5948e0 Various, accumulated typos collected from around the tree.
Fix various misspellings of:

 * deprecated
 * partition
 * preceding,preceded
 * preparation
 * its versus it's
 * export
 * existing
 * scenario
 * redundant
 * remaining
 * value
 * architecture

Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
Reviewed-by: Jagan Teki <jteki@openedev.com>
Reviewed-by: Stefan Roese <sr@denx.de>
2016-10-06 20:57:40 -04:00
Simon Glass 9404fc85ab fdtgrep: Improve error handling with invalid device tree
This tool requires that the aliases node be the first node in the tree. But
when it is not, it does not handle things gracefully. In fact it crashes.

Fix this, and add a more helpful error message.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2016-03-14 15:34:50 -06:00
Simon Glass f403914dfc fdtgrep: Simplify the alias generation code
We don't need to allocate a new region list when we run out of space.
The outer function can take care of this for us.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
2015-11-04 14:49:51 +01:00
Simon Glass 1043d0a029 fdt: Add fdtgrep tool
This tool allows us to extract subsets of a device tree file. It is used by
the SPL vuild, which needs to cut down the device tree size for use in
limited memory.

This tool was originally written for libfdt but it has not been accepted
upstream, so for now, include it in U-Boot. Several utilfdt library
functions been included inline here.

If fdtgrep is eventually accepted in libfdt then we can bring that version
of libfdt in here, and drop fdtgrep (requiring that fdtgrep is provided by
the user).

If it is not accepted then another approach would be to write a special
tool for chopping down device tree files for SPL. While it would use the
same libfdt support, it would be less code than fdtgrep.c because it would
not have general-purpose functions.

Another approach (which was used with v1 of this series) is to sprinkler all
the device tree files with #ifdef. I don't like that idea.

Signed-off-by: Simon Glass <sjg@chromium.org>
2015-07-21 17:39:20 -06:00