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=-19.4 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, 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 17D10C4338F for ; Sun, 1 Aug 2021 21:03:45 +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 97B9C60F55 for ; Sun, 1 Aug 2021 21:03:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 97B9C60F55 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 4432383352; Sun, 1 Aug 2021 23:01:46 +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="Ql9hixz2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 61B0C8333D; Sun, 1 Aug 2021 23:01:24 +0200 (CEST) Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) (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 5A7D283322 for ; Sun, 1 Aug 2021 23:00:55 +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-ot1-x32b.google.com with SMTP id f20-20020a9d6c140000b02904bb9756274cso3758330otq.6 for ; Sun, 01 Aug 2021 14:00:55 -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=INHl0H4PbjyUgFLhTLpT8h43+ZxckCpcVHhQTqPuVoc=; b=Ql9hixz2SXKtqBCaFAdIeGJkfyYkXTGCT+SUTMlbTlEf+zNvXQ08vwwT13xMgMrEoh 0mvWDrVC4XsbBjhMFAKzzrQ5KsjA4UUSjt1K9jSTO4azb9QHhmpfaDazx681k0CoGEZe iXRUdIRFlpewpfHd/T/61mswj90KmU82VY50Y= 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=INHl0H4PbjyUgFLhTLpT8h43+ZxckCpcVHhQTqPuVoc=; b=HNWkgRBI59Vf7J6o1CjAFrSPg9hJnOn3V9An3tJgGmhs9MRMSU/QtB3fKOy8aZPQLE hXtN75T94LgCpifX0zd5ZlHGYuv1i4OHUYKGmp/dDfZ/SHZjIBDQfKH5ObA0QOTbGyNs 9Tu8go+T11nqn0flV34eJ1Gzc+od0pbTy86GdjzL2MfhDTglNjFhyP3UJ8rj2Of+lEq0 dvvNxk2xnnTozc8z0dvcRndbbRBDSghv1/K0ObsR0/7SJ011tVz4P3yri2n18yQZOw4G jUNfb1i5kITm8JNGfNMZGNcGfJKw3Zx8TF8BTpj2Ug4HMLwh97RWx7Hh/8elKGCh0j46 ZlzQ== X-Gm-Message-State: AOAM530W1cIBtLQzmy71JGH71sc7LaVRB661WBqfbGcfVJ7u3t+BgEEy Q8SdmriAMoEf01tmqotaTLBMY+SWK9/vGvKv X-Google-Smtp-Source: ABdhPJxTNOns08mzcyUug+IDDaPpA3KETfIOj3YhJtvMubGYR9N/Ni0/DMPlc7VpSmMGktjv0auKZA== X-Received: by 2002:a05:6830:4186:: with SMTP id r6mr9466766otu.136.1627851653822; Sun, 01 Aug 2021 14:00:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Aug 2021 14:00:53 -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 Subject: [PATCH v3 13/15] image: Create a function to do manual relocation Date: Sun, 1 Aug 2021 15:00:30 -0600 Message-Id: <20210801150024.v3.13.Iea4abe7ae3455f42385e0d1c2b5776485b1ab88b@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 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 --- (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 0ef8f30fcfa..086ae609f29 100644 --- a/common/image.c +++ b/common/image.c @@ -63,6 +63,7 @@ DECLARE_GLOBAL_DATA_PTR; #include #include #include +#include #include #include #include @@ -563,11 +564,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); } /** @@ -587,11 +584,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) @@ -641,11 +634,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) @@ -675,11 +664,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) @@ -722,12 +707,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 +#ifndef USE_HOSTCC +#include + +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.32.0.554.ge1b32706d8-goog