aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTom Rini2022-06-27 10:15:50 -0400
committerTom Rini2022-06-27 10:15:50 -0400
commitc316ee674f25b73285f241ce922307296616a92a (patch)
tree9067e60451612dee5fbd0d3132548d3e84063f53 /tools
parent31016a5a853cb5b8e27e9fdf956d8250ae59eca9 (diff)
parent728a86edb63a647e6faf211c0dbc7bd0e4ff7ac6 (diff)
Merge tag 'xilinx-for-v2022.10' of https://source.denx.de/u-boot/custodians/u-boot-microblaze into next
Xilinx changes for v2022.10 cpu: - Add driver for microblaze cpu net: - Add support for DM_ETH_PHY to AXI emac and emaclite xilinx: - Switch platforms to DM_ETH_PHY - DT chagnes in ZynqMP and Zynq - Enable support for SquashFS zynqmp: - Add support for KR260 boards - Move BSS from address 0 - Move platform identification from board code to soc driver - Improve zynqmp_psu_init_minimize versal: - Enable loading app at EL1 serial: - Setup default address and clock rates for DEBUG uarts pinctrl: - Add support for tri state and output enable properties relocate-rela: - Clean relocate-rela implementation for ARM64 - Add support for Microblaze microblaze: - Add support for runtime relocation - Rework cache handling (wiring, Kconfig) based on cpuinfo - Remove interrupt support timer: - Extract axi timer driver from Microblaze to generic location
Diffstat (limited to 'tools')
-rw-r--r--tools/relocate-rela.c545
-rwxr-xr-xtools/zynqmp_psu_init_minimize.sh27
2 files changed, 535 insertions, 37 deletions
diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
index f0bc548617a..090fb1acb20 100644
--- a/tools/relocate-rela.c
+++ b/tools/relocate-rela.c
@@ -20,6 +20,10 @@
#define R_AARCH64_RELATIVE 1027
#endif
+static int ei_class;
+
+static uint64_t rela_start, rela_end, text_base, dyn_start;
+
static const bool debug_en;
static void debug(const char *fmt, ...)
@@ -52,58 +56,310 @@ static bool supported_rela(Elf64_Rela *rela)
}
}
-static bool read_num(const char *str, uint64_t *num)
+static int decode_elf64(FILE *felf, char **argv)
{
- char *endptr;
- *num = strtoull(str, &endptr, 16);
- return str[0] && !endptr[0];
+ size_t size;
+ Elf64_Ehdr header;
+ uint64_t section_header_base, section_header_size, sh_offset, sh_size;
+ Elf64_Shdr *sh_table; /* Elf symbol table */
+ int ret, i, machine;
+ char *sh_str;
+
+ debug("64bit version\n");
+
+ /* Make sure we are at start */
+ rewind(felf);
+
+ size = fread(&header, 1, sizeof(header), felf);
+ if (size != sizeof(header)) {
+ fclose(felf);
+ return 25;
+ }
+
+ machine = header.e_machine;
+ debug("Machine\t%d\n", machine);
+
+ if (machine != EM_AARCH64) {
+ fprintf(stderr, "%s: Not supported machine type\n", argv[0]);
+ return 30;
+ }
+
+ text_base = header.e_entry;
+ section_header_base = header.e_shoff;
+ section_header_size = header.e_shentsize * header.e_shnum;
+
+ sh_table = malloc(section_header_size);
+ if (!sh_table) {
+ fprintf(stderr, "%s: Cannot allocate space for section header\n",
+ argv[0]);
+ fclose(felf);
+ return 26;
+ }
+
+ ret = fseek(felf, section_header_base, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "%s: Can't set pointer to section header: %x/%lx\n",
+ argv[0], ret, section_header_base);
+ free(sh_table);
+ fclose(felf);
+ return 26;
+ }
+
+ size = fread(sh_table, 1, section_header_size, felf);
+ if (size != section_header_size) {
+ fprintf(stderr, "%s: Can't read section header: %lx/%lx\n",
+ argv[0], size, section_header_size);
+ free(sh_table);
+ fclose(felf);
+ return 27;
+ }
+
+ sh_size = sh_table[header.e_shstrndx].sh_size;
+ debug("e_shstrndx\t0x%08x\n", header.e_shstrndx);
+ debug("sh_size\t\t0x%08lx\n", sh_size);
+
+ sh_str = malloc(sh_size);
+ if (!sh_str) {
+ fprintf(stderr, "malloc failed\n");
+ free(sh_table);
+ fclose(felf);
+ return 28;
+ }
+
+ /*
+ * Specifies the byte offset from the beginning of the file
+ * to the first byte in the section.
+ */
+ sh_offset = sh_table[header.e_shstrndx].sh_offset;
+
+ debug("sh_offset\t0x%08x\n", header.e_shnum);
+
+ ret = fseek(felf, sh_offset, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "Setting up sh_offset failed\n");
+ free(sh_str);
+ free(sh_table);
+ fclose(felf);
+ return 29;
+ }
+
+ size = fread(sh_str, 1, sh_size, felf);
+ if (size != sh_size) {
+ fprintf(stderr, "%s: Can't read section: %lx/%lx\n",
+ argv[0], size, sh_size);
+ free(sh_str);
+ free(sh_table);
+ fclose(felf);
+ return 30;
+ }
+
+ for (i = 0; i < header.e_shnum; i++) {
+ /* fprintf(stderr, "%s\n", sh_str + sh_table[i].sh_name); Debug only */
+ if (!strcmp(".rela.dyn", (sh_str + sh_table[i].sh_name))) {
+ debug("Found section\t\".rela_dyn\"\n");
+ debug(" at addr\t0x%08x\n",
+ (unsigned int)sh_table[i].sh_addr);
+ debug(" at offset\t0x%08x\n",
+ (unsigned int)sh_table[i].sh_offset);
+ debug(" of size\t0x%08x\n",
+ (unsigned int)sh_table[i].sh_size);
+ rela_start = sh_table[i].sh_addr;
+ rela_end = rela_start + sh_table[i].sh_size;
+ break;
+ }
+ }
+
+ /* Clean up */
+ free(sh_str);
+ free(sh_table);
+ fclose(felf);
+
+ debug("text_base\t0x%08lx\n", text_base);
+ debug("rela_start\t0x%08lx\n", rela_start);
+ debug("rela_end\t0x%08lx\n", rela_end);
+
+ if (!rela_start)
+ return 1;
+
+ return 0;
}
-int main(int argc, char **argv)
+static int decode_elf32(FILE *felf, char **argv)
{
- FILE *f;
- int i, num;
- uint64_t rela_start, rela_end, text_base, file_size;
+ size_t size;
+ Elf32_Ehdr header;
+ uint64_t section_header_base, section_header_size, sh_offset, sh_size;
+ Elf32_Shdr *sh_table; /* Elf symbol table */
+ int ret, i, machine;
+ char *sh_str;
- if (argc != 5) {
- fprintf(stderr, "Statically apply ELF rela relocations\n");
- fprintf(stderr, "Usage: %s <bin file> <text base> " \
- "<rela start> <rela end>\n", argv[0]);
- fprintf(stderr, "All numbers in hex.\n");
- return 1;
+ debug("32bit version\n");
+
+ /* Make sure we are at start */
+ rewind(felf);
+
+ size = fread(&header, 1, sizeof(header), felf);
+ if (size != sizeof(header)) {
+ fclose(felf);
+ return 25;
}
- f = fopen(argv[1], "r+b");
- if (!f) {
+ machine = header.e_machine;
+ debug("Machine %d\n", machine);
+
+ if (machine != EM_MICROBLAZE) {
+ fprintf(stderr, "%s: Not supported machine type\n", argv[0]);
+ return 30;
+ }
+
+ text_base = header.e_entry;
+ section_header_base = header.e_shoff;
+
+ debug("Section header base %x\n", section_header_base);
+
+ section_header_size = header.e_shentsize * header.e_shnum;
+
+ debug("Section header size %d\n", section_header_size);
+
+ sh_table = malloc(section_header_size);
+ if (!sh_table) {
+ fprintf(stderr, "%s: Cannot allocate space for section header\n",
+ argv[0]);
+ fclose(felf);
+ return 26;
+ }
+
+ ret = fseek(felf, section_header_base, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "%s: Can't set pointer to section header: %x/%lx\n",
+ argv[0], ret, section_header_base);
+ free(sh_table);
+ fclose(felf);
+ return 26;
+ }
+
+ size = fread(sh_table, 1, section_header_size, felf);
+ if (size != section_header_size) {
+ fprintf(stderr, "%s: Can't read section header: %lx/%lx\n",
+ argv[0], size, section_header_size);
+ free(sh_table);
+ fclose(felf);
+ return 27;
+ }
+
+ sh_size = sh_table[header.e_shstrndx].sh_size;
+ debug("e_shstrndx %x, sh_size %lx\n", header.e_shstrndx, sh_size);
+
+ sh_str = malloc(sh_size);
+ if (!sh_str) {
+ fprintf(stderr, "malloc failed\n");
+ free(sh_table);
+ fclose(felf);
+ return 28;
+ }
+
+ /*
+ * Specifies the byte offset from the beginning of the file
+ * to the first byte in the section.
+ */
+ sh_offset = sh_table[header.e_shstrndx].sh_offset;
+
+ debug("sh_offset %x\n", header.e_shnum);
+
+ ret = fseek(felf, sh_offset, SEEK_SET);
+ if (ret) {
+ fprintf(stderr, "Setting up sh_offset failed\n");
+ free(sh_str);
+ free(sh_table);
+ fclose(felf);
+ return 29;
+ }
+
+ size = fread(sh_str, 1, sh_size, felf);
+ if (size != sh_size) {
+ fprintf(stderr, "%s: Can't read section: %lx/%lx\n",
+ argv[0], size, sh_size);
+ free(sh_str);
+ free(sh_table);
+ fclose(felf);
+ return 30;
+ }
+
+ for (i = 0; i < header.e_shnum; i++) {
+ debug("%s\n", sh_str + sh_table[i].sh_name);
+ if (!strcmp(".rela.dyn", (sh_str + sh_table[i].sh_name))) {
+ debug("Found section\t\".rela_dyn\"\n");
+ debug(" at addr\t0x%08x\n", (unsigned int)sh_table[i].sh_addr);
+ debug(" at offset\t0x%08x\n", (unsigned int)sh_table[i].sh_offset);
+ debug(" of size\t0x%08x\n", (unsigned int)sh_table[i].sh_size);
+ rela_start = sh_table[i].sh_addr;
+ rela_end = rela_start + sh_table[i].sh_size;
+ }
+ if (!strcmp(".dynsym", (sh_str + sh_table[i].sh_name))) {
+ debug("Found section\t\".dynsym\"\n");
+ debug(" at addr\t0x%08x\n", (unsigned int)sh_table[i].sh_addr);
+ debug(" at offset\t0x%08x\n", (unsigned int)sh_table[i].sh_offset);
+ debug(" of size\t0x%08x\n", (unsigned int)sh_table[i].sh_size);
+ dyn_start = sh_table[i].sh_addr;
+ }
+ }
+
+ /* Clean up */
+ free(sh_str);
+ free(sh_table);
+ fclose(felf);
+
+ debug("text_base\t0x%08lx\n", text_base);
+ debug("rela_start\t0x%08lx\n", rela_start);
+ debug("rela_end\t0x%08lx\n", rela_end);
+ debug("dyn_start\t0x%08lx\n", dyn_start);
+
+ if (!rela_start)
+ return 1;
+
+ return 0;
+}
+
+static int decode_elf(char **argv)
+{
+ FILE *felf;
+ size_t size;
+ unsigned char e_ident[EI_NIDENT];
+
+ felf = fopen(argv[2], "r+b");
+ if (!felf) {
fprintf(stderr, "%s: Cannot open %s: %s\n",
- argv[0], argv[1], strerror(errno));
+ argv[0], argv[5], strerror(errno));
return 2;
}
- if (!read_num(argv[2], &text_base) ||
- !read_num(argv[3], &rela_start) ||
- !read_num(argv[4], &rela_end)) {
- fprintf(stderr, "%s: bad number\n", argv[0]);
- return 3;
+ size = fread(e_ident, 1, EI_NIDENT, felf);
+ if (size != EI_NIDENT) {
+ fclose(felf);
+ return 25;
}
- if (rela_start > rela_end || rela_start < text_base) {
- fprintf(stderr, "%s: bad rela bounds\n", argv[0]);
- return 3;
+ /* Check if this is really ELF file */
+ if (e_ident[0] != 0x7f &&
+ e_ident[1] != 'E' &&
+ e_ident[2] != 'L' &&
+ e_ident[3] != 'F') {
+ fclose(felf);
+ return 1;
}
- rela_start -= text_base;
- rela_end -= text_base;
+ ei_class = e_ident[4];
+ debug("EI_CLASS(1=32bit, 2=64bit) %d\n", ei_class);
- fseek(f, 0, SEEK_END);
- file_size = ftell(f);
- rewind(f);
+ if (ei_class == 2)
+ return decode_elf64(felf, argv);
- if (rela_end > file_size) {
- // Most likely compiler inserted some section that didn't get
- // objcopy-ed into the final binary
- rela_end = file_size;
- }
+ return decode_elf32(felf, argv);
+}
+
+static int rela_elf64(char **argv, FILE *f)
+{
+ int i, num;
if ((rela_end - rela_start) % sizeof(Elf64_Rela)) {
fprintf(stderr, "%s: rela size isn't a multiple of Elf64_Rela\n", argv[0]);
@@ -161,11 +417,228 @@ int main(int argc, char **argv)
}
}
+ return 0;
+}
+
+static bool supported_rela32(Elf32_Rela *rela, uint32_t *type)
+{
+ uint32_t mask = 0xffULL; /* would be different on 32-bit */
+ *type = rela->r_info & mask;
+
+ debug("Type:\t");
+
+ switch (*type) {
+ case R_MICROBLAZE_32:
+ debug("R_MICROBLAZE_32\n");
+ return true;
+ case R_MICROBLAZE_GLOB_DAT:
+ debug("R_MICROBLAZE_GLOB_DAT\n");
+ return true;
+ case R_MICROBLAZE_NONE:
+ debug("R_MICROBLAZE_NONE - ignoring - do nothing\n");
+ return false;
+ case R_MICROBLAZE_REL:
+ debug("R_MICROBLAZE_REL\n");
+ return true;
+ default:
+ fprintf(stderr, "warning: unsupported relocation type %"
+ PRIu32 " at %" PRIx32 "\n", *type, rela->r_offset);
+
+ return false;
+ }
+}
+
+static int rela_elf32(char **argv, FILE *f)
+{
+ int i, num, index;
+ uint32_t value, type;
+
+ if ((rela_end - rela_start) % sizeof(Elf32_Rela)) {
+ fprintf(stderr, "%s: rela size isn't a multiple of Elf32_Rela\n", argv[0]);
+ return 3;
+ }
+
+ num = (rela_end - rela_start) / sizeof(Elf32_Rela);
+
+ debug("Number of entries: %u\n", num);
+
+ for (i = 0; i < num; i++) {
+ Elf32_Rela rela, swrela;
+ Elf32_Sym symbols;
+ uint32_t pos = rela_start + sizeof(Elf32_Rela) * i;
+ uint32_t addr, pos_dyn;
+
+ debug("\nPossition:\t%d/0x%x\n", i, pos);
+
+ if (fseek(f, pos, SEEK_SET) < 0) {
+ fprintf(stderr, "%s: %s: seek to %" PRIx32
+ " failed: %s\n",
+ argv[0], argv[1], pos, strerror(errno));
+ }
+
+ if (fread(&rela, sizeof(rela), 1, f) != 1) {
+ fprintf(stderr, "%s: %s: read rela failed at %"
+ PRIx32 "\n",
+ argv[0], argv[1], pos);
+ return 4;
+ }
+
+ debug("Rela:\toffset:\t%" PRIx32 " r_info:\t%"
+ PRIu32 " r_addend:\t%" PRIx32 "\n",
+ rela.r_offset, rela.r_info, rela.r_addend);
+
+ swrela.r_offset = cpu_to_le32(rela.r_offset);
+ swrela.r_info = cpu_to_le32(rela.r_info);
+ swrela.r_addend = cpu_to_le32(rela.r_addend);
+
+ debug("SWRela:\toffset:\t%" PRIx32 " r_info:\t%"
+ PRIu32 " r_addend:\t%" PRIx32 "\n",
+ swrela.r_offset, swrela.r_info, swrela.r_addend);
+
+ if (!supported_rela32(&swrela, &type))
+ continue;
+
+ if (swrela.r_offset < text_base) {
+ fprintf(stderr, "%s: %s: bad rela at %" PRIx32 "\n",
+ argv[0], argv[1], pos);
+ return 4;
+ }
+
+ addr = swrela.r_offset - text_base;
+
+ debug("Addr:\t0x%" PRIx32 "\n", addr);
+
+ switch (type) {
+ case R_MICROBLAZE_REL:
+ if (fseek(f, addr, SEEK_SET) < 0) {
+ fprintf(stderr, "%s: %s: seek to %"
+ PRIx32 " failed: %s\n",
+ argv[0], argv[1], addr, strerror(errno));
+ return 5;
+ }
+
+ debug("Write addend\n");
+
+ if (fwrite(&rela.r_addend, sizeof(rela.r_addend), 1, f) != 1) {
+ fprintf(stderr, "%s: %s: write failed at %" PRIx32 "\n",
+ argv[0], argv[1], addr);
+ return 4;
+ }
+ break;
+ case R_MICROBLAZE_32:
+ case R_MICROBLAZE_GLOB_DAT:
+ /* global symbols read it and add reloc offset */
+ index = swrela.r_info >> 8;
+ pos_dyn = dyn_start + sizeof(Elf32_Sym) * index;
+
+ debug("Index:\t%d\n", index);
+ debug("Pos_dyn:\t0x%x\n", pos_dyn);
+
+ if (fseek(f, pos_dyn, SEEK_SET) < 0) {
+ fprintf(stderr, "%s: %s: seek to %"
+ PRIx32 " failed: %s\n",
+ argv[0], argv[1], pos_dyn, strerror(errno));
+ return 5;
+ }
+
+ if (fread(&symbols, sizeof(symbols), 1, f) != 1) {
+ fprintf(stderr, "%s: %s: read symbols failed at %"
+ PRIx32 "\n",
+ argv[0], argv[1], pos_dyn);
+ return 4;
+ }
+
+ debug("Symbol description:\n");
+ debug(" st_name:\t0x%x\n", symbols.st_name);
+ debug(" st_value:\t0x%x\n", symbols.st_value);
+ debug(" st_size:\t0x%x\n", symbols.st_size);
+
+ value = swrela.r_addend + symbols.st_value;
+
+ debug("Value:\t0x%x\n", value);
+
+ if (fseek(f, addr, SEEK_SET) < 0) {
+ fprintf(stderr, "%s: %s: seek to %"
+ PRIx32 " failed: %s\n",
+ argv[0], argv[1], addr, strerror(errno));
+ return 5;
+ }
+
+ if (fwrite(&value, sizeof(rela.r_addend), 1, f) != 1) {
+ fprintf(stderr, "%s: %s: write failed at %" PRIx32 "\n",
+ argv[0], argv[1], addr);
+ return 4;
+ }
+
+ break;
+ case R_MICROBLAZE_NONE:
+ debug("R_MICROBLAZE_NONE - skip\n");
+ break;
+ default:
+ fprintf(stderr, "warning: unsupported relocation type %"
+ PRIu32 " at %" PRIx32 "\n",
+ type, rela.r_offset);
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ FILE *f;
+ int ret;
+ uint64_t file_size;
+
+ if (argc != 3) {
+ fprintf(stderr, "Statically apply ELF rela relocations\n");
+ fprintf(stderr, "Usage: %s <bin file> <u-boot ELF>\n",
+ argv[0]);
+ return 1;
+ }
+
+ ret = decode_elf(argv);
+ if (ret) {
+ fprintf(stderr, "ELF decoding failed\n");
+ return ret;
+ }
+
+ if (rela_start > rela_end || rela_start < text_base) {
+ fprintf(stderr, "%s: bad rela bounds\n", argv[0]);
+ return 3;
+ }
+
+ rela_start -= text_base;
+ rela_end -= text_base;
+ dyn_start -= text_base;
+
+ f = fopen(argv[1], "r+b");
+ if (!f) {
+ fprintf(stderr, "%s: Cannot open %s: %s\n",
+ argv[0], argv[1], strerror(errno));
+ return 2;
+ }
+
+ fseek(f, 0, SEEK_END);
+ file_size = ftell(f);
+ rewind(f);
+
+ if (rela_end > file_size) {
+ // Most likely compiler inserted some section that didn't get
+ // objcopy-ed into the final binary
+ rela_end = file_size;
+ }
+
+ if (ei_class == 2)
+ ret = rela_elf64(argv, f);
+ else
+ ret = rela_elf32(argv, f);
+
if (fclose(f) < 0) {
fprintf(stderr, "%s: %s: close failed: %s\n",
argv[0], argv[1], strerror(errno));
return 4;
}
- return 0;
+ return ret;
}
diff --git a/tools/zynqmp_psu_init_minimize.sh b/tools/zynqmp_psu_init_minimize.sh
index 4ee418f07ea..16c622f6ce7 100755
--- a/tools/zynqmp_psu_init_minimize.sh
+++ b/tools/zynqmp_psu_init_minimize.sh
@@ -2,6 +2,8 @@
# SPDX-License-Identifier: GPL-2.0+
# Copyright (C) 2018 Michal Simek <michal.simek@xilinx.com>
# Copyright (C) 2019 Luca Ceresoli <luca@lucaceresoli.net>
+# Copyright (C) 2022 Weidmüller Interface GmbH & Co. KG
+# Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
usage()
{
@@ -119,7 +121,7 @@ tr "\n" "\r" <${OUT} >${TMP}
# | | ==> |while (e)|
# | } | | ; |
# | |
-sed -i -r 's| \{\r+(\t*)\}\r\r|\n\1\t;\n|g' ${TMP}
+sed -i -r 's| \{\r+(\t*)\}\r\r|\r\1\t;\r|g' ${TMP}
# Remove empty line between variable declaration
sed -i -r 's|\r(\r\t(unsigned )?int )|\1|g' ${TMP}
@@ -141,7 +143,30 @@ sed -i -r 's| \{(\r[^\r]*;)\r\t*\}|\1|g' ${TMP}
# if ((p_code >= 0x26) && ...) -> if (p_code >= 0x26 && ...)
sed -i -r 's|\((._code .= [x[:xdigit:]]+)\)|\1|g' ${TMP}
+# Move helper functions below header includes
+TARGET="#include <xil_io.h>"
+START="static int serdes_rst_seq"
+END="static int serdes_enb_coarse_saturation"
+
+sed -i -e "s|\(${TARGET}\r\r\)\(.*\)\(${START}(.*\)\(${END}(\)|\1\3\2\4|g" \
+ ${TMP}
+
# Convert back newlines
tr "\r" "\n" <${TMP} >${OUT}
+# Remove unnecessary settings
+# - Low level UART
+SETTINGS_TO_REMOVE="0xFF000000
+0xFF000004
+0xFF000018
+0xFF000034
+0xFF010000
+0xFF010004
+0xFF010018
+0xFF010034
+"
+for i in $SETTINGS_TO_REMOVE; do
+sed -i "/^\tpsu_mask_write($i,.*$/d" ${OUT}
+done
+
rm ${TMP}