diff options
author | Marek Vasut <marek.vasut+renesas@gmail.com> | 2017-11-27 05:32:42 +0100 |
---|---|---|
committer | Marek Vasut <marek.vasut+renesas@gmail.com> | 2017-11-30 02:32:33 +0100 |
commit | 942ee0933e881ff500aae7e42309bf6abbc495d4 (patch) | |
tree | 47d2e6e8ad6453e9d2acade3ff0b69f086cd51e9 | |
parent | 9db60e257be0d928726c7ffe273039860e968d46 (diff) | |
download | u-boot-942ee0933e881ff500aae7e42309bf6abbc495d4.zip u-boot-942ee0933e881ff500aae7e42309bf6abbc495d4.tar.gz u-boot-942ee0933e881ff500aae7e42309bf6abbc495d4.tar.bz2 |
fdtdec: Support parsing multiple /memory nodes
It is legal to have multiple /memory nodes in a device tree . Currently,
fdtdec_setup_memory_size() only supports parsing the first node . This
patch extends the function such that if a particular /memory node does
no longer have further "reg" entries and CONFIG_NR_DRAM_BANKS still
allows for more DRAM banks, the code moves on to the next memory node
and checks it's "reg"s. This makes it possible to handle both systems
with single memory node with multiple entries and systems with multiple
memory nodes with single entry.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>
-rw-r--r-- | lib/fdtdec.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index c4582ea..46df0f1 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1176,21 +1176,33 @@ int fdtdec_setup_memory_size(void) #if defined(CONFIG_NR_DRAM_BANKS) int fdtdec_setup_memory_banksize(void) { - int bank, ret, mem; + int bank, ret, mem, reg = 0; struct fdt_resource res; - mem = fdt_path_offset(gd->fdt_blob, "/memory"); + mem = fdt_node_offset_by_prop_value(gd->fdt_blob, -1, "device_type", + "memory", 7); if (mem < 0) { debug("%s: Missing /memory node\n", __func__); return -EINVAL; } for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", bank, &res); - if (ret == -FDT_ERR_NOTFOUND) - break; - if (ret != 0) + ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); + if (ret == -FDT_ERR_NOTFOUND) { + reg = 0; + mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem, + "device_type", + "memory", 7); + if (mem == -FDT_ERR_NOTFOUND) + break; + + ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); + if (ret == -FDT_ERR_NOTFOUND) + break; + } + if (ret != 0) { return -EINVAL; + } gd->bd->bi_dram[bank].start = (phys_addr_t)res.start; gd->bd->bi_dram[bank].size = |