X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=common%2Ffdt_support.c;h=f31e9b0cc5a899ade8f400d1af83fe08e5c593cd;hb=634931fea542fc59cf7537b6c2c163942a6ccd15;hp=724452d754523a39f4a57fce208a80ae49cea2bd;hpb=3bb6dc04a9b78c3db7c130bea7e817d77add275e;p=oweals%2Fu-boot.git diff --git a/common/fdt_support.c b/common/fdt_support.c index 724452d754..f31e9b0cc5 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1,19 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2007 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com * * Copyright 2010-2011 Freescale Semiconductor, Inc. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include -#include +#include #include #include #include #include -#include +#include #include #include #include @@ -410,46 +409,7 @@ static int fdt_pack_reg(const void *fdt, void *buf, u64 *address, u64 *size, return p - (char *)buf; } -int fdt_record_loadable(void *blob, u32 index, const char *name, - uintptr_t load_addr, u32 size, uintptr_t entry_point, - const char *type, const char *os) -{ - int err, node; - - err = fdt_check_header(blob); - if (err < 0) { - printf("%s: %s\n", __func__, fdt_strerror(err)); - return err; - } - - /* find or create "/fit-images" node */ - node = fdt_find_or_add_subnode(blob, 0, "fit-images"); - if (node < 0) - return node; - - /* find or create "/fit-images/" node */ - node = fdt_find_or_add_subnode(blob, node, name); - if (node < 0) - return node; - - /* - * We record these as 32bit entities, possibly truncating addresses. - * However, spl_fit.c is not 64bit safe either: i.e. we should not - * have an issue here. - */ - fdt_setprop_u32(blob, node, "load-addr", load_addr); - if (entry_point != -1) - fdt_setprop_u32(blob, node, "entry-point", entry_point); - fdt_setprop_u32(blob, node, "size", size); - if (type) - fdt_setprop_string(blob, node, "type", type); - if (os) - fdt_setprop_string(blob, node, "os", os); - - return node; -} - -#ifdef CONFIG_NR_DRAM_BANKS +#if CONFIG_NR_DRAM_BANKS > 4 #define MEMORY_BANKS_MAX CONFIG_NR_DRAM_BANKS #else #define MEMORY_BANKS_MAX 4 @@ -457,7 +417,7 @@ int fdt_record_loadable(void *blob, u32 index, const char *name, int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) { int err, nodeoffset; - int len; + int len, i; u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */ if (banks > MEMORY_BANKS_MAX) { @@ -486,6 +446,13 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) return err; } + for (i = 0; i < banks; i++) { + if (start[i] == 0 && size[i] == 0) + break; + } + + banks = i; + if (!banks) return 0; @@ -584,6 +551,45 @@ void fdt_fixup_ethernet(void *fdt) } } +int fdt_record_loadable(void *blob, u32 index, const char *name, + uintptr_t load_addr, u32 size, uintptr_t entry_point, + const char *type, const char *os) +{ + int err, node; + + err = fdt_check_header(blob); + if (err < 0) { + printf("%s: %s\n", __func__, fdt_strerror(err)); + return err; + } + + /* find or create "/fit-images" node */ + node = fdt_find_or_add_subnode(blob, 0, "fit-images"); + if (node < 0) + return node; + + /* find or create "/fit-images/" node */ + node = fdt_find_or_add_subnode(blob, node, name); + if (node < 0) + return node; + + /* + * We record these as 32bit entities, possibly truncating addresses. + * However, spl_fit.c is not 64bit safe either: i.e. we should not + * have an issue here. + */ + fdt_setprop_u32(blob, node, "load-addr", load_addr); + if (entry_point != -1) + fdt_setprop_u32(blob, node, "entry-point", entry_point); + fdt_setprop_u32(blob, node, "size", size); + if (type) + fdt_setprop_string(blob, node, "type", type); + if (os) + fdt_setprop_string(blob, node, "os", os); + + return node; +} + /* Resize the fdt to its actual size + a bit of padding */ int fdt_shrink_to_minimum(void *blob, uint extrasize) { @@ -591,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize) uint64_t addr, size; int total, ret; uint actualsize; + int fdt_memrsv = 0; if (!blob) return 0; @@ -600,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize) fdt_get_mem_rsv(blob, i, &addr, &size); if (addr == (uintptr_t)blob) { fdt_del_mem_rsv(blob, i); + fdt_memrsv = 1; break; } } @@ -621,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize) /* Change the fdt header to reflect the correct size */ fdt_set_totalsize(blob, actualsize); - /* Add the new reservation */ - ret = fdt_add_mem_rsv(blob, (uintptr_t)blob, actualsize); - if (ret < 0) - return ret; + if (fdt_memrsv) { + /* Add the new reservation */ + ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize); + if (ret < 0) + return ret; + } return actualsize; } @@ -712,12 +722,7 @@ int fdt_increase_size(void *fdt, int add_len) #include #include -struct reg_cell { - unsigned int r0; - unsigned int r1; -}; - -int fdt_del_subnodes(const void *blob, int parent_offset) +static int fdt_del_subnodes(const void *blob, int parent_offset) { int off, ndepth; int ret; @@ -742,7 +747,7 @@ int fdt_del_subnodes(const void *blob, int parent_offset) return 0; } -int fdt_del_partitions(void *blob, int parent_offset) +static int fdt_del_partitions(void *blob, int parent_offset) { const void *prop; int ndepth = 0; @@ -775,15 +780,22 @@ int fdt_node_set_part_info(void *blob, int parent_offset, { struct list_head *pentry; struct part_info *part; - struct reg_cell cell; int off, ndepth = 0; int part_num, ret; + int sizecell; char buf[64]; ret = fdt_del_partitions(blob, parent_offset); if (ret < 0) return ret; + /* + * Check if size/address is 1 or 2 cells. + * We assume #address-cells and #size-cells have same value. + */ + sizecell = fdt_getprop_u32_default_node(blob, parent_offset, + 0, "#size-cells", 1); + /* * Check if it is nand {}; subnode, adjust * the offset in this case @@ -832,10 +844,21 @@ add_ro: goto err_prop; } - cell.r0 = cpu_to_fdt32(part->offset); - cell.r1 = cpu_to_fdt32(part->size); add_reg: - ret = fdt_setprop(blob, newoff, "reg", &cell, sizeof(cell)); + if (sizecell == 2) { + ret = fdt_setprop_u64(blob, newoff, + "reg", part->offset); + if (!ret) + ret = fdt_appendprop_u64(blob, newoff, + "reg", part->size); + } else { + ret = fdt_setprop_u32(blob, newoff, + "reg", part->offset); + if (!ret) + ret = fdt_appendprop_u32(blob, newoff, + "reg", part->size); + } + if (ret == -FDT_ERR_NOSPACE) { ret = fdt_increase_size(blob, 512); if (!ret) @@ -881,9 +904,9 @@ err_prop: * * fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); */ -void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size) +void fdt_fixup_mtdparts(void *blob, const struct node_info *node_info, + int node_info_size) { - struct node_info *ni = node_info; struct mtd_device *dev; int i, idx; int noff; @@ -893,12 +916,13 @@ void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size) for (i = 0; i < node_info_size; i++) { idx = 0; - noff = fdt_node_offset_by_compatible(blob, -1, ni[i].compat); + noff = fdt_node_offset_by_compatible(blob, -1, + node_info[i].compat); while (noff != -FDT_ERR_NOTFOUND) { debug("%s: %s, mtd dev type %d\n", fdt_get_name(blob, noff, 0), - ni[i].compat, ni[i].type); - dev = device_find(ni[i].type, idx++); + node_info[i].compat, node_info[i].type); + dev = device_find(node_info[i].type, idx++); if (dev) { if (fdt_node_set_part_info(blob, noff, dev)) return; /* return on error */ @@ -906,7 +930,7 @@ void fdt_fixup_mtdparts(void *blob, void *node_info, int node_info_size) /* Jump to next flash node */ noff = fdt_node_offset_by_compatible(blob, noff, - ni[i].compat); + node_info[i].compat); } } } @@ -1012,8 +1036,7 @@ static u64 of_bus_default_map(fdt32_t *addr, const fdt32_t *range, s = fdt_read_number(range + na + pna, ns); da = fdt_read_number(addr, na); - debug("OF: default map, cp=%" PRIu64 ", s=%" PRIu64 - ", da=%" PRIu64 "\n", cp, s, da); + debug("OF: default map, cp=%llx, s=%llx, da=%llx\n", cp, s, da); if (da < cp || da >= (cp + s)) return OF_BAD_ADDR; @@ -1068,8 +1091,7 @@ static u64 of_bus_isa_map(fdt32_t *addr, const fdt32_t *range, s = fdt_read_number(range + na + pna, ns); da = fdt_read_number(addr + 1, na - 1); - debug("OF: ISA map, cp=%" PRIu64 ", s=%" PRIu64 - ", da=%" PRIu64 "\n", cp, s, da); + debug("OF: ISA map, cp=%llx, s=%llx, da=%llx\n", cp, s, da); if (da < cp || da >= (cp + s)) return OF_BAD_ADDR; @@ -1175,7 +1197,7 @@ static int of_translate_one(const void *blob, int parent, struct of_bus *bus, finish: of_dump_addr("OF: parent translation for:", addr, pna); - debug("OF: with offset: %" PRIu64 "\n", offset); + debug("OF: with offset: %llu\n", offset); /* Translate it into parent bus space */ return pbus->translate(addr, offset, pna); @@ -1505,9 +1527,9 @@ int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr) dt_addr = fdt_translate_address(fdt, node, reg); if (addr != dt_addr) { - printf("Warning: U-Boot configured device %s at address %" - PRIx64 ",\n but the device tree has it address %" - PRIx64 ".\n", alias, addr, dt_addr); + printf("Warning: U-Boot configured device %s at address %llu,\n" + "but the device tree has it address %llx.\n", + alias, addr, dt_addr); return 0; } @@ -1655,7 +1677,7 @@ int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width, if (ret < 0) return ret; - snprintf(name, sizeof(name), "framebuffer@%" PRIx64, base_address); + snprintf(name, sizeof(name), "framebuffer@%llx", base_address); ret = fdt_set_name(fdt, node, name); if (ret < 0) return ret;