diff options
author | Laurentiu Tudor <laurentiu.tudor@nxp.com> | 2020-04-03 13:43:03 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-04-16 08:07:58 -0600 |
commit | b9200b191f62254036cd0d7818bfb24125b7585b (patch) | |
tree | ff846bc4c0caf56aa610472bea05653ff844a1a4 /lib/fdtdec.c | |
parent | 5c9c9bc9571f23d4c8bab18fc50fc1238da0c6c1 (diff) | |
download | u-boot-b9200b191f62254036cd0d7818bfb24125b7585b.zip u-boot-b9200b191f62254036cd0d7818bfb24125b7585b.tar.gz u-boot-b9200b191f62254036cd0d7818bfb24125b7585b.tar.bz2 |
fdtdec: support multiple phandles in memory carveout
fdtdec_set_carveout() is limited to only one phandle. Fix this
limitation by adding support for multiple phandles.
Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/fdtdec.c')
-rw-r--r-- | lib/fdtdec.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index eb11fc8..9ecfa2a 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1433,14 +1433,9 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name, const struct fdt_memory *carveout) { uint32_t phandle; - int err, offset; + int err, offset, len; fdt32_t value; - - /* XXX implement support for multiple phandles */ - if (index > 0) { - debug("invalid index %u\n", index); - return -FDT_ERR_BADOFFSET; - } + void *prop; err = fdtdec_add_reserved_memory(blob, name, carveout, &phandle); if (err < 0) { @@ -1456,10 +1451,31 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name, value = cpu_to_fdt32(phandle); - err = fdt_setprop(blob, offset, prop_name, &value, sizeof(value)); + if (!fdt_getprop(blob, offset, prop_name, &len)) { + if (len == -FDT_ERR_NOTFOUND) + len = 0; + else + return len; + } + + if ((index + 1) * sizeof(value) > len) { + err = fdt_setprop_placeholder(blob, offset, prop_name, + (index + 1) * sizeof(value), + &prop); + if (err < 0) { + debug("failed to resize reserved memory property: %s\n", + fdt_strerror(err)); + return err; + } + } + + err = fdt_setprop_inplace_namelen_partial(blob, offset, prop_name, + strlen(prop_name), + index * sizeof(value), + &value, sizeof(value)); if (err < 0) { - debug("failed to set %s property for node %s: %d\n", prop_name, - node, err); + debug("failed to update %s property for node %s: %s\n", + prop_name, node, fdt_strerror(err)); return err; } |