[PATCH 1/2] tools: relocate-rela: Add M68K support
Angelo Dureghello
angelo at kernel-space.org
Sat Aug 26 09:44:17 CEST 2023
Hi Marek,
thanks a lot for the job i should have done.
Tested on real hw:
m5282evb worked out of the box
mcf54415 not working,
had a lot of unsupported relocation type for R_68K_JMP_SLOT
mcf5307 need to fix the hw, will do in short
i had to add this fix:
diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
index 2d008c7f60..9722a6291a 100644
--- a/tools/relocate-rela.c
+++ b/tools/relocate-rela.c
@@ -40,6 +40,10 @@
#define R_68K_GLOB_DAT 20
#endif
+#ifndef R_68K_JMP_SLOT
+#define R_68K_JMP_SLOT 21
+#endif
+
#ifndef R_68K_RELATIVE
#define R_68K_RELATIVE 22
#endif
@@ -531,6 +535,9 @@ static bool supported_rela32(Elf32_Rela *rela,
uint32_t *type)
case R_68K_RELATIVE:
debug("R_68K_RELATIVE\n");
return true;
+ case R_68K_JMP_SLOT:
+ debug("R_68K_JMP_SLOT\n");
+ return true;
}
} else {
switch (*type) {
@@ -631,8 +638,9 @@ static int rela_elf32(char **argv, FILE *f)
return 4;
}
} else if ((machine == EM_M68K &&
- (type == R_68K_32 || type == R_68K_GLOB_DAT)) ||
- (machine == EM_MICROBLAZE &&
+ (type == R_68K_32 || type == R_68K_GLOB_DAT ||
+ type == R_68K_JMP_SLOT)) ||
+ (machine == EM_MICROBLAZE &&
(type == R_MICROBLAZE_32 ||
type == R_MICROBLAZE_GLOB_DAT))) {
/* global symbols read it and add reloc offset */
On 31/07/23 12:20 AM, Marek Vasut wrote:
> Add M68K ELF32 support into this tool, so it can patch static rela
> into M68K u-boot-nodtb.bin . This is the first step toward M68K
> relocation support, and in turn, removal of NEEDS_MANUAL_RELOC
> from the codebase altogether.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
> ---
> Cc: Angelo Dureghello <angelo at kernel-space.org>
> Cc: Angelo Durgehello <angelo.dureghello at timesys.com>
> Cc: Bin Meng <bmeng.cn at gmail.com>
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Cc: Huan Wang <alison.wang at nxp.com>
> Cc: Marek Vasut <marek.vasut+renesas at mailbox.org>
> Cc: Michal Simek <michal.simek at amd.com>
> Cc: Ovidiu Panait <ovpanait at gmail.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Zong Li <zong.li at sifive.com>
> ---
> tools/relocate-rela.c | 108 ++++++++++++++++++++++++++++++------------
> 1 file changed, 77 insertions(+), 31 deletions(-)
>
> diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
> index e28e7fcc6f5..2d008c7f602 100644
> --- a/tools/relocate-rela.c
> +++ b/tools/relocate-rela.c
> @@ -24,6 +24,26 @@
> #define R_AARCH64_RELATIVE 1027
> #endif
>
> +#ifndef EM_M68K
> +#define EM_M68K 4
> +#endif
> +
> +#ifndef R_68K_NONE
> +#define R_68K_NONE 0
> +#endif
> +
> +#ifndef R_68K_32
> +#define R_68K_32 1
> +#endif
> +
> +#ifndef R_68K_GLOB_DAT
> +#define R_68K_GLOB_DAT 20
> +#endif
> +
> +#ifndef R_68K_RELATIVE
> +#define R_68K_RELATIVE 22
> +#endif
> +
> #ifndef EM_MICROBLAZE
> #define EM_MICROBLAZE 189
> #endif
> @@ -46,6 +66,7 @@
>
> static int ei_class;
> static int ei_data;
> +static int machine;
>
> static uint64_t rela_start, rela_end, text_base, dyn_start;
>
> @@ -111,7 +132,7 @@ static int decode_elf64(FILE *felf, char **argv)
> uint64_t sh_addr, sh_offset, sh_size;
> Elf64_Half sh_index, sh_num;
> Elf64_Shdr *sh_table; /* Elf symbol table */
> - int ret, i, machine;
> + int ret, i;
> char *sh_str;
>
> debug("64bit version\n");
> @@ -245,7 +266,7 @@ static int decode_elf32(FILE *felf, char **argv)
> uint32_t sh_addr, sh_offset, sh_size;
> Elf32_Half sh_index, sh_num;
> Elf32_Shdr *sh_table; /* Elf symbol table */
> - int ret, i, machine;
> + int ret, i;
> char *sh_str;
>
> debug("32bit version\n");
> @@ -262,12 +283,20 @@ static int decode_elf32(FILE *felf, char **argv)
> machine = elf16_to_cpu(header.e_machine);
> debug("Machine %d\n", machine);
>
> - if (machine != EM_MICROBLAZE) {
> + if (machine != EM_MICROBLAZE && machine != EM_M68K) {
> fprintf(stderr, "%s: Not supported machine type\n", argv[0]);
> return 30;
> }
>
> text_base = elf32_to_cpu(header.e_entry);
> + /*
> + * M68K ELF entry point is MONITOR_BASE, not TEXT_BASE.
> + * TEXT_BASE is always MONITOR_BASE &~ 0x7ff, so clear
> + * those bits here.
> + */
> + if (machine == EM_M68K)
> + text_base &= ~0x7ff;
> +
> section_header_base = elf32_to_cpu(header.e_shoff);
> section_header_size = elf16_to_cpu(header.e_shentsize) *
> elf16_to_cpu(header.e_shnum);
> @@ -488,25 +517,41 @@ static bool supported_rela32(Elf32_Rela *rela, uint32_t *type)
>
> 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;
> + if (machine == EM_M68K) {
> + switch (*type) {
> + case R_68K_32:
> + debug("R_68K_32\n");
> + return true;
> + case R_68K_GLOB_DAT:
> + debug("R_68K_GLOB_DAT\n");
> + return true;
> + case R_68K_NONE:
> + debug("R_68K_NONE - ignoring - do nothing\n");
> + return false;
> + case R_68K_RELATIVE:
> + debug("R_68K_RELATIVE\n");
> + return true;
> + }
> + } else {
> + 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;
> + }
> }
> + fprintf(stderr, "warning: unsupported relocation type %"
> + PRIu32 " at %" PRIx32 "\n", *type, rela->r_offset);
> +
> + return false;
> }
>
> static int rela_elf32(char **argv, FILE *f)
> @@ -569,8 +614,8 @@ static int rela_elf32(char **argv, FILE *f)
>
> debug("Addr:\t0x%" PRIx32 "\n", addr);
>
> - switch (type) {
> - case R_MICROBLAZE_REL:
> + if ((machine == EM_M68K && type == R_68K_RELATIVE) ||
> + (machine == EM_MICROBLAZE && type == R_MICROBLAZE_REL)) {
> if (fseek(f, addr, SEEK_SET) < 0) {
> fprintf(stderr, "%s: %s: seek to %"
> PRIx32 " failed: %s\n",
> @@ -585,9 +630,11 @@ static int rela_elf32(char **argv, FILE *f)
> argv[0], argv[1], addr);
> return 4;
> }
> - break;
> - case R_MICROBLAZE_32:
> - case R_MICROBLAZE_GLOB_DAT:
> + } else if ((machine == EM_M68K &&
> + (type == R_68K_32 || type == R_68K_GLOB_DAT)) ||
> + (machine == EM_MICROBLAZE &&
> + (type == R_MICROBLAZE_32 ||
> + type == 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;
> @@ -632,12 +679,11 @@ static int rela_elf32(char **argv, FILE *f)
> argv[0], argv[1], addr);
> return 4;
> }
> -
> - break;
> - case R_MICROBLAZE_NONE:
> + } else if (machine == EM_M68K && type == R_68K_NONE) {
> + debug("R_68K_NONE - skip\n");
> + } else if (machine == EM_MICROBLAZE && type == R_MICROBLAZE_NONE) {
> debug("R_MICROBLAZE_NONE - skip\n");
> - break;
> - default:
> + } else {
> fprintf(stderr, "warning: unsupported relocation type %"
> PRIu32 " at %" PRIx32 "\n",
> type, rela.r_offset);
Regards,
angelo
More information about the U-Boot
mailing list