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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A73A2C6FD1C for ; Sat, 11 Mar 2023 17:39:28 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 190A485FDB; Sat, 11 Mar 2023 18:39:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HpkEltjQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9423185FCB; Sat, 11 Mar 2023 18:38:57 +0100 (CET) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 0AF0285FCB for ; Sat, 11 Mar 2023 18:38:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ovpanait@gmail.com Received: by mail-ed1-x533.google.com with SMTP id cn21so2869501edb.0 for ; Sat, 11 Mar 2023 09:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678556332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AKp4d/zjLIGCFH3ikFRvdJblSW/55iOpuzBSPPH4rt0=; b=HpkEltjQkw3No9LuTYJegLErtkSeh9wTkoCsNqU3IfSy/rjGfEjnxpsP8FeWo1077A lJFTeWY81/t0nLRSyiWBzzSyy1zyhVBTBX7EEq97eI8iJuPAWVl02nwAI/JFRIuOK1Dx ri/M+xUlgf2nKzapI6f9SD0YRTyJSPoRaKOvOEruUlwZHz6MVH+DNEmCkbJBIZCLNCeq 5opmFplQwZuevlJ1jpzQjNyNQ88dkwlfCX1fw8QGwwDUSyXdBdTefwTLehvFStmAT18U CXxBwsaHEGv+2zrNGcamw3SfSjiO+zxyv92mi/6xAaZNMUpfvEHV/Xe5NagaBb78Iq7R HrCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678556332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AKp4d/zjLIGCFH3ikFRvdJblSW/55iOpuzBSPPH4rt0=; b=NnWCRa2ztz5FCxPLnYrDpVwUhkS21zGgyMbmlCHHLAi5Ugv7LhwFpevkBbAdxTNSFJ tSanvJogRAATzysm79XlQFqMFPtHK/MJ2nvLWTCiXJD7yJOhXWt77QRsSKJX7M7EVi3m XCz6ivhXw6qvPkx1nZKY2XnVmc3cA+/yiIHHDLtdEPorRuz7954vVn/kiUtTg8enudFP nkJEuqHKj8M+abHZsREKUm3s9/i/ezqUbY3E0YO9r2OMCug+Zi5LjqwDZE9BORGY9J/5 5L+uJvwsKkPe/LZ5fv57zwJfM9vg3R0RJ5YH8E/qDadxKUm9Yn+FPRRVvSXEm7wyPWv+ uNWQ== X-Gm-Message-State: AO0yUKXIUPYf03rbqx9mMHCvQtglHaNsNp7Lc7hm4jy52su28Mi1hnBG XxRTq2Ryxt3v7MprjMPKcKTvee+Cg04= X-Google-Smtp-Source: AK7set+ROOnCbLsq7mzeN84OqK2AJfP4EWOq0Qto5LL372F6r9VBy+4s4a2KhopZp71awg1K+bc2rQ== X-Received: by 2002:a17:906:d928:b0:8b1:7eaf:4708 with SMTP id rn8-20020a170906d92800b008b17eaf4708mr28004163ejb.65.1678556332697; Sat, 11 Mar 2023 09:38:52 -0800 (PST) Received: from localhost.localdomain ([2a02:2f0e:c915:3800:d24b:dc4a:599b:7c80]) by smtp.gmail.com with ESMTPSA id p10-20020a170906614a00b008e7916f0bdesm1303986ejl.138.2023.03.11.09.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Mar 2023 09:38:52 -0800 (PST) From: Ovidiu Panait To: u-boot@lists.denx.de Cc: Ovidiu Panait , Michal Simek , Samuel Holland Subject: [PATCH v2 3/5] tools: relocate-rela: add support for handling 32-bit big endian files Date: Sat, 11 Mar 2023 19:38:36 +0200 Message-Id: <20230311173838.521804-3-ovpanait@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230311173838.521804-1-ovpanait@gmail.com> References: <20230311173838.521804-1-ovpanait@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean Currently, a microblaze build with CONFIG_SYS_BIG_ENDIAN=y and CONFIG_STATIC_RELA=y fails with: tools/relocate-rela: Not supported machine type ELF decoding failed make[2]: *** [u-boot/Makefile:1306: u-boot-nodtb.bin] Error 1 To fix this, convert the 32-bit codepath to use the previously added elf{16,32}_to_cpu() functions. The aarch64 codepath is left untouched. This commit ensures that CI doesn't fail for the next patches which enable runtime relocation by default for microblaze. Reviewed-by: Michal Simek Signed-off-by: Ovidiu Panait --- (no changes since v1) tools/relocate-rela.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index b27c41b96f..fe8cd6bda9 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -251,7 +251,7 @@ static int decode_elf32(FILE *felf, char **argv) return 25; } - machine = le16_to_cpu(header.e_machine); + machine = elf16_to_cpu(header.e_machine); debug("Machine %d\n", machine); if (machine != EM_MICROBLAZE) { @@ -259,10 +259,10 @@ static int decode_elf32(FILE *felf, char **argv) return 30; } - text_base = le32_to_cpu(header.e_entry); - section_header_base = le32_to_cpu(header.e_shoff); - section_header_size = le16_to_cpu(header.e_shentsize) * - le16_to_cpu(header.e_shnum); + text_base = elf32_to_cpu(header.e_entry); + section_header_base = elf32_to_cpu(header.e_shoff); + section_header_size = elf16_to_cpu(header.e_shentsize) * + elf16_to_cpu(header.e_shnum); sh_table = malloc(section_header_size); if (!sh_table) { @@ -290,8 +290,8 @@ static int decode_elf32(FILE *felf, char **argv) return 27; } - sh_index = le16_to_cpu(header.e_shstrndx); - sh_size = le32_to_cpu(sh_table[sh_index].sh_size); + sh_index = elf16_to_cpu(header.e_shstrndx); + sh_size = elf32_to_cpu(sh_table[sh_index].sh_size); debug("e_shstrndx %x, sh_size %lx\n", sh_index, sh_size); sh_str = malloc(sh_size); @@ -306,8 +306,8 @@ static int decode_elf32(FILE *felf, char **argv) * Specifies the byte offset from the beginning of the file * to the first byte in the section. */ - sh_offset = le32_to_cpu(sh_table[sh_index].sh_offset); - sh_num = le16_to_cpu(header.e_shnum); + sh_offset = elf32_to_cpu(sh_table[sh_index].sh_offset); + sh_num = elf16_to_cpu(header.e_shnum); ret = fseek(felf, sh_offset, SEEK_SET); if (ret) { @@ -329,13 +329,13 @@ static int decode_elf32(FILE *felf, char **argv) } for (i = 0; i < sh_num; i++) { - char *sh_name = sh_str + le32_to_cpu(sh_table[i].sh_name); + char *sh_name = sh_str + elf32_to_cpu(sh_table[i].sh_name); debug("%s\n", sh_name); - sh_addr = le32_to_cpu(sh_table[i].sh_addr); - sh_offset = le32_to_cpu(sh_table[i].sh_offset); - sh_size = le32_to_cpu(sh_table[i].sh_size); + sh_addr = elf32_to_cpu(sh_table[i].sh_addr); + sh_offset = elf32_to_cpu(sh_table[i].sh_offset); + sh_size = elf32_to_cpu(sh_table[i].sh_size); if (!strcmp(".rela.dyn", sh_name)) { debug("Found section\t\".rela_dyn\"\n"); @@ -540,9 +540,9 @@ static int rela_elf32(char **argv, FILE *f) PRIu32 " r_addend:\t%" PRIx32 "\n", rela.r_offset, rela.r_info, rela.r_addend); - swrela.r_offset = le32_to_cpu(rela.r_offset); - swrela.r_info = le32_to_cpu(rela.r_info); - swrela.r_addend = le32_to_cpu(rela.r_addend); + swrela.r_offset = elf32_to_cpu(rela.r_offset); + swrela.r_info = elf32_to_cpu(rela.r_info); + swrela.r_addend = elf32_to_cpu(rela.r_addend); debug("SWRela:\toffset:\t%" PRIx32 " r_info:\t%" PRIu32 " r_addend:\t%" PRIx32 "\n", -- 2.25.1