From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A701FC4338F for ; Sun, 1 Aug 2021 21:03:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C22460F55 for ; Sun, 1 Aug 2021 21:03:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2C22460F55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 32DCC83351; Sun, 1 Aug 2021 23:01:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="UbA0YTqm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 13DA883346; Sun, 1 Aug 2021 23:01:16 +0200 (CEST) Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 91E4983329 for ; Sun, 1 Aug 2021 23:00:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22a.google.com with SMTP id n16so15160792oij.2 for ; Sun, 01 Aug 2021 14:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MXi2xbJi0JR2d4RPpaNwpGVZCkjj7NzUEQmxw7wLX9c=; b=UbA0YTqmK5R6bbaIIvMRP/LzicG0YChjXjxo+pVtGP0SNUOKzXTcYloVdtWObH4Tzl qccuaKNpm5j4H/cgfucGhGx2m/96Sa6YxTJKqIVLugoH/uoom+u3jYp8uzUry8LKnR7V sRC2DgW7veHlQOUvmrJ0lDz1kNwkdvMY1uNuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MXi2xbJi0JR2d4RPpaNwpGVZCkjj7NzUEQmxw7wLX9c=; b=DaSC/v3PhrxevdmerFnLZrmhw8W1fNu+XG24k/mdnNJRkH35M2Xd62SefV24fJcMDU EnkwoVdqTB6/rlXcoVH7HO1XngZS9M8SVosqyO74fVLvtyzNJSfundTNO5YY1/iXFrSa Vlamm6Q6gr1+8YZniP9gf1SJBKY/nxH7V1eV+cXS9/xIE92gz7gjJPlCqTx8TNa3KmAx FYlX7k3VBoxvbcOY3Yaimupyg7xAgIbCRc/U1vDx/US6rOYKW25qRQMSH5BSWkBvCola GPGfpYwI3LUfGTqJG/dx+eAiImkC4TMsSN4Excyeruhdkv7IWWHL8P33oT9TGnBO50lW ZglA== X-Gm-Message-State: AOAM531hat2JbWwxMVPgfwwK/ZtbfeYeqvu82l4L+UbbFS82bPyEnqnp nmXqBpsLDno6zyEXj3XD0eV5/wGIp5J8tvTp X-Google-Smtp-Source: ABdhPJyviLmkDp/2fNuV6lyONZbbT3ZpaRK4iIe7oUmQAKoNJK0+otxisslik5fswxWpufxHvgxblw== X-Received: by 2002:a05:6808:144a:: with SMTP id x10mr575885oiv.68.1627851654899; Sun, 01 Aug 2021 14:00:54 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id s16sm1560707otg.51.2021.08.01.14.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 14:00:54 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Bin Meng , Tom Rini , Alexandru Gagniuc , Simon Glass , Joe Hershberger , Marek Vasut , T Karthik Reddy Subject: [PATCH v3 14/15] image: Avoid #ifdefs for manual relocation Date: Sun, 1 Aug 2021 15:00:31 -0600 Message-Id: <20210801150024.v3.14.Ic1283f25f151e715fdde093760ee004e15e19a96@changeid> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog In-Reply-To: <20210801210032.2203104-1-sjg@chromium.org> References: <20210801210032.2203104-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 --- (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 DECLARE_GLOBAL_DATA_PTR; #include +#include #include #include #include @@ -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