X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Ffdt_support.c;h=3778de5368661369e41b8c6b435e86202e31f225;hb=60c7facfc965af6ff8ea14ee26c9d49cd2d0ec22;hp=86de5b8f05bd49375c14028057ef2fe5c427b945;hpb=bfe28bc70fc8b192878d6e8b7f7db344091643cf;p=oweals%2Fu-boot.git diff --git a/common/fdt_support.c b/common/fdt_support.c index 86de5b8f05..3778de5368 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -7,7 +7,10 @@ */ #include +#include +#include #include +#include #include #include #include @@ -466,6 +469,41 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) } return 0; } + +int fdt_set_usable_memory(void *blob, u64 start[], u64 size[], int areas) +{ + int err, nodeoffset; + int len; + u8 tmp[8 * 16]; /* Up to 64-bit address + 64-bit size */ + + if (areas > 8) { + printf("%s: num areas %d exceeds hardcoded limit %d\n", + __func__, areas, 8); + return -1; + } + + err = fdt_check_header(blob); + if (err < 0) { + printf("%s: %s\n", __func__, fdt_strerror(err)); + return err; + } + + /* find or create "/memory" node. */ + nodeoffset = fdt_find_or_add_subnode(blob, 0, "memory"); + if (nodeoffset < 0) + return nodeoffset; + + len = fdt_pack_reg(blob, tmp, start, size, areas); + + err = fdt_setprop(blob, nodeoffset, "linux,usable-memory", tmp, len); + if (err < 0) { + printf("WARNING: could not set %s %s.\n", + "reg", fdt_strerror(err)); + return err; + } + + return 0; +} #endif int fdt_fixup_memory(void *blob, u64 start, u64 size) @@ -1565,7 +1603,7 @@ static int fdt_read_prop(const fdt32_t *prop, int prop_len, int cell_off, uint64_t *val, int cells) { const fdt32_t *prop32 = &prop[cell_off]; - const fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off]; + const unaligned_fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off]; if ((cell_off + cells) > prop_len) return -FDT_ERR_NOSPACE;