Compare commits

..

2 commits

Author SHA1 Message Date
Herve Codina
5976c4a660 libfdt: fdt_rw: Introduce fdt_downgrade_version()
Some checks failed
Build test / build-make (alpine) (push) Has been cancelled
Build test / build-make (archlinux) (push) Has been cancelled
Build test / build-make (fedora) (push) Has been cancelled
Build test / build-make (ubuntu) (push) Has been cancelled
Build test / build-meson (alpine) (push) Has been cancelled
Build test / build-meson (archlinux) (push) Has been cancelled
Build test / build-meson (fedora) (push) Has been cancelled
Build test / build-meson (ubuntu) (push) Has been cancelled
Build test / clang64 (push) Has been cancelled
Build test / mingw32 (push) Has been cancelled
Build test / mingw64 (push) Has been cancelled
Build test / ucrt64 (push) Has been cancelled
Current code perform a version downgrade at one place only, the end of
fdt_rw_probe_().

In order to offer a finer grain and choose to downgrade or not depending
on the exact writes done, introduce fdt_downgrade_version() to perform
the downgrade operation.

The modification doesn't introduce any functional changes.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Message-ID: <20260210173349.636766-5-herve.codina@bootlin.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2026-02-24 17:00:38 +11:00
Herve Codina
5bb5bedd34 fdtdump: Return an error code on wrong tag value
fdtdump prints a message on stderr when it encounters a wrong tag and
stop its processing without returning an error code.

Having a wrong tag is really a failure. Indeed, the processing cannot
continue.

Be more strict. Stop the processing, print a message and return an
error code. In other words, call die().

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Message-ID: <20260210173349.636766-4-herve.codina@bootlin.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2026-02-24 16:52:47 +11:00
2 changed files with 8 additions and 4 deletions

View file

@ -146,8 +146,7 @@ static void dump_blob(void *blob, bool debug)
continue;
}
fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
break;
die("** Unknown tag 0x%08"PRIx32"\n", tag);
}
}

View file

@ -22,6 +22,12 @@ static int fdt_blocks_misordered_(const void *fdt,
(fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)));
}
static void fdt_downgrade_version(void *fdt)
{
if (!can_assume(LATEST) && fdt_version(fdt) > FDT_LAST_SUPPORTED_VERSION)
fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION);
}
static int fdt_rw_probe_(void *fdt)
{
if (can_assume(VALID_DTB))
@ -33,9 +39,8 @@ static int fdt_rw_probe_(void *fdt)
if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry),
fdt_size_dt_struct(fdt)))
return -FDT_ERR_BADLAYOUT;
if (!can_assume(LATEST) && fdt_version(fdt) > 17)
fdt_set_version(fdt, 17);
fdt_downgrade_version(fdt);
return 0;
}