From 18f4b7dd3b97f7dc42337445ea0290b65e0b2a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Fri, 24 Aug 2012 17:56:45 +0200 Subject: [PATCH] U-Boot: dump the passed FDT * add some helpers for Flattened Device Trees, for now a dump call * dump the passed FDT on startup for now Conflicts: src/system/boot/platform/u-boot/Jamfile (cherry picked from my sam460ex branch) --- src/system/boot/platform/u-boot/Jamfile | 1 + .../boot/platform/u-boot/fdt_support.cpp | 108 ++++++++++++++++++ src/system/boot/platform/u-boot/start.cpp | 7 +- 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/system/boot/platform/u-boot/fdt_support.cpp diff --git a/src/system/boot/platform/u-boot/Jamfile b/src/system/boot/platform/u-boot/Jamfile index 918257b35b..029fd3da54 100644 --- a/src/system/boot/platform/u-boot/Jamfile +++ b/src/system/boot/platform/u-boot/Jamfile @@ -51,6 +51,7 @@ KernelMergeObject boot_platform_u-boot_common.o : cpu.cpp uimage.cpp video.cpp + fdt_support.cpp $(genericPlatformSources) $(libFDTSources) diff --git a/src/system/boot/platform/u-boot/fdt_support.cpp b/src/system/boot/platform/u-boot/fdt_support.cpp new file mode 100644 index 0000000000..3fba564ef0 --- /dev/null +++ b/src/system/boot/platform/u-boot/fdt_support.cpp @@ -0,0 +1,108 @@ +/* + * Copyright 2012, François Revol, revol@free.fr. + * Distributed under the terms of the MIT License. + */ + +#include +#include +#include +#include +#include + +extern "C" { +#include +#include +#include +}; + + +extern "C" void dump_fdt(const void *fdt); + +static const char *sTabTab = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; +#define DS "%.*s" +#define DA depth - 1, sTabTab + +#define FDT_DUMP_PROPS +//#define FDT_DUMP_PROP_VALUES + + +static void dump_hex(const char *data, int32 len, int depth) +{ + char str[128]; + char astr[32]; + char *p; + int l; + int i; + + for (i = 0; i < len; ) { + p = str; + l = sizeof(str); + for (; i < len && (p == str || (i % 16 != 0)); i++) { + snprintf(p, l - 1, "%02x ", data[i]); + l -= strlen(p); + p += strlen(p); + astr[i % 16] = isprint(data[i]) ? data[i] : '.'; + astr[i % 16] = isprint(data[i]) ? data[i] : '.'; + astr[(i % 16) + 1] = '\0'; + } + dprintf(DS" %-32.32s %s\n", DA, str, astr); + } +} + + +void dump_fdt(const void *fdt) +{ + uint32 *sizes; + int i, err, len; + int node = -1; + int depth = 0; + const struct fdt_property *property; + + dprintf("FDT @ %p:\n", fdt); + + if (!fdt) + return; + + err = fdt_check_header(fdt); + if (err) { + dprintf("fdt error: %s\n", fdt_strerror(err)); + return; + } + + dprintf("fdt_totalsize: %d\n", fdt_totalsize(fdt)); + dprintf("fdt_off_dt_struct: %d\n", fdt_off_dt_struct(fdt)); + dprintf("fdt_off_dt_strings: %d\n", fdt_off_dt_strings(fdt)); + dprintf("fdt_off_mem_rsvmap: %d\n", fdt_off_mem_rsvmap(fdt)); + dprintf("fdt_version: %d\n", fdt_version(fdt)); + dprintf("fdt_last_comp_version: %d\n", fdt_last_comp_version(fdt)); + dprintf("fdt_boot_cpuid_phys: %d\n", fdt_boot_cpuid_phys(fdt)); + dprintf("fdt_size_dt_strings: %d\n", fdt_size_dt_strings(fdt)); + dprintf("fdt_size_dt_struct: %d\n", fdt_size_dt_struct(fdt)); + + dprintf("fdt tree:\n"); + + while ((node = fdt_next_node(fdt, node, &depth)) >= 0) { + dprintf(DS"node at %d: '%s'\n", DA, node, + fdt_get_name(fdt, node, NULL)); +#ifdef FDT_DUMP_PROPS + int prop; + prop = fdt_first_property_offset(fdt, node); + while (prop >= 0) { + property = fdt_get_property_by_offset(fdt, prop, &len); + if (property == NULL) { + dprintf("getting prop at %d: %s\n", prop, fdt_strerror(len)); + break; + } + dprintf(DS" prop at %d: '%s', len %d\n", DA, prop, + fdt_string(fdt, fdt32_to_cpu(property->nameoff)), + fdt32_to_cpu(property->len)); +#ifdef FDT_DUMP_PROP_VALUES + dump_hex(property->data, fdt32_to_cpu(property->len), depth); +#endif + prop = fdt_next_property_offset(fdt, prop); + } +#endif + } +} + + diff --git a/src/system/boot/platform/u-boot/start.cpp b/src/system/boot/platform/u-boot/start.cpp index 9b87c906f4..a6ad586dd6 100644 --- a/src/system/boot/platform/u-boot/start.cpp +++ b/src/system/boot/platform/u-boot/start.cpp @@ -50,6 +50,7 @@ extern "C" int main(stage2_args *args); extern "C" void _start(void); extern "C" int start_raw(int argc, const char **argv); extern "C" void dump_uimage(struct image_header *image); +extern "C" void dump_fdt(const void *fdt); // declared in shell.S // those are initialized to NULL but not in the BSS @@ -186,11 +187,13 @@ start_raw(int argc, const char **argv) dprintf("argv[%d] @%lx = '%s'\n", i, (uint32)argv[i], argv[i]); dprintf("os: %d\n", (int)gUBootOS); dprintf("gd @ %p\n", gUBootGlobalData); - dprintf("gd->bd @ %p\n", gUBootGlobalData->bd); + if (gUBootGlobalData) + dprintf("gd->bd @ %p\n", gUBootGlobalData->bd); //dprintf("fb_base %p\n", (void*)gUBootGlobalData->fb_base); - dprintf("uimage @ %p\n", gUImage); if (gUImage) dump_uimage(gUImage); + if (gFDT) + dump_fdt(gFDT); } mmu_init();