aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWesley W. Terpstra <wesley@sifive.com>2017-03-23 19:11:44 -0700
committerWesley W. Terpstra <wesley@sifive.com>2017-03-23 19:17:22 -0700
commita1a5cbcacbbb43527fb6a4991ead1ae64cf18463 (patch)
treeff7a3fc6d9969d19d125af3d4713f398c47c309e
parentfc1af65c1585b2a9ad1dd2cf1b50d552ee65c742 (diff)
downloadriscv-pk-a1a5cbcacbbb43527fb6a4991ead1ae64cf18463.zip
riscv-pk-a1a5cbcacbbb43527fb6a4991ead1ae64cf18463.tar.gz
riscv-pk-a1a5cbcacbbb43527fb6a4991ead1ae64cf18463.tar.bz2
fdt: add a size method
-rw-r--r--machine/fdt.c10
-rw-r--r--machine/fdt.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/machine/fdt.c b/machine/fdt.c
index f297e52..a040e87 100644
--- a/machine/fdt.c
+++ b/machine/fdt.c
@@ -68,6 +68,16 @@ void fdt_scan(uintptr_t fdt, fdt_cb cb, void *extra)
fdt_scan_helper(lex, strings, "/", 0, cb, extra);
}
+uint32_t fdt_size(uintptr_t fdt)
+{
+ struct fdt_header *header = (struct fdt_header *)fdt;
+
+ // Only process FDT that we understand
+ if (bswap(header->magic) != FDT_MAGIC ||
+ bswap(header->last_comp_version) > FDT_VERSION) return 0;
+ return bswap(header->totalsize);
+}
+
const uint32_t *fdt_get_address(const struct fdt_scan_node *node, const uint32_t *value, uintptr_t *result)
{
*result = 0;
diff --git a/machine/fdt.h b/machine/fdt.h
index 71726ce..8b01bc8 100644
--- a/machine/fdt.h
+++ b/machine/fdt.h
@@ -41,6 +41,7 @@ struct fdt_scan_prop {
// Scan the contents of FDT
typedef void (*fdt_cb)(const struct fdt_scan_prop *prop, void *extra);
void fdt_scan(uintptr_t fdt, fdt_cb cb, void *extra);
+uint32_t fdt_size(uintptr_t fdt);
// Extract fields
const uint32_t *fdt_get_address(const struct fdt_scan_node *node, const uint32_t *base, uintptr_t *value);