diff options
author | Simon Glass <sjg@chromium.org> | 2021-09-25 07:03:18 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-10-08 15:53:26 -0400 |
commit | 2ac00c050582389e667374bccc5cc19b4fce80f5 (patch) | |
tree | fd0e0dbb49a39e9b10cf179c1cb43b51d467f5f6 | |
parent | 5d3248a688c2368be54aaa9407be30adfa994abc (diff) | |
download | u-boot-2ac00c050582389e667374bccc5cc19b4fce80f5.tar.gz u-boot-2ac00c050582389e667374bccc5cc19b4fce80f5.tar.bz2 u-boot-2ac00c050582389e667374bccc5cc19b4fce80f5.zip |
image: Create a function to do manual relocation
Rather than adding an #ifdef and open-coding this calculation, add a
helper function to handle it. Use this in the image code.
Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | common/image.c | 33 | ||||
-rw-r--r-- | include/relocate.h | 24 |
2 files changed, 30 insertions, 27 deletions
diff --git a/common/image.c b/common/image.c index 3eb6a7fca1..2f2fd052c5 100644 --- a/common/image.c +++ b/common/image.c @@ -63,6 +63,7 @@ DECLARE_GLOBAL_DATA_PTR; #include <image.h> #include <lz4.h> #include <imximage.h> +#include <relocate.h> #include <linux/lzo.h> #include <linux/zstd.h> #include <linux/kconfig.h> @@ -565,11 +566,7 @@ const char *genimg_get_cat_name(enum ih_category category, uint id) entry = get_table_entry(table_info[category].table, id); if (!entry) return unknown_msg(category); -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return entry->lname; -#else - return entry->lname + gd->reloc_off; -#endif + return manual_reloc(entry->lname); } /** @@ -589,11 +586,7 @@ const char *genimg_get_cat_short_name(enum ih_category category, uint id) entry = get_table_entry(table_info[category].table, id); if (!entry) return unknown_msg(category); -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return entry->sname; -#else - return entry->sname + gd->reloc_off; -#endif + return manual_reloc(entry->sname); } int genimg_get_cat_count(enum ih_category category) @@ -643,11 +636,7 @@ char *get_table_entry_name(const table_entry_t *table, char *msg, int id) table = get_table_entry(table, id); if (!table) return msg; -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return table->lname; -#else - return table->lname + gd->reloc_off; -#endif + return manual_reloc(table->lname); } const char *genimg_get_os_name(uint8_t os) @@ -677,11 +666,7 @@ static const char *genimg_get_short_name(const table_entry_t *table, int val) table = get_table_entry(table, val); if (!table) return "unknown"; -#if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC) - return table->sname; -#else - return table->sname + gd->reloc_off; -#endif + return manual_reloc(table->sname); } const char *genimg_get_type_short_name(uint8_t type) @@ -724,12 +709,8 @@ int get_table_entry_id(const table_entry_t *table, const table_entry_t *t; for (t = table; t->id >= 0; ++t) { -#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC) - if (t->sname && strcasecmp(t->sname + gd->reloc_off, name) == 0) -#else - if (t->sname && strcasecmp(t->sname, name) == 0) -#endif - return (t->id); + if (t->sname && !strcasecmp(manual_reloc(t->sname), name)) + return t->id; } debug("Invalid %s Type: %s\n", table_name, name); diff --git a/include/relocate.h b/include/relocate.h index 9ceeecdbe7..c4fad33612 100644 --- a/include/relocate.h +++ b/include/relocate.h @@ -7,7 +7,11 @@ #ifndef _RELOCATE_H_ #define _RELOCATE_H_ -#include <common.h> +#ifndef USE_HOSTCC +#include <asm/global_data.h> + +DECLARE_GLOBAL_DATA_PTR; +#endif /** * copy_uboot_to_ram() - Copy U-Boot to its new relocated position @@ -35,4 +39,22 @@ int clear_bss(void); */ int do_elf_reloc_fixups(void); +/** + * manual_reloc() - Manually relocate a pointer if needed + * + * This is a nop in almost all cases, except for the systems with a broken gcc + * which need to manually relocate some things. + * + * @ptr: Pointer to relocate + * @return new pointer value + */ +static inline void *manual_reloc(void *ptr) +{ +#ifndef USE_HOSTCC + if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) + return ptr + gd->reloc_off; +#endif + return ptr; +} + #endif /* _RELOCATE_H_ */ |