From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
Alexandru Gagniuc <mr.nuke.me@gmail.com>,
Bin Meng <bmeng.cn@gmail.com>, Tom Rini <trini@konsulko.com>,
Simon Glass <sjg@chromium.org>,
Joe Hershberger <joe.hershberger@ni.com>,
Marek Vasut <marex@denx.de>
Subject: [PATCH v4 13/15] image: Create a function to do manual relocation
Date: Sat, 25 Sep 2021 07:03:18 -0600 [thread overview]
Message-ID: <20210925070255.v4.13.Iea4abe7ae3455f42385e0d1c2b5776485b1ab88b@changeid> (raw)
In-Reply-To: <20210925130320.7824-1-sjg@chromium.org>
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>
---
(no changes since v1)
common/image.c | 33 +++++++--------------------------
include/relocate.h | 24 +++++++++++++++++++++++-
2 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/common/image.c b/common/image.c
index 3eb6a7fca1d..2f2fd052c50 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 9ceeecdbe71..c4fad336128 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_ */
--
2.33.0.685.g46640cef36-goog
next prev parent reply other threads:[~2021-09-25 13:06 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-25 13:03 [PATCH v4 00/15] image: A partial series for the image clean-up Simon Glass
2021-09-25 13:03 ` [PATCH v4 01/15] lib: Add memdup() Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 02/15] Add support for an owned buffer Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 03/15] compiler: Add a comment to host_build() Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 04/15] zstd: Create a function for use from U-Boot Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 05/15] btrfs: Use U-Boot API for decompression Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 06/15] image: Avoid switch default in image_decomp() Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 07/15] image: Update zstd to avoid reporting error twice Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 08/15] gzip: Avoid use of u64 Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 09/15] image: Update image_decomp() to avoid ifdefs Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 10/15] image: Split board code out into its own file Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 11/15] image: Fix up checkpatch warnings in image-board.c Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 12/15] image: Split host code out into its own file Simon Glass
2021-10-09 1:38 ` Tom Rini
2021-09-25 13:03 ` Simon Glass [this message]
2021-10-09 1:39 ` [PATCH v4 13/15] image: Create a function to do manual relocation Tom Rini
2021-09-25 13:03 ` [PATCH v4 14/15] image: Avoid #ifdefs for " Simon Glass
2021-10-09 1:39 ` Tom Rini
2021-09-25 13:03 ` [PATCH v4 15/15] image: Remove ifdefs around image_setup_linux() el at Simon Glass
2021-10-09 1:39 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210925070255.v4.13.Iea4abe7ae3455f42385e0d1c2b5776485b1ab88b@changeid \
--to=sjg@chromium.org \
--cc=bmeng.cn@gmail.com \
--cc=joe.hershberger@ni.com \
--cc=marex@denx.de \
--cc=mr.nuke.me@gmail.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).