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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7027AC433F5 for ; Sat, 25 Sep 2021 13:06:13 +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 C5B0D610CF for ; Sat, 25 Sep 2021 13:06:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C5B0D610CF 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 D875183550; Sat, 25 Sep 2021 15:05:31 +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="HZ0rKfLq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D078583550; Sat, 25 Sep 2021 15:04:21 +0200 (CEST) Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) (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 93A7A83549 for ; Sat, 25 Sep 2021 15:03:53 +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-x332.google.com with SMTP id x33-20020a9d37a4000000b0054733a85462so17101528otb.10 for ; Sat, 25 Sep 2021 06:03:53 -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=i2NgxRk2RFP8rpopfGkIuhO/ngG2ZhS1+/xX5JcJFtw=; b=HZ0rKfLqW4DbnC7k8B4rQ/L/A9YOXkp3cTVk7qNPa1p/SAo2ZzRX6BaUpYcUD+IlW8 wETEctD0myc33UcsIBl+r2h+e4IdZ710nxvfXR9NZlM4nJ+5tfG5ZILybcXQL5oiPhN0 9//I+a4DKwHwKg2ACq380F+s+zL3yjF6w3sDE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i2NgxRk2RFP8rpopfGkIuhO/ngG2ZhS1+/xX5JcJFtw=; b=Lp/gspp/h3YluRWT0+4D9RAn8sIzaQ74lmUcch5wTM08Ae2tM9Lk8NoHNlH6eNszNl uN9ZJS8iYWRZAaGTtn2uBGslLJp0TePAXbux1af9QuT7IJNuA1j9U0DUQZTMdjbfdWdi 7ZYr/sgTNFKIPP9b4t7UVoccKewaQaTsgpDReNMGLCn5GP9aCq0RzXFJd07U1C8Gu2d5 Eybe8CNXLaLlTTtQs8t0BAZumsCfgRX41C3Q9Gr4Cd4jZXGet6u4z1L3hK6d13dZ8Fp7 rU3FQyRZ1Qxz6S3M1nZn8Cr0I5nfu9t7F1gIBv9YiNK+B32vnXVSvVed1c0rmJ2gMiXl 6/fA== X-Gm-Message-State: AOAM532Y+FFCnffagiydKCpteRwdLO7rbZ02LlrFZCm5V9oBqC+I6bc6 AbYiA9lDM394nlJUgOs/HObK+iaGSHpUdQ== X-Google-Smtp-Source: ABdhPJwPoUgtLYguIjnLcrXa+ic1jWpEVCbyoryKOcquzZyfDvUf8Qr+5NAYJHDj+4qSwRZ1Y+jjxw== X-Received: by 2002:a9d:75d5:: with SMTP id c21mr8700578otl.47.1632575031980; Sat, 25 Sep 2021 06:03:51 -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 f61sm2770018otf.73.2021.09.25.06.03.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Sep 2021 06:03:51 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Alexandru Gagniuc , Bin Meng , Tom Rini , Simon Glass , Joe Hershberger , Marek Vasut Subject: [PATCH v4 13/15] image: Create a function to do manual relocation Date: Sat, 25 Sep 2021 07:03:18 -0600 Message-Id: <20210925070255.v4.13.Iea4abe7ae3455f42385e0d1c2b5776485b1ab88b@changeid> X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog In-Reply-To: <20210925130320.7824-1-sjg@chromium.org> References: <20210925130320.7824-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 3eb6a7fca1d..2f2fd052c50 100644 --- a/common/image.c +++ b/common/image.c @@ -63,6 +63,7 @@ DECLARE_GLOBAL_DATA_PTR; #include #include #include +#include #include #include #include @@ -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 +#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.33.0.685.g46640cef36-goog