summaryrefslogtreecommitdiff
path: root/tools/fdtgrep.c
Commit message (Collapse)AuthorAgeFilesLines
* tools: fdtgrep: Fix handle leakMikhail Ilin2022-12-081-2/+6
| | | | | | | | | | | The handle "fd" was created in fdtgrep.c:708 by calling the "open" function and is lost in fdtgrep.c:716 and fdtgrep.c:723. Close file descriptor 'fd' before exiting with an error from function utilfdt_read_err_len(const char *filename, char **buffp, off_t *len). Fixes: 1043d0a0296a ("fdt: Add fdtgrep tool") Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* fdtgrep: Correct alignment of struct sectionSimon Glass2021-12-171-2/+1
| | | | | | | | | | When outputting a devicetree we should not align the struct section to a 16-byte boundary. The normal position is fine, which is 8-byte aligned. This avoids leaving adding 8 extra zero bytes in the output tree in the case where the reserved section is empty (i.e has 16 zero bytes). Signed-off-by: Simon Glass <sjg@chromium.org>
* tools: fdtgrep: Use unsigned chars for arraysSamuel Dionne-Riel2021-03-221-1/+1
| | | | | | | | 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>
* tools: ftdgrep: use /* fallthrough */ as neededHeinrich Schuchardt2020-05-151-4/+7
| | | | | | | GCC recognizes /* fallthrough */ if -Wimplicit-fallthrough=3 is enabled. Let's use it consistently. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* libfdt: split fdt_region declarations out to <fdt_region.h>Masahiro Yamada2020-04-261-0/+1
| | | | | | | | | 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>
* tools: ftdgrep: correct the find regions loop in do_fdtgrepPatrick Delaunay2020-01-241-2/+4
| | | | | | | | | | | | | | | | 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>
* fdtgrep: Separate out checking of two allocationsSimon Glass2018-06-191-4/+7
| | | | | | | | | | | | | 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>
* fdtgrep: Fix logic of free() in do_fdtgrep()Simon Glass2018-06-191-2/+5
| | | | | | | | | | 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>
* SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini2018-05-071-2/+1
| | | | | | | | | | | | | | | | | | | | 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>
* tools: include necessary headers explicitlyMasahiro Yamada2018-01-281-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* libfdt: migrate fdt_rw.c to a wrapper of scripts/dtc/libfdt/fdt_rw.cMasahiro Yamada2018-01-281-1/+1
| | | | | | | | | | | | 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>
* Do not attempt to use the systemwide libfdtJan Kundrát2017-11-061-2/+2
| | | | | | | | | | | | | 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>
* fdtgrep: Deal with NULL data passed to check_type_include()Simon Glass2017-06-121-11/+14
| | | | | | | | | 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)
* fdtgrep: Cope with the /aliases node being lastSimon Glass2017-04-131-3/+0
| | | | | | | | 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>
* Various, accumulated typos collected from around the tree.Robert P. J. Day2016-10-061-1/+1
| | | | | | | | | | | | | | | | | | | | | 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>
* fdtgrep: Improve error handling with invalid device treeSimon Glass2016-03-141-4/+10
| | | | | | | | | | 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>
* fdtgrep: Simplify the alias generation codeSimon Glass2015-11-041-22/+10
| | | | | | | | 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>
* fdt: Add fdtgrep toolSimon Glass2015-07-211-0/+1234
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>