scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
Subsystems (2)
PATCH v2 1/1 scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7 # scripts/dtc: consolidate include path options in Makefileb5b3d9b63b0ee # scripts/dtc: Add yamltree.c to dtc sources7d97a76f226d6 # scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4 ea6f243be74e5 # scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d145 02d435d4eccd8 # scripts/dtc: Update to upstream version v1.5.0-23-g87963ee20693 6e321b7637396 # scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e73 9f19ec91a7a35 # scripts/dtc: dtx_diff - add color output support8287d642f38d1 # scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a 4c52deef9225d # scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles" 5d3827e1452ed # scripts/dtc: Remove unused makefile fragments40dd266887654 # scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff9 8d4cf6b6acb59 # scripts/dtc: use pkg-config to include <yaml.h> in non-standard path b9bf9ace5ae90 # scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c 69a883b6f5ac0 # scripts/dtc: dtx_diff - make help text formatting consistent 8f829108b8aed # scripts/dtc: only append to HOST_EXTRACFLAGS instead of overwriting b39b4342ac495 # scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea121 93c6424c486b3 # scripts: dtc: Fetch fdtoverlay.c from external DTC project 0dd574a1d75c3 # scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9 ec38b5df8a231 # scripts: dtc: Build fdtoverlay toola0c8c431411f5 # scripts: dtc: Remove the unused fdtdump.c filee7dc653d4e890 # scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c # scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8 a60878f5532d0 # scripts/dtc: dtx_diff: remove broken example from help text 8b739d8658a9b # scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00 # scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61 f96cc4c787588 # scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e 09ab9c092ef2b # scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43 ded8a5a498f2d # scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429 ee6ff6fca7e71 # scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
This also includes forward port of U-Boot commit e8c2d25845c7 ("libfdt: Revert 6dcb8ba4 from upstream libfdt") to avoid binary size growth.
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: - Fix off-by-one in fdt_remove_unused_strings()
- Restore e8c2d25845c7 ("libfdt: Revert 6dcb8ba4 from upstream libfdt")
--- scripts/Makefile.lib | 4 +- scripts/dtc/.gitignore | 1 + scripts/dtc/Makefile | 23 +- scripts/dtc/Makefile.dtc | 18 - scripts/dtc/checks.c | 686 +++++++++++++++++++++------ scripts/dtc/data.c | 74 ++- scripts/dtc/dtc-lexer.l | 38 +- scripts/dtc/dtc-parser.y | 109 +++-- scripts/dtc/dtc.c | 58 ++- scripts/dtc/dtc.h | 137 ++++-- scripts/dtc/fdtoverlay.c | 214 +++++++++ scripts/dtc/flattree.c | 70 ++- scripts/dtc/fstree.c | 26 +- scripts/dtc/libfdt/fdt.c | 84 ++-- scripts/dtc/libfdt/fdt.h | 4 +- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/fdt_overlay.c | 386 +++++++++++---- scripts/dtc/libfdt/fdt_ro.c | 100 ++-- scripts/dtc/libfdt/fdt_rw.c | 101 ++-- scripts/dtc/libfdt/fdt_strerror.c | 1 + scripts/dtc/libfdt/fdt_sw.c | 26 +- scripts/dtc/libfdt/libfdt.h | 414 +++++++++++++--- scripts/dtc/libfdt/libfdt_internal.h | 141 ++++-- scripts/dtc/livetree.c | 156 +++--- scripts/dtc/srcpos.c | 190 ++++++-- scripts/dtc/srcpos.h | 31 +- scripts/dtc/treesource.c | 319 ++++++++----- scripts/dtc/update-dtc-source.sh | 7 +- scripts/dtc/util.c | 122 ++--- scripts/dtc/util.h | 61 +-- scripts/dtc/version_gen.h | 2 +- scripts/dtc/yamltree.c | 235 +++++++++ tools/libfdt/fdt_rw.c | 2 +- 33 files changed, 2830 insertions(+), 1012 deletions(-) delete mode 100644 scripts/dtc/Makefile.dtc create mode 100644 scripts/dtc/fdtoverlay.c create mode 100644 scripts/dtc/yamltree.c
scripts/Makefile.lib +3 -1
@@ -319,6 +319,7 @@ quiet_cmd_gzip = GZIP $@ # DTC # --------------------------------------------------------------------------- DTC ?= $(objtree)/scripts/dtc/dtc +DTC_FLAGS += -Wno-interrupt_provider # Disable noisy checks by default ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
@@ -338,7 +339,8 @@ endif ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) DTC_FLAGS += -Wnode_name_chars_strict \ - -Wproperty_name_chars_strict + -Wproperty_name_chars_strict \ + -Winterrupt_provider endif DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
scripts/dtc/.gitignore +1 -0
@@ -1 +1,2 @@ /dtc +/fdtoverlay
scripts/dtc/Makefile +20 -3
@@ -1,15 +1,32 @@ # SPDX-License-Identifier: GPL-2.0 # scripts/dtc makefile -hostprogs-y := dtc -always := $(hostprogs-y) +# *** Also keep .gitignore in sync when changing *** +hostprogs-y += dtc fdtoverlay +always += dtc dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ srcpos.o checks.o util.o dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o +# The upstream project builds libfdt as a separate library. We are choosing to +# instead directly link the libfdt object files into fdtoverlay. +libfdt-objs := fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o +libfdt = $(addprefix libfdt/,$(libfdt-objs)) +fdtoverlay-objs := $(libfdt) fdtoverlay.o util.o + # Source files need to get at the userspace version of libfdt_env.h to compile -HOST_EXTRACFLAGS := -I$(src)/libfdt +HOST_EXTRACFLAGS += -I$(src)/libfdt + +ifeq ($(wildcard /usr/include/yaml.h),) +HOST_EXTRACFLAGS += -DNO_YAML +else +dtc-objs += yamltree.o +# To include <yaml.h> installed in a non-default path +HOSTCFLAGS_yamltree.o := $(shell pkg-config --cflags yaml-0.1) +# To link libyaml installed in a non-default path +HOSTLDLIBS_dtc := $(shell pkg-config --libs yaml-0.1) +endif # Generated files need one more search path to include headers in source tree HOSTCFLAGS_dtc-lexer.lex.o := -I$(src)
scripts/dtc/Makefile.dtc deleted +0 -18
@@ -1,18 +0,0 @@ -# Makefile.dtc -# -# This is not a complete Makefile of itself. Instead, it is designed to -# be easily embeddable into other systems of Makefiles. -# -DTC_SRCS = \ - checks.c \ - data.c \ - dtc.c \ - flattree.c \ - fstree.c \ - livetree.c \ - srcpos.c \ - treesource.c \ - util.c - -DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c -DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)
scripts/dtc/checks.c +540 -146
1,129 lines not on this page · raw message
scripts/dtc/data.c +49 -25
111 lines not on this page · raw message
scripts/dtc/dtc-lexer.l +19 -19
@@ -1,21 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) Copyright David Gibson <[email protected]>, 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
@@ -72,7 +57,7 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); push_input_file(name); } -<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { +<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)* { char *line, *fnstart, *fnend; struct data fn; /* skip text before line # */
@@ -166,6 +151,21 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); return DT_LABEL; } +<V1>{LABEL} { + /* Missed includes or macro definitions while + * preprocessing can lead to unexpected identifiers in + * the input. Report a slightly more informative error + * in this case */ + + lexical_error("Unexpected '%s'", yytext); + + /* Treat it as a literal which often generates further + * useful error messages */ + + yylval.integer = 0; + return DT_LITERAL; + } + <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? { char *e; DPRINT("Integer Literal: '%s'\n", yytext);
@@ -212,14 +212,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} {
scripts/dtc/dtc-parser.y +70 -39
245 lines not on this page · raw message
scripts/dtc/dtc.c +37 -21
140 lines not on this page · raw message
scripts/dtc/dtc.h +106 -31
241 lines not on this page · raw message
scripts/dtc/fdtoverlay.c new file +214 -0
214 lines not on this page · raw message
scripts/dtc/flattree.c +27 -43
200 lines not on this page · raw message
scripts/dtc/fstree.c +6 -20
@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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"
@@ -34,7 +19,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;
@@ -45,7 +30,7 @@ static struct node *read_fstree(const char *dirname) tmpname =join_path (dirname, de->d_name); -if (lstat (tmpname, &st) <0 ) +if (stat (tmpname, &st) <0 )die ("stat(%s): %s\n" , tmpname,strerror (errno));if (S_ISREG (st.st_mode)) {
@@ -58,9 +43,10 @@ static struct node *read_fstree(const char *dirname)"WARNING: Cannot open %s: %s\n" , tmpname, strerror(errno)); }else { - prop =build_property (xstrdup (de->d_name), + prop =build_property (de->d_name,data_copy_file (pfile, - st.st_size)); + st.st_size), +NULL );add_property (tree, prop);fclose (pfile); }
scripts/dtc/libfdt/fdt.c +52 -32
195 lines not on this page · raw message
scripts/dtc/libfdt/fdt.h +2 -2
@@ -7,7 +7,7 @@* Copyright 2012 Kim Phillips, Freescale Semiconductor. */ -#ifndef __ASSEMBLY__ +#ifndef __ASSEMBLER__ struct fdt_header { fdt32_t magic; /* magic word FDT_MAGIC */
@@ -45,7 +45,7 @@ struct fdt_property { char data[0]; }; -#endif /* !__ASSEMBLY */ +#endif /* !__ASSEMBLER__ */ #define FDT_MAGIC 0xd00dfeed/* 4: version, 4: total size */ #define FDT_TAGSIZE sizeof(fdt32_t)
scripts/dtc/libfdt/fdt_addresses.c +1 -1
@@ -73,7 +73,7 @@ int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,/* check validity of address */ prop = data;if (addr_cells ==1 ) { -if ((addr >UINT32_MAX ) || ((UINT32_MAX +1 - addr) < size)) +if ((addr >UINT32_MAX ) || (((uint64_t )UINT32_MAX +1 - addr) < size))return -FDT_ERR_BADVALUE ;fdt32_st (prop, (uint32_t )addr);
scripts/dtc/libfdt/fdt_overlay.c +302 -84
313 lines not on this page · raw message
scripts/dtc/libfdt/fdt_ro.c +65 -35
100 lines not on this page · raw message
scripts/dtc/libfdt/fdt_rw.c +58 -43
101 lines not on this page · raw message
scripts/dtc/libfdt/libfdt.h +343 -71
414 lines not on this page · raw message
scripts/dtc/libfdt/libfdt_internal.h +102 -39
141 lines not on this page · raw message
scripts/dtc/livetree.c +90 -66
156 lines not on this page · raw message
scripts/dtc/srcpos.c +158 -32
190 lines not on this page · raw message
scripts/dtc/treesource.c +211 -108
319 lines not on this page · raw message
scripts/dtc/util.c +66 -56
122 lines not on this page · raw message
scripts/dtc/util.h +25 -36
61 lines not on this page · raw message
scripts/dtc/yamltree.c new file +235 -0
235 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.51.0
Part of the diff is not shown here. View the raw message.
Quoted 38 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
Quoted 5 lines
This also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>
This gets us 95% of the way to where I'd like things to be, and so it's good enough for -next once the pre-requisite patches are merged, which should be soon. The remaining 5% are changes that need to be pushed to upstream dtc and I've started that work here:
https://lore.kernel.org/devicetree-compiler/[email protected]/
Signature · 1 line
Tom
Quoted 9 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
[...]
Applied to u-boot/next, thanks!
[1/1] scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c
commit: 0535e46d55d7423094d8b553d704a0f7f678de77
Signature · 1 line
Tom
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>
Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in fdt_check_header in scripts/dtc/libfdt/fdt.c:95 but the binaries generated don't have 8-byte aligned FDTs.
I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Are we ensuring the fdt present in the SPL binary is properly aligned?
Regards,
Anshul
Quoted 6,995 lines
---
V2: - Fix off-by-one infdt_remove_unused_strings()
- Restoree8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt")--- scripts/Makefile.lib | 4 +- scripts/dtc/.gitignore | 1 + scripts/dtc/Makefile | 23 +- scripts/dtc/Makefile.dtc | 18 - scripts/dtc/checks.c | 686 +++++++++++++++++++++------ scripts/dtc/data.c | 74 ++- scripts/dtc/dtc-lexer.l | 38 +- scripts/dtc/dtc-parser.y | 109 +++-- scripts/dtc/dtc.c | 58 ++- scripts/dtc/dtc.h | 137 ++++-- scripts/dtc/fdtoverlay.c | 214 +++++++++ scripts/dtc/flattree.c | 70 ++- scripts/dtc/fstree.c | 26 +- scripts/dtc/libfdt/fdt.c | 84 ++-- scripts/dtc/libfdt/fdt.h | 4 +- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/fdt_overlay.c | 386 +++++++++++---- scripts/dtc/libfdt/fdt_ro.c | 100 ++-- scripts/dtc/libfdt/fdt_rw.c | 101 ++-- scripts/dtc/libfdt/fdt_strerror.c | 1 + scripts/dtc/libfdt/fdt_sw.c | 26 +- scripts/dtc/libfdt/libfdt.h | 414 +++++++++++++--- scripts/dtc/libfdt/libfdt_internal.h | 141 ++++-- scripts/dtc/livetree.c | 156 +++--- scripts/dtc/srcpos.c | 190 ++++++-- scripts/dtc/srcpos.h | 31 +- scripts/dtc/treesource.c | 319 ++++++++----- scripts/dtc/update-dtc-source.sh | 7 +- scripts/dtc/util.c | 122 ++--- scripts/dtc/util.h | 61 +-- scripts/dtc/version_gen.h | 2 +- scripts/dtc/yamltree.c | 235 +++++++++ tools/libfdt/fdt_rw.c | 2 +- 33 files changed, 2830 insertions(+), 1012 deletions(-) delete mode 100644 scripts/dtc/Makefile.dtc create mode 100644 scripts/dtc/fdtoverlay.c create mode 100644 scripts/dtc/yamltree.cscripts/Makefile.lib +3
-1@@ -319,6 +319,7 @@ quiet_cmd_gzip = GZIP $@ # DTC # --------------------------------------------------------------------------- DTC ?= $(objtree)/scripts/dtc/dtc +DTC_FLAGS += -Wno-interrupt_provider # Disable noisy checks by default ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)@@ -338,7 +339,8 @@ endif ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) DTC_FLAGS += -Wnode_name_chars_strict \ - -Wproperty_name_chars_strict + -Wproperty_name_chars_strict \ + -Winterrupt_provider endif DTC_FLAGS += $(DTC_FLAGS_$(basetarget))scripts/dtc/.gitignore +1
-0@@ -1 +1,2 @@ /dtc +/fdtoverlayscripts/dtc/Makefile +20
-3@@ -1,15 +1,32 @@ # SPDX-License-Identifier: GPL-2.0 # scripts/dtc makefile -hostprogs-y := dtc -always := $(hostprogs-y) +# *** Also keep .gitignore in sync when changing *** +hostprogs-y += dtc fdtoverlay +always += dtc dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ srcpos.o checks.o util.o dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o +# The upstream project builds libfdt as a separate library. We are choosing to +# instead directly link the libfdt object files into fdtoverlay. +libfdt-objs := fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o +libfdt = $(addprefix libfdt/,$(libfdt-objs)) +fdtoverlay-objs := $(libfdt) fdtoverlay.o util.o + # Source files need to get at the userspace version of libfdt_env.h to compile -HOST_EXTRACFLAGS := -I$(src)/libfdt +HOST_EXTRACFLAGS += -I$(src)/libfdt + +ifeq ($(wildcard /usr/include/yaml.h),) +HOST_EXTRACFLAGS += -DNO_YAML +else +dtc-objs += yamltree.o +# To include <yaml.h> installed in a non-default path +HOSTCFLAGS_yamltree.o := $(shell pkg-config --cflags yaml-0.1) +# To link libyaml installed in a non-default path +HOSTLDLIBS_dtc := $(shell pkg-config --libs yaml-0.1) +endif # Generated files need one more search path to include headers in source tree HOSTCFLAGS_dtc-lexer.lex.o := -I$(src)scripts/dtc/Makefile.dtc deleted +0
-18@@ -1,18 +0,0 @@ -# Makefile.dtc -# -# This is not a complete Makefile of itself. Instead, it is designed to -# be easily embeddable into other systems of Makefiles. -# -DTC_SRCS = \ - checks.c \ - data.c \ - dtc.c \ - flattree.c \ - fstree.c \ - livetree.c \ - srcpos.c \ - treesource.c \ - util.c - -DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c -DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)scripts/dtc/checks.c +540
-146@@ -1,24 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, IBM Corporation. 2007. -* -* -* 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" #ifdef TRACE_CHECKS #define TRACE (c, ...) \@@ -45,7 +31,7 @@ typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *nodestruct check {const char *name;check_fn fn; -void *data; +const void *data;bool warn, error;enum checkstatus status;bool inprogress;@@ -78,23 +64,57 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti, const char *fmt, ...) {va_list ap; -va_start (ap, fmt); +char *str =NULL ; +struct srcpos *pos =NULL ; +char *file_str; + +if (!(c->warn && (quiet <1 )) && !(c->error && (quiet <2 ))) +return ; -if ((c->warn && (quiet <1 )) - || (c->error && (quiet <2 ))) { -fprintf (stderr,"%s: %s (%s): " , -strcmp (dti->outname,"-" ) ? dti->outname :"<stdout>" , +if (prop && prop->srcpos) + pos = prop->srcpos; +else if (node && node->srcpos) + pos = node->srcpos; + +if (pos) { + file_str =srcpos_string (pos); +xasprintf (&str,"%s" , file_str); +free (file_str); + }else if (streq (dti->outname,"-" )) { +xasprintf (&str,"<stdout>" ); + }else { +xasprintf (&str,"%s" , dti->outname); + } + +xasprintf_append (&str,": %s (%s): " , (c->error) ?"ERROR" :"Warning" , c->name); -if (node) { -fprintf (stderr,"%s" , node->fullpath); -if (prop) -fprintf (stderr,":%s" , prop->name); -fputs (": " , stderr); - } -vfprintf (stderr, fmt, ap); -fprintf (stderr,"\n" ); + +if (node) { +if (prop) +xasprintf_append (&str,"%s:%s: " , node->fullpath, prop->name); +else +xasprintf_append (&str,"%s: " , node->fullpath); } + +va_start (ap, fmt); +xavsprintf_append (&str, fmt, ap);va_end (ap); + +xasprintf_append (&str,"\n" ); + +if (!prop && pos) { + pos = node->srcpos; +while (pos->next) { + pos = pos->next; + + file_str =srcpos_string (pos); +xasprintf_append (&str," also defined at %s\n" , file_str); +free (file_str); + } + } + +fputs (str, stderr); +free (str); }#define FAIL (c, dti, node, ...) \@@ -123,6 +143,14 @@ static void check_nodes_props(struct check *c, struct dt_info *dti, struct nodecheck_nodes_props (c, dti, child); } +static bool is_multiple_of (int multiple,int divisor) +{ +if (divisor ==0 ) +return multiple ==0 ; +else +return (multiple % divisor) ==0 ; +} +static bool run_check (struct check *c,struct dt_info *dti) {struct node *dt = dti->dt;@@ -179,7 +207,7 @@ static void check_is_string(struct check *c, struct dt_info *dti, struct node *node) {struct property *prop; -char *propname = c->data; +const char *propname = c->data; prop =get_property (node, propname);if (!prop)@@ -198,7 +226,7 @@ static void check_is_string_list(struct check *c, struct dt_info *dti, {int rem, l;struct property *prop; -char *propname = c->data; +const char *propname = c->data;char *str; prop =get_property (node, propname);@@ -226,7 +254,7 @@ static void check_is_cell(struct check *c, struct dt_info *dti, struct node *node) {struct property *prop; -char *propname = c->data; +const char *propname = c->data; prop =get_property (node, propname);if (!prop)@@ -277,19 +305,20 @@ ERROR(duplicate_property_names, check_duplicate_property_names, NULL);#define LOWERCASE "abcdefghijklmnopqrstuvwxyz"#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"#define DIGITS "0123456789" -#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" +#define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@" +#define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"#define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"static void check_node_name_chars (struct check *c,struct dt_info *dti,struct node *node) { -int n =strspn (node->name, c->data); +size_t n =strspn (node->name, c->data);if (n <strlen (node->name))FAIL (c, dti, node,"Bad character '%c' in node name" , node->name[n]); } -ERROR (node_name_chars, check_node_name_chars,PROPNODECHARS "@" ); +ERROR (node_name_chars, check_node_name_chars,NODECHARS );static void check_node_name_chars_strict (struct check *c,struct dt_info *dti,struct node *node)@@ -310,6 +339,20 @@ static void check_node_name_format(struct check *c, struct dt_info *dti, }ERROR (node_name_format, check_node_name_format,NULL , &node_name_chars); +static void check_node_name_vs_property_name (struct check *c, +struct dt_info *dti, +struct node *node) +{ +if (!node->parent) +return ; + +if (get_property (node->parent, node->name)) { +FAIL (c, dti, node,"node name and property name conflict" ); + } +} +WARNING (node_name_vs_property_name, check_node_name_vs_property_name, +NULL , &node_name_chars); +static void check_unit_address_vs_reg (struct check *c,struct dt_info *dti,struct node *node) {@@ -332,7 +375,7 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,FAIL (c, dti, node,"node has a reg or ranges property, but no unit name" ); }else {if (unitname[0 ]) -FAIL (c, dti, node,"node has a unit name, but no reg property" ); +FAIL (c, dti, node,"node has a unit name, but no reg or ranges property" ); } }WARNING (unit_address_vs_reg, check_unit_address_vs_reg,NULL );@@ -343,14 +386,14 @@ static void check_property_name_chars(struct check *c, struct dt_info *dti,struct property *prop;for_each_property (node, prop) { -int n =strspn (prop->name, c->data); +size_t n =strspn (prop->name, c->data);if (n <strlen (prop->name))FAIL_PROP (c, dti, node, prop,"Bad character '%c' in property name" , prop->name[n]); } } -ERROR (property_name_chars, check_property_name_chars,PROPNODECHARS ); +ERROR (property_name_chars, check_property_name_chars,PROPCHARS ); static void check_property_name_chars_strict(struct check *c, struct dt_info *dti,@@ -360,7 +403,7 @@ static void check_property_name_chars_strict(struct check *c,for_each_property (node, prop) {const char *name = prop->name; -int n =strspn (name, c->data); +size_t n =strspn (name, c->data);if (n ==strlen (prop->name))continue ;@@ -477,7 +520,7 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, phandle =propval_cell (prop); -if ((phandle ==0 ) || (phandle ==-1 )) { +if (!phandle_is_valid (phandle)) {FAIL_PROP (c, dti, node, prop,"bad value (0x%x) in %s property" , phandle, prop->name);return 0 ;@@ -536,7 +579,7 @@ static void check_name_properties(struct check *c, struct dt_info *dti,if (!prop)return ;/* No name property, that's fine */ -if ((prop->val.len != node->basenamelen+1 ) +if ((prop->val.len != node->basenamelen +1U ) || (memcmp (prop->val.val, node->name, node->basenamelen) !=0 )) {FAIL (c, dti, node,"\"name\" property is incorrect (\"%s\" instead" " of base node name)" , prop->val.val);@@ -625,6 +668,8 @@ ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);static void fixup_omit_unused_nodes (struct check *c,struct dt_info *dti,struct node *node) { +if (generate_symbols && node->labels) +return ;if (node->omit_if_unused && !node->is_referenced)delete_node (node); }@@ -635,7 +680,6 @@ ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &pa*/ WARNING_IF_NOT_CELL (address_cells_is_cell,"#address-cells" );WARNING_IF_NOT_CELL (size_cells_is_cell,"#size-cells" ); -WARNING_IF_NOT_CELL (interrupt_cells_is_cell,"#interrupt-cells" );WARNING_IF_NOT_STRING (device_type_is_string,"device_type" );WARNING_IF_NOT_STRING (model_is_string,"model" );@@ -650,8 +694,7 @@ static void check_names_is_string_list(struct check *c, struct dt_info *dti,struct property *prop;for_each_property (node, prop) { -const char *s =strrchr (prop->name,'-' ); -if (!s || !streq (s,"-names" )) +if (!strends (prop->name,"-names" ))continue ; c->data = prop->name;@@ -669,6 +712,11 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,return ;for_each_property (node, prop) { +if (streq (prop->name,"phandle" ) + ||streq (prop->name,"linux,phandle" )) { +continue ; + } +if (!prop->val.val || !get_node_by_path (dti->dt, prop->val.val)) {FAIL_PROP (c, dti, node, prop,"aliases property is not a valid node (%s)" , prop->val.val);@@ -726,7 +774,7 @@ static void check_reg_format(struct check *c, struct dt_info *dti, size_cells =node_size_cells (node->parent); entrylen = (addr_cells + size_cells) *sizeof (cell_t); -if (!entrylen || (prop->val.len % entrylen) !=0 ) +if (!is_multiple_of (prop->val.len, entrylen))FAIL_PROP (c, dti, node, prop,"property has invalid length (%d bytes) " "(#address-cells == %d, #size-cells == %d)" , prop->val.len, addr_cells, size_cells);@@ -738,13 +786,15 @@ static void check_ranges_format(struct check *c, struct dt_info *dti, {struct property *prop;int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen; +const char *ranges = c->data; - prop =get_property (node,"ranges" ); + prop =get_property (node, ranges);if (!prop)return ;if (!node->parent) { -FAIL_PROP (c, dti, node, prop,"Root node has a \"ranges\" property" ); +FAIL_PROP (c, dti, node, prop,"Root node has a \"%s\" property" , + ranges);return ; }@@ -756,23 +806,24 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,if (prop->val.len ==0 ) {if (p_addr_cells != c_addr_cells) -FAIL_PROP (c, dti, node, prop,"empty \"ranges\" property but its " +FAIL_PROP (c, dti, node, prop,"empty \"%s\" property but its " "#address-cells (%d) differs from %s (%d)" , - c_addr_cells, node->parent->fullpath, + ranges, c_addr_cells, node->parent->fullpath, p_addr_cells);if (p_size_cells != c_size_cells) -FAIL_PROP (c, dti, node, prop,"empty \"ranges\" property but its " +FAIL_PROP (c, dti, node, prop,"empty \"%s\" property but its " "#size-cells (%d) differs from %s (%d)" , - c_size_cells, node->parent->fullpath, + ranges, c_size_cells, node->parent->fullpath, p_size_cells); - }else if ((prop->val.len % entrylen) !=0 ) { -FAIL_PROP (c, dti, node, prop,"\"ranges\" property has invalid length (%d bytes) " + }else if (!is_multiple_of (prop->val.len, entrylen)) { +FAIL_PROP (c, dti, node, prop,"\"%s\" property has invalid length (%d bytes) " "(parent #address-cells == %d, child #address-cells == %d, " -"#size-cells == %d)" , prop->val.len, +"#size-cells == %d)" , ranges, prop->val.len, p_addr_cells, c_addr_cells, c_size_cells); } } -WARNING (ranges_format, check_ranges_format,NULL , &addr_size_cells); +WARNING (ranges_format, check_ranges_format,"ranges" , &addr_size_cells); +WARNING (dma_ranges_format, check_ranges_format,"dma-ranges" , &addr_size_cells);static const struct bus_type pci_bus = { .name ="PCI" ,@@ -842,7 +893,7 @@ static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struc }else { cells = (cell_t *)prop->val.val; min_bus =fdt32_to_cpu (cells[0 ]); - max_bus =fdt32_to_cpu (cells[0 ]); + max_bus =fdt32_to_cpu (cells[1 ]); }if ((bus_num < min_bus) || (bus_num > max_bus)) FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",@@ -862,10 +913,8 @@ static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct noreturn ; prop =get_property (node,"reg" ); -if (!prop) { -FAIL (c, dti, node,"missing PCI reg property" ); +if (!prop)return ; - } cells = (cell_t *)prop->val.val;if (cells[1 ] || cells[2 ])@@ -910,7 +959,7 @@ static bool node_is_compatible(struct node *node, const char *compat)for (str = prop->val.val, end = str + prop->val.len; str < end; str +=strnlen (str, end - str) +1 ) { -if (strprefixeq (str, end - str, compat)) +if (streq (str, compat))return true; }return false;@@ -921,7 +970,8 @@ static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, structif (node_is_compatible (node,"simple-bus" )) node->bus = &simple_bus; } -WARNING (simple_bus_bridge, check_simple_bus_bridge,NULL , &addr_size_cells); +WARNING (simple_bus_bridge, check_simple_bus_bridge,NULL , + &addr_size_cells, &compatible_is_string_list);static void check_simple_bus_reg (struct check *c,struct dt_info *dti,struct node *node) {@@ -962,6 +1012,160 @@ static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct no }WARNING (simple_bus_reg, check_simple_bus_reg,NULL , ®_format, &simple_bus_bridge); +static const struct bus_type i2c_bus = { + .name ="i2c-bus" , +}; + +static void check_i2c_bus_bridge (struct check *c,struct dt_info *dti,struct node *node) +{ +if (strprefixeq (node->name, node->basenamelen,"i2c-bus" ) || +strprefixeq (node->name, node->basenamelen,"i2c-arb" )) { + node->bus = &i2c_bus; + }else if (strprefixeq (node->name, node->basenamelen,"i2c" )) { +struct node *child; +for_each_child (node, child) { +if (strprefixeq (child->name, child->basenamelen,"i2c-bus" )) +return ; + } + node->bus = &i2c_bus; + }else +return ; + +if (!node->children) +return ; + +if (node_addr_cells (node) !=1 ) +FAIL (c, dti, node,"incorrect #address-cells for I2C bus" ); +if (node_size_cells (node) !=0 ) +FAIL (c, dti, node,"incorrect #size-cells for I2C bus" ); + +} +WARNING (i2c_bus_bridge, check_i2c_bus_bridge,NULL , &addr_size_cells); + +#define I2C_OWN_SLAVE_ADDRESS (1U << 30) +#define I2C_TEN_BIT_ADDRESS (1U << 31) + +static void check_i2c_bus_reg (struct check *c,struct dt_info *dti,struct node *node) +{ +struct property *prop; +const char *unitname =get_unitname (node); +char unit_addr[17 ]; +uint32_t reg =0 ; +int len; +cell_t *cells =NULL ; + +if (!node->parent || (node->parent->bus != &i2c_bus)) +return ; + + prop =get_property (node,"reg" ); +if (prop) + cells = (cell_t *)prop->val.val; + +if (!cells) { +FAIL (c, dti, node,"missing or empty reg property" ); +return ; + } + + reg =fdt32_to_cpu (*cells); +/* Ignore I2C_OWN_SLAVE_ADDRESS */ + reg &= ~I2C_OWN_SLAVE_ADDRESS ; +snprintf (unit_addr,sizeof (unit_addr),"%x" , reg); +if (!streq (unitname, unit_addr)) +FAIL (c, dti, node,"I2C bus unit address format error, expected \"%s\"" , + unit_addr); + +for (len = prop->val.len; len >0 ; len -=4 ) { + reg =fdt32_to_cpu (*(cells++)); +/* Ignore I2C_OWN_SLAVE_ADDRESS */ + reg &= ~I2C_OWN_SLAVE_ADDRESS ; + +if (reg &I2C_TEN_BIT_ADDRESS ) { +if ((reg & ~I2C_TEN_BIT_ADDRESS ) >0x3ff ) +FAIL_PROP (c, dti, node, prop,"I2C address must be less than 10-bits, got \"0x%x\"" , + reg); + }else if (reg >0x7f ) +FAIL_PROP (c, dti, node, prop,"I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property" , + reg); + } +} +WARNING (i2c_bus_reg, check_i2c_bus_reg,NULL , ®_format, &i2c_bus_bridge); + +static const struct bus_type spi_bus = { + .name ="spi-bus" , +}; + +static void check_spi_bus_bridge (struct check *c,struct dt_info *dti,struct node *node) +{ +int spi_addr_cells =1 ; + +if (strprefixeq (node->name, node->basenamelen,"spi" )) { + node->bus = &spi_bus; + }else { +/* Try to detect SPI buses which don't have proper node name */ +struct node *child; + +if (node_addr_cells (node) !=1 ||node_size_cells (node) !=0 ) +return ; + +for_each_child (node, child) { +struct property *prop; +for_each_property (child, prop) { +if (strstarts (prop->name,"spi-" )) { + node->bus = &spi_bus; +break ; + } + } +if (node->bus == &spi_bus) +break ; + } + +if (node->bus == &spi_bus &&get_property (node,"reg" )) +FAIL (c, dti, node,"node name for SPI buses should be 'spi'" ); + } +if (node->bus != &spi_bus || !node->children) +return ; + +if (get_property (node,"spi-slave" )) + spi_addr_cells =0 ; +if (node_addr_cells (node) != spi_addr_cells) +FAIL (c, dti, node,"incorrect #address-cells for SPI bus" ); +if (node_size_cells (node) !=0 ) +FAIL (c, dti, node,"incorrect #size-cells for SPI bus" ); + +} +WARNING (spi_bus_bridge, check_spi_bus_bridge,NULL , &addr_size_cells); + +static void check_spi_bus_reg (struct check *c,struct dt_info *dti,struct node *node) +{ +struct property *prop; +const char *unitname =get_unitname (node); +char unit_addr[9 ]; +uint32_t reg =0 ; +cell_t *cells =NULL ; + +if (!node->parent || (node->parent->bus != &spi_bus)) +return ; + +if (get_property (node->parent,"spi-slave" )) +return ; + + prop =get_property (node,"reg" ); +if (prop) + cells = (cell_t *)prop->val.val; + +if (!cells) { +FAIL (c, dti, node,"missing or empty reg property" ); +return ; + } + + reg =fdt32_to_cpu (*cells); +snprintf (unit_addr,sizeof (unit_addr),"%x" , reg); +if (!streq (unitname, unit_addr)) +FAIL (c, dti, node,"SPI bus unit address format error, expected \"%s\"" , + unit_addr); +} +WARNING (spi_bus_reg, check_spi_bus_reg,NULL , ®_format, &spi_bus_bridge); +static void check_unit_address_format (struct check *c,struct dt_info *dti,struct node *node) {@@ -978,7 +1182,7 @@ static void check_unit_address_format(struct check *c, struct dt_info *dti,/* skip over 0x for next test */ unitname +=2 ; } -if (unitname[0 ] =='0' &&isxdigit (unitname[1 ])) +if (unitname[0 ] =='0' &&isxdigit ((unsigned char )unitname[1 ]))FAIL (c, dti, node,"unit name should not have leading 0s" ); } WARNING(unit_address_format, check_unit_address_format, NULL,@@ -1013,29 +1217,48 @@ WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,static void check_avoid_unnecessary_addr_size (struct check *c,struct dt_info *dti,struct node *node) { -struct property *prop;struct node *child; -bool has_reg = false;if (!node->parent || node->addr_cells <0 || node->size_cells <0 )return ; -if (get_property (node,"ranges" ) || !node->children) +if (get_property (node,"ranges" ) ||get_property (node,"dma-ranges" ) || !node->children)return ;for_each_child (node, child) { - prop =get_property (child,"reg" ); -if (prop) - has_reg = true; +/* +* Even if the child devices' address space is not mapped into +* the parent bus (no 'ranges' property on node), children can +* still have registers on a local bus, or map local addresses +* to another subordinate address space. The properties on the +* child nodes then make #address-cells/#size-cells necessary: +*/ +if (get_property (child,"reg" ) ||get_property (child,"ranges" )) +return ; } -if (!has_reg) -FAIL (c, dti, node,"unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property" ); +FAIL (c, dti, node,"unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property" ); }WARNING (avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size,NULL , &avoid_default_addr_size); -static void check_unique_unit_address (struct check *c,struct dt_info *dti, -struct node *node) +static bool node_is_disabled (struct node *node) +{ +struct property *prop; + + prop =get_property (node,"status" ); +if (prop) { +char *str = prop->val.val; +if (streq ("disabled" , str)) +return true; + } + +return false; +} + +static void check_unique_unit_address_common (struct check *c, +struct dt_info *dti, +struct node *node, +bool disable_check) {struct node *childa;@@ -1052,18 +1275,38 @@ static void check_unique_unit_address(struct check *c, struct dt_info *dti,if (!strlen (addr_a))continue ; +if (disable_check &&node_is_disabled (childa)) +continue ; +for_each_child (node, childb) {const char *addr_b =get_unitname (childb);if (childa == childb)break ; +if (disable_check &&node_is_disabled (childb)) +continue ; +if (streq (addr_a, addr_b))FAIL (c, dti, childb,"duplicate unit-address (also used in node %s)" , childa->fullpath); } } } + +static void check_unique_unit_address (struct check *c,struct dt_info *dti, +struct node *node) +{ +check_unique_unit_address_common (c, dti, node, false); +}WARNING (unique_unit_address, check_unique_unit_address,NULL , &avoid_default_addr_size); +static void check_unique_unit_address_if_enabled (struct check *c,struct dt_info *dti, +struct node *node) +{ +check_unique_unit_address_common (c, dti, node, true); +} +CHECK_ENTRY (unique_unit_address_if_enabled, check_unique_unit_address_if_enabled, +NULL , false, false, &avoid_default_addr_size); +static void check_obsolete_chosen_interrupt_controller (struct check *c,struct dt_info *dti,struct node *node)@@ -1143,15 +1386,15 @@ struct provider { };static void check_property_phandle_args (struct check *c, -struct dt_info *dti, -struct node *node, -struct property *prop, -const struct provider *provider) +struct dt_info *dti, +struct node *node, +struct property *prop, +const struct provider *provider) {struct node *root = dti->dt; -int cell, cellsize =0 ; +unsigned int cell, cellsize =0 ; -if (prop->val.len %sizeof (cell_t)) { +if (!is_multiple_of (prop->val.len,sizeof (cell_t))) {FAIL_PROP (c, dti, node, prop,"property size (%d) is invalid, expected multiple of %zu" , prop->val.len,sizeof (cell_t));@@ -1161,14 +1404,15 @@ static void check_property_phandle_args(struct check *c,for (cell =0 ; cell < prop->val.len /sizeof (cell_t); cell += cellsize +1 ) {struct node *provider_node;struct property *cellprop; -int phandle; +cell_t phandle; +unsigned int expected; phandle =propval_cell_n (prop, cell);/* * Some bindings use a cell value 0 or -1 to skip over optional * entries when each index position has a specific definition. */ -if (phandle ==0 || phandle ==-1 ) { +if (!phandle_is_valid (phandle)) {/* Give up if this is an overlay with external references */ if (dti->dtsflags &DTSF_PLUGIN )break ;@@ -1211,10 +1455,12 @@ static void check_property_phandle_args(struct check *c,break ; } -if (prop->val.len < ((cell + cellsize +1 ) *sizeof (cell_t))) { + expected = (cell + cellsize +1 ) *sizeof (cell_t); +if ((expected <= cell) || prop->val.len < expected) {FAIL_PROP (c, dti, node, prop, -"property size (%d) too small for cell size %d" , +"property size (%d) too small for cell size %u" , prop->val.len, cellsize); +break ; } } }@@ -1223,7 +1469,7 @@ static void check_provider_cells_property(struct check *c,struct dt_info *dti, struct node *node) { - struct provider *provider = c->data; + const struct provider *provider = c->data;struct property *prop; prop =get_property (node, provider->prop_name);@@ -1234,7 +1480,8 @@ static void check_provider_cells_property(struct check *c, }#define WARNING_PROPERTY_PHANDLE_CELLS (nm, propname, cells_name, ...) \ static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \ - WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references); + WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \ + WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references);WARNING_PROPERTY_PHANDLE_CELLS (clocks,"clocks" ,"#clock-cells" );WARNING_PROPERTY_PHANDLE_CELLS (cooling_device,"cooling-device" ,"#cooling-cells" );@@ -1255,24 +1502,17 @@ WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-senstatic bool prop_is_gpio (struct property *prop) { -char *str; -/* * *-gpios and *-gpio can appear in property names, * so skip over any false matches (only one known ATM) */ -if (strstr (prop->name,"nr-gpio" )) +if (strends (prop->name,",nr-gpios" ))return false; - str =strrchr (prop->name,'-' ); -if (str) - str++; -else - str = prop->name; -if (!(streq (str,"gpios" ) ||streq (str,"gpio" ))) -return false; - -return true; +return strends (prop->name,"-gpios" ) || +streq (prop->name,"gpios" ) || +strends (prop->name,"-gpio" ) || +streq (prop->name,"gpio" ); } static void check_gpios_property(struct check *c,@@ -1307,13 +1547,10 @@ static void check_deprecated_gpio_property(struct check *c,struct property *prop;for_each_property (node, prop) { -char *str; -if (!prop_is_gpio (prop))continue ; - str =strstr (prop->name,"gpio" ); -if (!streq (str,"gpio" )) +if (!strends (prop->name,"gpio" ))continue ; FAIL_PROP(c, dti, node, prop,@@ -1337,6 +1574,121 @@ static bool node_is_interrupt_provider(struct node *node)return false; } + +static void check_interrupt_provider (struct check *c, +struct dt_info *dti, +struct node *node) +{ +struct property *prop; +bool irq_provider =node_is_interrupt_provider (node); + + prop =get_property (node,"#interrupt-cells" ); +if (irq_provider && !prop) { +FAIL (c, dti, node, +"Missing '#interrupt-cells' in interrupt provider" ); +return ; + } + +if (!irq_provider && prop) { +FAIL (c, dti, node, +"'#interrupt-cells' found, but node is not an interrupt provider" ); +return ; + } +} +WARNING (interrupt_provider, check_interrupt_provider,NULL , &interrupts_extended_is_cell); + +static void check_interrupt_map (struct check *c, +struct dt_info *dti, +struct node *node) +{ +struct node *root = dti->dt; +struct property *prop, *irq_map_prop; +size_t cellsize, cell, map_cells; + + irq_map_prop =get_property (node,"interrupt-map" ); +if (!irq_map_prop) +return ; + +if (node->addr_cells <0 ) { +FAIL (c, dti, node, +"Missing '#address-cells' in interrupt-map provider" ); +return ; + } + cellsize =node_addr_cells (node); + cellsize +=propval_cell (get_property (node,"#interrupt-cells" )); + + prop =get_property (node,"interrupt-map-mask" ); +if (prop && (prop->val.len != (cellsize *sizeof (cell_t)))) +FAIL_PROP (c, dti, node, prop, +"property size (%d) is invalid, expected %zu" , + prop->val.len, cellsize *sizeof (cell_t)); + +if (!is_multiple_of (irq_map_prop->val.len,sizeof (cell_t))) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) is invalid, expected multiple of %zu" , + irq_map_prop->val.len,sizeof (cell_t)); +return ; + } + + map_cells = irq_map_prop->val.len /sizeof (cell_t); +for (cell =0 ; cell < map_cells; ) { +struct node *provider_node; +struct property *cellprop; +int phandle; +size_t parent_cellsize; + +if ((cell + cellsize) >= map_cells) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) too small, expected > %zu" , + irq_map_prop->val.len, (cell + cellsize) *sizeof (cell_t)); +break ; + } + cell += cellsize; + + phandle =propval_cell_n (irq_map_prop, cell); +if (!phandle_is_valid (phandle)) { +/* Give up if this is an overlay with external references */ +if (!(dti->dtsflags &DTSF_PLUGIN )) +FAIL_PROP (c, dti, node, irq_map_prop, +"Cell %zu is not a phandle(%d)" , + cell, phandle); +break ; + } + + provider_node =get_node_by_phandle (root, phandle); +if (!provider_node) { +FAIL_PROP (c, dti, node, irq_map_prop, +"Could not get phandle(%d) node for (cell %zu)" , + phandle, cell); +break ; + } + + cellprop =get_property (provider_node,"#interrupt-cells" ); +if (cellprop) { + parent_cellsize =propval_cell (cellprop); + }else { +FAIL (c, dti, node,"Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])" , + provider_node->fullpath, cell); +break ; + } + + cellprop =get_property (provider_node,"#address-cells" ); +if (cellprop) + parent_cellsize +=propval_cell (cellprop); +else +FAIL_PROP (c, dti, node, irq_map_prop, +"Missing property '#address-cells' in node %s, using 0 as fallback" , + provider_node->fullpath); + + cell +=1 + parent_cellsize; +if (cell > map_cells) +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) mismatch, expected %zu" , + irq_map_prop->val.len, cell *sizeof (cell_t)); + } +} +WARNING (interrupt_map, check_interrupt_map,NULL , &phandle_references, &addr_size_cells, &interrupt_provider); +static void check_interrupts_property (struct check *c,struct dt_info *dti,struct node *node)@@ -1344,13 +1696,13 @@ static void check_interrupts_property(struct check *c,struct node *root = dti->dt;struct node *irq_node =NULL , *parent = node;struct property *irq_prop, *prop =NULL ; -int irq_cells, phandle; +cell_t irq_cells, phandle; irq_prop =get_property (node,"interrupts" );if (!irq_prop)return ; -if (irq_prop->val.len %sizeof (cell_t)) +if (!is_multiple_of (irq_prop->val.len,sizeof (cell_t)))FAIL_PROP (c, dti, node, irq_prop,"size (%d) is invalid, expected multiple of %zu" , irq_prop->val.len,sizeof (cell_t));@@ -1363,10 +1715,14 @@ static void check_interrupts_property(struct check *c, prop =get_property (parent,"interrupt-parent" );if (prop) { phandle =propval_cell (prop); -/* Give up if this is an overlay with external references */ -if ((phandle ==0 || phandle ==-1 ) && - (dti->dtsflags &DTSF_PLUGIN )) +if (!phandle_is_valid (phandle)) { +/* Give up if this is an overlay with +* external references */ +if (dti->dtsflags &DTSF_PLUGIN )return ; +FAIL_PROP (c, dti, parent, prop,"Invalid phandle" ); +continue ; + } irq_node =get_node_by_phandle (root, phandle);if (!irq_node) {@@ -1390,12 +1746,12 @@ static void check_interrupts_property(struct check *c, prop =get_property (irq_node,"#interrupt-cells" );if (!prop) { -FAIL (c, dti, irq_node,"Missing #interrupt-cells in interrupt-parent" ); +/* We warn about that already in another test. */ return ; } irq_cells =propval_cell (prop); -if (irq_prop->val.len % (irq_cells *sizeof (cell_t))) { +if (!is_multiple_of (irq_prop->val.len, irq_cells *sizeof (cell_t))) {FAIL_PROP (c, dti, node, prop,"size is (%d), expected multiple of %d" , irq_prop->val.len, (int )(irq_cells *sizeof (cell_t)));@@ -1421,6 +1777,11 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti, get_property(child, "remote-endpoint")))continue ; +/* The root node cannot be a port */ +if (!node->parent) { +FAIL (c, dti, node,"root node contains endpoint node '%s', potentially misplaced remote-endpoint property" , child->name); +continue ; + } node->bus = &graph_port_bus;/* The parent of 'port' nodes can be either 'ports' or a device */ @@ -1434,31 +1795,6 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti, }WARNING (graph_nodes, check_graph_nodes,NULL ); -static void check_graph_child_address (struct check *c,struct dt_info *dti, -struct node *node) -{ -int cnt =0 ; -struct node *child; - -if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus) -return ; - -for_each_child (node, child) { -struct property *prop =get_property (child,"reg" ); - -/* No error if we have any non-zero unit address */ -if (prop &&propval_cell (prop) !=0 ) -return ; - - cnt++; - } - -if (cnt ==1 && node->addr_cells !=-1 ) -FAIL (c, dti, node,"graph node has single child node '%s', #address-cells/#size-cells are not necessary" , - node->children->name); -} -WARNING (graph_child_address, check_graph_child_address,NULL , &graph_nodes); -static void check_graph_reg (struct check *c,struct dt_info *dti,struct node *node) {@@ -1496,17 +1832,21 @@ static void check_graph_port(struct check *c, struct dt_info *dti,if (node->bus != &graph_port_bus)return ; +check_graph_reg (c, dti, node); + +/* skip checks below for overlays */ +if (dti->dtsflags &DTSF_PLUGIN ) +return ; +if (!strprefixeq (node->name, node->basenamelen,"port" ))FAIL (c, dti, node,"graph port node name should be 'port'" ); - -check_graph_reg (c, dti, node); }WARNING (graph_port, check_graph_port,NULL , &graph_nodes);static struct node *get_remote_endpoint (struct check *c,struct dt_info *dti,struct node *endpoint) { -int phandle; +cell_t phandle;struct node *node;struct property *prop;@@ -1516,7 +1856,7 @@ static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti, phandle =propval_cell (prop);/* Give up if this is an overlay with external references */ -if (phandle ==0 || phandle ==-1 ) +if (!phandle_is_valid (phandle))return NULL ; node =get_node_by_phandle (dti->dt, phandle);@@ -1534,11 +1874,15 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti,if (!node->parent || node->parent->bus != &graph_port_bus)return ; -if (!strprefixeq (node->name, node->basenamelen,"endpoint" )) -FAIL (c, dti, node,"graph endpont node name should be 'endpoint'" ); -check_graph_reg (c, dti, node); +/* skip checks below for overlays */ +if (dti->dtsflags &DTSF_PLUGIN ) +return ; + +if (!strprefixeq (node->name, node->basenamelen,"endpoint" )) +FAIL (c, dti, node,"graph endpoint node name should be 'endpoint'" ); + remote_node =get_remote_endpoint (c, dti, node);if (!remote_node)return ;@@ -1549,10 +1893,35 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti, }WARNING (graph_endpoint, check_graph_endpoint,NULL , &graph_nodes); +static void check_graph_child_address (struct check *c,struct dt_info *dti, +struct node *node) +{ +int cnt =0 ; +struct node *child; + +if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus) +return ; + +for_each_child (node, child) { +struct property *prop =get_property (child,"reg" ); + +/* No error if we have any non-zero unit address */ +if (prop &&propval_cell (prop) !=0 ) +return ; + + cnt++; + } + +if (cnt ==1 && node->addr_cells !=-1 ) +FAIL (c, dti, node,"graph node has single child node '%s', #address-cells/#size-cells are not necessary" , + node->children->name); +} +WARNING (graph_child_address, check_graph_child_address,NULL , &graph_nodes, &graph_port, &graph_endpoint); +static struct check *check_table[] = { &duplicate_node_names, &duplicate_property_names, &node_name_chars, &node_name_format, &property_name_chars, - &name_is_string, &name_properties, + &name_is_string, &name_properties, &node_name_vs_property_name, &duplicate_label,@@ -1560,7 +1929,7 @@ static struct check *check_table[] = { &phandle_references, &path_references, &omit_unused_nodes, - &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, + &address_cells_is_cell, &size_cells_is_cell, &device_type_is_string, &model_is_string, &status_is_string, &label_is_string,@@ -1569,7 +1938,7 @@ static struct check *check_table[] = { &property_name_chars_strict, &node_name_chars_strict, - &addr_size_cells, ®_format, &ranges_format, + &addr_size_cells, ®_format, &ranges_format, &dma_ranges_format, &unit_address_vs_reg, &unit_address_format,@@ -1581,32 +1950,57 @@ static struct check *check_table[] = { &simple_bus_bridge, &simple_bus_reg, + &i2c_bus_bridge, + &i2c_bus_reg, + + &spi_bus_bridge, + &spi_bus_reg, + &avoid_default_addr_size, &avoid_unnecessary_addr_size, &unique_unit_address, + &unique_unit_address_if_enabled, &obsolete_chosen_interrupt_controller, &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path, &clocks_property, + &clocks_is_cell, &cooling_device_property, + &cooling_device_is_cell, &dmas_property, + &dmas_is_cell, &hwlocks_property, + &hwlocks_is_cell, &interrupts_extended_property, + &interrupts_extended_is_cell, &io_channels_property, + &io_channels_is_cell, &iommus_property, + &iommus_is_cell, &mboxes_property, + &mboxes_is_cell, &msi_parent_property, + &msi_parent_is_cell, &mux_controls_property, + &mux_controls_is_cell, &phys_property, + &phys_is_cell, &power_domains_property, + &power_domains_is_cell, &pwms_property, + &pwms_is_cell, &resets_property, + &resets_is_cell, &sound_dai_property, + &sound_dai_is_cell, &thermal_sensors_property, + &thermal_sensors_is_cell, &deprecated_gpio_property, &gpios_property, &interrupts_property, + &interrupt_provider, + &interrupt_map, &alias_paths,@@ -1630,7 +2024,7 @@ static void enable_warning_error(struct check *c, bool warn, bool error)static void disable_warning_error (struct check *c,bool warn,bool error) { -int i; +unsigned int i;/* Lowering level, also lower it for things this is the prereq * for */ @@ -1651,7 +2045,7 @@ static void disable_warning_error(struct check *c, bool warn, bool error)void parse_checks_option (bool warn,bool error,const char *arg) { -int i; +unsigned int i;const char *name = arg;bool enable = true;@@ -1678,7 +2072,7 @@ void parse_checks_option(bool warn, bool error, const char *arg)void process_checks (bool force,struct dt_info *dti) { -int i; +unsigned int i;int error =0 ;for (i =0 ; i <ARRAY_SIZE (check_table); i++) {scripts/dtc/data.c +49
-25@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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,10 +21,10 @@ void data_free(struct data d)free (d.val); } -struct data data_grow_for (struct data d,int xlen) +struct data data_grow_for (struct data d,unsigned int xlen) {struct data nd; -int newsize; +unsigned int newsize;if (xlen ==0 )return d;@@ -74,7 +59,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) {@@ -94,10 +80,11 @@ 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; -if (maxlen ==-1 ) +if (maxlen == (size_t )-1 ) chunksize =4096 ;else chunksize = maxlen - d.len;@@ -241,11 +228,7 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref) {struct marker *m; - m =xmalloc (sizeof (*m)); - m->offset = d.len; - m->type = type; - m->ref = ref; - m->next =NULL ; + m =alloc_marker (d.len, type, ref);return data_append_markers (d, m); }@@ -267,3 +250,44 @@ bool data_is_one_string(struct data d)return true; } + +struct data data_insert_data (struct data d,struct marker *m,struct data old) +{ +unsigned int offset = m->offset; +struct marker *next = m->next; +struct marker *marker; +struct data new_data; +char *ref; + + new_data =data_insert_at_marker (d, m, old.val, old.len); + +/* Copy all markers from old value */ + marker = old.markers; +for_each_marker (marker) { + ref =NULL ; + +if (marker->ref) + ref =xstrdup (marker->ref); + + m->next =alloc_marker (marker->offset + offset, marker->type, + ref); + m = m->next; + } + m->next = next; + +return new_data; +} + +struct marker *alloc_marker (unsigned int offset,enum markertype type, +char *ref) +{ +struct marker *m; + + m =xmalloc (sizeof (*m)); + m->offset = offset; + m->type = type; + m->ref = ref; + m->next =NULL ; + +return m; +}scripts/dtc/dtc-lexer.l +19
-19@@ -1,21 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) Copyright David Gibson <[email protected]>, 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@@ -72,7 +57,7 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); push_input_file(name); } -<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { +<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)* { char *line, *fnstart, *fnend; struct data fn; /* skip text before line # */@@ -166,6 +151,21 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); return DT_LABEL; } +<V1>{LABEL} { + /* Missed includes or macro definitions while + * preprocessing can lead to unexpected identifiers in + * the input. Report a slightly more informative error + * in this case */ + + lexical_error("Unexpected '%s'", yytext); + + /* Treat it as a literal which often generates further + * useful error messages */ + + yylval.integer = 0; + return DT_LITERAL; + } + <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? { char *e; DPRINT("Integer Literal: '%s'\n", yytext);@@ -212,14 +212,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} {scripts/dtc/dtc-parser.y +70
-39@@ -1,22 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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 */ +%locations + %{ #include <stdio.h> #include <inttypes.h>@@ -32,6 +19,8 @@ extern void yyerror(char const *s); treesource_error = true; \ } while (0) +#define YYERROR_CALL(msg) yyerror(msg) + extern struct dt_info *parser_output; extern bool treesource_error;@@ -76,7 +65,8 @@ static bool is_ref_relative(const char *ref) %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@@ -89,6 +79,7 @@ static bool is_ref_relative(const char *ref) %type <data> bytestring %type <prop> propdef %type <proplist> proplist +%type <labelref> dt_ref %type <node> devicetree %type <node> nodedef@@ -164,6 +155,8 @@ memreserve: } ; +dt_ref: DT_LABEL_REF | DT_PATH_REF; + devicetree: '/' nodedef {@@ -173,7 +166,7 @@ devicetree: { $$ = merge_nodes($1, $3); } - | DT_REF nodedef + | dt_ref nodedef { /* * We rely on the rule being always:@@ -184,9 +177,12 @@ devicetree: ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); - $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1); + $$ = add_orphan_node( + name_node(build_node(NULL, NULL, NULL), + ""), + $2, $1); } - | devicetree DT_LABEL DT_REF nodedef + | devicetree DT_LABEL dt_ref nodedef { struct node *target = get_node_by_ref($1, $3);@@ -200,7 +196,7 @@ 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:@@ -221,7 +217,26 @@ devicetree: } $$ = $1; } - | devicetree DT_DEL_NODE DT_REF ';' + | devicetree DT_LABEL_REF nodedef + { + struct node *target = get_node_by_ref($1, $2); + + if (target) { + merge_nodes(target, $3); + } 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 ';' { struct node *target = get_node_by_ref($1, $3);@@ -233,7 +248,7 @@ devicetree: $$ = $1; } - | devicetree DT_OMIT_NO_REF DT_REF ';' + | devicetree DT_OMIT_NO_REF dt_ref ';' { struct node *target = get_node_by_ref($1, $3);@@ -250,7 +265,7 @@ devicetree: nodedef: '{' proplist subnodes '}' ';' { - $$ = build_node($2, $3); + $$ = build_node($2, $3, &@$); } ;@@ -268,15 +283,18 @@ proplist: propdef: DT_PROPNODENAME '=' propdata ';' { - $$ = build_property($1, $3); + $$ = build_property($1, $3, &@$); + free($1); } | DT_PROPNODENAME ';' { - $$ = build_property($1, empty_data); + $$ = build_property($1, empty_data, &@$); + free($1); } | DT_DEL_PROP DT_PROPNODENAME ';' { $$ = build_property_delete($2); + free($2); } | DT_LABEL propdef {@@ -298,8 +316,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 ')'@@ -353,22 +372,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@@ -383,14 +407,19 @@ arrayprefix: * within the mask to one (i.e. | in the * mask), all bits are one. */ - if (($2 > mask) && (($2 | mask) != -1ULL)) - ERROR(&@2, "Value out of range for" - " %d-bit array element", $1.bits); + if (($2 > mask) && (($2 | mask) != -1ULL)) { + char *loc = srcpos_string(&@2); + fprintf(stderr, + "WARNING: %s: Value 0x%016" PRIx64 + " truncated to 0x%0*" PRIx64 "\n", + loc, $2, $1.bits / 4, ($2 & mask)); + free(loc); + } } $$.data = data_append_integer($1.data, $2, $1.bits); } - | arrayprefix DT_REF + | arrayprefix dt_ref { uint64_t val = ~0ULL >> (64 - $1.bits);@@ -468,8 +497,8 @@ integer_rela: ; integer_shift: - integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } - | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } + integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; } + | integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; } | integer_add ;@@ -512,7 +541,7 @@ integer_unary: bytestring: /* empty */ { - $$ = empty_data; + $$ = data_add_marker(empty_data, TYPE_UINT8, NULL); } | bytestring DT_BYTE {@@ -544,10 +573,12 @@ subnode: DT_PROPNODENAME nodedef { $$ = name_node($2, $1); + free($1); } | DT_DEL_NODE DT_PROPNODENAME ';' { - $$ = name_node(build_node_delete(), $2); + $$ = name_node(build_node_delete(&@$), $2); + free($2); } | DT_OMIT_NO_REF subnode {scripts/dtc/dtc.c +37
-21@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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> @@ -27,14 +12,16 @@* Command line options */ int quiet;/* Level of quietness */ -int reservenum;/* Number of memory reservation slots */ +unsigned 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 alignsize;/* Additional padding to blob according to the alignsize */ 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) {@@ -60,7 +47,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)/* Usage related data. */ 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:@LAThv" ;static struct option const usage_long_opts[] = { {"quiet" , no_argument,NULL ,'q' }, {"in-format" , a_argument,NULL ,'I' },@@ -80,7 +67,9 @@ static struct option const usage_long_opts[] = { {"warning", a_argument, NULL, 'W'}, {"error", a_argument, NULL, 'E'}, {"symbols", no_argument, NULL, '@'}, + {"local-fixups", no_argument, NULL, 'L'}, {"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},@@ -95,6 +84,9 @@ 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 "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)", "\n\tOutput dependency file",@@ -113,7 +105,9 @@ static const char * const usage_opts_help[] = {"\n\tEnable/disable warnings (prefix with \"no-\")" ,"\n\tEnable/disable errors (prefix with \"no-\")" ,"\n\tEnable generation of symbols" , +"\n\tPossibly generates a __local_fixups__ and a __fixups__ node at the root node" ,"\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,@@ -128,6 +122,10 @@ 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,".dtbo" )) +return "dtb" ;if (!strcasecmp (s,".dtb" ))return "dtb" ;return fallback;@@ -201,7 +199,7 @@ int main(int argc, char *argv[]) depname = optarg;break ;case 'R' : - reservenum =strtol (optarg,NULL ,0 ); + reservenum =strtoul (optarg,NULL ,0 );break ;case 'S' : minsize =strtol (optarg,NULL ,0 );@@ -256,9 +254,17 @@ int main(int argc, char *argv[])case '@' : generate_symbols =1 ;break ; + +case 'L' : + generate_fixups =1 ; +break ; +case 'A' : auto_label_aliases =1 ;break ; +case 'T' : + annotate++; +break ;case 'h' :usage (NULL );@@ -283,7 +289,9 @@ int main(int argc, char *argv[])if (!depfile)die ("Couldn't open dependency file %s: %s\n" , depname,strerror (errno)); -fprintf (depfile,"%s:" , outname); + +fprint_path_escaped (depfile, outname); +fputc (':' , depfile); }if (inform ==NULL )@@ -297,6 +305,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" ))@@ -350,6 +360,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" )) {scripts/dtc/dtc.h +106
-31@@ -1,24 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef DTC_H #define DTC_H /* * (C) Copyright David Gibson <[email protected]>, 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> @@ -50,14 +35,15 @@* Command line options */ extern int quiet;/* Level of quietness */ -extern int reservenum;/* Number of memory reservation slots */ +extern unsigned int reservenum;/* Number of memory reservation slots */ extern int minsize;/* Minimum blob size */ extern int padsize;/* Additional padding to blob */ -extern int alignsize;/* Additional padding to blob accroding to the alignsize */ +extern int alignsize;/* Additional padding to blob according to the alignsize */ 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@@ -65,28 +51,88 @@ extern int auto_label_aliases; /* auto generate labels -> aliases */typedef uint32_t cell_t ; +static inline bool phandle_is_valid (cell_t phandle) +{ +return phandle !=0 && phandle != ~0U ; +} + +static inline uint16_t dtb_ld16 (const void *p) +{ +const uint8_t *bp = (const uint8_t *)p; + +return ((uint16_t )bp[0 ] <<8 ) + | bp[1 ]; +} + +static inline uint32_t dtb_ld32 (const void *p) +{ +const uint8_t *bp = (const uint8_t *)p; + +return ((uint32_t )bp[0 ] <<24 ) + | ((uint32_t )bp[1 ] <<16 ) + | ((uint32_t )bp[2 ] <<8 ) + | bp[3 ]; +} + +static inline uint64_t dtb_ld64 (const void *p) +{ +const uint8_t *bp = (const uint8_t *)p; + +return ((uint64_t )bp[0 ] <<56 ) + | ((uint64_t )bp[1 ] <<48 ) + | ((uint64_t )bp[2 ] <<40 ) + | ((uint64_t )bp[3 ] <<32 ) + | ((uint64_t )bp[4 ] <<24 ) + | ((uint64_t )bp[5 ] <<16 ) + | ((uint64_t )bp[6 ] <<8 ) + | bp[7 ]; +} +#define streq (a, b) (strcmp((a), (b)) == 0)#define strstarts (s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)#define strprefixeq (a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0)) +static inline bool strends (const char *str,const char *suffix) +{ +unsigned int len, suffix_len; + + len =strlen (str); + suffix_len =strlen (suffix); +if (len < suffix_len) +return false; +return streq (str + len - suffix_len, suffix); +}#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 , }; +static inline bool is_type_marker (enum markertype type) +{ +return type >=TYPE_UINT8 ; +} + +extern const char *markername (enum markertype markertype); +struct marker {enum markertype type; -int offset; +unsigned int offset;char *ref;struct marker *next; };struct data { -int len; +unsigned int len;char *val;struct marker *markers; };@@ -99,9 +145,26 @@ struct data { for_each_marker(m) \ if ((m)->type == (t)) +static inline struct marker *next_type_marker(struct marker *m) +{ + for_each_marker(m) + if (is_type_marker(m->type)) + break; + return m; +} + +static inline size_t type_marker_length(struct marker *m) +{ + struct marker *next = next_type_marker(m->next); + + if (next) + return next->offset - m->offset; + return 0; +} + void data_free(struct data d); -struct data data_grow_for(struct data d, int xlen); +struct data data_grow_for(struct data d, unsigned int xlen); struct data data_copy_mem(const char *mem, int len); struct data data_copy_escape_string(const char *s, int len);@@ -118,7 +181,10 @@ struct data data_append_addr(struct data d, uint64_t addr);struct data data_append_byte (struct data d,uint8_t byte);struct data data_append_zeroes (struct data d,int len);struct data data_append_align (struct data d,int align); +struct data data_insert_data (struct data d,struct marker *m,struct data old); +struct marker *alloc_marker (unsigned int offset,enum markertype type, +char *ref);struct data data_add_marker (struct data d,enum markertype type,char *ref);bool data_is_one_string (struct data d);@@ -147,6 +213,7 @@ struct property {struct property *next;struct label *labels; +struct srcpos *srcpos; };struct node {@@ -166,6 +233,7 @@ struct node {struct label *labels;const struct bus_type *bus; +struct srcpos *srcpos;bool omit_if_unused, is_referenced; };@@ -194,14 +262,16 @@ 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_delete (char *name); +struct property *build_property (const char *name,struct data val, +struct srcpos *srcpos); +struct property *build_property_delete (const 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 *name_node (struct node *node,char *name); +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,const 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);@@ -215,12 +285,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); +cell_t propval_cell_n (struct property *prop,unsigned 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,@@ -266,9 +337,9 @@ struct dt_info *build_dt_info(unsigned int dtsflags,struct reserve_info *reservelist, struct node *tree, uint32_t boot_cpuid_phys);void sort_tree (struct dt_info *dti); -void generate_label_tree (struct dt_info *dti,char *name,bool allocph); -void generate_fixups_tree (struct dt_info *dti,char *name); -void generate_local_fixups_tree (struct dt_info *dti,char *name); +void generate_label_tree (struct dt_info *dti,const char *name,bool allocph); +void generate_fixups_tree (struct dt_info *dti,const char *name); +void generate_local_fixups_tree (struct dt_info *dti,const char *name);/* Checks */ @@ -287,6 +358,10 @@ 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);scripts/dtc/fdtoverlay.c new file +214
-0@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2017 Konsulko Group Inc. All rights reserved. +* +* Author: +* Pantelis Antoniou <[email protected]> +*/ + +#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>]]" ; +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; +bool has_symbols; + +/* +* We take copies first, because 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; + } + ret =fdt_path_offset (tmp,"/__symbols__" ); + has_symbols = ret >=0 ; + +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)); +if (!has_symbols) { +fprintf (stderr, +"base blob does not have a '/__symbols__' node, " +"make sure you have compiled the base blob with '-@' option\n" ); + } + 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; + } + +/* 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 ; +}scripts/dtc/flattree.c +27
-43@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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" @@ -139,7 +124,8 @@ static void asm_emit_cell(void *e, cell_t val) {FILE *f = e; -fprintf (f,"\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n" , +fprintf (f,"\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n" +"\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n" , (val >>24 ) &0xff , (val >>16 ) &0xff , (val >>8 ) &0xff , val &0xff ); }@@ -149,9 +135,9 @@ static void asm_emit_string(void *e, const char *str, int len)FILE *f = e;if (len !=0 ) -fprintf (f,"\t.string\t\"%.*s\"\n" , len, str); +fprintf (f,"\t.asciz\t\"%.*s\"\n" , len, str);else -fprintf (f,"\t.string\t\"%s\"\n" , str); +fprintf (f,"\t.asciz\t\"%s\"\n" , str); }static void asm_emit_align (void *e,int a)@@ -164,14 +150,14 @@ static void asm_emit_align(void *e, int a)static void asm_emit_data (void *e,struct data d) {FILE *f = e; -int off =0 ; +unsigned int off =0 ;struct marker *m = d.markers;for_each_marker_of_type (m,LABEL )emit_offset_label (f, m->ref, m->offset);while ((d.len - off) >=sizeof (uint32_t )) { -asm_emit_cell (e,fdt32_to_cpu (*((fdt32_t *)(d.val+off)))); +asm_emit_cell (e,dtb_ld32 (d.val + off)); off +=sizeof (uint32_t ); }@@ -234,7 +220,7 @@ static struct emitter asm_emitter = {static int stringtable_insert (struct data *d,const char *str) { -int i; +unsigned int i;/* FIXME: do this more efficiently? */ @@ -310,7 +296,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist, {struct reserve_info *re;struct data d = empty_data; -int j; +unsigned int j;for (re = reservelist; re; re = re->next) { d =data_append_re (d, re->address, re->size);@@ -360,7 +346,7 @@ static void make_fdt_header(struct fdt_header *fdt,void dt_to_blob (FILE *f,struct dt_info *dti,int version) {struct version_info *vi =NULL ; -int i; +unsigned int i;struct data blob = empty_data;struct data reservebuf = empty_data;struct data dtbuf = empty_data;@@ -393,7 +379,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); } }@@ -453,7 +439,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)while (p < (strbuf.val + strbuf.len)) { len =strlen (p); -fprintf (f,"\t.string \"%s\"\n" , p); +fprintf (f,"\t.asciz \"%s\"\n" , p); p += len+1 ; } }@@ -461,7 +447,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)void dt_to_asm (FILE *f,struct dt_info *dti,int version) {struct version_info *vi =NULL ; -int i; +unsigned int i;struct data strbuf = empty_data;struct reserve_info *re;const char *symprefix ="dt" ;@@ -517,7 +503,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)* Reserve map entries. * Align the reserve map to a doubleword boundary. * Each entry is an (address, size) pair of u64 values. -* Always supply a zero-sized temination entry. +* Always supply a zero-sized termination entry. */ asm_emit_align (f,8 );emit_label (f, symprefix,"reserve_map" );@@ -525,7 +511,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) {@@ -618,11 +604,11 @@ static void flat_realign(struct inbuf *inb, int align)die ("Premature end of data parsing flat device tree\n" ); } -static char *flat_read_string (struct inbuf *inb) +static const char *flat_read_string (struct inbuf *inb) {int len =0 ;const char *p = inb->ptr; -char *str; +const char *str; do { if (p >= inb->limit)@@ -630,7 +616,7 @@ static char *flat_read_string(struct inbuf *inb) len++; }while ((*p++) !='\0' ); - str =xstrdup (inb->ptr); + str = inb->ptr; inb->ptr += len;@@ -692,7 +678,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 ); }static struct reserve_info *flat_read_mem_reserve (struct inbuf *inb)@@ -723,7 +709,8 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)return reservelist; } -static char *nodename_from_path (const char *ppath,const char *cpath) + +static const char *nodename_from_path (const char *ppath,const char *cpath) {int plen;@@ -737,7 +724,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)if (!streq (ppath,"/" )) plen++; -return xstrdup (cpath + plen); +return cpath + plen; } static struct node *unflatten_tree(struct inbuf *dtbuf,@@ -745,17 +732,18 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, const char *parent_flatname, int flags) {struct node *node; -char *flatname; +const char *flatname;uint32_t val; - node =build_node (NULL ,NULL ); + node =build_node (NULL ,NULL ,NULL ); flatname =flat_read_string (dtbuf);if (flags &FTF_FULLPATH ) - node->name =nodename_from_path (parent_flatname, flatname); + node->name =xstrdup (nodename_from_path (parent_flatname, + flatname));else - node->name = flatname; + node->name =xstrdup (flatname); do { struct property *prop;@@ -797,10 +785,6 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, } }while (val !=FDT_END_NODE ); -if (node->name != flatname) { -free (flatname); - } -return node; }scripts/dtc/fstree.c +6
-20@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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" @@ -34,7 +19,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;@@ -45,7 +30,7 @@ static struct node *read_fstree(const char *dirname) tmpname =join_path (dirname, de->d_name); -if (lstat (tmpname, &st) <0 ) +if (stat (tmpname, &st) <0 )die ("stat(%s): %s\n" , tmpname,strerror (errno));if (S_ISREG (st.st_mode)) {@@ -58,9 +43,10 @@ static struct node *read_fstree(const char *dirname)"WARNING: Cannot open %s: %s\n" , tmpname, strerror(errno)); }else { - prop =build_property (xstrdup (de->d_name), + prop =build_property (de->d_name,data_copy_file (pfile, - st.st_size)); + st.st_size), +NULL );add_property (tree, prop);fclose (pfile); }scripts/dtc/libfdt/fdt.c +52
-32@@ -19,9 +19,16 @@ int32_t fdt_ro_probe_(const void *fdt) {uint32_t totalsize =fdt_totalsize (fdt); +if (can_assume (VALID_DTB )) +return totalsize; + +/* The device tree must be at an 8-byte aligned address */ +if ((uintptr_t )fdt &7 ) +return -FDT_ERR_ALIGNMENT ; +if (fdt_magic (fdt) ==FDT_MAGIC ) {/* Complete tree */ -if (fdt_chk_version ()) { +if (!can_assume (LATEST )) {if (fdt_version (fdt) <FDT_FIRST_SUPPORTED_VERSION )return -FDT_ERR_BADVERSION ; if (fdt_last_comp_version(fdt) >@@ -30,7 +37,7 @@ int32_t fdt_ro_probe_(const void *fdt) } }else if (fdt_magic (fdt) ==FDT_SW_MAGIC ) {/* Unfinished sequential-write blob */ -if (fdt_size_dt_struct (fdt) ==0 ) +if (!can_assume (VALID_INPUT ) &&fdt_size_dt_struct (fdt) ==0 )return -FDT_ERR_BADSTATE ; }else {return -FDT_ERR_BADMAGIC ;@@ -75,17 +82,21 @@ size_t fdt_header_size_(uint32_t version)size_t fdt_header_size (const void *fdt) { -return fdt_chk_version () ?fdt_header_size_ (fdt_version (fdt)) : -FDT_V17_SIZE ; +return can_assume (LATEST ) ?FDT_V17_SIZE : +fdt_header_size_ (fdt_version (fdt)); }int fdt_check_header (const void *fdt) {size_t hdrsize; +/* The device tree must be at an 8-byte aligned address */ +if ((uintptr_t )fdt &7 ) +return -FDT_ERR_ALIGNMENT ; +if (fdt_magic (fdt) !=FDT_MAGIC )return -FDT_ERR_BADMAGIC ; -if (fdt_chk_version ()) { +if (!can_assume (LATEST )) {if ((fdt_version (fdt) <FDT_FIRST_SUPPORTED_VERSION ) || (fdt_last_comp_version (fdt) >FDT_LAST_SUPPORTED_VERSION ))@@ -94,8 +105,7 @@ int fdt_check_header(const void *fdt)return -FDT_ERR_BADVERSION ; } hdrsize =fdt_header_size (fdt); -if (fdt_chk_basic ()) { - +if (!can_assume (VALID_DTB )) {if ((fdt_totalsize (fdt) < hdrsize) || (fdt_totalsize (fdt) >INT_MAX ))return -FDT_ERR_TRUNCATED ;@@ -104,11 +114,9 @@ int fdt_check_header(const void *fdt)if (!check_off_ (hdrsize,fdt_totalsize (fdt),fdt_off_mem_rsvmap (fdt)))return -FDT_ERR_TRUNCATED ; - } -if (fdt_chk_extra ()) {/* Bounds check structure block */ -if (fdt_chk_version () &&fdt_version (fdt) <17 ) { +if (!can_assume (LATEST ) &&fdt_version (fdt) <17 ) {if (!check_off_ (hdrsize,fdt_totalsize (fdt),fdt_off_dt_struct (fdt)))return -FDT_ERR_TRUNCATED ;@@ -137,13 +145,13 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)if (offset <0 )return NULL ; -if (fdt_chk_basic ()) +if (!can_assume (VALID_INPUT ))if ((absoffset < uoffset) || ((absoffset + len) < absoffset) || (absoffset + len) >fdt_totalsize (fdt))return NULL ; -if (!fdt_chk_version () ||fdt_version (fdt) >=0x11 ) +if (can_assume (LATEST ) ||fdt_version (fdt) >=0x11 )if (((uoffset + len) < uoffset) || ((offset + len) >fdt_size_dt_struct (fdt)))return NULL ;@@ -154,13 +162,13 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)uint32_t fdt_next_tag (const void *fdt,int startoffset,int *nextoffset) {const fdt32_t *tagp, *lenp; -uint32_t tag; +uint32_t tag, len, sum;int offset = startoffset;const char *p; *nextoffset = -FDT_ERR_TRUNCATED ; tagp =fdt_offset_ptr (fdt, offset,FDT_TAGSIZE ); -if (fdt_chk_basic () && !tagp) +if (!can_assume (VALID_DTB ) && !tagp)return FDT_END ;/* premature end */ tag =fdt32_to_cpu (*tagp); offset +=FDT_TAGSIZE ;@@ -172,20 +180,27 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)do { p =fdt_offset_ptr (fdt, offset++,1 ); }while (p && (*p !='\0' )); -if (fdt_chk_basic () && !p) +if (!can_assume (VALID_DTB ) && !p)return FDT_END ;/* premature end */ break ;case FDT_PROP : lenp =fdt_offset_ptr (fdt, offset,sizeof (*lenp)); -if (fdt_chk_basic () && !lenp) +if (!can_assume (VALID_DTB ) && !lenp)return FDT_END ;/* premature end */ + + len =fdt32_to_cpu (*lenp); + sum = len + offset; +if (!can_assume (VALID_DTB ) && + (INT_MAX <= sum || sum < (uint32_t ) offset)) +return FDT_END ;/* premature end */ +/* skip-name offset, length and value */ - offset +=sizeof (struct fdt_property ) -FDT_TAGSIZE - +fdt32_to_cpu (*lenp); -if (fdt_chk_version () && -fdt_version (fdt) <0x10 &&fdt32_to_cpu (*lenp) >=8 && - ((offset -fdt32_to_cpu (*lenp)) %8 ) !=0 ) + offset +=sizeof (struct fdt_property ) -FDT_TAGSIZE + len; + +if (!can_assume (LATEST ) && +fdt_version (fdt) <0x10 && len >=8 && + ((offset - len) %8 ) !=0 ) offset +=4 ;break ;@@ -198,8 +213,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)return FDT_END ; } -if (fdt_chk_basic () && - !fdt_offset_ptr (fdt, startoffset, offset - startoffset)) +if (!fdt_offset_ptr (fdt, startoffset, offset - startoffset))return FDT_END ;/* premature end */ *nextoffset =FDT_TAGALIGN (offset);@@ -208,8 +222,11 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)int fdt_check_node_offset_ (const void *fdt,int offset) { -if ((offset <0 ) || (offset %FDT_TAGSIZE ) - || (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )) +if (!can_assume (VALID_INPUT ) + && ((offset <0 ) || (offset %FDT_TAGSIZE ))) +return -FDT_ERR_BADOFFSET ; + +if (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )return -FDT_ERR_BADOFFSET ;return offset;@@ -217,8 +234,11 @@ int fdt_check_node_offset_(const void *fdt, int offset)int fdt_check_prop_offset_ (const void *fdt,int offset) { -if ((offset <0 ) || (offset %FDT_TAGSIZE ) - || (fdt_next_tag (fdt, offset, &offset) !=FDT_PROP )) +if (!can_assume (VALID_INPUT ) + && ((offset <0 ) || (offset %FDT_TAGSIZE ))) +return -FDT_ERR_BADOFFSET ; + +if (fdt_next_tag (fdt, offset, &offset) !=FDT_PROP )return -FDT_ERR_BADOFFSET ;return offset;@@ -292,21 +312,21 @@ int fdt_next_subnode(const void *fdt, int offset)return offset; } -const char *fdt_find_string_ (const char *strtab,int tabsize,const char *s) +const char *fdt_find_string_len_ (const char *strtab,int tabsize,const char *s, +int slen) { -int len =strlen (s) +1 ; -const char *last = strtab + tabsize - len; +const char *last = strtab + tabsize - (slen +1 );const char *p;for (p = strtab; p <= last; p++) -if (memcmp (p, s, len) ==0 ) +if (memcmp (p, s, slen) ==0 && p[slen] =='\0' )return p;return NULL ; }int fdt_move (const void *fdt,void *buf,int bufsize) { -if (fdt_chk_basic () && bufsize <0 ) +if (!can_assume (VALID_INPUT ) && bufsize <0 )return -FDT_ERR_NOSPACE ;FDT_RO_PROBE (fdt);scripts/dtc/libfdt/fdt.h +2
-2@@ -7,7 +7,7 @@* Copyright 2012 Kim Phillips, Freescale Semiconductor. */ -#ifndef __ASSEMBLY__ +#ifndef __ASSEMBLER__ struct fdt_header { fdt32_t magic; /* magic word FDT_MAGIC */@@ -45,7 +45,7 @@ struct fdt_property { char data[0]; }; -#endif /* !__ASSEMBLY */ +#endif /* !__ASSEMBLER__ */ #define FDT_MAGIC 0xd00dfeed/* 4: version, 4: total size */ #define FDT_TAGSIZE sizeof(fdt32_t)scripts/dtc/libfdt/fdt_addresses.c +1
-1@@ -73,7 +73,7 @@ int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,/* check validity of address */ prop = data;if (addr_cells ==1 ) { -if ((addr >UINT32_MAX ) || ((UINT32_MAX +1 - addr) < size)) +if ((addr >UINT32_MAX ) || (((uint64_t )UINT32_MAX +1 - addr) < size))return -FDT_ERR_BADVALUE ;fdt32_st (prop, (uint32_t )addr);scripts/dtc/libfdt/fdt_overlay.c +302
-84@@ -40,37 +40,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)return fdt32_to_cpu (*val); } -/** -* overlay_get_target - retrieves the offset of a fragment's target -* @fdt: Base device tree blob -* @fdto: Device tree overlay blob -* @fragment: node offset of the fragment in the overlay -* @pathp: pointer which receives the path of the target (or NULL) -* -* overlay_get_target() retrieves the target offset in the base -* device tree of a fragment, no matter how the actual targeting is -* done (through a phandle or a path) -* -* returns: -* the targeted node offset in the base device tree -* Negative error code on error -*/ -static int overlay_get_target (const void *fdt,const void *fdto, -int fragment,char const **pathp) +int fdt_overlay_target_offset (const void *fdt,const void *fdto, +int fragment_offset,char const **pathp) {uint32_t phandle;const char *path =NULL ;int path_len =0 , ret;/* Try first to do a phandle based lookup */ - phandle =overlay_get_target_phandle (fdto, fragment); + phandle =overlay_get_target_phandle (fdto, fragment_offset);if (phandle == (uint32_t )-1 )return -FDT_ERR_BADPHANDLE ;/* no phandle, try path */ if (!phandle) {/* And then a path based lookup */ - path =fdt_getprop (fdto, fragment,"target-path" , &path_len); + path =fdt_getprop (fdto, fragment_offset,"target-path" , &path_len);if (path) ret =fdt_path_offset (fdt, path);else @@ -116,26 +101,22 @@ static int overlay_get_target(const void *fdt, const void *fdto,static int overlay_phandle_add_offset (void *fdt,int node,const char *name,uint32_t delta) { -const fdt32_t *val; -uint32_t adj_val; +fdt32_t *valp, val;int len; - val =fdt_getprop (fdt, node, name, &len); -if (!val) + valp =fdt_getprop_w (fdt, node, name, &len); +if (!valp)return len; -if (len !=sizeof (*val)) +if (len !=sizeof (val))return -FDT_ERR_BADPHANDLE ; - adj_val =fdt32_to_cpu (*val); -if ((adj_val + delta) < adj_val) + val =fdt32_ld (valp); +if (val + delta < val || val + delta == (uint32_t )-1 )return -FDT_ERR_NOPHANDLES ; - adj_val += delta; -if (adj_val == (uint32_t )-1 ) -return -FDT_ERR_NOPHANDLES ; - -return fdt_setprop_inplace_u32 (fdt, node, name, adj_val); +fdt32_st (valp, val + delta); +return 0 ; }/** @@ -228,8 +209,8 @@ static int overlay_update_local_node_references(void *fdto,fdt_for_each_property_offset (fixup_prop, fdto, fixup_node) {const fdt32_t *fixup_val; -const char *tree_val;const char *name; +char *tree_val;int fixup_len;int tree_len;int i;@@ -243,7 +224,7 @@ static int overlay_update_local_node_references(void *fdto,return -FDT_ERR_BADOVERLAY ; fixup_len /=sizeof (uint32_t ); - tree_val =fdt_getprop (fdto, tree_node, name, &tree_len); + tree_val =fdt_getprop_w (fdto, tree_node, name, &tree_len);if (!tree_val) {if (tree_len == -FDT_ERR_NOTFOUND )return -FDT_ERR_BADOVERLAY ;@@ -252,33 +233,15 @@ static int overlay_update_local_node_references(void *fdto, }for (i =0 ; i < fixup_len; i++) { -fdt32_t adj_val; -uint32_t poffset; +fdt32_t *refp; - poffset =fdt32_to_cpu (fixup_val[i]); + refp = (fdt32_t *)(tree_val +fdt32_ld_ (fixup_val + i));/* -* phandles to fixup can be unaligned. -* -* Use a memcpy for the architectures that do -* not support unaligned accesses. +* phandles to fixup can be unaligned, so use +* fdt32_{ld,st}() to read/write them. */ -memcpy (&adj_val, tree_val + poffset,sizeof (adj_val)); - - adj_val =cpu_to_fdt32 (fdt32_to_cpu (adj_val) + delta); - - ret =fdt_setprop_inplace_namelen_partial (fdto, - tree_node, - name, -strlen (name), - poffset, - &adj_val, -sizeof (adj_val)); -if (ret == -FDT_ERR_NOSPACE ) -return -FDT_ERR_BADOVERLAY ; - -if (ret) -return ret; +fdt32_st (refp,fdt32_ld (refp) + delta); } }@@ -344,7 +307,6 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)/** * overlay_fixup_one_phandle - Set an overlay phandle to the base one -* @fdt: Base Device Tree blob * @fdto: Device tree overlay blob * @symbols_off: Node offset of the symbols node in the base device tree * @path: Path to a node holding a phandle in the overlay @@ -352,7 +314,7 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)* @name: Name of the property holding the phandle reference in the overlay * @name_len: number of name characters to consider * @poffset: Offset within the overlay property where the phandle is stored -* @label: Label of the node referenced by the phandle +* @phandle: Phandle referencing the node * * overlay_fixup_one_phandle() resolves an overlay phandle pointing to * a node in the base device tree. @@ -365,34 +327,17 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)* 0 on success * Negative error code on failure */ -static int overlay_fixup_one_phandle (void *fdt,void *fdto, -int symbols_off, +static int overlay_fixup_one_phandle (void *fdto,int symbols_off,const char *path,uint32_t path_len,const char *name,uint32_t name_len, -int poffset,const char *label) +int poffset,uint32_t phandle) { -const char *symbol_path; -uint32_t phandle;fdt32_t phandle_prop; -int symbol_off, fixup_off; -int prop_len; +int fixup_off;if (symbols_off <0 )return symbols_off; - symbol_path =fdt_getprop (fdt, symbols_off, label, - &prop_len); -if (!symbol_path) -return prop_len; - - symbol_off =fdt_path_offset (fdt, symbol_path); -if (symbol_off <0 ) -return symbol_off; - - phandle =fdt_get_phandle (fdt, symbol_off); -if (!phandle) -return -FDT_ERR_NOTFOUND ; - fixup_off =fdt_path_offset_namelen (fdto, path, path_len);if (fixup_off == -FDT_ERR_NOTFOUND )return -FDT_ERR_BADOVERLAY ;@@ -404,7 +349,7 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto, name, name_len, poffset, &phandle_prop, sizeof(phandle_prop)); -}; +}/** * overlay_fixup_phandle - Set an overlay phandle to the base one @@ -431,6 +376,10 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,const char *value;const char *label;int len; +const char *symbol_path; +int prop_len; +int symbol_off; +uint32_t phandle; value =fdt_getprop_by_offset (fdto, property, &label, &len);@@ -441,6 +390,18 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,return len; } + symbol_path =fdt_getprop (fdt, symbols_off, label, &prop_len); +if (!symbol_path) +return prop_len; + + symbol_off =fdt_path_offset (fdt, symbol_path); +if (symbol_off <0 ) +return symbol_off; + + phandle =fdt_get_phandle (fdt, symbol_off); +if (!phandle) +return -FDT_ERR_NOTFOUND ; + do { const char *path, *name, *fixup_end; const char *fixup_str = value;@@ -480,9 +441,9 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,if ((*endptr !='\0' ) || (endptr <= (sep +1 )))return -FDT_ERR_BADOVERLAY ; - ret =overlay_fixup_one_phandle (fdt, fdto, symbols_off, + ret =overlay_fixup_one_phandle (fdto, symbols_off, path, path_len, name, name_len, - poffset, label); + poffset, phandle);if (ret)return ret; }while (len >0 );@@ -535,6 +496,255 @@ static int overlay_fixup_phandles(void *fdt, void *fdto)return 0 ; } +/** +* overlay_adjust_local_conflicting_phandle: Changes a phandle value +* @fdto: Device tree overlay +* @node: The node the phandle is set for +* @fdt_phandle: The new value for the phandle +* +* returns: +* 0 on success +* Negative error code on failure +*/ +static int overlay_adjust_local_conflicting_phandle (void *fdto,int node, +uint32_t fdt_phandle) +{ +const fdt32_t *php; +int len, ret; + + php =fdt_getprop (fdto, node,"phandle" , &len); +if (php && len ==sizeof (*php)) { + ret =fdt_setprop_inplace_u32 (fdto, node,"phandle" , fdt_phandle); +if (ret) +return ret; + } + + php =fdt_getprop (fdto, node,"linux,phandle" , &len); +if (php && len ==sizeof (*php)) { + ret =fdt_setprop_inplace_u32 (fdto, node,"linux,phandle" , fdt_phandle); +if (ret) +return ret; + } + +return 0 ; +} + +/** +* overlay_update_node_conflicting_references - Recursively replace phandle values +* @fdto: Device tree overlay blob +* @tree_node: Node to recurse into +* @fixup_node: Node offset of the matching local fixups node +* @fdt_phandle: Value to replace phandles with +* @fdto_phandle: Value to be replaced +* +* Replaces all phandles with value @fdto_phandle by @fdt_phandle. +* +* returns: +* 0 on success +* Negative error code on failure +*/ +static int overlay_update_node_conflicting_references (void *fdto,int tree_node, +int fixup_node, +uint32_t fdt_phandle, +uint32_t fdto_phandle) +{ +int fixup_prop; +int fixup_child; +int ret; + +fdt_for_each_property_offset (fixup_prop, fdto, fixup_node) { +const fdt32_t *fixup_val; +const char *name; +char *tree_val; +int fixup_len; +int tree_len; +int i; + + fixup_val =fdt_getprop_by_offset (fdto, fixup_prop, + &name, &fixup_len); +if (!fixup_val) +return fixup_len; + +if (fixup_len %sizeof (uint32_t )) +return -FDT_ERR_BADOVERLAY ; + fixup_len /=sizeof (uint32_t ); + + tree_val =fdt_getprop_w (fdto, tree_node, name, &tree_len); +if (!tree_val) { +if (tree_len == -FDT_ERR_NOTFOUND ) +return -FDT_ERR_BADOVERLAY ; + +return tree_len; + } +Lines of this file are not shown. View the raw message.
scripts/dtc/libfdt/libfdt_internal.h +102
-39Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
CC+: TI folks
Quoted 7,070 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Are we ensuring the fdt present in the SPL binary is properly aligned?
Regards,
AnshulQuoted 6,995 lines
---
V2: - Fix off-by-one infdt_remove_unused_strings()
- Restoree8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt")--- scripts/Makefile.lib | 4 +- scripts/dtc/.gitignore | 1 + scripts/dtc/Makefile | 23 +- scripts/dtc/Makefile.dtc | 18 - scripts/dtc/checks.c | 686 +++++++++++++++++++++------ scripts/dtc/data.c | 74 ++- scripts/dtc/dtc-lexer.l | 38 +- scripts/dtc/dtc-parser.y | 109 +++-- scripts/dtc/dtc.c | 58 ++- scripts/dtc/dtc.h | 137 ++++-- scripts/dtc/fdtoverlay.c | 214 +++++++++ scripts/dtc/flattree.c | 70 ++- scripts/dtc/fstree.c | 26 +- scripts/dtc/libfdt/fdt.c | 84 ++-- scripts/dtc/libfdt/fdt.h | 4 +- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/fdt_overlay.c | 386 +++++++++++---- scripts/dtc/libfdt/fdt_ro.c | 100 ++-- scripts/dtc/libfdt/fdt_rw.c | 101 ++-- scripts/dtc/libfdt/fdt_strerror.c | 1 + scripts/dtc/libfdt/fdt_sw.c | 26 +- scripts/dtc/libfdt/libfdt.h | 414 +++++++++++++--- scripts/dtc/libfdt/libfdt_internal.h | 141 ++++-- scripts/dtc/livetree.c | 156 +++--- scripts/dtc/srcpos.c | 190 ++++++-- scripts/dtc/srcpos.h | 31 +- scripts/dtc/treesource.c | 319 ++++++++----- scripts/dtc/update-dtc-source.sh | 7 +- scripts/dtc/util.c | 122 ++--- scripts/dtc/util.h | 61 +-- scripts/dtc/version_gen.h | 2 +- scripts/dtc/yamltree.c | 235 +++++++++ tools/libfdt/fdt_rw.c | 2 +- 33 files changed, 2830 insertions(+), 1012 deletions(-) delete mode 100644 scripts/dtc/Makefile.dtc create mode 100644 scripts/dtc/fdtoverlay.c create mode 100644 scripts/dtc/yamltree.cscripts/Makefile.lib +3
-1@@ -319,6 +319,7 @@ quiet_cmd_gzip = GZIP $@ # DTC # --------------------------------------------------------------------------- DTC ?= $(objtree)/scripts/dtc/dtc +DTC_FLAGS += -Wno-interrupt_provider # Disable noisy checks by default ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)@@ -338,7 +339,8 @@ endif ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) DTC_FLAGS += -Wnode_name_chars_strict \ - -Wproperty_name_chars_strict + -Wproperty_name_chars_strict \ + -Winterrupt_provider endif DTC_FLAGS += $(DTC_FLAGS_$(basetarget))scripts/dtc/.gitignore +1
-0@@ -1 +1,2 @@ /dtc +/fdtoverlayscripts/dtc/Makefile +20
-3@@ -1,15 +1,32 @@ # SPDX-License-Identifier: GPL-2.0 # scripts/dtc makefile -hostprogs-y := dtc -always := $(hostprogs-y) +# *** Also keep .gitignore in sync when changing *** +hostprogs-y += dtc fdtoverlay +always += dtc dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ srcpos.o checks.o util.o dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o +# The upstream project builds libfdt as a separate library. We are choosing to +# instead directly link the libfdt object files into fdtoverlay. +libfdt-objs := fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o +libfdt = $(addprefix libfdt/,$(libfdt-objs)) +fdtoverlay-objs := $(libfdt) fdtoverlay.o util.o + # Source files need to get at the userspace version of libfdt_env.h to compile -HOST_EXTRACFLAGS := -I$(src)/libfdt +HOST_EXTRACFLAGS += -I$(src)/libfdt + +ifeq ($(wildcard /usr/include/yaml.h),) +HOST_EXTRACFLAGS += -DNO_YAML +else +dtc-objs += yamltree.o +# To include <yaml.h> installed in a non-default path +HOSTCFLAGS_yamltree.o := $(shell pkg-config --cflags yaml-0.1) +# To link libyaml installed in a non-default path +HOSTLDLIBS_dtc := $(shell pkg-config --libs yaml-0.1) +endif # Generated files need one more search path to include headers in source tree HOSTCFLAGS_dtc-lexer.lex.o := -I$(src)scripts/dtc/Makefile.dtc deleted +0
-18@@ -1,18 +0,0 @@ -# Makefile.dtc -# -# This is not a complete Makefile of itself. Instead, it is designed to -# be easily embeddable into other systems of Makefiles. -# -DTC_SRCS = \ - checks.c \ - data.c \ - dtc.c \ - flattree.c \ - fstree.c \ - livetree.c \ - srcpos.c \ - treesource.c \ - util.c - -DTC_GEN_SRCS = dtc-lexer.lex.c dtc-parser.tab.c -DTC_OBJS = $(DTC_SRCS:%.c=%.o) $(DTC_GEN_SRCS:%.c=%.o)scripts/dtc/checks.c +540
-146@@ -1,24 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, IBM Corporation. 2007. -* -* -* 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" #ifdef TRACE_CHECKS #define TRACE (c, ...) \@@ -45,7 +31,7 @@ typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *nodestruct check {const char *name;check_fn fn; -void *data; +const void *data;bool warn, error;enum checkstatus status;bool inprogress;@@ -78,23 +64,57 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti, const char *fmt, ...) {va_list ap; -va_start (ap, fmt); +char *str =NULL ; +struct srcpos *pos =NULL ; +char *file_str; + +if (!(c->warn && (quiet <1 )) && !(c->error && (quiet <2 ))) +return ; -if ((c->warn && (quiet <1 )) - || (c->error && (quiet <2 ))) { -fprintf (stderr,"%s: %s (%s): " , -strcmp (dti->outname,"-" ) ? dti->outname :"<stdout>" , +if (prop && prop->srcpos) + pos = prop->srcpos; +else if (node && node->srcpos) + pos = node->srcpos; + +if (pos) { + file_str =srcpos_string (pos); +xasprintf (&str,"%s" , file_str); +free (file_str); + }else if (streq (dti->outname,"-" )) { +xasprintf (&str,"<stdout>" ); + }else { +xasprintf (&str,"%s" , dti->outname); + } + +xasprintf_append (&str,": %s (%s): " , (c->error) ?"ERROR" :"Warning" , c->name); -if (node) { -fprintf (stderr,"%s" , node->fullpath); -if (prop) -fprintf (stderr,":%s" , prop->name); -fputs (": " , stderr); - } -vfprintf (stderr, fmt, ap); -fprintf (stderr,"\n" ); + +if (node) { +if (prop) +xasprintf_append (&str,"%s:%s: " , node->fullpath, prop->name); +else +xasprintf_append (&str,"%s: " , node->fullpath); } + +va_start (ap, fmt); +xavsprintf_append (&str, fmt, ap);va_end (ap); + +xasprintf_append (&str,"\n" ); + +if (!prop && pos) { + pos = node->srcpos; +while (pos->next) { + pos = pos->next; + + file_str =srcpos_string (pos); +xasprintf_append (&str," also defined at %s\n" , file_str); +free (file_str); + } + } + +fputs (str, stderr); +free (str); }#define FAIL (c, dti, node, ...) \@@ -123,6 +143,14 @@ static void check_nodes_props(struct check *c, struct dt_info *dti, struct nodecheck_nodes_props (c, dti, child); } +static bool is_multiple_of (int multiple,int divisor) +{ +if (divisor ==0 ) +return multiple ==0 ; +else +return (multiple % divisor) ==0 ; +} +static bool run_check (struct check *c,struct dt_info *dti) {struct node *dt = dti->dt;@@ -179,7 +207,7 @@ static void check_is_string(struct check *c, struct dt_info *dti, struct node *node) {struct property *prop; -char *propname = c->data; +const char *propname = c->data; prop =get_property (node, propname);if (!prop)@@ -198,7 +226,7 @@ static void check_is_string_list(struct check *c, struct dt_info *dti, {int rem, l;struct property *prop; -char *propname = c->data; +const char *propname = c->data;char *str; prop =get_property (node, propname);@@ -226,7 +254,7 @@ static void check_is_cell(struct check *c, struct dt_info *dti, struct node *node) {struct property *prop; -char *propname = c->data; +const char *propname = c->data; prop =get_property (node, propname);if (!prop)@@ -277,19 +305,20 @@ ERROR(duplicate_property_names, check_duplicate_property_names, NULL);#define LOWERCASE "abcdefghijklmnopqrstuvwxyz"#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"#define DIGITS "0123456789" -#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" +#define NODECHARS LOWERCASE UPPERCASE DIGITS ",._+-@" +#define PROPCHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"#define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"static void check_node_name_chars (struct check *c,struct dt_info *dti,struct node *node) { -int n =strspn (node->name, c->data); +size_t n =strspn (node->name, c->data);if (n <strlen (node->name))FAIL (c, dti, node,"Bad character '%c' in node name" , node->name[n]); } -ERROR (node_name_chars, check_node_name_chars,PROPNODECHARS "@" ); +ERROR (node_name_chars, check_node_name_chars,NODECHARS );static void check_node_name_chars_strict (struct check *c,struct dt_info *dti,struct node *node)@@ -310,6 +339,20 @@ static void check_node_name_format(struct check *c, struct dt_info *dti, }ERROR (node_name_format, check_node_name_format,NULL , &node_name_chars); +static void check_node_name_vs_property_name (struct check *c, +struct dt_info *dti, +struct node *node) +{ +if (!node->parent) +return ; + +if (get_property (node->parent, node->name)) { +FAIL (c, dti, node,"node name and property name conflict" ); + } +} +WARNING (node_name_vs_property_name, check_node_name_vs_property_name, +NULL , &node_name_chars); +static void check_unit_address_vs_reg (struct check *c,struct dt_info *dti,struct node *node) {@@ -332,7 +375,7 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,FAIL (c, dti, node,"node has a reg or ranges property, but no unit name" ); }else {if (unitname[0 ]) -FAIL (c, dti, node,"node has a unit name, but no reg property" ); +FAIL (c, dti, node,"node has a unit name, but no reg or ranges property" ); } }WARNING (unit_address_vs_reg, check_unit_address_vs_reg,NULL );@@ -343,14 +386,14 @@ static void check_property_name_chars(struct check *c, struct dt_info *dti,struct property *prop;for_each_property (node, prop) { -int n =strspn (prop->name, c->data); +size_t n =strspn (prop->name, c->data);if (n <strlen (prop->name))FAIL_PROP (c, dti, node, prop,"Bad character '%c' in property name" , prop->name[n]); } } -ERROR (property_name_chars, check_property_name_chars,PROPNODECHARS ); +ERROR (property_name_chars, check_property_name_chars,PROPCHARS ); static void check_property_name_chars_strict(struct check *c, struct dt_info *dti,@@ -360,7 +403,7 @@ static void check_property_name_chars_strict(struct check *c,for_each_property (node, prop) {const char *name = prop->name; -int n =strspn (name, c->data); +size_t n =strspn (name, c->data);if (n ==strlen (prop->name))continue ;@@ -477,7 +520,7 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti, phandle =propval_cell (prop); -if ((phandle ==0 ) || (phandle ==-1 )) { +if (!phandle_is_valid (phandle)) {FAIL_PROP (c, dti, node, prop,"bad value (0x%x) in %s property" , phandle, prop->name);return 0 ;@@ -536,7 +579,7 @@ static void check_name_properties(struct check *c, struct dt_info *dti,if (!prop)return ;/* No name property, that's fine */ -if ((prop->val.len != node->basenamelen+1 ) +if ((prop->val.len != node->basenamelen +1U ) || (memcmp (prop->val.val, node->name, node->basenamelen) !=0 )) {FAIL (c, dti, node,"\"name\" property is incorrect (\"%s\" instead" " of base node name)" , prop->val.val);@@ -625,6 +668,8 @@ ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);static void fixup_omit_unused_nodes (struct check *c,struct dt_info *dti,struct node *node) { +if (generate_symbols && node->labels) +return ;if (node->omit_if_unused && !node->is_referenced)delete_node (node); }@@ -635,7 +680,6 @@ ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &pa*/ WARNING_IF_NOT_CELL (address_cells_is_cell,"#address-cells" );WARNING_IF_NOT_CELL (size_cells_is_cell,"#size-cells" ); -WARNING_IF_NOT_CELL (interrupt_cells_is_cell,"#interrupt-cells" );WARNING_IF_NOT_STRING (device_type_is_string,"device_type" );WARNING_IF_NOT_STRING (model_is_string,"model" );@@ -650,8 +694,7 @@ static void check_names_is_string_list(struct check *c, struct dt_info *dti,struct property *prop;for_each_property (node, prop) { -const char *s =strrchr (prop->name,'-' ); -if (!s || !streq (s,"-names" )) +if (!strends (prop->name,"-names" ))continue ; c->data = prop->name;@@ -669,6 +712,11 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,return ;for_each_property (node, prop) { +if (streq (prop->name,"phandle" ) + ||streq (prop->name,"linux,phandle" )) { +continue ; + } +if (!prop->val.val || !get_node_by_path (dti->dt, prop->val.val)) {FAIL_PROP (c, dti, node, prop,"aliases property is not a valid node (%s)" , prop->val.val);@@ -726,7 +774,7 @@ static void check_reg_format(struct check *c, struct dt_info *dti, size_cells =node_size_cells (node->parent); entrylen = (addr_cells + size_cells) *sizeof (cell_t); -if (!entrylen || (prop->val.len % entrylen) !=0 ) +if (!is_multiple_of (prop->val.len, entrylen))FAIL_PROP (c, dti, node, prop,"property has invalid length (%d bytes) " "(#address-cells == %d, #size-cells == %d)" , prop->val.len, addr_cells, size_cells);@@ -738,13 +786,15 @@ static void check_ranges_format(struct check *c, struct dt_info *dti, {struct property *prop;int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen; +const char *ranges = c->data; - prop =get_property (node,"ranges" ); + prop =get_property (node, ranges);if (!prop)return ;if (!node->parent) { -FAIL_PROP (c, dti, node, prop,"Root node has a \"ranges\" property" ); +FAIL_PROP (c, dti, node, prop,"Root node has a \"%s\" property" , + ranges);return ; }@@ -756,23 +806,24 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,if (prop->val.len ==0 ) {if (p_addr_cells != c_addr_cells) -FAIL_PROP (c, dti, node, prop,"empty \"ranges\" property but its " +FAIL_PROP (c, dti, node, prop,"empty \"%s\" property but its " "#address-cells (%d) differs from %s (%d)" , - c_addr_cells, node->parent->fullpath, + ranges, c_addr_cells, node->parent->fullpath, p_addr_cells);if (p_size_cells != c_size_cells) -FAIL_PROP (c, dti, node, prop,"empty \"ranges\" property but its " +FAIL_PROP (c, dti, node, prop,"empty \"%s\" property but its " "#size-cells (%d) differs from %s (%d)" , - c_size_cells, node->parent->fullpath, + ranges, c_size_cells, node->parent->fullpath, p_size_cells); - }else if ((prop->val.len % entrylen) !=0 ) { -FAIL_PROP (c, dti, node, prop,"\"ranges\" property has invalid length (%d bytes) " + }else if (!is_multiple_of (prop->val.len, entrylen)) { +FAIL_PROP (c, dti, node, prop,"\"%s\" property has invalid length (%d bytes) " "(parent #address-cells == %d, child #address-cells == %d, " -"#size-cells == %d)" , prop->val.len, +"#size-cells == %d)" , ranges, prop->val.len, p_addr_cells, c_addr_cells, c_size_cells); } } -WARNING (ranges_format, check_ranges_format,NULL , &addr_size_cells); +WARNING (ranges_format, check_ranges_format,"ranges" , &addr_size_cells); +WARNING (dma_ranges_format, check_ranges_format,"dma-ranges" , &addr_size_cells);static const struct bus_type pci_bus = { .name ="PCI" ,@@ -842,7 +893,7 @@ static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struc }else { cells = (cell_t *)prop->val.val; min_bus =fdt32_to_cpu (cells[0 ]); - max_bus =fdt32_to_cpu (cells[0 ]); + max_bus =fdt32_to_cpu (cells[1 ]); }if ((bus_num < min_bus) || (bus_num > max_bus)) FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",@@ -862,10 +913,8 @@ static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct noreturn ; prop =get_property (node,"reg" ); -if (!prop) { -FAIL (c, dti, node,"missing PCI reg property" ); +if (!prop)return ; - } cells = (cell_t *)prop->val.val;if (cells[1 ] || cells[2 ])@@ -910,7 +959,7 @@ static bool node_is_compatible(struct node *node, const char *compat)for (str = prop->val.val, end = str + prop->val.len; str < end; str +=strnlen (str, end - str) +1 ) { -if (strprefixeq (str, end - str, compat)) +if (streq (str, compat))return true; }return false;@@ -921,7 +970,8 @@ static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, structif (node_is_compatible (node,"simple-bus" )) node->bus = &simple_bus; } -WARNING (simple_bus_bridge, check_simple_bus_bridge,NULL , &addr_size_cells); +WARNING (simple_bus_bridge, check_simple_bus_bridge,NULL , + &addr_size_cells, &compatible_is_string_list);static void check_simple_bus_reg (struct check *c,struct dt_info *dti,struct node *node) {@@ -962,6 +1012,160 @@ static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct no }WARNING (simple_bus_reg, check_simple_bus_reg,NULL , ®_format, &simple_bus_bridge); +static const struct bus_type i2c_bus = { + .name ="i2c-bus" , +}; + +static void check_i2c_bus_bridge (struct check *c,struct dt_info *dti,struct node *node) +{ +if (strprefixeq (node->name, node->basenamelen,"i2c-bus" ) || +strprefixeq (node->name, node->basenamelen,"i2c-arb" )) { + node->bus = &i2c_bus; + }else if (strprefixeq (node->name, node->basenamelen,"i2c" )) { +struct node *child; +for_each_child (node, child) { +if (strprefixeq (child->name, child->basenamelen,"i2c-bus" )) +return ; + } + node->bus = &i2c_bus; + }else +return ; + +if (!node->children) +return ; + +if (node_addr_cells (node) !=1 ) +FAIL (c, dti, node,"incorrect #address-cells for I2C bus" ); +if (node_size_cells (node) !=0 ) +FAIL (c, dti, node,"incorrect #size-cells for I2C bus" ); + +} +WARNING (i2c_bus_bridge, check_i2c_bus_bridge,NULL , &addr_size_cells); + +#define I2C_OWN_SLAVE_ADDRESS (1U << 30) +#define I2C_TEN_BIT_ADDRESS (1U << 31) + +static void check_i2c_bus_reg (struct check *c,struct dt_info *dti,struct node *node) +{ +struct property *prop; +const char *unitname =get_unitname (node); +char unit_addr[17 ]; +uint32_t reg =0 ; +int len; +cell_t *cells =NULL ; + +if (!node->parent || (node->parent->bus != &i2c_bus)) +return ; + + prop =get_property (node,"reg" ); +if (prop) + cells = (cell_t *)prop->val.val; + +if (!cells) { +FAIL (c, dti, node,"missing or empty reg property" ); +return ; + } + + reg =fdt32_to_cpu (*cells); +/* Ignore I2C_OWN_SLAVE_ADDRESS */ + reg &= ~I2C_OWN_SLAVE_ADDRESS ; +snprintf (unit_addr,sizeof (unit_addr),"%x" , reg); +if (!streq (unitname, unit_addr)) +FAIL (c, dti, node,"I2C bus unit address format error, expected \"%s\"" , + unit_addr); + +for (len = prop->val.len; len >0 ; len -=4 ) { + reg =fdt32_to_cpu (*(cells++)); +/* Ignore I2C_OWN_SLAVE_ADDRESS */ + reg &= ~I2C_OWN_SLAVE_ADDRESS ; + +if (reg &I2C_TEN_BIT_ADDRESS ) { +if ((reg & ~I2C_TEN_BIT_ADDRESS ) >0x3ff ) +FAIL_PROP (c, dti, node, prop,"I2C address must be less than 10-bits, got \"0x%x\"" , + reg); + }else if (reg >0x7f ) +FAIL_PROP (c, dti, node, prop,"I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property" , + reg); + } +} +WARNING (i2c_bus_reg, check_i2c_bus_reg,NULL , ®_format, &i2c_bus_bridge); + +static const struct bus_type spi_bus = { + .name ="spi-bus" , +}; + +static void check_spi_bus_bridge (struct check *c,struct dt_info *dti,struct node *node) +{ +int spi_addr_cells =1 ; + +if (strprefixeq (node->name, node->basenamelen,"spi" )) { + node->bus = &spi_bus; + }else { +/* Try to detect SPI buses which don't have proper node name */ +struct node *child; + +if (node_addr_cells (node) !=1 ||node_size_cells (node) !=0 ) +return ; + +for_each_child (node, child) { +struct property *prop; +for_each_property (child, prop) { +if (strstarts (prop->name,"spi-" )) { + node->bus = &spi_bus; +break ; + } + } +if (node->bus == &spi_bus) +break ; + } + +if (node->bus == &spi_bus &&get_property (node,"reg" )) +FAIL (c, dti, node,"node name for SPI buses should be 'spi'" ); + } +if (node->bus != &spi_bus || !node->children) +return ; + +if (get_property (node,"spi-slave" )) + spi_addr_cells =0 ; +if (node_addr_cells (node) != spi_addr_cells) +FAIL (c, dti, node,"incorrect #address-cells for SPI bus" ); +if (node_size_cells (node) !=0 ) +FAIL (c, dti, node,"incorrect #size-cells for SPI bus" ); + +} +WARNING (spi_bus_bridge, check_spi_bus_bridge,NULL , &addr_size_cells); + +static void check_spi_bus_reg (struct check *c,struct dt_info *dti,struct node *node) +{ +struct property *prop; +const char *unitname =get_unitname (node); +char unit_addr[9 ]; +uint32_t reg =0 ; +cell_t *cells =NULL ; + +if (!node->parent || (node->parent->bus != &spi_bus)) +return ; + +if (get_property (node->parent,"spi-slave" )) +return ; + + prop =get_property (node,"reg" ); +if (prop) + cells = (cell_t *)prop->val.val; + +if (!cells) { +FAIL (c, dti, node,"missing or empty reg property" ); +return ; + } + + reg =fdt32_to_cpu (*cells); +snprintf (unit_addr,sizeof (unit_addr),"%x" , reg); +if (!streq (unitname, unit_addr)) +FAIL (c, dti, node,"SPI bus unit address format error, expected \"%s\"" , + unit_addr); +} +WARNING (spi_bus_reg, check_spi_bus_reg,NULL , ®_format, &spi_bus_bridge); +static void check_unit_address_format (struct check *c,struct dt_info *dti,struct node *node) {@@ -978,7 +1182,7 @@ static void check_unit_address_format(struct check *c, struct dt_info *dti,/* skip over 0x for next test */ unitname +=2 ; } -if (unitname[0 ] =='0' &&isxdigit (unitname[1 ])) +if (unitname[0 ] =='0' &&isxdigit ((unsigned char )unitname[1 ]))FAIL (c, dti, node,"unit name should not have leading 0s" ); } WARNING(unit_address_format, check_unit_address_format, NULL,@@ -1013,29 +1217,48 @@ WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,static void check_avoid_unnecessary_addr_size (struct check *c,struct dt_info *dti,struct node *node) { -struct property *prop;struct node *child; -bool has_reg = false;if (!node->parent || node->addr_cells <0 || node->size_cells <0 )return ; -if (get_property (node,"ranges" ) || !node->children) +if (get_property (node,"ranges" ) ||get_property (node,"dma-ranges" ) || !node->children)return ;for_each_child (node, child) { - prop =get_property (child,"reg" ); -if (prop) - has_reg = true; +/* +* Even if the child devices' address space is not mapped into +* the parent bus (no 'ranges' property on node), children can +* still have registers on a local bus, or map local addresses +* to another subordinate address space. The properties on the +* child nodes then make #address-cells/#size-cells necessary: +*/ +if (get_property (child,"reg" ) ||get_property (child,"ranges" )) +return ; } -if (!has_reg) -FAIL (c, dti, node,"unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property" ); +FAIL (c, dti, node,"unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property" ); }WARNING (avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size,NULL , &avoid_default_addr_size); -static void check_unique_unit_address (struct check *c,struct dt_info *dti, -struct node *node) +static bool node_is_disabled (struct node *node) +{ +struct property *prop; + + prop =get_property (node,"status" ); +if (prop) { +char *str = prop->val.val; +if (streq ("disabled" , str)) +return true; + } + +return false; +} + +static void check_unique_unit_address_common (struct check *c, +struct dt_info *dti, +struct node *node, +bool disable_check) {struct node *childa;@@ -1052,18 +1275,38 @@ static void check_unique_unit_address(struct check *c, struct dt_info *dti,if (!strlen (addr_a))continue ; +if (disable_check &&node_is_disabled (childa)) +continue ; +for_each_child (node, childb) {const char *addr_b =get_unitname (childb);if (childa == childb)break ; +if (disable_check &&node_is_disabled (childb)) +continue ; +if (streq (addr_a, addr_b))FAIL (c, dti, childb,"duplicate unit-address (also used in node %s)" , childa->fullpath); } } } + +static void check_unique_unit_address (struct check *c,struct dt_info *dti, +struct node *node) +{ +check_unique_unit_address_common (c, dti, node, false); +}WARNING (unique_unit_address, check_unique_unit_address,NULL , &avoid_default_addr_size); +static void check_unique_unit_address_if_enabled (struct check *c,struct dt_info *dti, +struct node *node) +{ +check_unique_unit_address_common (c, dti, node, true); +} +CHECK_ENTRY (unique_unit_address_if_enabled, check_unique_unit_address_if_enabled, +NULL , false, false, &avoid_default_addr_size); +static void check_obsolete_chosen_interrupt_controller (struct check *c,struct dt_info *dti,struct node *node)@@ -1143,15 +1386,15 @@ struct provider { };static void check_property_phandle_args (struct check *c, -struct dt_info *dti, -struct node *node, -struct property *prop, -const struct provider *provider) +struct dt_info *dti, +struct node *node, +struct property *prop, +const struct provider *provider) {struct node *root = dti->dt; -int cell, cellsize =0 ; +unsigned int cell, cellsize =0 ; -if (prop->val.len %sizeof (cell_t)) { +if (!is_multiple_of (prop->val.len,sizeof (cell_t))) {FAIL_PROP (c, dti, node, prop,"property size (%d) is invalid, expected multiple of %zu" , prop->val.len,sizeof (cell_t));@@ -1161,14 +1404,15 @@ static void check_property_phandle_args(struct check *c,for (cell =0 ; cell < prop->val.len /sizeof (cell_t); cell += cellsize +1 ) {struct node *provider_node;struct property *cellprop; -int phandle; +cell_t phandle; +unsigned int expected; phandle =propval_cell_n (prop, cell);/* * Some bindings use a cell value 0 or -1 to skip over optional * entries when each index position has a specific definition. */ -if (phandle ==0 || phandle ==-1 ) { +if (!phandle_is_valid (phandle)) {/* Give up if this is an overlay with external references */ if (dti->dtsflags &DTSF_PLUGIN )break ;@@ -1211,10 +1455,12 @@ static void check_property_phandle_args(struct check *c,break ; } -if (prop->val.len < ((cell + cellsize +1 ) *sizeof (cell_t))) { + expected = (cell + cellsize +1 ) *sizeof (cell_t); +if ((expected <= cell) || prop->val.len < expected) {FAIL_PROP (c, dti, node, prop, -"property size (%d) too small for cell size %d" , +"property size (%d) too small for cell size %u" , prop->val.len, cellsize); +break ; } } }@@ -1223,7 +1469,7 @@ static void check_provider_cells_property(struct check *c,struct dt_info *dti, struct node *node) { - struct provider *provider = c->data; + const struct provider *provider = c->data;struct property *prop; prop =get_property (node, provider->prop_name);@@ -1234,7 +1480,8 @@ static void check_provider_cells_property(struct check *c, }#define WARNING_PROPERTY_PHANDLE_CELLS (nm, propname, cells_name, ...) \ static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \ - WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references); + WARNING_IF_NOT_CELL(nm##_is_cell, cells_name); \ + WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &nm##_is_cell, &phandle_references);WARNING_PROPERTY_PHANDLE_CELLS (clocks,"clocks" ,"#clock-cells" );WARNING_PROPERTY_PHANDLE_CELLS (cooling_device,"cooling-device" ,"#cooling-cells" );@@ -1255,24 +1502,17 @@ WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-senstatic bool prop_is_gpio (struct property *prop) { -char *str; -/* * *-gpios and *-gpio can appear in property names, * so skip over any false matches (only one known ATM) */ -if (strstr (prop->name,"nr-gpio" )) +if (strends (prop->name,",nr-gpios" ))return false; - str =strrchr (prop->name,'-' ); -if (str) - str++; -else - str = prop->name; -if (!(streq (str,"gpios" ) ||streq (str,"gpio" ))) -return false; - -return true; +return strends (prop->name,"-gpios" ) || +streq (prop->name,"gpios" ) || +strends (prop->name,"-gpio" ) || +streq (prop->name,"gpio" ); } static void check_gpios_property(struct check *c,@@ -1307,13 +1547,10 @@ static void check_deprecated_gpio_property(struct check *c,struct property *prop;for_each_property (node, prop) { -char *str; -if (!prop_is_gpio (prop))continue ; - str =strstr (prop->name,"gpio" ); -if (!streq (str,"gpio" )) +if (!strends (prop->name,"gpio" ))continue ; FAIL_PROP(c, dti, node, prop,@@ -1337,6 +1574,121 @@ static bool node_is_interrupt_provider(struct node *node)return false; } + +static void check_interrupt_provider (struct check *c, +struct dt_info *dti, +struct node *node) +{ +struct property *prop; +bool irq_provider =node_is_interrupt_provider (node); + + prop =get_property (node,"#interrupt-cells" ); +if (irq_provider && !prop) { +FAIL (c, dti, node, +"Missing '#interrupt-cells' in interrupt provider" ); +return ; + } + +if (!irq_provider && prop) { +FAIL (c, dti, node, +"'#interrupt-cells' found, but node is not an interrupt provider" ); +return ; + } +} +WARNING (interrupt_provider, check_interrupt_provider,NULL , &interrupts_extended_is_cell); + +static void check_interrupt_map (struct check *c, +struct dt_info *dti, +struct node *node) +{ +struct node *root = dti->dt; +struct property *prop, *irq_map_prop; +size_t cellsize, cell, map_cells; + + irq_map_prop =get_property (node,"interrupt-map" ); +if (!irq_map_prop) +return ; + +if (node->addr_cells <0 ) { +FAIL (c, dti, node, +"Missing '#address-cells' in interrupt-map provider" ); +return ; + } + cellsize =node_addr_cells (node); + cellsize +=propval_cell (get_property (node,"#interrupt-cells" )); + + prop =get_property (node,"interrupt-map-mask" ); +if (prop && (prop->val.len != (cellsize *sizeof (cell_t)))) +FAIL_PROP (c, dti, node, prop, +"property size (%d) is invalid, expected %zu" , + prop->val.len, cellsize *sizeof (cell_t)); + +if (!is_multiple_of (irq_map_prop->val.len,sizeof (cell_t))) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) is invalid, expected multiple of %zu" , + irq_map_prop->val.len,sizeof (cell_t)); +return ; + } + + map_cells = irq_map_prop->val.len /sizeof (cell_t); +for (cell =0 ; cell < map_cells; ) { +struct node *provider_node; +struct property *cellprop; +int phandle; +size_t parent_cellsize; + +if ((cell + cellsize) >= map_cells) { +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) too small, expected > %zu" , + irq_map_prop->val.len, (cell + cellsize) *sizeof (cell_t)); +break ; + } + cell += cellsize; + + phandle =propval_cell_n (irq_map_prop, cell); +if (!phandle_is_valid (phandle)) { +/* Give up if this is an overlay with external references */ +if (!(dti->dtsflags &DTSF_PLUGIN )) +FAIL_PROP (c, dti, node, irq_map_prop, +"Cell %zu is not a phandle(%d)" , + cell, phandle); +break ; + } + + provider_node =get_node_by_phandle (root, phandle); +if (!provider_node) { +FAIL_PROP (c, dti, node, irq_map_prop, +"Could not get phandle(%d) node for (cell %zu)" , + phandle, cell); +break ; + } + + cellprop =get_property (provider_node,"#interrupt-cells" ); +if (cellprop) { + parent_cellsize =propval_cell (cellprop); + }else { +FAIL (c, dti, node,"Missing property '#interrupt-cells' in node %s or bad phandle (referred from interrupt-map[%zu])" , + provider_node->fullpath, cell); +break ; + } + + cellprop =get_property (provider_node,"#address-cells" ); +if (cellprop) + parent_cellsize +=propval_cell (cellprop); +else +FAIL_PROP (c, dti, node, irq_map_prop, +"Missing property '#address-cells' in node %s, using 0 as fallback" , + provider_node->fullpath); + + cell +=1 + parent_cellsize; +if (cell > map_cells) +FAIL_PROP (c, dti, node, irq_map_prop, +"property size (%d) mismatch, expected %zu" , + irq_map_prop->val.len, cell *sizeof (cell_t)); + } +} +WARNING (interrupt_map, check_interrupt_map,NULL , &phandle_references, &addr_size_cells, &interrupt_provider); +static void check_interrupts_property (struct check *c,struct dt_info *dti,struct node *node)@@ -1344,13 +1696,13 @@ static void check_interrupts_property(struct check *c,struct node *root = dti->dt;struct node *irq_node =NULL , *parent = node;struct property *irq_prop, *prop =NULL ; -int irq_cells, phandle; +cell_t irq_cells, phandle; irq_prop =get_property (node,"interrupts" );if (!irq_prop)return ; -if (irq_prop->val.len %sizeof (cell_t)) +if (!is_multiple_of (irq_prop->val.len,sizeof (cell_t)))FAIL_PROP (c, dti, node, irq_prop,"size (%d) is invalid, expected multiple of %zu" , irq_prop->val.len,sizeof (cell_t));@@ -1363,10 +1715,14 @@ static void check_interrupts_property(struct check *c, prop =get_property (parent,"interrupt-parent" );if (prop) { phandle =propval_cell (prop); -/* Give up if this is an overlay with external references */ -if ((phandle ==0 || phandle ==-1 ) && - (dti->dtsflags &DTSF_PLUGIN )) +if (!phandle_is_valid (phandle)) { +/* Give up if this is an overlay with +* external references */ +if (dti->dtsflags &DTSF_PLUGIN )return ; +FAIL_PROP (c, dti, parent, prop,"Invalid phandle" ); +continue ; + } irq_node =get_node_by_phandle (root, phandle);if (!irq_node) {@@ -1390,12 +1746,12 @@ static void check_interrupts_property(struct check *c, prop =get_property (irq_node,"#interrupt-cells" );if (!prop) { -FAIL (c, dti, irq_node,"Missing #interrupt-cells in interrupt-parent" ); +/* We warn about that already in another test. */ return ; } irq_cells =propval_cell (prop); -if (irq_prop->val.len % (irq_cells *sizeof (cell_t))) { +if (!is_multiple_of (irq_prop->val.len, irq_cells *sizeof (cell_t))) {FAIL_PROP (c, dti, node, prop,"size is (%d), expected multiple of %d" , irq_prop->val.len, (int )(irq_cells *sizeof (cell_t)));@@ -1421,6 +1777,11 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti, get_property(child, "remote-endpoint")))continue ; +/* The root node cannot be a port */ +if (!node->parent) { +FAIL (c, dti, node,"root node contains endpoint node '%s', potentially misplaced remote-endpoint property" , child->name); +continue ; + } node->bus = &graph_port_bus;/* The parent of 'port' nodes can be either 'ports' or a device */ @@ -1434,31 +1795,6 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti, }WARNING (graph_nodes, check_graph_nodes,NULL ); -static void check_graph_child_address (struct check *c,struct dt_info *dti, -struct node *node) -{ -int cnt =0 ; -struct node *child; - -if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus) -return ; - -for_each_child (node, child) { -struct property *prop =get_property (child,"reg" ); - -/* No error if we have any non-zero unit address */ -if (prop &&propval_cell (prop) !=0 ) -return ; - - cnt++; - } - -if (cnt ==1 && node->addr_cells !=-1 ) -FAIL (c, dti, node,"graph node has single child node '%s', #address-cells/#size-cells are not necessary" , - node->children->name); -} -WARNING (graph_child_address, check_graph_child_address,NULL , &graph_nodes); -static void check_graph_reg (struct check *c,struct dt_info *dti,struct node *node) {@@ -1496,17 +1832,21 @@ static void check_graph_port(struct check *c, struct dt_info *dti,if (node->bus != &graph_port_bus)return ; +check_graph_reg (c, dti, node); + +/* skip checks below for overlays */ +if (dti->dtsflags &DTSF_PLUGIN ) +return ; +if (!strprefixeq (node->name, node->basenamelen,"port" ))FAIL (c, dti, node,"graph port node name should be 'port'" ); - -check_graph_reg (c, dti, node); }WARNING (graph_port, check_graph_port,NULL , &graph_nodes);static struct node *get_remote_endpoint (struct check *c,struct dt_info *dti,struct node *endpoint) { -int phandle; +cell_t phandle;struct node *node;struct property *prop;@@ -1516,7 +1856,7 @@ static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti, phandle =propval_cell (prop);/* Give up if this is an overlay with external references */ -if (phandle ==0 || phandle ==-1 ) +if (!phandle_is_valid (phandle))return NULL ; node =get_node_by_phandle (dti->dt, phandle);@@ -1534,11 +1874,15 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti,if (!node->parent || node->parent->bus != &graph_port_bus)return ; -if (!strprefixeq (node->name, node->basenamelen,"endpoint" )) -FAIL (c, dti, node,"graph endpont node name should be 'endpoint'" ); -check_graph_reg (c, dti, node); +/* skip checks below for overlays */ +if (dti->dtsflags &DTSF_PLUGIN ) +return ; + +if (!strprefixeq (node->name, node->basenamelen,"endpoint" )) +FAIL (c, dti, node,"graph endpoint node name should be 'endpoint'" ); + remote_node =get_remote_endpoint (c, dti, node);if (!remote_node)return ;@@ -1549,10 +1893,35 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti, }WARNING (graph_endpoint, check_graph_endpoint,NULL , &graph_nodes); +static void check_graph_child_address (struct check *c,struct dt_info *dti, +struct node *node) +{ +int cnt =0 ; +struct node *child; + +if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus) +return ; + +for_each_child (node, child) { +struct property *prop =get_property (child,"reg" ); + +/* No error if we have any non-zero unit address */ +if (prop &&propval_cell (prop) !=0 ) +return ; + + cnt++; + } + +if (cnt ==1 && node->addr_cells !=-1 ) +FAIL (c, dti, node,"graph node has single child node '%s', #address-cells/#size-cells are not necessary" , + node->children->name); +} +WARNING (graph_child_address, check_graph_child_address,NULL , &graph_nodes, &graph_port, &graph_endpoint); +static struct check *check_table[] = { &duplicate_node_names, &duplicate_property_names, &node_name_chars, &node_name_format, &property_name_chars, - &name_is_string, &name_properties, + &name_is_string, &name_properties, &node_name_vs_property_name, &duplicate_label,@@ -1560,7 +1929,7 @@ static struct check *check_table[] = { &phandle_references, &path_references, &omit_unused_nodes, - &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, + &address_cells_is_cell, &size_cells_is_cell, &device_type_is_string, &model_is_string, &status_is_string, &label_is_string,@@ -1569,7 +1938,7 @@ static struct check *check_table[] = { &property_name_chars_strict, &node_name_chars_strict, - &addr_size_cells, ®_format, &ranges_format, + &addr_size_cells, ®_format, &ranges_format, &dma_ranges_format, &unit_address_vs_reg, &unit_address_format,@@ -1581,32 +1950,57 @@ static struct check *check_table[] = { &simple_bus_bridge, &simple_bus_reg, + &i2c_bus_bridge, + &i2c_bus_reg, + + &spi_bus_bridge, + &spi_bus_reg, + &avoid_default_addr_size, &avoid_unnecessary_addr_size, &unique_unit_address, + &unique_unit_address_if_enabled, &obsolete_chosen_interrupt_controller, &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path, &clocks_property, + &clocks_is_cell, &cooling_device_property, + &cooling_device_is_cell, &dmas_property, + &dmas_is_cell, &hwlocks_property, + &hwlocks_is_cell, &interrupts_extended_property, + &interrupts_extended_is_cell, &io_channels_property, + &io_channels_is_cell, &iommus_property, + &iommus_is_cell, &mboxes_property, + &mboxes_is_cell, &msi_parent_property, + &msi_parent_is_cell, &mux_controls_property, + &mux_controls_is_cell, &phys_property, + &phys_is_cell, &power_domains_property, + &power_domains_is_cell, &pwms_property, + &pwms_is_cell, &resets_property, + &resets_is_cell, &sound_dai_property, + &sound_dai_is_cell, &thermal_sensors_property, + &thermal_sensors_is_cell, &deprecated_gpio_property, &gpios_property, &interrupts_property, + &interrupt_provider, + &interrupt_map, &alias_paths,@@ -1630,7 +2024,7 @@ static void enable_warning_error(struct check *c, bool warn, bool error)static void disable_warning_error (struct check *c,bool warn,bool error) { -int i; +unsigned int i;/* Lowering level, also lower it for things this is the prereq * for */ @@ -1651,7 +2045,7 @@ static void disable_warning_error(struct check *c, bool warn, bool error)void parse_checks_option (bool warn,bool error,const char *arg) { -int i; +unsigned int i;const char *name = arg;bool enable = true;@@ -1678,7 +2072,7 @@ void parse_checks_option(bool warn, bool error, const char *arg)void process_checks (bool force,struct dt_info *dti) { -int i; +unsigned int i;int error =0 ;for (i =0 ; i <ARRAY_SIZE (check_table); i++) {scripts/dtc/data.c +49
-25@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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,10 +21,10 @@ void data_free(struct data d)free (d.val); } -struct data data_grow_for (struct data d,int xlen) +struct data data_grow_for (struct data d,unsigned int xlen) {struct data nd; -int newsize; +unsigned int newsize;if (xlen ==0 )return d;@@ -74,7 +59,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) {@@ -94,10 +80,11 @@ 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; -if (maxlen ==-1 ) +if (maxlen == (size_t )-1 ) chunksize =4096 ;else chunksize = maxlen - d.len;@@ -241,11 +228,7 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref) {struct marker *m; - m =xmalloc (sizeof (*m)); - m->offset = d.len; - m->type = type; - m->ref = ref; - m->next =NULL ; + m =alloc_marker (d.len, type, ref);return data_append_markers (d, m); }@@ -267,3 +250,44 @@ bool data_is_one_string(struct data d)return true; } + +struct data data_insert_data (struct data d,struct marker *m,struct data old) +{ +unsigned int offset = m->offset; +struct marker *next = m->next; +struct marker *marker; +struct data new_data; +char *ref; + + new_data =data_insert_at_marker (d, m, old.val, old.len); + +/* Copy all markers from old value */ + marker = old.markers; +for_each_marker (marker) { + ref =NULL ; + +if (marker->ref) + ref =xstrdup (marker->ref); + + m->next =alloc_marker (marker->offset + offset, marker->type, + ref); + m = m->next; + } + m->next = next; + +return new_data; +} + +struct marker *alloc_marker (unsigned int offset,enum markertype type, +char *ref) +{ +struct marker *m; + + m =xmalloc (sizeof (*m)); + m->offset = offset; + m->type = type; + m->ref = ref; + m->next =NULL ; + +return m; +}scripts/dtc/dtc-lexer.l +19
-19@@ -1,21 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) Copyright David Gibson <[email protected]>, 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@@ -72,7 +57,7 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); push_input_file(name); } -<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? { +<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)* { char *line, *fnstart, *fnend; struct data fn; /* skip text before line # */@@ -166,6 +151,21 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...); return DT_LABEL; } +<V1>{LABEL} { + /* Missed includes or macro definitions while + * preprocessing can lead to unexpected identifiers in + * the input. Report a slightly more informative error + * in this case */ + + lexical_error("Unexpected '%s'", yytext); + + /* Treat it as a literal which often generates further + * useful error messages */ + + yylval.integer = 0; + return DT_LITERAL; + } + <V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? { char *e; DPRINT("Integer Literal: '%s'\n", yytext);@@ -212,14 +212,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} {scripts/dtc/dtc-parser.y +70
-39@@ -1,22 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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 */ +%locations + %{ #include <stdio.h> #include <inttypes.h>@@ -32,6 +19,8 @@ extern void yyerror(char const *s); treesource_error = true; \ } while (0) +#define YYERROR_CALL(msg) yyerror(msg) + extern struct dt_info *parser_output; extern bool treesource_error;@@ -76,7 +65,8 @@ static bool is_ref_relative(const char *ref) %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@@ -89,6 +79,7 @@ static bool is_ref_relative(const char *ref) %type <data> bytestring %type <prop> propdef %type <proplist> proplist +%type <labelref> dt_ref %type <node> devicetree %type <node> nodedef@@ -164,6 +155,8 @@ memreserve: } ; +dt_ref: DT_LABEL_REF | DT_PATH_REF; + devicetree: '/' nodedef {@@ -173,7 +166,7 @@ devicetree: { $$ = merge_nodes($1, $3); } - | DT_REF nodedef + | dt_ref nodedef { /* * We rely on the rule being always:@@ -184,9 +177,12 @@ devicetree: ERROR(&@2, "Label or path %s not found", $1); else if (is_ref_relative($1)) ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); - $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1); + $$ = add_orphan_node( + name_node(build_node(NULL, NULL, NULL), + ""), + $2, $1); } - | devicetree DT_LABEL DT_REF nodedef + | devicetree DT_LABEL dt_ref nodedef { struct node *target = get_node_by_ref($1, $3);@@ -200,7 +196,7 @@ 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:@@ -221,7 +217,26 @@ devicetree: } $$ = $1; } - | devicetree DT_DEL_NODE DT_REF ';' + | devicetree DT_LABEL_REF nodedef + { + struct node *target = get_node_by_ref($1, $2); + + if (target) { + merge_nodes(target, $3); + } 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 ';' { struct node *target = get_node_by_ref($1, $3);@@ -233,7 +248,7 @@ devicetree: $$ = $1; } - | devicetree DT_OMIT_NO_REF DT_REF ';' + | devicetree DT_OMIT_NO_REF dt_ref ';' { struct node *target = get_node_by_ref($1, $3);@@ -250,7 +265,7 @@ devicetree: nodedef: '{' proplist subnodes '}' ';' { - $$ = build_node($2, $3); + $$ = build_node($2, $3, &@$); } ;@@ -268,15 +283,18 @@ proplist: propdef: DT_PROPNODENAME '=' propdata ';' { - $$ = build_property($1, $3); + $$ = build_property($1, $3, &@$); + free($1); } | DT_PROPNODENAME ';' { - $$ = build_property($1, empty_data); + $$ = build_property($1, empty_data, &@$); + free($1); } | DT_DEL_PROP DT_PROPNODENAME ';' { $$ = build_property_delete($2); + free($2); } | DT_LABEL propdef {@@ -298,8 +316,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 ')'@@ -353,22 +372,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@@ -383,14 +407,19 @@ arrayprefix: * within the mask to one (i.e. | in the * mask), all bits are one. */ - if (($2 > mask) && (($2 | mask) != -1ULL)) - ERROR(&@2, "Value out of range for" - " %d-bit array element", $1.bits); + if (($2 > mask) && (($2 | mask) != -1ULL)) { + char *loc = srcpos_string(&@2); + fprintf(stderr, + "WARNING: %s: Value 0x%016" PRIx64 + " truncated to 0x%0*" PRIx64 "\n", + loc, $2, $1.bits / 4, ($2 & mask)); + free(loc); + } } $$.data = data_append_integer($1.data, $2, $1.bits); } - | arrayprefix DT_REF + | arrayprefix dt_ref { uint64_t val = ~0ULL >> (64 - $1.bits);@@ -468,8 +497,8 @@ integer_rela: ; integer_shift: - integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } - | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } + integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; } + | integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; } | integer_add ;@@ -512,7 +541,7 @@ integer_unary: bytestring: /* empty */ { - $$ = empty_data; + $$ = data_add_marker(empty_data, TYPE_UINT8, NULL); } | bytestring DT_BYTE {@@ -544,10 +573,12 @@ subnode: DT_PROPNODENAME nodedef { $$ = name_node($2, $1); + free($1); } | DT_DEL_NODE DT_PROPNODENAME ';' { - $$ = name_node(build_node_delete(), $2); + $$ = name_node(build_node_delete(&@$), $2); + free($2); } | DT_OMIT_NO_REF subnode {scripts/dtc/dtc.c +37
-21@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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> @@ -27,14 +12,16 @@* Command line options */ int quiet;/* Level of quietness */ -int reservenum;/* Number of memory reservation slots */ +unsigned 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 alignsize;/* Additional padding to blob according to the alignsize */ 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) {@@ -60,7 +47,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)/* Usage related data. */ 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:@LAThv" ;static struct option const usage_long_opts[] = { {"quiet" , no_argument,NULL ,'q' }, {"in-format" , a_argument,NULL ,'I' },@@ -80,7 +67,9 @@ static struct option const usage_long_opts[] = { {"warning", a_argument, NULL, 'W'}, {"error", a_argument, NULL, 'E'}, {"symbols", no_argument, NULL, '@'}, + {"local-fixups", no_argument, NULL, 'L'}, {"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},@@ -95,6 +84,9 @@ 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 "stringify(DEFAULT_FDT_VERSION)" (for dtb and asm output)", "\n\tOutput dependency file",@@ -113,7 +105,9 @@ static const char * const usage_opts_help[] = {"\n\tEnable/disable warnings (prefix with \"no-\")" ,"\n\tEnable/disable errors (prefix with \"no-\")" ,"\n\tEnable generation of symbols" , +"\n\tPossibly generates a __local_fixups__ and a __fixups__ node at the root node" ,"\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,@@ -128,6 +122,10 @@ 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,".dtbo" )) +return "dtb" ;if (!strcasecmp (s,".dtb" ))return "dtb" ;return fallback;@@ -201,7 +199,7 @@ int main(int argc, char *argv[]) depname = optarg;break ;case 'R' : - reservenum =strtol (optarg,NULL ,0 ); + reservenum =strtoul (optarg,NULL ,0 );break ;case 'S' : minsize =strtol (optarg,NULL ,0 );@@ -256,9 +254,17 @@ int main(int argc, char *argv[])case '@' : generate_symbols =1 ;break ; + +case 'L' : + generate_fixups =1 ; +break ; +case 'A' : auto_label_aliases =1 ;break ; +case 'T' : + annotate++; +break ;case 'h' :usage (NULL );@@ -283,7 +289,9 @@ int main(int argc, char *argv[])if (!depfile)die ("Couldn't open dependency file %s: %s\n" , depname,strerror (errno)); -fprintf (depfile,"%s:" , outname); + +fprint_path_escaped (depfile, outname); +fputc (':' , depfile); }if (inform ==NULL )@@ -297,6 +305,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" ))@@ -350,6 +360,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" )) {scripts/dtc/dtc.h +106
-31@@ -1,24 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef DTC_H #define DTC_H /* * (C) Copyright David Gibson <[email protected]>, 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> @@ -50,14 +35,15 @@* Command line options */ extern int quiet;/* Level of quietness */ -extern int reservenum;/* Number of memory reservation slots */ +extern unsigned int reservenum;/* Number of memory reservation slots */ extern int minsize;/* Minimum blob size */ extern int padsize;/* Additional padding to blob */ -extern int alignsize;/* Additional padding to blob accroding to the alignsize */ +extern int alignsize;/* Additional padding to blob according to the alignsize */ 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@@ -65,28 +51,88 @@ extern int auto_label_aliases; /* auto generate labels -> aliases */typedef uint32_t cell_t ; +static inline bool phandle_is_valid (cell_t phandle) +{ +return phandle !=0 && phandle != ~0U ; +} + +static inline uint16_t dtb_ld16 (const void *p) +{ +const uint8_t *bp = (const uint8_t *)p; + +return ((uint16_t )bp[0 ] <<8 ) + | bp[1 ]; +} + +static inline uint32_t dtb_ld32 (const void *p) +{ +const uint8_t *bp = (const uint8_t *)p; + +return ((uint32_t )bp[0 ] <<24 ) + | ((uint32_t )bp[1 ] <<16 ) + | ((uint32_t )bp[2 ] <<8 ) + | bp[3 ]; +} + +static inline uint64_t dtb_ld64 (const void *p) +{ +const uint8_t *bp = (const uint8_t *)p; + +return ((uint64_t )bp[0 ] <<56 ) + | ((uint64_t )bp[1 ] <<48 ) + | ((uint64_t )bp[2 ] <<40 ) + | ((uint64_t )bp[3 ] <<32 ) + | ((uint64_t )bp[4 ] <<24 ) + | ((uint64_t )bp[5 ] <<16 ) + | ((uint64_t )bp[6 ] <<8 ) + | bp[7 ]; +} +#define streq (a, b) (strcmp((a), (b)) == 0)#define strstarts (s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)#define strprefixeq (a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0)) +static inline bool strends (const char *str,const char *suffix) +{ +unsigned int len, suffix_len; + + len =strlen (str); + suffix_len =strlen (suffix); +if (len < suffix_len) +return false; +return streq (str + len - suffix_len, suffix); +}#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 , }; +static inline bool is_type_marker (enum markertype type) +{ +return type >=TYPE_UINT8 ; +} + +extern const char *markername (enum markertype markertype); +struct marker {enum markertype type; -int offset; +unsigned int offset;char *ref;struct marker *next; };struct data { -int len; +unsigned int len;char *val;struct marker *markers; };@@ -99,9 +145,26 @@ struct data { for_each_marker(m) \ if ((m)->type == (t)) +static inline struct marker *next_type_marker(struct marker *m) +{ + for_each_marker(m) + if (is_type_marker(m->type)) + break; + return m; +} + +static inline size_t type_marker_length(struct marker *m) +{ + struct marker *next = next_type_marker(m->next); + + if (next) + return next->offset - m->offset; + return 0; +} + void data_free(struct data d); -struct data data_grow_for(struct data d, int xlen); +struct data data_grow_for(struct data d, unsigned int xlen); struct data data_copy_mem(const char *mem, int len); struct data data_copy_escape_string(const char *s, int len);@@ -118,7 +181,10 @@ struct data data_append_addr(struct data d, uint64_t addr);struct data data_append_byte (struct data d,uint8_t byte);struct data data_append_zeroes (struct data d,int len);struct data data_append_align (struct data d,int align); +struct data data_insert_data (struct data d,struct marker *m,struct data old); +struct marker *alloc_marker (unsigned int offset,enum markertype type, +char *ref);struct data data_add_marker (struct data d,enum markertype type,char *ref);bool data_is_one_string (struct data d);@@ -147,6 +213,7 @@ struct property {struct property *next;struct label *labels; +struct srcpos *srcpos; };struct node {@@ -166,6 +233,7 @@ struct node {struct label *labels;const struct bus_type *bus; +struct srcpos *srcpos;bool omit_if_unused, is_referenced; };@@ -194,14 +262,16 @@ 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_delete (char *name); +struct property *build_property (const char *name,struct data val, +struct srcpos *srcpos); +struct property *build_property_delete (const 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 *name_node (struct node *node,char *name); +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,const 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);@@ -215,12 +285,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); +cell_t propval_cell_n (struct property *prop,unsigned 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,@@ -266,9 +337,9 @@ struct dt_info *build_dt_info(unsigned int dtsflags,struct reserve_info *reservelist, struct node *tree, uint32_t boot_cpuid_phys);void sort_tree (struct dt_info *dti); -void generate_label_tree (struct dt_info *dti,char *name,bool allocph); -void generate_fixups_tree (struct dt_info *dti,char *name); -void generate_local_fixups_tree (struct dt_info *dti,char *name); +void generate_label_tree (struct dt_info *dti,const char *name,bool allocph); +void generate_fixups_tree (struct dt_info *dti,const char *name); +void generate_local_fixups_tree (struct dt_info *dti,const char *name);/* Checks */ @@ -287,6 +358,10 @@ 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);scripts/dtc/fdtoverlay.c new file +214
-0@@ -0,0 +1,214 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2017 Konsulko Group Inc. All rights reserved. +* +* Author: +* Pantelis Antoniou <[email protected]> +*/ + +#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>]]" ; +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; +bool has_symbols; + +/* +* We take copies first, because 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; + } + ret =fdt_path_offset (tmp,"/__symbols__" ); + has_symbols = ret >=0 ; + +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)); +if (!has_symbols) { +fprintf (stderr, +"base blob does not have a '/__symbols__' node, " +"make sure you have compiled the base blob with '-@' option\n" ); + } + 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; + } + +/* 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 ; +}scripts/dtc/flattree.c +27
-43@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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" @@ -139,7 +124,8 @@ static void asm_emit_cell(void *e, cell_t val) {FILE *f = e; -fprintf (f,"\t.byte 0x%02x; .byte 0x%02x; .byte 0x%02x; .byte 0x%02x\n" , +fprintf (f,"\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n" +"\t.byte\t0x%02x\n" "\t.byte\t0x%02x\n" , (val >>24 ) &0xff , (val >>16 ) &0xff , (val >>8 ) &0xff , val &0xff ); }@@ -149,9 +135,9 @@ static void asm_emit_string(void *e, const char *str, int len)FILE *f = e;if (len !=0 ) -fprintf (f,"\t.string\t\"%.*s\"\n" , len, str); +fprintf (f,"\t.asciz\t\"%.*s\"\n" , len, str);else -fprintf (f,"\t.string\t\"%s\"\n" , str); +fprintf (f,"\t.asciz\t\"%s\"\n" , str); }static void asm_emit_align (void *e,int a)@@ -164,14 +150,14 @@ static void asm_emit_align(void *e, int a)static void asm_emit_data (void *e,struct data d) {FILE *f = e; -int off =0 ; +unsigned int off =0 ;struct marker *m = d.markers;for_each_marker_of_type (m,LABEL )emit_offset_label (f, m->ref, m->offset);while ((d.len - off) >=sizeof (uint32_t )) { -asm_emit_cell (e,fdt32_to_cpu (*((fdt32_t *)(d.val+off)))); +asm_emit_cell (e,dtb_ld32 (d.val + off)); off +=sizeof (uint32_t ); }@@ -234,7 +220,7 @@ static struct emitter asm_emitter = {static int stringtable_insert (struct data *d,const char *str) { -int i; +unsigned int i;/* FIXME: do this more efficiently? */ @@ -310,7 +296,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist, {struct reserve_info *re;struct data d = empty_data; -int j; +unsigned int j;for (re = reservelist; re; re = re->next) { d =data_append_re (d, re->address, re->size);@@ -360,7 +346,7 @@ static void make_fdt_header(struct fdt_header *fdt,void dt_to_blob (FILE *f,struct dt_info *dti,int version) {struct version_info *vi =NULL ; -int i; +unsigned int i;struct data blob = empty_data;struct data reservebuf = empty_data;struct data dtbuf = empty_data;@@ -393,7 +379,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); } }@@ -453,7 +439,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)while (p < (strbuf.val + strbuf.len)) { len =strlen (p); -fprintf (f,"\t.string \"%s\"\n" , p); +fprintf (f,"\t.asciz \"%s\"\n" , p); p += len+1 ; } }@@ -461,7 +447,7 @@ static void dump_stringtable_asm(FILE *f, struct data strbuf)void dt_to_asm (FILE *f,struct dt_info *dti,int version) {struct version_info *vi =NULL ; -int i; +unsigned int i;struct data strbuf = empty_data;struct reserve_info *re;const char *symprefix ="dt" ;@@ -517,7 +503,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)* Reserve map entries. * Align the reserve map to a doubleword boundary. * Each entry is an (address, size) pair of u64 values. -* Always supply a zero-sized temination entry. +* Always supply a zero-sized termination entry. */ asm_emit_align (f,8 );emit_label (f, symprefix,"reserve_map" );@@ -525,7 +511,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) {@@ -618,11 +604,11 @@ static void flat_realign(struct inbuf *inb, int align)die ("Premature end of data parsing flat device tree\n" ); } -static char *flat_read_string (struct inbuf *inb) +static const char *flat_read_string (struct inbuf *inb) {int len =0 ;const char *p = inb->ptr; -char *str; +const char *str; do { if (p >= inb->limit)@@ -630,7 +616,7 @@ static char *flat_read_string(struct inbuf *inb) len++; }while ((*p++) !='\0' ); - str =xstrdup (inb->ptr); + str = inb->ptr; inb->ptr += len;@@ -692,7 +678,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 ); }static struct reserve_info *flat_read_mem_reserve (struct inbuf *inb)@@ -723,7 +709,8 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)return reservelist; } -static char *nodename_from_path (const char *ppath,const char *cpath) + +static const char *nodename_from_path (const char *ppath,const char *cpath) {int plen;@@ -737,7 +724,7 @@ static char *nodename_from_path(const char *ppath, const char *cpath)if (!streq (ppath,"/" )) plen++; -return xstrdup (cpath + plen); +return cpath + plen; } static struct node *unflatten_tree(struct inbuf *dtbuf,@@ -745,17 +732,18 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, const char *parent_flatname, int flags) {struct node *node; -char *flatname; +const char *flatname;uint32_t val; - node =build_node (NULL ,NULL ); + node =build_node (NULL ,NULL ,NULL ); flatname =flat_read_string (dtbuf);if (flags &FTF_FULLPATH ) - node->name =nodename_from_path (parent_flatname, flatname); + node->name =xstrdup (nodename_from_path (parent_flatname, + flatname));else - node->name = flatname; + node->name =xstrdup (flatname); do { struct property *prop;@@ -797,10 +785,6 @@ static struct node *unflatten_tree(struct inbuf *dtbuf, } }while (val !=FDT_END_NODE ); -if (node->name != flatname) { -free (flatname); - } -return node; }scripts/dtc/fstree.c +6
-20@@ -1,21 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * (C) Copyright David Gibson <[email protected]>, 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" @@ -34,7 +19,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;@@ -45,7 +30,7 @@ static struct node *read_fstree(const char *dirname) tmpname =join_path (dirname, de->d_name); -if (lstat (tmpname, &st) <0 ) +if (stat (tmpname, &st) <0 )die ("stat(%s): %s\n" , tmpname,strerror (errno));if (S_ISREG (st.st_mode)) {@@ -58,9 +43,10 @@ static struct node *read_fstree(const char *dirname)"WARNING: Cannot open %s: %s\n" , tmpname, strerror(errno)); }else { - prop =build_property (xstrdup (de->d_name), + prop =build_property (de->d_name,data_copy_file (pfile, - st.st_size)); + st.st_size), +NULL );add_property (tree, prop);fclose (pfile); }scripts/dtc/libfdt/fdt.c +52
-32@@ -19,9 +19,16 @@ int32_t fdt_ro_probe_(const void *fdt) {uint32_t totalsize =fdt_totalsize (fdt); +if (can_assume (VALID_DTB )) +return totalsize; + +/* The device tree must be at an 8-byte aligned address */ +if ((uintptr_t )fdt &7 ) +return -FDT_ERR_ALIGNMENT ; +if (fdt_magic (fdt) ==FDT_MAGIC ) {/* Complete tree */ -if (fdt_chk_version ()) { +if (!can_assume (LATEST )) {if (fdt_version (fdt) <FDT_FIRST_SUPPORTED_VERSION )return -FDT_ERR_BADVERSION ; if (fdt_last_comp_version(fdt) >@@ -30,7 +37,7 @@ int32_t fdt_ro_probe_(const void *fdt) } }else if (fdt_magic (fdt) ==FDT_SW_MAGIC ) {/* Unfinished sequential-write blob */ -if (fdt_size_dt_struct (fdt) ==0 ) +if (!can_assume (VALID_INPUT ) &&fdt_size_dt_struct (fdt) ==0 )return -FDT_ERR_BADSTATE ; }else {return -FDT_ERR_BADMAGIC ;@@ -75,17 +82,21 @@ size_t fdt_header_size_(uint32_t version)size_t fdt_header_size (const void *fdt) { -return fdt_chk_version () ?fdt_header_size_ (fdt_version (fdt)) : -FDT_V17_SIZE ; +return can_assume (LATEST ) ?FDT_V17_SIZE : +fdt_header_size_ (fdt_version (fdt)); }int fdt_check_header (const void *fdt) {size_t hdrsize; +/* The device tree must be at an 8-byte aligned address */ +if ((uintptr_t )fdt &7 ) +return -FDT_ERR_ALIGNMENT ; +if (fdt_magic (fdt) !=FDT_MAGIC )return -FDT_ERR_BADMAGIC ; -if (fdt_chk_version ()) { +if (!can_assume (LATEST )) {if ((fdt_version (fdt) <FDT_FIRST_SUPPORTED_VERSION ) || (fdt_last_comp_version (fdt) >FDT_LAST_SUPPORTED_VERSION ))@@ -94,8 +105,7 @@ int fdt_check_header(const void *fdt)return -FDT_ERR_BADVERSION ; } hdrsize =fdt_header_size (fdt); -if (fdt_chk_basic ()) { - +if (!can_assume (VALID_DTB )) {if ((fdt_totalsize (fdt) < hdrsize) || (fdt_totalsize (fdt) >INT_MAX ))return -FDT_ERR_TRUNCATED ;@@ -104,11 +114,9 @@ int fdt_check_header(const void *fdt)if (!check_off_ (hdrsize,fdt_totalsize (fdt),fdt_off_mem_rsvmap (fdt)))return -FDT_ERR_TRUNCATED ; - } -if (fdt_chk_extra ()) {/* Bounds check structure block */ -if (fdt_chk_version () &&fdt_version (fdt) <17 ) { +if (!can_assume (LATEST ) &&fdt_version (fdt) <17 ) {if (!check_off_ (hdrsize,fdt_totalsize (fdt),fdt_off_dt_struct (fdt)))return -FDT_ERR_TRUNCATED ;@@ -137,13 +145,13 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)if (offset <0 )return NULL ; -if (fdt_chk_basic ()) +if (!can_assume (VALID_INPUT ))if ((absoffset < uoffset) || ((absoffset + len) < absoffset) || (absoffset + len) >fdt_totalsize (fdt))return NULL ; -if (!fdt_chk_version () ||fdt_version (fdt) >=0x11 ) +if (can_assume (LATEST ) ||fdt_version (fdt) >=0x11 )if (((uoffset + len) < uoffset) || ((offset + len) >fdt_size_dt_struct (fdt)))return NULL ;@@ -154,13 +162,13 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)uint32_t fdt_next_tag (const void *fdt,int startoffset,int *nextoffset) {const fdt32_t *tagp, *lenp; -uint32_t tag; +uint32_t tag, len, sum;int offset = startoffset;const char *p; *nextoffset = -FDT_ERR_TRUNCATED ; tagp =fdt_offset_ptr (fdt, offset,FDT_TAGSIZE ); -if (fdt_chk_basic () && !tagp) +if (!can_assume (VALID_DTB ) && !tagp)return FDT_END ;/* premature end */ tag =fdt32_to_cpu (*tagp); offset +=FDT_TAGSIZE ;@@ -172,20 +180,27 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)do { p =fdt_offset_ptr (fdt, offset++,1 ); }while (p && (*p !='\0' )); -if (fdt_chk_basic () && !p) +if (!can_assume (VALID_DTB ) && !p)return FDT_END ;/* premature end */ break ;case FDT_PROP : lenp =fdt_offset_ptr (fdt, offset,sizeof (*lenp)); -if (fdt_chk_basic () && !lenp) +if (!can_assume (VALID_DTB ) && !lenp)return FDT_END ;/* premature end */ + + len =fdt32_to_cpu (*lenp); + sum = len + offset; +if (!can_assume (VALID_DTB ) && + (INT_MAX <= sum || sum < (uint32_t ) offset)) +return FDT_END ;/* premature end */ +/* skip-name offset, length and value */ - offset +=sizeof (struct fdt_property ) -FDT_TAGSIZE - +fdt32_to_cpu (*lenp); -if (fdt_chk_version () && -fdt_version (fdt) <0x10 &&fdt32_to_cpu (*lenp) >=8 && - ((offset -fdt32_to_cpu (*lenp)) %8 ) !=0 ) + offset +=sizeof (struct fdt_property ) -FDT_TAGSIZE + len; + +if (!can_assume (LATEST ) && +fdt_version (fdt) <0x10 && len >=8 && + ((offset - len) %8 ) !=0 ) offset +=4 ;break ;@@ -198,8 +213,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)return FDT_END ; } -if (fdt_chk_basic () && - !fdt_offset_ptr (fdt, startoffset, offset - startoffset)) +if (!fdt_offset_ptr (fdt, startoffset, offset - startoffset))return FDT_END ;/* premature end */ *nextoffset =FDT_TAGALIGN (offset);@@ -208,8 +222,11 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)int fdt_check_node_offset_ (const void *fdt,int offset) { -if ((offset <0 ) || (offset %FDT_TAGSIZE ) - || (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )) +if (!can_assume (VALID_INPUT ) + && ((offset <0 ) || (offset %FDT_TAGSIZE ))) +return -FDT_ERR_BADOFFSET ; + +if (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )return -FDT_ERR_BADOFFSET ;return offset;@@ -217,8 +234,11 @@ int fdt_check_node_offset_(const void *fdt, int offset)int fdt_check_prop_offset_ (const void *fdt,int offset) { -if ((offset <0 ) || (offset %FDT_TAGSIZE ) - || (fdt_next_tag (fdt, offset, &offset) !=FDT_PROP )) +if (!can_assume (VALID_INPUT ) + && ((offset <0 ) || (offset %FDT_TAGSIZE ))) +return -FDT_ERR_BADOFFSET ; + +if (fdt_next_tag (fdt, offset, &offset) !=FDT_PROP )return -FDT_ERR_BADOFFSET ;return offset;@@ -292,21 +312,21 @@ int fdt_next_subnode(const void *fdt, int offset)return offset; } -const char *fdt_find_string_ (const char *strtab,int tabsize,const char *s) +const char *fdt_find_string_len_ (const char *strtab,int tabsize,const char *s, +int slen) { -int len =strlen (s) +1 ; -const char *last = strtab + tabsize - len; +const char *last = strtab + tabsize - (slen +1 );const char *p;for (p = strtab; p <= last; p++) -if (memcmp (p, s, len) ==0 ) +if (memcmp (p, s, slen) ==0 && p[slen] =='\0' )return p;return NULL ; }int fdt_move (const void *fdt,void *buf,int bufsize) { -if (fdt_chk_basic () && bufsize <0 ) +if (!can_assume (VALID_INPUT ) && bufsize <0 )return -FDT_ERR_NOSPACE ;FDT_RO_PROBE (fdt);scripts/dtc/libfdt/fdt.h +2
-2@@ -7,7 +7,7 @@* Copyright 2012 Kim Phillips, Freescale Semiconductor. */ -#ifndef __ASSEMBLY__ +#ifndef __ASSEMBLER__ struct fdt_header { fdt32_t magic; /* magic word FDT_MAGIC */@@ -45,7 +45,7 @@ struct fdt_property { char data[0]; }; -#endif /* !__ASSEMBLY */ +#endif /* !__ASSEMBLER__ */ #define FDT_MAGIC 0xd00dfeed/* 4: version, 4: total size */ #define FDT_TAGSIZE sizeof(fdt32_t)scripts/dtc/libfdt/fdt_addresses.c +1
-1@@ -73,7 +73,7 @@ int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,/* check validity of address */ prop = data;if (addr_cells ==1 ) { -if ((addr >UINT32_MAX ) || ((UINT32_MAX +1 - addr) < size)) +if ((addr >UINT32_MAX ) || (((uint64_t )UINT32_MAX +1 - addr) < size))return -FDT_ERR_BADVALUE ;fdt32_st (prop, (uint32_t )addr);scripts/dtc/libfdt/fdt_overlay.c +302
-84@@ -40,37 +40,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)return fdt32_to_cpu (*val); } -/** -* overlay_get_target - retrieves the offset of a fragment's target -* @fdt: Base device tree blob -* @fdto: Device tree overlay blob -* @fragment: node offset of the fragment in the overlay -* @pathp: pointer which receives the path of the target (or NULL) -* -* overlay_get_target() retrieves the target offset in the base -* device tree of a fragment, no matter how the actual targeting is -* done (through a phandle or a path) -* -* returns: -* the targeted node offset in the base device tree -* Negative error code on error -*/ -static int overlay_get_target (const void *fdt,const void *fdto, -int fragment,char const **pathp) +int fdt_overlay_target_offset (const void *fdt,const void *fdto, +int fragment_offset,char const **pathp) {uint32_t phandle;const char *path =NULL ;int path_len =0 , ret;/* Try first to do a phandle based lookup */ - phandle =overlay_get_target_phandle (fdto, fragment); + phandle =overlay_get_target_phandle (fdto, fragment_offset);if (phandle == (uint32_t )-1 )return -FDT_ERR_BADPHANDLE ;/* no phandle, try path */ if (!phandle) {/* And then a path based lookup */ - path =fdt_getprop (fdto, fragment,"target-path" , &path_len); + path =fdt_getprop (fdto, fragment_offset,"target-path" , &path_len);if (path) ret =fdt_path_offset (fdt, path);else @@ -116,26 +101,22 @@ static int overlay_get_target(const void *fdt, const void *fdto,static int overlay_phandle_add_offset (void *fdt,int node,const char *name,uint32_t delta) { -const fdt32_t *val; -uint32_t adj_val; +fdt32_t *valp, val;int len; - val =fdt_getprop (fdt, node, name, &len); -if (!val) + valp =fdt_getprop_w (fdt, node, name, &len); +if (!valp)return len; -if (len !=sizeof (*val)) +if (len !=sizeof (val))return -FDT_ERR_BADPHANDLE ; - adj_val =fdt32_to_cpu (*val); -if ((adj_val + delta) < adj_val) + val =fdt32_ld (valp); +if (val + delta < val || val + delta == (uint32_t )-1 )return -FDT_ERR_NOPHANDLES ; - adj_val += delta; -if (adj_val == (uint32_t )-1 ) -return -FDT_ERR_NOPHANDLES ; - -return fdt_setprop_inplace_u32 (fdt, node, name, adj_val); +fdt32_st (valp, val + delta); +return 0 ; }/** @@ -228,8 +209,8 @@ static int overlay_update_local_node_references(void *fdto,fdt_for_each_property_offset (fixup_prop, fdto, fixup_node) {const fdt32_t *fixup_val; -const char *tree_val;const char *name; +char *tree_val;int fixup_len;int tree_len;int i;@@ -243,7 +224,7 @@ static int overlay_update_local_node_references(void *fdto,return -FDT_ERR_BADOVERLAY ; fixup_len /=sizeof (uint32_t ); - tree_val =fdt_getprop (fdto, tree_node, name, &tree_len); + tree_val =fdt_getprop_w (fdto, tree_node, name, &tree_len);if (!tree_val) {if (tree_len == -FDT_ERR_NOTFOUND )return -FDT_ERR_BADOVERLAY ;@@ -252,33 +233,15 @@ static int overlay_update_local_node_references(void *fdto, }for (i =0 ; i < fixup_len; i++) { -fdt32_t adj_val; -uint32_t poffset; +fdt32_t *refp; - poffset =fdt32_to_cpu (fixup_val[i]); + refp = (fdt32_t *)(tree_val +fdt32_ld_ (fixup_val + i));/* -* phandles to fixup can be unaligned. -* -* Use a memcpy for the architectures that do -* not support unaligned accesses. +* phandles to fixup can be unaligned, so use +* fdt32_{ld,st}() to read/write them. */ -memcpy (&adj_val, tree_val + poffset,sizeof (adj_val)); - - adj_val =cpu_to_fdt32 (fdt32_to_cpu (adj_val) + delta); - - ret =fdt_setprop_inplace_namelen_partial (fdto, - tree_node, - name, -strlen (name), - poffset, - &adj_val, -sizeof (adj_val)); -if (ret == -FDT_ERR_NOSPACE ) -return -FDT_ERR_BADOVERLAY ; - -if (ret) -return ret; +fdt32_st (refp,fdt32_ld (refp) + delta); } }@@ -344,7 +307,6 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)/** * overlay_fixup_one_phandle - Set an overlay phandle to the base one -* @fdt: Base Device Tree blob * @fdto: Device tree overlay blob * @symbols_off: Node offset of the symbols node in the base device tree * @path: Path to a node holding a phandle in the overlay @@ -352,7 +314,7 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)* @name: Name of the property holding the phandle reference in the overlay * @name_len: number of name characters to consider * @poffset: Offset within the overlay property where the phandle is stored -* @label: Label of the node referenced by the phandle +* @phandle: Phandle referencing the node * * overlay_fixup_one_phandle() resolves an overlay phandle pointing to * a node in the base device tree. @@ -365,34 +327,17 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)* 0 on success * Negative error code on failure */ -static int overlay_fixup_one_phandle (void *fdt,void *fdto, -int symbols_off, +static int overlay_fixup_one_phandle (void *fdto,int symbols_off,const char *path,uint32_t path_len,const char *name,uint32_t name_len, -int poffset,const char *label) +int poffset,uint32_t phandle) { -const char *symbol_path; -uint32_t phandle;fdt32_t phandle_prop; -int symbol_off, fixup_off; -int prop_len; +int fixup_off;if (symbols_off <0 )return symbols_off; - symbol_path =fdt_getprop (fdt, symbols_off, label, - &prop_len); -if (!symbol_path) -return prop_len; - - symbol_off =fdt_path_offset (fdt, symbol_path); -if (symbol_off <0 ) -return symbol_off; - - phandle =fdt_get_phandle (fdt, symbol_off); -if (!phandle) -return -FDT_ERR_NOTFOUND ; - fixup_off =fdt_path_offset_namelen (fdto, path, path_len);if (fixup_off == -FDT_ERR_NOTFOUND )return -FDT_ERR_BADOVERLAY ;@@ -404,7 +349,7 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto, name, name_len, poffset, &phandle_prop, sizeof(phandle_prop)); -}; +}/** * overlay_fixup_phandle - Set an overlay phandle to the base one @@ -431,6 +376,10 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,const char *value;const char *label;int len; +const char *symbol_path; +int prop_len; +int symbol_off; +uint32_t phandle; value =fdt_getprop_by_offset (fdto, property, &label, &len);@@ -441,6 +390,18 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,return len; } + symbol_path =fdt_getprop (fdt, symbols_off, label, &prop_len); +if (!symbol_path) +return prop_len; + + symbol_off =fdt_path_offset (fdt, symbol_path); +if (symbol_off <0 ) +return symbol_off; + + phandle =fdt_get_phandle (fdt, symbol_off); +if (!phandle) +return -FDT_ERR_NOTFOUND ; + do { const char *path, *name, *fixup_end; const char *fixup_str = value;@@ -480,9 +441,9 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,if ((*endptr !='\0' ) || (endptr <= (sep +1 )))return -FDT_ERR_BADOVERLAY ; - ret =overlay_fixup_one_phandle (fdt, fdto, symbols_off, + ret =overlay_fixup_one_phandle (fdto, symbols_off, path, path_len, name, name_len, - poffset, label); + poffset, phandle);if (ret)return ret; }while (len >0 );@@ -535,6 +496,255 @@ static int overlay_fixup_phandles(void *fdt, void *fdto)return 0 ; } +/** +* overlay_adjust_local_conflicting_phandle: Changes a phandle value +* @fdto: Device tree overlay +* @node: The node the phandle is set for +* @fdt_phandle: The new value for the phandle +* +* returns: +* 0 on success +* Negative error code on failure +*/ +static int overlay_adjust_local_conflicting_phandle (void *fdto,int node, +uint32_t fdt_phandle) +{ +const fdt32_t *php; +int len, ret; + + php =fdt_getprop (fdto, node,"phandle" , &len); +if (php && len ==sizeof (*php)) { + ret =fdt_setprop_inplace_u32 (fdto, node,"phandle" , fdt_phandle); +if (ret) +return ret; + } + + php =fdt_getprop (fdto, node,"linux,phandle" , &len); +if (php && len ==sizeof (*php)) { + ret =fdt_setprop_inplace_u32 (fdto, node,"linux,phandle" , fdt_phandle); +if (ret) +return ret; + } + +return 0 ; +} + +/** +* overlay_update_node_conflicting_references - Recursively replace phandle values +* @fdto: Device tree overlay blob +* @tree_node: Node to recurse into +* @fixup_node: Node offset of the matching local fixups node +* @fdt_phandle: Value to replace phandles with +* @fdto_phandle: Value to be replaced +* +* Replaces all phandles with value @fdto_phandle by @fdt_phandle. +* +* returns: +* 0 on success +* Negative error code on failure +*/ +static int overlay_update_node_conflicting_references (void *fdto,int tree_node, +int fixup_node, +uint32_t fdt_phandle, +uint32_t fdto_phandle) +{ +int fixup_prop; +int fixup_child; +int ret; + +fdt_for_each_property_offset (fixup_prop, fdto, fixup_node) { +const fdt32_t *fixup_val; +const char *name; +char *tree_val; +int fixup_len; +int tree_len; +int i; + + fixup_val =fdt_getprop_by_offset (fdto, fixup_prop, + &name, &fixup_len); +if (!fixup_val) +return fixup_len; + +if (fixup_len %sizeof (uint32_t )) +return -FDT_ERR_BADOVERLAY ; + fixup_len /=sizeof (uint32_t ); + + tree_val =fdt_getprop_w (fdto, tree_node, name, &tree_len); +if (!tree_val) { +if (tree_len == -FDT_ERR_NOTFOUND ) +return -FDT_ERR_BADOVERLAY ; + +return tree_len; + } +Lines of this file are not shown. View the raw message.
scripts/dtc/libfdt/libfdt_internal.h +102
-39Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 72 lines · Anshul Dalal
CC+: TI folks
Quoted 69 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Are we ensuring the fdt present in the SPL binary is properly aligned?
Yes, the device tree must be 8-byte aligned, this is a requirement of the device tree spec itself that we had been lax over until now.
Signature · 1 line
Tom
Hi Tom, Marek,
Quoted 72 lines · Tom Rini
Quoted 71 lines · Anshul Dalal
CC+: TI folks
Quoted 68 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Are we ensuring the fdt present in the SPL binary is properly aligned?
Yes, the device tree must be 8-byte aligned, this is a requirement of the device tree spec itself that we had been lax over until now.
We found iMX95/iMX94 EVK boards are broken after this fdt lib update. The root cause is default value of CONFIG_SPL_OF_LIBFDT_ASSUME_MASK is 0xff. In this update, fdt_check_node_offset_ is changed as below to check the CONFIG_SPL_OF_LIBFDT_ASSUME_MASK. When it is 0xff, fdt_check_node_offset_ will skip offset check.
int fdt_check_node_offset_(const void *fdt, int offset) {
- if ((offset < 0) || (offset % FDT_TAGSIZE)
- || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
+ if (!can_assume(VALID_INPUT)
+ && ((offset < 0) || (offset % FDT_TAGSIZE)))
+ return -FDT_ERR_BADOFFSET;
+
+ if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)
return -FDT_ERR_BADOFFSET;
This cause a problem to SCMI agent uclass driver. In scmi_bind_protocols function, a ofnode_null() is used when creating scmi-base.0 device to bind with driver. This null node which has offset value -1 can successfully pass the fdt_check_node_offset_, so causes crash in device_probe()->dev_power_domain_on() when finding power-domains phandle.
I notice the default value of CONFIG_OF_LIBFDT_ASSUME_MASK used by u-boot is 0. So why does SPL have different default value? Should we change the SPL default value to 0 to align with u-boot? Otherwise, any idea for fix.
Best regards,
Ye Li
Quoted 1 line
Quoted 97 lines · Ye Li
Hi Tom, Marek,
Quoted 72 lines · Tom Rini
Quoted 71 lines · Anshul Dalal
CC+: TI folks
Quoted 68 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Are we ensuring the fdt present in the SPL binary is properly aligned?
Yes, the device tree must be 8-byte aligned, this is a requirement of the device tree spec itself that we had been lax over until now.
We found iMX95/iMX94 EVK boards are broken after this fdt lib update. The root cause is default value of
CONFIG_SPL_OF_LIBFDT_ASSUME_MASKis0xff. In this update,fdt_check_node_offset_is changed as below to check theCONFIG_SPL_OF_LIBFDT_ASSUME_MASK. When it is0xff,fdt_check_node_offset_will skip offset check.int
fdt_check_node_offset_(const void *fdt, int offset){scripts/dtc/libfdt/fdt.c +5
-2-if ((offset <0 ) || (offset %FDT_TAGSIZE ) - || (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )) +if (!can_assume (VALID_INPUT ) + && ((offset <0 ) || (offset %FDT_TAGSIZE ))) +return -FDT_ERR_BADOFFSET ; + +if (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )return -FDT_ERR_BADOFFSET ;
Quoted 5 lines
This cause a problem to SCMI agent uclass driver. In
scmi_bind_protocolsfunction, aofnode_null()is used when creating scmi-base.0 device to bind with driver. This null node which has offset value -1 can successfully pass thefdt_check_node_offset_, so causes crash in device_probe()->dev_power_domain_on() when finding power-domains phandle.
Thanks for the analysis.
Quoted 3 lines
I notice the default value of
CONFIG_OF_LIBFDT_ASSUME_MASKused by u-boot is
0. So why does SPL have different default value? Should we change the SPL default value to 0 to align with u-boot? Otherwise, any idea for fix.
In SPL we must assume a perfect device tree has been passed to us, both for design reasons (it's not a user interactively, we built it, or it came from some other firmware stack) as well as practical (performing the sanity tests would grow all platforms by several kilobytes and overflow size constraints). I think the SCMI code needs to be reworked, in short.
Signature · 1 line
Tom
Quoted 110 lines · Tom Rini
Quoted 97 lines · Ye Li
Hi Tom, Marek,
Quoted 72 lines · Tom Rini
Quoted 71 lines · Anshul Dalal
CC+: TI folks
Quoted 68 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Are we ensuring the fdt present in the SPL binary is properly aligned?
Yes, the device tree must be 8-byte aligned, this is a requirement of the device tree spec itself that we had been lax over until now.
We found iMX95/iMX94 EVK boards are broken after this fdt lib update. The root cause is default value of
CONFIG_SPL_OF_LIBFDT_ASSUME_MASKis0xff. In this update,fdt_check_node_offset_is changed as below to check theCONFIG_SPL_OF_LIBFDT_ASSUME_MASK. When it is0xff,fdt_check_node_offset_will skip offset check.int fdt_check_node_offset_(const void *fdt, int offset) {scripts/dtc/libfdt/fdt.c +5
-2-if ((offset <0 ) || (offset %FDT_TAGSIZE ) - || (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )) +if (!can_assume (VALID_INPUT ) + && ((offset <0 ) || (offset %FDT_TAGSIZE ))) +return -FDT_ERR_BADOFFSET ; + +if (fdt_next_tag (fdt, offset, &offset) !=FDT_BEGIN_NODE )return -FDT_ERR_BADOFFSET ;Quoted 5 lines
This cause a problem to SCMI agent uclass driver. In
scmi_bind_protocolsfunction, aofnode_null()is used when creating scmi-base.0 device to bind with driver. This null node which has offset value -1 can successfully pass thefdt_check_node_offset_, so causes crash in device_probe()->dev_power_domain_on() when finding power-domains phandle.Thanks for the analysis.
Quoted 3 lines
I notice the default value of
CONFIG_OF_LIBFDT_ASSUME_MASKused by u-boot is
0. So why does SPL have different default value? Should we change the SPL default value to 0 to align with u-boot? Otherwise, any idea for fix.
Quoted 7 lines
In SPL we must assume a perfect device tree has been passed to us, both for design reasons (it's not a user interactively, we built it, or it came from some other firmware stack) as well as practical (performing the sanity tests would grow all platforms by several kilobytes and overflow size constraints). I think the SCMI code needs to be reworked, in short.
Thanks for explanation. It is reasonable to have 0xff as default for SPL. For SCMI, because its base protocol(0x10) is mandatory, there is no dts node for this protocol. So SCMI agent uclass driver dynamically creates a device for base protocol with null node. See commit (7eb4eb541c1 firmware: scmi: install base protocol to SCMI agent). This implementation seems also proper. Do you think if we should set CONFIG_SPL_OF_LIBFDT_ASSUME_MASK to 0 when SCMI is used?
Best regards,
Ye Li
Quoted 120 lines · Ye Li
Quoted 110 lines · Tom Rini
Quoted 97 lines · Ye Li
Hi Tom, Marek,
Quoted 72 lines · Tom Rini
Quoted 71 lines · Anshul Dalal
CC+: TI folks
Quoted 68 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14-gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57-gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23-g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30-g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22-gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2-g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11-g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31-gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51-g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19-g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66-gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93-g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95-gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Are we ensuring the fdt present in the SPL binary is properly aligned?
Yes, the device tree must be 8-byte aligned, this is a requirement of the device tree spec itself that we had been lax over until now.
We found iMX95/iMX94 EVK boards are broken after this fdt lib update. The root cause is default value of
CONFIG_SPL_OF_LIBFDT_ASSUME_MASKis0xff. In this update,fdt_check_node_offset_is changed as below to check theCONFIG_SPL_OF_LIBFDT_ASSUME_MASK. When it is0xff,fdt_check_node_offset_will skip offset check.int fdt_check_node_offset_(const void *fdt, int offset) {(quoted diff) +5
-2- if ((offset < 0) || (offset % FDT_TAGSIZE) - || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE)) + if (!can_assume(VALID_INPUT) + && ((offset < 0) || (offset % FDT_TAGSIZE))) + return -FDT_ERR_BADOFFSET; + + if (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE) return -FDT_ERR_BADOFFSET;Quoted 5 lines
This cause a problem to SCMI agent uclass driver. In
scmi_bind_protocolsfunction, aofnode_null()is used when creating scmi-base.0 device to bind with driver. This null node which has offset value -1 can successfully pass thefdt_check_node_offset_, so causes crash in device_probe()->dev_power_domain_on() when finding power-domains phandle.Thanks for the analysis.
Quoted 3 lines
I notice the default value of
CONFIG_OF_LIBFDT_ASSUME_MASKused by u-boot is
0. So why does SPL have different default value? Should we change the SPL default value to 0 to align with u-boot? Otherwise, any idea for fix.Quoted 7 lines
In SPL we must assume a perfect device tree has been passed to us, both for design reasons (it's not a user interactively, we built it, or it came from some other firmware stack) as well as practical (performing the sanity tests would grow all platforms by several kilobytes and overflow size constraints). I think the SCMI code needs to be reworked, in short.
Quoted 7 lines
Thanks for explanation. It is reasonable to have
0xffas default for SPL. For SCMI, because its base protocol(0x10) is mandatory, there is no dts node for this protocol. So SCMI agent uclass driver dynamically creates a device for base protocol with null node. See commit (7eb4eb541c1firmware: scmi:
install base protocol to SCMI agent). This implementation seems also proper. Do you think if we should setCONFIG_SPL_OF_LIBFDT_ASSUME_MASKto 0 when SCMI is used?
It's also a massive hit on boot time and I know that will be a regression on some SCMI using platforms. So no, we need to figure out hwo to rework the code.
Signature · 1 line
Tom
Quoted 93 lines · Ye Li
Hi Tom, Marek,
Quoted 72 lines · Tom Rini
Quoted 71 lines · Anshul Dalal
CC+: TI folks
Quoted 68 lines · Anshul Dalal
Hi all,
Quoted 43 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14- gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57- gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23- g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30- g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22- gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2- g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11- g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31- gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51- g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19- g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63- g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66- gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93- g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95- gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35- g52f07dcca47cThis also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.Signed-off-by Marek Vasut <[email protected]>Quoted 11 lines
---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]We observed several boot failures on K3 platforms since the addition of this patch at the R5 SPL stage, the issue seems to be the newly added check for alignment in
fdt_check_headerinscripts/dtc/libfdt/fdt.c:95but the binaries generated don't have 8-byte aligned FDTs.I have been able to reproduce the issue on AM62p EVM with a clean working directory (this is important since any minor change to the SPL binary size such as by the added "-dirty" tag could make the address aligned) and GCC 13.3[1].
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Are we ensuring the fdt present in the SPL binary is properly aligned?
Yes, the device tree must be 8-byte aligned, this is a requirement of the device tree spec itself that we had been lax over until now.
We found iMX95/iMX94 EVK boards are broken after this fdt lib update. The root cause is default value of
CONFIG_SPL_OF_LIBFDT_ASSUME_MASKis0xff. In this update,fdt_check_node_offset_is changed as below to check theCONFIG_SPL_OF_LIBFDT_ASSUME_MASK. When it is0xff,fdt_check_node_offset_will skip offset check.int
fdt_check_node_offset_(const void *fdt, int offset){
- if ((offset < 0) || (offset %FDT_TAGSIZE)
- || (fdt_next_tag(fdt, offset, &offset)!=FDT_BEGIN_NODE)) + if (!can_assume(VALID_INPUT)
+ && ((offset < 0) || (offset %FDT_TAGSIZE)))
+ return -FDT_ERR_BADOFFSET;
+
+ if (fdt_next_tag(fdt, offset, &offset)!=FDT_BEGIN_NODE)
return -FDT_ERR_BADOFFSET;
Quoted 3 lines
This cause a problem to SCMI agent uclass driver. In
scmi_bind_protocolsfunction, aofnode_null()is used when creating scmi-base.0 device to bind with driver. This null node which has offset value -1 can successfully pass thefdt_check_node_offset_, so causes crash in device_probe()->dev_power_domain_on() when finding power-domains phandle.I notice the default value of
CONFIG_OF_LIBFDT_ASSUME_MASKused by u- boot is 0. So why does SPL have different default value? Should we change the SPL default value to 0 to align with u-boot? Otherwise, any idea for fix.
Could ti be that you need a fix similar to:
3c43ca3025ef ("clk: fixed_rate: Avoid calling dev_read_*() if CONFIG_OF_PLATDATA=y")
Maybe there is some node missing and you are trying to look it up and use it ?
Hi Tom, Marek,
Quoted 60 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14- gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57- gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23- g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30- g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22- gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2- g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11- g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31- gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51- g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19- g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63- g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66- gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93- g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95- gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35- g52f07dcca47c
Quoted 4 lines
This also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.
During testing I discovered the following error on Microchip's PolarFire SoC Icicle kit. I found it during a bisect between the v2026.01 tag and the master branch while looking to solve another issue. With these other issues solved I am left with this one still on master and I am looking for some help.
The error is: failed on fdt_open_into for DTO, i.e. overlay application fdt error. This was introduced by 0535e46d55d scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c, i.e. this patch. Please see the attached log which includes a printenv attached.
Thanks in advance,
Jamie.
Quoted 51 lines
Signed-off-by Marek Vasut <[email protected]>---
Cc: Adriano Cordova <[email protected]>
Cc: Andrew Goodbody <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Sam Edwards <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
V2: - Fix off-by-one infdt_remove_unused_strings()
- Restoree8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt")
---
scripts/Makefile.lib | 4 +- scripts/dtc/.gitignore | 1 + scripts/dtc/Makefile | 23 +- scripts/dtc/Makefile.dtc | 18 - scripts/dtc/checks.c | 686 +++++++++++++++++++++----- -
scripts/dtc/data.c | 74 ++- scripts/dtc/dtc-lexer.l | 38 +- scripts/dtc/dtc-parser.y | 109 +++-- scripts/dtc/dtc.c | 58 ++- scripts/dtc/dtc.h | 137 ++++-- scripts/dtc/fdtoverlay.c | 214 +++++++++ scripts/dtc/flattree.c | 70 ++- scripts/dtc/fstree.c | 26 +- scripts/dtc/libfdt/fdt.c | 84 ++-- scripts/dtc/libfdt/fdt.h | 4 +- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/fdt_overlay.c | 386 +++++++++++---- scripts/dtc/libfdt/fdt_ro.c | 100 ++-- scripts/dtc/libfdt/fdt_rw.c | 101 ++-- scripts/dtc/libfdt/fdt_strerror.c | 1 + scripts/dtc/libfdt/fdt_sw.c | 26 +- scripts/dtc/libfdt/libfdt.h | 414 +++++++++++++---scripts/dtc/libfdt/libfdt_internal.h| 141 ++++-- scripts/dtc/livetree.c | 156 +++--- scripts/dtc/srcpos.c | 190 ++++++-- scripts/dtc/srcpos.h | 31 +- scripts/dtc/treesource.c | 319 ++++++++----- scripts/dtc/update-dtc-source.sh | 7 +- scripts/dtc/util.c | 122 ++--- scripts/dtc/util.h | 61 +-- scripts/dtc/version_gen.h | 2 +- scripts/dtc/yamltree.c | 235 +++++++++ tools/libfdt/fdt_rw.c | 2 +-
Quoted 5 lines
33 files changed, 2830 insertions(+), 1012 deletions(-)delete mode 100644
scripts/dtc/Makefile.dtc
create mode 100644scripts/dtc/fdtoverlay.c
create mode 100644scripts/dtc/yamltree.c
U-Boot 2026.01-rc5-00487-g0535e46d55d7-dirty (Jan 16 2026 - 15:59:54 +0000)
CPU: sifive,u54-mc Model: Microchip PolarFire-SoC Icicle Kit DRAM: 1020 MiB (total 2 GiB) Core: 66 devices, 15 uclasses, devicetree: fit MMC: mmc@20008000: 0 Loading Environment from nowhere... OK In: serial@20100000 Out: serial@20100000 Err: serial@20100000 Net: eth1: ethernet@20110000, eth0: ethernet@20112000 Hit any key to stop autoboot: 0
RISC-V # printenv
arch=riscv
baudrate=115200
board=mpfs_generic
board_name=mpfs_generic
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootriscv64.efi; if fdt addr -q ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi
boot_efi_bootmgr=if fdt addr -q ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr;fi
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc0 dhcp
bootcmd=run distro_bootcmd
bootcmd_dhcp=devtype=dhcp; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; setenv efi_old_vci ${bootp_vci};setenv efi_old_arch ${bootp_arch};setenv bootp_vci PXEClient:Arch:00027:UNDI:003000;setenv bootp_arch 0x1b;if dhcp ${kernel_addr_r}; then tftpboot ${fdt_addr_r} dtb/${efi_fdtfile};if fdt addr -q ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r}; else bootefi ${kernel_addr_r} ${fdtcontroladdr};fi;fi;setenv bootp_vci ${efi_old_vci};setenv bootp_arch ${efi_old_arch};setenv efi_fdtfile;setenv efi_old_arch;setenv efi_old_vci; bootcmd_mmc0=devnum=0; run mmc_boot
bootdelay=2
bootm_size=0x10000000
cpu=mpfs
distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done
dtbo_size=0
efi_dtb_prefixes=/ /dtb/ /dtb/current/
eth1addr=00:04:a3:62:80:4b
ethaddr=00:04:a3:62:80:4a
fdt_addr_r=0x88000000
fdtcontroladdr=bf349500
fdtfile=microchip/mpfs-icicle-kit.dtb
kernel_addr_r=0x84000000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
loadaddr=0x80200000
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
no_of_overlays=0
pxefile_addr_r=0x88200000
ramdisk_addr_r=0x88300000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then part uuid ${devtype} ${devnum}:${distro_bootpart} distro_bootpart_uuid ; run scan_dev_for_boot; fi; done; setenv devplist
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;run boot_efi_bootmgr;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootriscv64.efi; then echo Found EFI removable media binary efi/boot/bootriscv64.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo EXTLINUX FAILED: continuing...; fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done
scriptaddr=0x88100000
stderr=serial@20100000
stdin=serial@20100000
stdout=serial@20100000
vendor=microchip
Environment size: 3579/8188 bytes
RISC-V # boot
switch to partitions #0, OK
mmc0(part 0) is current device
Scanning mmc 0:2...
Found U-Boot script /boot.scr
624 bytes read in 8 ms (76.2 KiB/s)
## Executing script at 88100000
Working FDT set to bf349500
6420192 bytes read in 85 ms (72 MiB/s)
## Loading kernel (any) from FIT Image at 88100000 ...
Using 'conf-microchip,mpfs-icicle-kit' configuration Trying 'kernel' kernel subimage
Description: Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Start: 0x881000cc
Data Size: 6361629 Bytes = 6.1 MiB
Architecture: RISC-V
OS: Linux
Load Address: 0x80200000
Entry Point: 0x80200000
Hash algo: sha256
Hash value: e92dccad51bf9f61f2a08d26a3da904ed5a86950db78d939bd621ef9fe9b95ac Verifying Hash Integrity ... sha256+ OK
## Loading fdt (any) from FIT Image at 88100000 ...
Using 'conf-microchip,mpfs-icicle-kit' configuration Trying 'fdt-mpfs-icicle-kit.dtb' fdt subimage
Description: Flattened Device Tree blob
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x88711400
Data Size: 24242 Bytes = 23.7 KiB
Architecture: RISC-V
Load Address: 0x8a000000
Hash algo: sha256
Hash value: 2a111f7ecb21056e2e315fab673fef4d566d7cdb0284de3deb3663a4fa07c61f Verifying Hash Integrity ... sha256+ OK
Loading fdt from 0x88711400 to 0x8a000000
Loading Device Tree to 00000000be331000, end 00000000be339fff ... OK
Working FDT set to be331000
## Loading fdt (any) from FIT Image at 88100000 ...
Using 'conf-microchip,mpfs-icicle-cpu-opp' configuration Trying 'fdt-mpfs-icicle-cpu-opp.dtbo' fdt subimage
Description: Device Tree blob for CPU Operating Points
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x8871e8a4
Data Size: 1392 Bytes = 1.4 KiB
Architecture: RISC-V
Load Address: 0x8a0c0000
Hash algo: sha256
Hash value: 9355e3feaa4ce663cb5a223ee73a26ef227f02586327b3f9db48b5c35ddcdc78 Verifying Hash Integrity ... sha256+ OK
failed on fdt_open_into for DTO
Could not find a valid device tree
Uncompressing Kernel Image to 80200000
Device tree not found or missing FDT support
### ERROR ### Please RESET the board ###
Quoted 73 lines · On 1/16/26 5:13 PM, [email protected] wrote:
Hi Tom, Marek,
Quoted 60 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash was necessary, since the DTC here contains changes which were also part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.
The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7-14- gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7-57- gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0-23- g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0-30- g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1-22- gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2- g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0-11- g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0-31- gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0-51- g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1-19- g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1-63- g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1-66- gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0-93- g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0-95- gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2-35- g52f07dcca47cQuoted 4 lines
This also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.During testing I discovered the following error on Microchip's PolarFire SoC Icicle kit. I found it during a bisect between the v2026.01 tag and the master branch while looking to solve another issue. With these other issues solved I am left with this one still on master and I am looking for some help.
Quoted 4 lines
The error is: failed on
fdt_open_intofor DTO, i.e. overlay application fdt error. This was introduced by0535e46d55dscripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c, i.e. this patch. Please see the attached log which includes aprintenvattached.
Does this fix your problem ?
boot/image-fit.c +1 -1
@@ -2491,7 +2491,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, ov =map_sysmem (ovload, ovlen); ovcopylen =ALIGN (fdt_totalsize (ov),SZ_4K ); - ovcopy =malloc (ovcopylen); + ovcopy =memalign (8 , ovcopylen);if (!ovcopy) { printf("failed to duplicate DTO before
application\n");
fdt_noffset = -ENOMEM;Hi Marek,
Quoted 123 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 97 lines · On 1/16/26 5:13 PM, [email protected] wrote:
Hi Tom, Marek,
Quoted 80 lines · Marek Vasut
Synchronize local copy of DTC with Linux 6.17 . This includes the following picked and squashed commits from Linux kernel. The squash
was necessary, since the DTC here contains changes which were also
part of DTC in Linux alraedy, and the squash helped resolve those without going back and forth with the changes.The following commits from Linux are picked:
8f324cd712df7#scripts/dtc: consolidate include path options inMakefileb5b3d9b63b0ee#scripts/dtc: Addyamltree.cto dtc sources7d97a76f226d6#scripts/dtc: Update to upstream version v1.4.7- 14-
gc86da84d30e4ea6f243be74e5#scripts/dtc: Update to upstream version v1.4.7- 57-
gf267e674d14502d435d4eccd8#scripts/dtc: Update to upstream version v1.5.0- 23-
g87963ee206936e321b7637396#scripts/dtc: Update to upstream version v1.5.0- 30-
g702c1b6c0e739f19ec91a7a35#scripts/dtc:dtx_diff- add color output support8287d642f38d1#scripts/dtc: Update to upstream version v1.5.1- 22-
gc40aeb60b47a4c52deef9225d#scripts/dtc: Revert "yamltree: Ensure consistent bracketing of properties with phandles"5d3827e1452ed#scripts/dtc: Remove unused makefile fragments40dd266887654#scripts/dtc: Update to upstream version v1.6.0-2- g87a656ae5ff98d4cf6b6acb59#scripts/dtc: use pkg-config to include <yaml.h> in
non-standard pathb9bf9ace5ae90#scripts/dtc: Update to upstream version v1.6.0- 11-
g9d7888cbf19c69a883b6f5ac0#scripts/dtc:dtx_diff- make help text formatting consistent8f829108b8aed#scripts/dtc: only append toHOST_EXTRACFLAGSinstead
of overwritingb39b4342ac495#scripts/dtc: Update to upstream version v1.6.0- 31-
gcbca977ea12193c6424c486b3# scripts: dtc: Fetchfdtoverlay.cfrom external DTC
project0dd574a1d75c3#scripts/dtc: Update to upstream version v1.6.0- 51-
g183df9e9c2b9ec38b5df8a231# scripts: dtc: Build fdtoverlay toola0c8c431411f5# scripts: dtc: Remove the unusedfdtdump.cfilee7dc653d4e890#scripts/dtc: Add missing fdtoverlay to gitignored2bf5d2e3f09c#scripts/dtc: Update to upstream version v1.6.1- 19-
g0a3a9d3449c8a60878f5532d0#scripts/dtc:dtx_diff: remove broken example from help
text8b739d8658a9b#scripts/dtc: Call pkg-config POSIXly correctb6eeafa67df00#scripts/dtc: Update to upstream version v1.6.1- 63-
g55778a03df61f96cc4c787588#scripts/dtc: Update to upstream version v1.6.1- 66-
gabbd523bae6e09ab9c092ef2b#scripts/dtc: Update to upstream version v1.7.0- 93-
g1df7b047fe43ded8a5a498f2d#scripts/dtc: Update to upstream version v1.7.0- 95-
gbcd02b523429ee6ff6fca7e71#scripts/dtc: Update to upstream version v1.7.2- 35-
g52f07dcca47cQuoted 4 lines
This also includes forward port of U-Boot commit
e8c2d25845c7("libfdt: Revert6dcb8ba4from upstream libfdt") to avoid binary size growth.During testing I discovered the following error on Microchip's PolarFire
SoC Icicle kit. I found it during a bisect between the v2026.01 tag and
the master branch while looking to solve another issue. With these other
issues solved I am left with this one still on master and I am looking
for some help.Quoted 7 lines
The error is: failed on
fdt_open_intofor DTO, i.e. overlay application
fdt error. This was introduced by0535e46d55dscripts/dtc: Update to
upstream version v1.7.2-35-g52f07dcca47c, i.e. this patch. Please see
the attached log which includes aprintenvattached.Does this fix your problem ?
boot/image-fit.c +1
-1@@ -2491,7 +2491,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, ov = map_sysmem(ovload, ovlen); ovcopylen = ALIGN(fdt_totalsize(ov), SZ_4K); - ovcopy = malloc(ovcopylen); + ovcopy = memalign(8, ovcopylen); if (!ovcopy) {
Quoted 4 lines
printf("failed to duplicate DTO before application\n");
fdt_noffset=-ENOMEM;
Apologies for the delayed response. The above proposed solution did not change/fix the issue. Any other suggestions would be greatly appreciated.
Thanks again,
Jamie.
On 1/19/26 6:12 PM, [email protected] wrote:
Hello Jamie,
Quoted 18 lines
Quoted 18 lines
Quoted 7 lines
The error is: failed on
fdt_open_intofor DTO, i.e. overlay application
fdt error. This was introduced by0535e46d55dscripts/dtc: Update to
upstream version v1.7.2-35-g52f07dcca47c, i.e. this patch. Please see
the attached log which includes aprintenvattached.Does this fix your problem ?
boot/image-fit.c +0
-0@@ -2491,7 +2491,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, ov = map_sysmem(ovload, ovlen);
Quoted 11 lines
Quoted 8 lines
boot/image-fit.c +1
-1ovcopylen = ALIGN(fdt_totalsize(ov), SZ_4K); - ovcopy = malloc(ovcopylen); + ovcopy = memalign(8, ovcopylen); if (!ovcopy) {printf("failed to duplicate DTO before
application\n");
fdt_noffset=-ENOMEM;Apologies for the delayed response. The above proposed solution did not change/fix the issue. Any other suggestions would be greatly appreciated.
Look at this piece of code in boot/image-fit.c :
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n",
2490 uname, ovload, ovlen);
2491 ov = map_sysmem(ovload, ovlen);
2492
2493 ovcopylen = ALIGN(fdt_totalsize(ov), SZ_4K);
2494 ovcopy = memalign(8, ovcopylen);
2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO before application\n");
2497 fdt_noffset = -ENOMEM;
2498 goto out;2499 }
2500
2501 err = fdt_open_into(ov, ovcopy, ovcopylen);
2502 if (err < 0) {
2503 printf("failed on fdt_open_into for DTO\n");
This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable the debug() print at the beginning (or #define DEBUG at the beginning of this file) to find out.
If $ov is 4-byte aligned, try to generate your fitImage with "mkimage ... -E -B 8 ..." , does that make any difference ?
Hi Marek,
Quoted 59 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
On 1/19/26 6:12 PM, [email protected] wrote:
Hello Jamie,
Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
The error is: failed on
fdt_open_intofor DTO, i.e. overlay application
fdt error. This was introduced by0535e46d55dscripts/dtc:
Update
to
upstream version v1.7.2-35-g52f07dcca47c, i.e. this patch. Please
see
the attached log which includes aprintenvattached.Does this fix your problem ?
boot/image-fit.c +0
-0@@ -2491,7 +2491,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, ov = map_sysmem(ovload, ovlen);Quoted 12 lines
Quoted 8 lines
boot/image-fit.c +1
-1ovcopylen = ALIGN(fdt_totalsize(ov), SZ_4K); - ovcopy = malloc(ovcopylen); + ovcopy = memalign(8, ovcopylen); if (!ovcopy) {
printf("failed to duplicate DTO before application\n");
fdt_noffset=-ENOMEM;Apologies for the delayed response. The above proposed solution did not
change/fix the issue. Any other suggestions would be greatly appreciated.Look at this piece of code in
boot/image-fit.c:2489 debug("%s loaded at 0x%08lx len=0x%08lx\n", 2490 uname, ovload, ovlen); 2491 ov =
map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K); 2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496printf("failed to duplicate DTO before application\n");
2497fdt_noffset=-ENOMEM;
2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen); 2502 if (err < 0) {
2503printf("failed on fdt_open_into for DTO\n");
Quoted 6 lines
This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable the
debug()print at the beginning (or #define DEBUG at the beginning of this file) to find out.If $ov is 4-byte aligned, try to generate your fitImage with "mkimage ... -E -B 8 ..." , does that make any difference ?
Thank you for your suggestions.
I followed your advice and investigated the alignment of the overlay buffer. The error code returned by fdt_open_into was FDT_ERR_ALIGNMENT (-19), confirming that the overlay was not sufficiently aligned for the updated libfdt.
I modified our Buildroot post-image.sh script to generate the FIT image using the suggested arguments. With the -B 8 option, all blobs in the FIT image are now 8-byte aligned. This resolved the alignment error, and device tree overlays are now applied successfully in U-Boot.
Thanks again for your help.
Regards,
Jamie.
On 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 32 lines
Quoted 18 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n", 2490 uname, ovload, ovlen); 2491 ov =
map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K); 2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496printf("failed to duplicate DTO before application\n");
2497fdt_noffset=-ENOMEM;
2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen); 2502 if (err < 0) {
2503printf("failed on fdt_open_into for DTO\n");Quoted 6 lines
This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable the
debug()print at the beginning (or #define DEBUG at the beginning of this file) to find out.If $ov is 4-byte aligned, try to generate your fitImage with "mkimage ... -E -B 8 ..." , does that make any difference ?
Thank you for your suggestions.
I followed your advice and investigated the alignment of the overlay buffer. The error code returned by
fdt_open_intowasFDT_ERR_ALIGNMENT(-19), confirming that the overlay was not sufficiently aligned for the updated libfdt.
Quoted 4 lines
I modified our Buildroot
post-image.shscript to generate the FIT image using the suggested arguments. With the -B 8 option, all blobs in the FIT image are now 8-byte aligned. This resolved the alignment error, and device tree overlays are now applied successfully in U-Boot.
But this is not the fix. Which parameter of fdt_open_into() is unaligned, the ov or ovcopy ?
Hi Marek,
Quoted 54 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
On 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 39 lines
Quoted 25 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n", 2490 uname, ovload, ovlen); 2491 ov =
map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K); 2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO before
application\n");
2497fdt_noffset=-ENOMEM; 2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen); 2502 if (err < 0) {
2503printf("failed on fdt_open_into for DTO\n");This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable the
debug()print at the beginning (or #define DEBUG at the beginning of
this file) to find out.Quoted 3 lines
If $ov is 4-byte aligned, try to generate your fitImage with "mkimage
... -E -B 8 ..." , does that make any difference ?Thank you for your suggestions.
I followed your advice and investigated the alignment of the overlay
buffer. The error code returned byfdt_open_intowasFDT_ERR_ALIGNMENT
(-19), confirming that the overlay was not sufficiently aligned for the
updated libfdt.Quoted 7 lines
I modified our Buildroot
post-image.shscript to generate the FIT image
using the suggested arguments. With the -B 8 option, all blobs in the
FIT image are now 8-byte aligned. This resolved the alignment error,
and device tree overlays are now applied successfully in U-Boot.
Quoted 2 lines
But this is not the fix. Which parameter of
fdt_open_into()is unaligned, the ov or ovcopy ?
ov is unaligned
Thanks,
Jamie
Quoted 57 lines · On 1/20/26 2:53 PM, [email protected] wrote:
Hi Marek,
Quoted 54 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
On 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 46 lines
Quoted 25 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n", 2490 uname, ovload, ovlen); 2491 ov =
map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K); 2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO before
application\n");
2497fdt_noffset=-ENOMEM; 2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen); 2502 if (err < 0) {
2503printf("failed on fdt_open_into for DTO\n");This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable the
debug()print at the beginning (or #define DEBUG at the beginning of
this file) to find out.Quoted 3 lines
If $ov is 4-byte aligned, try to generate your fitImage with "mkimage
... -E -B 8 ..." , does that make any difference ?Thank you for your suggestions.
I followed your advice and investigated the alignment of the overlay
buffer. The error code returned byfdt_open_intowasFDT_ERR_ALIGNMENT
(-19), confirming that the overlay was not sufficiently aligned for the
updated libfdt.I modified our Buildroot
post-image.shscript to generate the FIT image
using the suggested arguments. With the -B 8 option, all blobs in the
FIT image are now 8-byte aligned. This resolved the alignment error,
and device tree overlays are now applied successfully in U-Boot.
Quoted 4 lines
Quoted 2 lines
But this is not the fix. Which parameter of
fdt_open_into()is unaligned, the ov or ovcopy ?ov is unaligned
Does this help even without the mkimage -B 8 ?
boot/image-fit.c +1 -1
@@ -2481,7 +2481,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, addr, &uname, &uconfig, arch,IH_TYPE_FLATDT ,BOOTSTAGE_ID_FIT_FDT_START , - FIT_LOAD_IGNORED, &ovload, &ovlen); + FIT_LOAD_OPTIONAL_NON_ZERO, &ovload, &ovlen);if (ov_noffset <0 ) {printf ("load of %s failed\n" , uname);continue ;
Quoted 90 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 67 lines · On 1/20/26 2:53 PM, [email protected] wrote:
Hi Marek,
Quoted 64 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
On 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 56 lines
Quoted 31 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n",
2490 uname, ovload, ovlen); 2491 ov =map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K);
2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO before
application\n");
2497fdt_noffset=-ENOMEM; 2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen);
2502 if (err < 0) {
2503 printf("failed onfdt_open_intofor
DTO\n");This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable
thedebug()print at the beginning (or #define DEBUG at the beginning
of
this file) to find out.Quoted 3 lines
If $ov is 4-byte aligned, try to generate your fitImage with "mkimage
... -E -B 8 ..." , does that make any difference ?Thank you for your suggestions.
I followed your advice and investigated the alignment of the overlay
buffer. The error code returned byfdt_open_intowasFDT_ERR_ALIGNMENT
(-19), confirming that the overlay was not sufficiently aligned for
the
updated libfdt.I modified our Buildroot
post-image.shscript to generate the FIT
image
using the suggested arguments. With the -B 8 option, all blobs in
the
FIT image are now 8-byte aligned. This resolved the alignment error,
and device tree overlays are now applied successfully in U- Boot.Quoted 4 lines
Quoted 2 lines
But this is not the fix. Which parameter of
fdt_open_into()is unaligned, the ov or ovcopy ?ov is unaligned
Does this help even without the mkimage -B 8 ?
boot/image-fit.c +1
-1@@ -2481,7 +2481,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, addr, &uname, &uconfig, arch, IH_TYPE_FLATDT, BOOTSTAGE_ID_FIT_FDT_START, - FIT_LOAD_IGNORED, &ovload, &ovlen); + FIT_LOAD_OPTIONAL_NON_ZERO, &ovload, &ovlen); if (ov_noffset < 0) {
Quoted 2 lines
printf("load of %s failed\n", uname); continue;
This solution removed this misalignment in ov and allowed the system to boot - without any change/additional arguments to mkimage.
Thanks,
Jamie
Quoted 87 lines · On 1/20/26 3:50 PM, [email protected] wrote:
Quoted 86 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 67 lines · On 1/20/26 2:53 PM, [email protected] wrote:
Hi Marek,
Quoted 64 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
On 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 56 lines
Quoted 31 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n",
2490 uname, ovload, ovlen); 2491 ov =map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K);
2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO before
application\n");
2497fdt_noffset=-ENOMEM; 2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen);
2502 if (err < 0) {
2503 printf("failed onfdt_open_intofor
DTO\n");This is where it fails. Is $ov or $ovcopy 4-byte aligned ? Enable
thedebug()print at the beginning (or #define DEBUG at the beginning
of
this file) to find out.Quoted 3 lines
If $ov is 4-byte aligned, try to generate your fitImage with "mkimage
... -E -B 8 ..." , does that make any difference ?Thank you for your suggestions.
I followed your advice and investigated the alignment of the overlay
buffer. The error code returned byfdt_open_intowasFDT_ERR_ALIGNMENT
(-19), confirming that the overlay was not sufficiently aligned for
the
updated libfdt.I modified our Buildroot
post-image.shscript to generate the FIT
image
using the suggested arguments. With the -B 8 option, all blobs in
the
FIT image are now 8-byte aligned. This resolved the alignment error,
and device tree overlays are now applied successfully in U- Boot.Quoted 4 lines
Quoted 2 lines
But this is not the fix. Which parameter of
fdt_open_into()is unaligned, the ov or ovcopy ?ov is unaligned
Does this help even without the mkimage -B 8 ?
boot/image-fit.c +0
-0@@ -2481,7 +2481,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, addr, &uname, &uconfig, arch, IH_TYPE_FLATDT,
Quoted 8 lines
Quoted 6 lines
boot/image-fit.c +1
-1BOOTSTAGE_ID_FIT_FDT_START, - FIT_LOAD_IGNORED, &ovload, &ovlen); + FIT_LOAD_OPTIONAL_NON_ZERO, &ovload, &ovlen); if (ov_noffset < 0) {
printf("load of %s failed\n", uname); continue;This solution removed this misalignment in ov and allowed the system to boot - without any change/additional arguments to mkimage.
Would you be willing to submit this as a bugfix ?
Quoted 113 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 101 lines · On 1/20/26 3:50 PM, [email protected] wrote:
Quoted 100 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 78 lines · On 1/20/26 2:53 PM, [email protected] wrote:
Hi Marek,
Quoted 75 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you
know the content is safeOn 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 66 lines
Quoted 35 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n",
2490 uname, ovload, ovlen);
2491 ov =map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K);
2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO
before
application\n");
2497fdt_noffset=-ENOMEM; 2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen);
2502 if (err < 0) {
2503 printf("failed onfdt_open_into
for
DTO\n");This is where it fails. Is $ov or $ovcopy 4-byte aligned ?
Enable
thedebug()print at the beginning (or #define DEBUG at the beginning
of
this file) to find out.Quoted 4 lines
If $ov is 4-byte aligned, try to generate your fitImage with
"mkimage
... -E -B 8 ..." , does that make any difference ?Thank you for your suggestions.
I followed your advice and investigated the alignment of the
overlay
buffer. The error code returned byfdt_open_intowasFDT_ERR_ALIGNMENT
(-19), confirming that the overlay was not sufficiently aligned
for
the
updated libfdt.I modified our Buildroot
post-image.shscript to generate the
FIT
image
using the suggested arguments. With the -B 8 option, all blobs
in
the
FIT image are now 8-byte aligned. This resolved the alignment
error,
and device tree overlays are now applied successfully in U- Boot.Quoted 5 lines
Quoted 3 lines
But this is not the fix. Which parameter of
fdt_open_into()is
unaligned, the ov or ovcopy ?ov is unaligned
Does this help even without the mkimage -B 8 ?
boot/image-fit.c +0
-1@@ -2481,7 +2481,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, addr, &uname, &uconfig, arch, IH_TYPE_FLATDT, BOOTSTAGE_ID_FIT_FDT_START, - FIT_LOAD_IGNORED, &ovload, &ovlen);Quoted 8 lines
Quoted 5 lines
boot/image-fit.c +1
-0+ FIT_LOAD_OPTIONAL_NON_ZERO, &ovload, &ovlen);if (
ov_noffset< 0) {
printf("load of %s failed\n", uname); continue;This solution removed this misalignment in ov and allowed the system to
boot - without any change/additional arguments to mkimage.
Quoted 1 line
Would you be willing to submit this as a bugfix ?
Yes, no problem. I will do so.
Thanks again for your help,
Jamie.
Quoted 114 lines · On 1/20/26 3:56 PM, [email protected] wrote:
Quoted 113 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 109 lines · On 1/20/26 3:50 PM, [email protected] wrote:
Quoted 102 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 78 lines · On 1/20/26 2:53 PM, [email protected] wrote:
Hi Marek,
Quoted 75 lines · Marek Vasut
EXTERNAL EMAIL: Do not click links or open attachments unless you
know the content is safeOn 1/20/26 11:45 AM, [email protected] wrote:
Hello Jamie,
Quoted 66 lines
Quoted 35 lines
2489 debug("%s loaded at 0x%08lx len=0x%08lx\n",
2490 uname, ovload, ovlen);
2491 ov =map_sysmem(ovload, ovlen); 2492
2493 ovcopylen =ALIGN(fdt_totalsize(ov), SZ_4K);
2494 ovcopy =memalign(8, ovcopylen); 2495 if (!ovcopy) {
2496 printf("failed to duplicate DTO
before
application\n");
2497fdt_noffset=-ENOMEM; 2498 goto out;
2499 }
2500
2501 err =fdt_open_into(ov, ovcopy, ovcopylen);
2502 if (err < 0) {
2503 printf("failed onfdt_open_into
for
DTO\n");This is where it fails. Is $ov or $ovcopy 4-byte aligned ?
Enable
thedebug()print at the beginning (or #define DEBUG at the beginning
of
this file) to find out.Quoted 4 lines
If $ov is 4-byte aligned, try to generate your fitImage with
"mkimage
... -E -B 8 ..." , does that make any difference ?Thank you for your suggestions.
I followed your advice and investigated the alignment of the
overlay
buffer. The error code returned byfdt_open_intowasFDT_ERR_ALIGNMENT
(-19), confirming that the overlay was not sufficiently aligned
for
the
updated libfdt.I modified our Buildroot
post-image.shscript to generate the
FIT
image
using the suggested arguments. With the -B 8 option, all blobs
in
the
FIT image are now 8-byte aligned. This resolved the alignment
error,
and device tree overlays are now applied successfully in U- Boot.Quoted 5 lines
Quoted 3 lines
But this is not the fix. Which parameter of
fdt_open_into()is
unaligned, the ov or ovcopy ?ov is unaligned
Does this help even without the mkimage -B 8 ?
boot/image-fit.c +1
-1@@ -2481,7 +2481,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr, addr, &uname, &uconfig, arch, IH_TYPE_FLATDT, BOOTSTAGE_ID_FIT_FDT_START, - FIT_LOAD_IGNORED, &ovload, &ovlen); + FIT_LOAD_OPTIONAL_NON_ZERO, &ovload, &ovlen);Quoted 3 lines
if (
ov_noffset< 0) {
printf("load of %s failed\n", uname); continue;This solution removed this misalignment in ov and allowed the system to
boot - without any change/additional arguments to mkimage.
Quoted 2 lines
Quoted 1 line
Would you be willing to submit this as a bugfix ?
Yes, no problem. I will do so.
Thank you !