diff options
author | Kory Maincent <kory.maincent@bootlin.com> | 2021-05-04 19:31:21 +0200 |
---|---|---|
committer | Han Gao <gaohan@iscas.ac.cn> | 2023-10-20 13:38:37 +0800 |
commit | 5468ecbaf0842e2ba20704cc46dfa19d510746c9 (patch) | |
tree | 7a0e709264f6ff53000bf63c90a7cd26c91f0eaf /common/fdt_support.c | |
parent | 4f8a362580bc7754a3cd7b961cd82c338607c06b (diff) |
fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c
Move the fdt_valid function to fdt_support.
This changes allow to be able to test the validity of a devicetree in
other c files.
Update code syntax.
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Maxime Ripard <maxime@cerno.tech>
Diffstat (limited to 'common/fdt_support.c')
-rw-r--r-- | common/fdt_support.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/common/fdt_support.c b/common/fdt_support.c index 02cf5c62..a334e008 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1809,3 +1809,49 @@ int fdt_overlay_apply_verbose(void *fdt, void *fdto) return err; } #endif + +/** + * fdt_valid() - Check if an FDT is valid. If not, change it to NULL + * + * @blobp: Pointer to FDT pointer + * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL) + */ +int fdt_valid(struct fdt_header **blobp) +{ + const void *blob = *blobp; + int err; + + if (!blob) { + printf("The address of the fdt is invalid (NULL).\n"); + return 0; + } + + err = fdt_check_header(blob); + if (err == 0) + return 1; /* valid */ + + if (err < 0) { + printf("libfdt fdt_check_header(): %s", fdt_strerror(err)); + /* + * Be more informative on bad version. + */ + if (err == -FDT_ERR_BADVERSION) { + if (fdt_version(blob) < + FDT_FIRST_SUPPORTED_VERSION) { + printf(" - too old, fdt %d < %d", + fdt_version(blob), + FDT_FIRST_SUPPORTED_VERSION); + } + if (fdt_last_comp_version(blob) > + FDT_LAST_SUPPORTED_VERSION) { + printf(" - too new, fdt %d > %d", + fdt_version(blob), + FDT_LAST_SUPPORTED_VERSION); + } + } + printf("\n"); + *blobp = NULL; + return 0; + } + return 1; +} |