From f9898c25c7b5763189a7c4f772f6d2c64f4da8a6 Mon Sep 17 00:00:00 2001 From: schulz Date: Wed, 30 Jan 2019 19:59:16 +0000 Subject: [PATCH] device tree stores header and provides function querying total DT size git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@55582 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- arch/armeb-raspi/boot/devicetree.c | 27 +++++++++++++++++++++------ arch/armeb-raspi/boot/include/devicetree.h | 9 +++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/arch/armeb-raspi/boot/devicetree.c b/arch/armeb-raspi/boot/devicetree.c index 51436d9582..1f6741bbdc 100644 --- a/arch/armeb-raspi/boot/devicetree.c +++ b/arch/armeb-raspi/boot/devicetree.c @@ -13,7 +13,7 @@ char *strings; struct dt_entry * dt_build_node(struct dt_entry *parent) { struct dt_entry *e = malloc(sizeof(struct dt_entry)); - + if (e != NULL) { e->dte_parent = parent; @@ -36,7 +36,7 @@ struct dt_entry * dt_build_node(struct dt_entry *parent) e->dte_children = e1; break; } - + case FDT_PROP: { struct dt_prop *p = malloc(sizeof (struct dt_prop)); @@ -64,11 +64,22 @@ struct dt_entry * dt_build_node(struct dt_entry *parent) return e; } +static struct fdt_header *hdr; + +long dt_total_size() +{ + if (hdr != NULL) + return AROS_BE2LONG(hdr->totalsize); + else + return 0; +} + struct dt_entry * dt_parse(void *dt) { - struct fdt_header *hdr = dt; uint32_t token = 0; + hdr = dt; + D(kprintf("[BOOT] Checking device tree at %p\n", hdr)); D(kprintf("[BOOT] magic=%08x\n", hdr->magic)); @@ -109,6 +120,10 @@ struct dt_entry * dt_parse(void *dt) } } while (token != FDT_END); } + else + { + hdr = NULL; + } return root; } @@ -206,13 +221,13 @@ void dt_dump_node(struct dt_entry *n, int level) else kprintf("."); } - + if (p->dtp_length) { kprintf(" ("); int max = 16; if (max > p->dtp_length) max = p->dtp_length; - + for (int i=0; i < p->dtp_length; i++) { char *pchar = p->dtp_value + i; kprintf("%02x", *pchar); @@ -233,4 +248,4 @@ void dt_dump_tree() dt_dump_node(root, 0); -} \ No newline at end of file +} diff --git a/arch/armeb-raspi/boot/include/devicetree.h b/arch/armeb-raspi/boot/include/devicetree.h index a9b437343f..e3757dbc11 100644 --- a/arch/armeb-raspi/boot/include/devicetree.h +++ b/arch/armeb-raspi/boot/include/devicetree.h @@ -4,16 +4,16 @@ #include #include -struct fdt_header { +struct fdt_header { uint32_t magic; uint32_t totalsize; uint32_t off_dt_struct; uint32_t off_dt_strings; uint32_t off_mem_rsvmap; uint32_t version; - uint32_t last_comp_version; - uint32_t boot_cpuid_phys; - uint32_t size_dt_strings; + uint32_t last_comp_version; + uint32_t boot_cpuid_phys; + uint32_t size_dt_strings; uint32_t size_dt_struct; }; @@ -52,6 +52,7 @@ struct dt_entry { void dt_dump_tree(); struct dt_entry *dt_parse(void *ptr); +long dt_total_size(); struct dt_entry *dt_find_node_by_phandle(uint32_t phandle); struct dt_entry *dt_find_node(char *key); struct dt_prop *dt_find_property(void *key, char *propname); -- 2.11.4.GIT