[PATCH v3 14/15] image: Avoid #ifdefs for manual relocation
Simon Glass
sjg at chromium.org
Sun Aug 1 23:00:31 CEST 2021
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 at 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 fb0035524e0..e92d0162084 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>
@@ -69,17 +70,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;
@@ -97,18 +100,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.32.0.554.ge1b32706d8-goog
More information about the U-Boot
mailing list