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 F2D42C6FA8E for ; Sun, 5 Mar 2023 17:50:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2452B84EEF; Sun, 5 Mar 2023 18:49:49 +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="FA5j7S13"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F237A85B9A; Sun, 5 Mar 2023 18:49:39 +0100 (CET) Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (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 AA31185B92 for ; Sun, 5 Mar 2023 18:49:35 +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-x52f.google.com with SMTP id s11so29650601edy.8 for ; Sun, 05 Mar 2023 09:49:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678038575; 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=UMklEZJ0tdzsdewlfd6YKUJbMWe58LKWfNhfHTP8FZk=; b=FA5j7S13zESeOor6e1t/aNteV/vUy1SP51My1C52PQXNTcX3o8hU7PiCk2RDjy7pWL u1bd1reLz+CzH+EofnhWFfzXqwpyKoKSHiD1wFCJeoVsxfipl7vqR8f2wOrc91+T7/o3 DJlpJMwiJ6VUrfGWnalH5f0JPw9YBy+YxI7lUByjIJ2ryOrYbTmYEUmfNv/7Sqgyf7Jx O9vPWh3wKOJYoQbsO9lbhu9Mzif2nJBjiuFIYF404JChTBJzVlNOJq7QbzHZkgdXm/+o jnJpw4sHrY7Dfgz/IrN4SWlPrja/dLA1ljWPFay4zCJunsSAJO26kmsMqO4BYugCBDs3 y7jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678038575; 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=UMklEZJ0tdzsdewlfd6YKUJbMWe58LKWfNhfHTP8FZk=; b=p7F2LD9fx7V4TP3k9DWgsVRgRtEOrBjfFEoECU6ScLAkwTDuxBaN3S7+wYDAfbHkAM AGO8AAg7LZS1YMde5+LmltvoIASwNvpSq47HXsKwIFkPK5fk/QQtncbR2BnUrDR+1T4e Z1r/pLaV1aV0VgO1DSFOrDHMiEqxXxBve0FCe538d3GPcOQbye6QQzCe5Rx/pmyEl9FS IfHWRdgNZ12VGzOtzfm9xjttSoJqG3haK3LbEYXQKnwwuqX0obpmvkj1BJPfQW90e5+/ HKjMnHc5viWyMbkQ8UFaXlomA8vd3050EzxJArxkj0PbZVPQE10shmIjvVMff6mLrx0d Vbng== X-Gm-Message-State: AO0yUKVw4SlGaEbOFfMIqHDhCG10Af6fw1iWr+pZ5vZpjjpFw5sT4b60 z7ZNGxDagaDb7ybIV7bvcjAiWTm7hig= X-Google-Smtp-Source: AK7set/x38QdbUxk4u7c+3UYtHdm8/0uW3G+4yFnkkMvRNFfbYMzPJaPL1teMPtXQwDlwtKhxArf9A== X-Received: by 2002:a05:6402:b1c:b0:4bc:b40:108b with SMTP id bm28-20020a0564020b1c00b004bc0b40108bmr7912976edb.9.1678038575281; Sun, 05 Mar 2023 09:49:35 -0800 (PST) Received: from localhost.localdomain ([2a02:2f0e:c915:3800:3ec7:a5bc:2321:4538]) by smtp.gmail.com with ESMTPSA id l26-20020a170906231a00b008b69aa62efcsm3464985eja.62.2023.03.05.09.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 09:49:35 -0800 (PST) From: Ovidiu Panait To: u-boot@lists.denx.de Cc: Ovidiu Panait , Michal Simek , Samuel Holland Subject: [PATCH 3/5] tools: relocate-rela: add support for handling 32-bit big endian files Date: Sun, 5 Mar 2023 19:49:17 +0200 Message-Id: <20230305174919.293393-3-ovpanait@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230305174919.293393-1-ovpanait@gmail.com> References: <20230305174919.293393-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.6 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. Signed-off-by: Ovidiu Panait --- 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 84531b23a6..2bc46a12d7 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