All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	T Karthik Reddy <t.karthik.reddy@xilinx.com>
Subject: [PATCH v4 14/15] image: Avoid #ifdefs for manual relocation
Date: Sat, 25 Sep 2021 07:03:19 -0600	[thread overview]
Message-ID: <20210925070255.v4.14.Ic1283f25f151e715fdde093760ee004e15e19a96@changeid> (raw)
In-Reply-To: <20210925130320.7824-1-sjg@chromium.org>

Add a macro to handle manually relocating a pointer. Update the iamge code
to use this to avoid needing #ifdefs.

This also fixes a bug where the 'done' flag was not set.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 common/image-sig.c | 40 ++++++++++++++++++++++------------------
 include/relocate.h |  6 ++++++
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/common/image-sig.c b/common/image-sig.c
index fa9407bb300..1aa0b586450 100644
--- a/common/image-sig.c
+++ b/common/image-sig.c
@@ -9,6 +9,7 @@
 #include <asm/global_data.h>
 DECLARE_GLOBAL_DATA_PTR;
 #include <image.h>
+#include <relocate.h>
 #include <u-boot/ecdsa.h>
 #include <u-boot/rsa.h>
 #include <u-boot/hash-checksum.h>
@@ -56,17 +57,19 @@ struct checksum_algo *image_get_checksum_algo(const char *full_name)
 	int i;
 	const char *name;
 
-#if defined(CONFIG_NEEDS_MANUAL_RELOC)
-	static bool done;
+	if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
+		static bool done;
 
-	if (!done) {
-		done = true;
-		for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
-			checksum_algos[i].name += gd->reloc_off;
-			checksum_algos[i].calculate += gd->reloc_off;
+		if (!done) {
+			done = true;
+			for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
+				struct checksum_algo *algo = &checksum_algos[i];
+
+				MANUAL_RELOC(algo->name);
+				MANUAL_RELOC(algo->calculate);
+			}
 		}
 	}
-#endif
 
 	for (i = 0; i < ARRAY_SIZE(checksum_algos); i++) {
 		name = checksum_algos[i].name;
@@ -84,18 +87,19 @@ struct crypto_algo *image_get_crypto_algo(const char *full_name)
 	struct crypto_algo *crypto, *end;
 	const char *name;
 
-#if defined(CONFIG_NEEDS_MANUAL_RELOC)
-	static bool done;
-
-	if (!done) {
-		crypto = ll_entry_start(struct crypto_algo, cryptos);
-		end = ll_entry_end(struct crypto_algo, cryptos);
-		for (; crypto < end; crypto++) {
-			crypto->name += gd->reloc_off;
-			crypto->verify += gd->reloc_off;
+	if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) {
+		static bool done;
+
+		if (!done) {
+			done = true;
+			crypto = ll_entry_start(struct crypto_algo, cryptos);
+			end = ll_entry_end(struct crypto_algo, cryptos);
+			for (; crypto < end; crypto++) {
+				MANUAL_RELOC(crypto->name);
+				MANUAL_RELOC(crypto->verify);
+			}
 		}
 	}
-#endif
 
 	/* Move name to after the comma */
 	name = strchr(full_name, ',');
diff --git a/include/relocate.h b/include/relocate.h
index c4fad336128..26682da955f 100644
--- a/include/relocate.h
+++ b/include/relocate.h
@@ -57,4 +57,10 @@ static inline void *manual_reloc(void *ptr)
 		return ptr;
 }
 
+#if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
+#define MANUAL_RELOC(ptr)	(ptr) = manual_reloc(ptr)
+#else
+#define MANUAL_RELOC(ptr)	(void)(ptr)
+#endif
+
 #endif	/* _RELOCATE_H_ */
-- 
2.33.0.685.g46640cef36-goog


  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 ` [PATCH v4 13/15] image: Create a function to do manual relocation Simon Glass
2021-10-09  1:39   ` Tom Rini
2021-09-25 13:03 ` Simon Glass [this message]
2021-10-09  1:39   ` [PATCH v4 14/15] image: Avoid #ifdefs for " 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.14.Ic1283f25f151e715fdde093760ee004e15e19a96@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=t.karthik.reddy@xilinx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.