From 46743c412de57158bde73a904511519d1fdab609 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 20 Dec 2016 15:58:44 +0100 Subject: libfdt: Correct fdt handling of overlays without fixups and base trees without symbols The fdt_overlay_apply() function purports to support the edge cases where an overlay has no fixups to be applied, or a base tree which has no symbols (the latter can only work if the former is also true). However it gets it wrong in a couple of small ways: * In the no fixups case, it doesn't fail immediately, but will attempt fdt_for_each_property_offset() giving -FDT_ERR_NOTFOUND as the node offset, which will fail. Instead it should succeed immediately, since there's nothing to do. * In the case of no symbols, it again doesn't fail immediately. However if there is an actual fixup it will fail with an unexpected error, because -FDT_ERR_NOTFOUND is passed to fdt_getprop() when attempting to look up the symbols. We should instead return -FDT_ERR_NOTFOUND directly. Both of these errors lead to the code returning misleading error codes in failing cases. [ DTC commit: 7d8ef6e1db9794f72805a0855f4f7f12fadd03d3 ] Signed-off-by: David Gibson Signed-off-by: Stefan Agner Acked-by: Simon Glass --- lib/libfdt/fdt_overlay.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/libfdt/fdt_overlay.c b/lib/libfdt/fdt_overlay.c index bb41404..56cb70e 100644 --- a/lib/libfdt/fdt_overlay.c +++ b/lib/libfdt/fdt_overlay.c @@ -359,6 +359,9 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto, int symbol_off, fixup_off; int prop_len; + if (symbols_off < 0) + return symbols_off; + symbol_path = fdt_getprop(fdt, symbols_off, label, &prop_len); if (!symbol_path) @@ -492,7 +495,9 @@ static int overlay_fixup_phandles(void *fdt, void *fdto) /* We can have overlays without any fixups */ fixups_off = fdt_path_offset(fdto, "/__fixups__"); - if ((fixups_off < 0 && (fixups_off != -FDT_ERR_NOTFOUND))) + if (fixups_off == -FDT_ERR_NOTFOUND) + return 0; /* nothing to do */ + if (fixups_off < 0) return fixups_off; /* And base DTs without symbols */ -- cgit v1.1 From 082b1414e80ffa94569613705eac319488324516 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 20 Dec 2016 15:58:45 +0100 Subject: cmd: fdt: Print error message when fdt application fails There are lots of reason why a FDT application might fail, the error code might give an indication. Let the error code translate in a error string so users can try to understand what went wrong. Signed-off-by: Stefan Agner Acked-by: Maxime Ripard Acked-by: Simon Glass --- cmd/fdt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 8bd345a..6883e75 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -642,6 +642,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) else if (strncmp(argv[1], "ap", 2) == 0) { unsigned long addr; struct fdt_header *blob; + int ret; if (argc != 3) return CMD_RET_USAGE; @@ -654,8 +655,11 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (!fdt_valid(&blob)) return CMD_RET_FAILURE; - if (fdt_overlay_apply(working_fdt, blob)) + ret = fdt_overlay_apply(working_fdt, blob); + if (ret) { + printf("fdt_overlay_apply(): %s\n", fdt_strerror(ret)); return CMD_RET_FAILURE; + } } #endif /* resize the fdt */ -- cgit v1.1 From b05bf6c75d03c925737e228472b694cbeaa503c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 9 Jan 2017 16:08:02 +0100 Subject: cmd/fdt: Make fdt get value endian-safe for single-cell properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a Raspberry Pi 2 disagreements on cell endianness can be observed: U-Boot> fdt print /soc/gpio@7e200000 phandle phandle = <0x0000000d> U-Boot> fdt get value myvar /soc/gpio@7e200000 phandle; printenv myvar myvar=0x0D000000 Fix this by always treating the pointer as BE and converting it in fdt_value_setenv(), like its counterpart fdt_parse_prop() already does. Consistently use fdt32_t, fdt32_to_cpu() and cpu_to_fdt32(). Fixes: bc80295 ("fdt: Add get commands to fdt") Cc: Joe Hershberger Cc: Gerald Van Baren Signed-off-by: Andreas Färber Acked-by: Simon Glass --- cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 6883e75..95dd673 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -58,7 +58,7 @@ static int fdt_value_setenv(const void *nodep, int len, const char *var) else if (len == 4) { char buf[11]; - sprintf(buf, "0x%08X", *(uint32_t *)nodep); + sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep)); setenv(var, buf); } else if (len%4 == 0 && len <= 20) { /* Needed to print things like sha1 hashes. */ @@ -768,7 +768,7 @@ static int fdt_parse_prop(char * const *newval, int count, char *data, int *len) cp = newp; tmp = simple_strtoul(cp, &newp, 0); - *(__be32 *)data = __cpu_to_be32(tmp); + *(fdt32_t *)data = cpu_to_fdt32(tmp); data += 4; *len += 4; -- cgit v1.1