summaryrefslogtreecommitdiff
path: root/common/fdt_support.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-05-13 13:09:14 -0400
committerTom Rini <trini@konsulko.com>2021-05-13 13:09:14 -0400
commit530c8d4af2e18c6142ab7cac6f11dd92c02b2bc9 (patch)
treee8b15ca22922539dc4500cc85679c537722ccc38 /common/fdt_support.c
parentea184cbff99ea1d82dcf94c95afe054e95da5069 (diff)
parent1569847e7c7b6cba6a04b5f5a5e7aa9caeeef41b (diff)
Merge branch '2021-05-13-extension-board-detection-and-DT-overlay-application'
- Improve support for various forms of extension boards and add DT overlay application support.
Diffstat (limited to 'common/fdt_support.c')
-rw-r--r--common/fdt_support.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 695d8e134aa..a9a32df1e78 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -1904,3 +1904,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;
+}