From patchwork Thu Jun 2 13:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638359 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=CwEPo5er; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSKF6XMFz9sFr for ; Thu, 2 Jun 2022 23:58:25 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2BF368432F; Thu, 2 Jun 2022 15:58:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="CwEPo5er"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 21C9E8432D; Thu, 2 Jun 2022 15:57:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 0BBDF80179 for ; Thu, 2 Jun 2022 15:57:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x531.google.com with SMTP id fd25so6386120edb.3 for ; Thu, 02 Jun 2022 06:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JVsVFRlSoq8u19YpmX78oXp/tP3k4SaCCAKM1FYjSoU=; b=CwEPo5erjtkAgpuL7OHYOstdv+Qv28WZXpEiywIm3feY4UrdfmjQowsVgO5B9q/XLD cn+q8cM6Lck/yGhDpPYR+8f3KjG3Vwa7JG/N5WMkwmSQWZCUI076DwlBe9dJ8UX8KLjS EtmS7aAwcJKCRRLtP9B/R4QQB6GysVSO1f7obujulugc3/KDW3UZzUZwKBx56y+ofa8M UYIU5sFy2znBfUoi61yKH9Av5Os+cYLyMr3gRPjFoXi0myLkNe0gI8GzPB7FmuH7Y1KF dMe4b6ZLyy6MtNipiwlOOtHcP1/phCH1rSnOrkYk5qXms2GusEM+tpBJ+LYUyHJE7h/4 rp0w== 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=JVsVFRlSoq8u19YpmX78oXp/tP3k4SaCCAKM1FYjSoU=; b=bvWheO5ND04sY1DrCz2bCLx3S8j5JERdOXSb5+5dybhQ+WUX8AomLn8sjcItynfFxN 7ugbcab4v6vZ7zWU1X/Ov5HJFOo2A/G7jci8dWjPYGIkNEGjLCOa1KI3fE7h5fdF+S1D pVr496L3hZv6VAkx2n7VZiQDwCwBZm3+Hz0+hM/2dLVU+0CGrqDx3j2WI4uI/CJQJTT0 1MT6qAocxRKqweTC1EubSCsLz4Uzb1ZpuNm5swNb5D23HZwYRxsr2U7kkpXgNx6DTLZx i9fGa9/vsxgKBQsXQqU9mer0H6yDOZg4jBqURaFYrH2OweGVJSiCtTnS0JGiCGAx/3e+ s2pg== X-Gm-Message-State: AOAM5331VSkLhTBVDsnxX/lhiZK9UvrC1CVWPnfVlYs+Cm9B2T7KW81b kXCbvyBX9WMypEoqKq7lXnOL9vjlxrKqkQ== X-Google-Smtp-Source: ABdhPJzffzeeaZ5cOErVsG7zPNfDcppOE9HrUH9CEspbCdZSNg7Pe/GPEjwXvBmoSJtr8pDohFjWzw== X-Received: by 2002:a05:6402:228d:b0:42d:e319:7297 with SMTP id cw13-20020a056402228d00b0042de3197297mr5601728edb.79.1654178273278; Thu, 02 Jun 2022 06:57:53 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id fg24-20020a1709069c5800b006fe9ec4ba9esm1728269ejc.52.2022.06.02.06.57.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:57:52 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH 01/22] tools: relocate-rela: Open binary u-boot file later Date: Thu, 2 Jun 2022 15:57:25 +0200 Message-Id: <9b636b14554e6ee75308e4ade9b48777f446d54f.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean There is no value to open u-boot binary file so early. Better to check all values first and then open binary file. Signed-off-by: Michal Simek --- tools/relocate-rela.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index f0bc548617a4..883987111869 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -73,13 +73,6 @@ int main(int argc, char **argv) return 1; } - f = fopen(argv[1], "r+b"); - if (!f) { - fprintf(stderr, "%s: Cannot open %s: %s\n", - argv[0], argv[1], strerror(errno)); - return 2; - } - if (!read_num(argv[2], &text_base) || !read_num(argv[3], &rela_start) || !read_num(argv[4], &rela_end)) { @@ -95,6 +88,13 @@ int main(int argc, char **argv) rela_start -= text_base; rela_end -= text_base; + f = fopen(argv[1], "r+b"); + if (!f) { + fprintf(stderr, "%s: Cannot open %s: %s\n", + argv[0], argv[1], strerror(errno)); + return 2; + } + fseek(f, 0, SEEK_END); file_size = ftell(f); rewind(f); From patchwork Thu Jun 2 13:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638360 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=vdUEjNg2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSKV66rsz9sFr for ; Thu, 2 Jun 2022 23:58:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BE33384343; Thu, 2 Jun 2022 15:58:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="vdUEjNg2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71AC58432E; Thu, 2 Jun 2022 15:58:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (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 6A7E88431A for ; Thu, 2 Jun 2022 15:57:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62d.google.com with SMTP id me5so9620624ejb.2 for ; Thu, 02 Jun 2022 06:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QGcv2xW7HRIjxOD8zToAcyThovnu1r4anMFv6LRPt0k=; b=vdUEjNg2wczzhQEa55fKkVkut/0iDGgo0mW16i4l5XQTWUR3E3eobXjZWQC7M0cXOg dbRCKaENBHbwhqWtmDMZX143hr3/M23v73eZFm7cVZUfoAzPqvgCJsfB/roPXdKg0RhQ IvVJ53NBFfgV3mifgJMiEgrGLlCl5ssDDWdvUVCVRPimsYneVfhFd72wxWJehAJWBQY+ bNGUvCDJ3VGQp11Ns9yzzMCiudoHDaES1VvBnAdtfG0SxPLw7BATigzeOwtKMEji8KY7 OVMkUtZGet8ho2gq+AdLguMvhlqK1UfnqIxsEZTD/oYsqoe85Mf4Fu4YAGdTgMMrGB8b nfKw== 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=QGcv2xW7HRIjxOD8zToAcyThovnu1r4anMFv6LRPt0k=; b=qo+Zea4f2Qu/2CqWpJS2XUghpVZi5ksW34+ZaVF9aglJ3M2tW+btDNIHnTXFn6hiFq 2rgPZvXWfc9DpVjZy5lAoTjBenEykZAkFmh7N2xnIAZF1HcQ43Zbvva1ohbGtT4gS/lE QPdC0vvHzYOc2OonM3CEfVoGtYXcUvoa3k3hYulkhw5IerEluiDMUH29Yl6sfRHM2juO Nnm5FRhMMRDwqbGmpFRkwT+kaO7fFhbo+FkJNk9b0cQhsKjOccBkpDvJAV06M3JjUBNQ jGeSoxGJchMXyEJoTbOSCoHcheCKgR5Pah+polvqXHyPui6cXYDYiY4knxY6BquPKMm9 PB3g== X-Gm-Message-State: AOAM53070/WEdCXpmn2r6hsYqUMx7m8gdMHM1/xDRxoW2b0ToTy4sly1 hncripZ04tAvUZQ1X8dFE7flF7xJ9fEgXw== X-Google-Smtp-Source: ABdhPJzhcEq4Iae+cI5MgzgJJRCavoSvifIim9RFhG0ReJTTfX6uHuso80w+SI/9bypueMZmYHSeEQ== X-Received: by 2002:a17:906:d550:b0:704:ae79:7db1 with SMTP id cr16-20020a170906d55000b00704ae797db1mr4445784ejc.478.1654178274718; Thu, 02 Jun 2022 06:57:54 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id 12-20020a170906058c00b006fed787478asm1749327ejn.92.2022.06.02.06.57.54 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:57:54 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Heinrich Schuchardt , Simon Glass Subject: [PATCH 02/22] Makefile: Fix description for relocate-rela parameters Date: Thu, 2 Jun 2022 15:57:26 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Numbers in comment are shifter which is visible from command which calls them. Also relocate-rela usage is describing them. "Usage: %s " Signed-off-by: Michal Simek --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 61927f8918b4..dfb655d1f764 100644 --- a/Makefile +++ b/Makefile @@ -922,7 +922,7 @@ endif # the raw binary, but certain simulators only accept an ELF file (but don't # do the relocation). ifneq ($(CONFIG_STATIC_RELA),) -# $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base +# $(2) is u-boot ELF, $(3) is u-boot bin, $(4) is text base quiet_cmd_static_rela = RELOC $@ cmd_static_rela = \ start=$$($(NM) $(2) | grep __rel_dyn_start | cut -f 1 -d ' '); \ From patchwork Thu Jun 2 13:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638361 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=KKlpN2qH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSKl5w9Vz9sFr for ; Thu, 2 Jun 2022 23:58:51 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 23F1484382; Thu, 2 Jun 2022 15:58:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="KKlpN2qH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B006B80179; Thu, 2 Jun 2022 15:57:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (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 DB86E84319 for ; Thu, 2 Jun 2022 15:57:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62e.google.com with SMTP id m20so10110598ejj.10 for ; Thu, 02 Jun 2022 06:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Py3vXfRKlh/229QolJrpNfG1+Jat0aXK51UtKgi5hE0=; b=KKlpN2qH1h+jmeigy9GM7Nd3SSs8d2uC+6rCpMyp1sOLBWbxDrTR8KgwKvCZsfyyow ONSGScAKe9pzrIurSDlkv6J1FnTIEZZkABdNwxh+fIGBbH5VgJVFbsOjQtkd5YedLP0J ywcxVrHWT+P67XCS9WG0dHYIJEEkCxeYlkzHIS/XJgY032NE+rW7nM1yW022r4/Yq6u/ mNiWsNQh/dgUEMXpjBINV56JqbQ6jBssAoDOsSgxhRjcJ4jzr0O1kiLtTkrju+TRIMBb KQNQ+WxZ3LBkNaxSNRsHwWDIdYv8K0trsXC8mi5J5MfrF33UT1436YytjSs1xGneUa3b qrmg== 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=Py3vXfRKlh/229QolJrpNfG1+Jat0aXK51UtKgi5hE0=; b=i8vmM4aHf/NjQPBIyY6IqDIg4H2DVNZmDF4RusRlrp+tQOrvjwU/UQDLLgEgkd6MaE 0PCC6XOvN5SNXCpUhBZsINbW/rfSOHjCCIMHeiItoc2awGBVgJJxzhupNz1euMaKfY0V AGr/vnZeEFkREcy6k0NepXzxTiB8MEioSx5ZtH6Rhr9gKGY+VWezgcLCVdswKaUyNI8r WJn7JgZFB0JHPA4qipVbtLLbOL6JDa68fssKwLbuLv59E4GwuQi6izGaMleusY8R07og BbfkDDLtUl8J59ZghwJrJ9UdkyVGiJ8qEXTWZKmrkynehf73pZJ3LWDEV/kCyCik1LcN RFtw== X-Gm-Message-State: AOAM5326+ZtzeASKI72ksLojJKB1pPLgJ7AhaP8+gOw9ek6Bo1F1cIeR 4n5oY3R5Lp4La6jbMBrZItOLO90UhbEt/Q== X-Google-Smtp-Source: ABdhPJzfmV1TpLSWJQiUtLD4bH94aWqlhnqOt6TfMnJ7BBLyTj+IF+SIdNSKQtvBpBK7A4k1QP70XA== X-Received: by 2002:a17:906:648c:b0:6ff:277f:5a77 with SMTP id e12-20020a170906648c00b006ff277f5a77mr4289836ejm.249.1654178276161; Thu, 02 Jun 2022 06:57:56 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id eg13-20020a056402288d00b0042dce73168csm2552813edb.13.2022.06.02.06.57.55 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:57:55 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH 03/22] tools: relocate-rela: Use global variables Date: Thu, 2 Jun 2022 15:57:27 +0200 Message-Id: <528afac0b8f12d2573beac4e9ea509ad773ff2d8.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Declare rela_start/end and text_base as global variables. It will help with using these variables for ELF decoding. Signed-off-by: Michal Simek --- tools/relocate-rela.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index 883987111869..67a138aa67d7 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -20,6 +20,8 @@ #define R_AARCH64_RELATIVE 1027 #endif +static uint64_t rela_start, rela_end, text_base; + static const bool debug_en; static void debug(const char *fmt, ...) @@ -63,7 +65,7 @@ int main(int argc, char **argv) { FILE *f; int i, num; - uint64_t rela_start, rela_end, text_base, file_size; + uint64_t file_size; if (argc != 5) { fprintf(stderr, "Statically apply ELF rela relocations\n"); From patchwork Thu Jun 2 13:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638363 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=mHNhww8e; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSLL01SJz9sFr for ; Thu, 2 Jun 2022 23:59:21 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 00C9084342; Thu, 2 Jun 2022 15:58:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="mHNhww8e"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5AED98432C; Thu, 2 Jun 2022 15:58:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 4635A8432C for ; Thu, 2 Jun 2022 15:57:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62f.google.com with SMTP id f21so10111025ejh.11 for ; Thu, 02 Jun 2022 06:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XeAndGS+KOyrSOyszicLpHYsq6+n8gsC3mVWMmgnBPQ=; b=mHNhww8e+kgZKxOJ6vsvZRm14tZLi0264leOXgIxQo8b0nMX5oHDoTnVibN7MXGvFr u6lYIJDIlNw0h5VTvjq2Ul/tN44Qb11vUte0kEzgA5EXvqXTnInaEMcM7QwBVCf0hvQh FP+mArxa923MtafSRDyZblmGtq6nRNF3JDWVv/l8Ciezd477w+l2c7iqA/SGHMXAYcfR ech8/Ut1E44hJwRxPkwU7FjR/OHHIYuKjuOjrfuEAb6Ig8r9F6MKMH3n5Dm7vhTrqHOi /odjCtwd2/5LfK610ZBJ0cbvEIa7nC9kV1UNVZGjNC37zgYmY25RvmBM8Z8AsTwA7UjA Ki9w== 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=XeAndGS+KOyrSOyszicLpHYsq6+n8gsC3mVWMmgnBPQ=; b=PUSIT4lZNqVkFw4vwslZUw/d6cZypyVRq4oAaaSQGLNGkYGL+hoo7P53CM9robDiWh uNVkSx8oIs8ZTxrXD769O5eM0CAhg3ApWQTz4PkA6u5Z1UkDBGlbzhkipMUQ5jb39ZmR P2B/3czYjgr2+Uw2CvJJNmObXITYT482xNxE+fMwH6zosolRr3rvPU07V1f8K0Os8FQ5 /HTsN7LFRNjHzHuTMcN/CbSTnwdsnlKRmv4JrKoeOeKceqK6puOHFidStcNK4orhSdBl X4yOQk7mbsoQCgEaFTspyrR/6+gwaef3FnowkkTctDyaBCmn9Ju4LyzCM2xWPuDvrDz1 nXGg== X-Gm-Message-State: AOAM5306oKHKu44T7mM2576tPrqOFl3kJIAVsE+kRqxlD0Nwx/bf9fq+ iCDc3kmPS0zHBPGomBm2uWmJ0WugLTW/5w== X-Google-Smtp-Source: ABdhPJy8AHab7FmH5u3OkAkdDe/bDJfraCFbep3rO/xJKwKqogqe+MK1SyP+rJzuaN5VduB7XVTCLA== X-Received: by 2002:a17:906:d54b:b0:6f4:d14b:bb91 with SMTP id cr11-20020a170906d54b00b006f4d14bbb91mr4373762ejc.314.1654178277561; Thu, 02 Jun 2022 06:57:57 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id bv15-20020a170906b1cf00b006f4c4330c49sm1793268ejb.57.2022.06.02.06.57.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:57:57 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva , Heinrich Schuchardt , Simon Glass Subject: [PATCH 04/22] tools: relocate-rela: Read rela start/end directly from ELF Date: Thu, 2 Jun 2022 15:57:28 +0200 Message-Id: <6dbdaceb27095bb596a19722d5468121578fdd67.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean There is no need to pass section information via parameters. Let's read text base and rela start/end directly from elf. It will help with reading other information from ELF for others architecture. Input to relocate-rela is u-boot binary and u-boot ELF. Signed-off-by: Michal Simek --- Makefile | 4 +- tools/relocate-rela.c | 181 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 168 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index dfb655d1f764..060aff1ff2d1 100644 --- a/Makefile +++ b/Makefile @@ -925,9 +925,7 @@ ifneq ($(CONFIG_STATIC_RELA),) # $(2) is u-boot ELF, $(3) is u-boot bin, $(4) is text base quiet_cmd_static_rela = RELOC $@ cmd_static_rela = \ - start=$$($(NM) $(2) | grep __rel_dyn_start | cut -f 1 -d ' '); \ - end=$$($(NM) $(2) | grep __rel_dyn_end | cut -f 1 -d ' '); \ - tools/relocate-rela $(3) $(4) $$start $$end + tools/relocate-rela $(3) $(2) else quiet_cmd_static_rela = cmd_static_rela = diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index 67a138aa67d7..36065edb3f01 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -20,6 +20,8 @@ #define R_AARCH64_RELATIVE 1027 #endif +static int ei_class; + static uint64_t rela_start, rela_end, text_base; static const bool debug_en; @@ -54,32 +56,183 @@ static bool supported_rela(Elf64_Rela *rela) } } -static bool read_num(const char *str, uint64_t *num) +static int decode_elf64(FILE *felf, char **argv) +{ + size_t size; + Elf64_Ehdr header; + uint64_t section_header_base, section_header_size, sh_offset, sh_size; + Elf64_Shdr *sh_table; /* Elf symbol table */ + int ret, i, machine; + char *sh_str; + + debug("64bit version\n"); + + /* Make sure we are at start */ + rewind(felf); + + size = fread(&header, 1, sizeof(header), felf); + if (size != sizeof(header)) { + fclose(felf); + return 25; + } + + machine = header.e_machine; + debug("Machine\t%d\n", machine); + + text_base = header.e_entry; + section_header_base = header.e_shoff; + section_header_size = header.e_shentsize * header.e_shnum; + + sh_table = malloc(section_header_size); + if (!sh_table) { + fprintf(stderr, "%s: Cannot allocate space for section header\n", + argv[0]); + fclose(felf); + return 26; + } + + ret = fseek(felf, section_header_base, SEEK_SET); + if (ret) { + fprintf(stderr, "%s: Can't set pointer to section header: %x/%lx\n", + argv[0], ret, section_header_base); + free(sh_table); + fclose(felf); + return 26; + } + + size = fread(sh_table, 1, section_header_size, felf); + if (size != section_header_size) { + fprintf(stderr, "%s: Can't read section header: %lx/%lx\n", + argv[0], size, section_header_size); + free(sh_table); + fclose(felf); + return 27; + } + + sh_size = sh_table[header.e_shstrndx].sh_size; + debug("e_shstrndx\t0x%08x\n", header.e_shstrndx); + debug("sh_size\t\t0x%08lx\n", sh_size); + + sh_str = malloc(sh_size); + if (!sh_str) { + fprintf(stderr, "malloc failed\n"); + free(sh_table); + fclose(felf); + return 28; + } + + /* + * Specifies the byte offset from the beginning of the file + * to the first byte in the section. + */ + sh_offset = sh_table[header.e_shstrndx].sh_offset; + + debug("sh_offset\t0x%08x\n", header.e_shnum); + + ret = fseek(felf, sh_offset, SEEK_SET); + if (ret) { + fprintf(stderr, "Setting up sh_offset failed\n"); + free(sh_str); + free(sh_table); + fclose(felf); + return 29; + } + + size = fread(sh_str, 1, sh_size, felf); + if (size != sh_size) { + fprintf(stderr, "%s: Can't read section: %lx/%lx\n", + argv[0], size, sh_size); + free(sh_str); + free(sh_table); + fclose(felf); + return 30; + } + + for (i = 0; i < header.e_shnum; i++) { + /* fprintf(stderr, "%s\n", sh_str + sh_table[i].sh_name); Debug only */ + if (!strcmp(".rela.dyn", (sh_str + sh_table[i].sh_name))) { + debug("Found section\t\".rela_dyn\"\n"); + debug(" at addr\t0x%08x\n", + (unsigned int)sh_table[i].sh_addr); + debug(" at offset\t0x%08x\n", + (unsigned int)sh_table[i].sh_offset); + debug(" of size\t0x%08x\n", + (unsigned int)sh_table[i].sh_size); + rela_start = sh_table[i].sh_addr; + rela_end = rela_start + sh_table[i].sh_size; + break; + } + } + + /* Clean up */ + free(sh_str); + free(sh_table); + fclose(felf); + + debug("text_base\t0x%08lx\n", text_base); + debug("rela_start\t0x%08lx\n", rela_start); + debug("rela_end\t0x%08lx\n", rela_end); + + if (!rela_start) + return 1; + + return 0; +} + +static int decode_elf(char **argv) { - char *endptr; - *num = strtoull(str, &endptr, 16); - return str[0] && !endptr[0]; + FILE *felf; + size_t size; + unsigned char e_ident[EI_NIDENT]; + + felf = fopen(argv[2], "r+b"); + if (!felf) { + fprintf(stderr, "%s: Cannot open %s: %s\n", + argv[0], argv[5], strerror(errno)); + return 2; + } + + size = fread(e_ident, 1, EI_NIDENT, felf); + if (size != EI_NIDENT) { + fclose(felf); + return 25; + } + + /* Check if this is really ELF file */ + if (e_ident[0] != 0x7f && + e_ident[1] != 'E' && + e_ident[2] != 'L' && + e_ident[3] != 'F') { + fclose(felf); + return 1; + } + + ei_class = e_ident[4]; + debug("EI_CLASS(1=32bit, 2=64bit) %d\n", ei_class); + + if (ei_class == 2) + return decode_elf64(felf, argv); + + return 1; } int main(int argc, char **argv) { FILE *f; - int i, num; + int i, num, ret; uint64_t file_size; - if (argc != 5) { + if (argc != 3) { fprintf(stderr, "Statically apply ELF rela relocations\n"); - fprintf(stderr, "Usage: %s " \ - " \n", argv[0]); - fprintf(stderr, "All numbers in hex.\n"); + fprintf(stderr, "Usage: %s \n", + argv[0]); return 1; } - if (!read_num(argv[2], &text_base) || - !read_num(argv[3], &rela_start) || - !read_num(argv[4], &rela_end)) { - fprintf(stderr, "%s: bad number\n", argv[0]); - return 3; + ret = decode_elf(argv); + if (ret) { + fprintf(stderr, "ELF decoding failed\n"); + return ret; } if (rela_start > rela_end || rela_start < text_base) { From patchwork Thu Jun 2 13:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638362 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=0v7DVpEj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSL24wvGz9sFr for ; Thu, 2 Jun 2022 23:59:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 93C5B84364; Thu, 2 Jun 2022 15:58:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="0v7DVpEj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71BA48433B; Thu, 2 Jun 2022 15:58:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (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 B51A083D9F for ; Thu, 2 Jun 2022 15:57:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x632.google.com with SMTP id u12so10135997eja.8 for ; Thu, 02 Jun 2022 06:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mlGCq7hf7tPw2FKkN/miKRVjj3AA2eU1EPaK8lbIbxY=; b=0v7DVpEjB3oN0tLGFo1y07VDnAnpHeCBaAYe/XxHEmypyoarm9z8tvGDhLhedWQcAZ TK9NmInyh32w1emiaC3nRUhk5obxOb6IriTWR4NU+SGb3mrQXK+ub8YkLk1sFFceHe+v Ffl7vp5MMyt1lPswEvZHEJXXUNM1CXNPC23Q9ctwL+B3r7f/iht3ECN7UCUfFFxiR7tp mQeeJjNcSjEoU43LQPinGBx+/D35w6GLtrfxWIo7XA4evCVI8okorjmPSfuAhvuttG1y +KbxdPcvjjTqAFgdEz0piwNiOWfE84PP8EOG4a9AkvPBOwmTQTEoIqiHgZgnk4Mxed3t jjxQ== 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=mlGCq7hf7tPw2FKkN/miKRVjj3AA2eU1EPaK8lbIbxY=; b=FPp1R7vKwiLTF4ZKpNHbkncyJTBJFTg8/s0S034nMnr75bcknOoHqde+b0celfVHKE neI5hM+lNfb8JG/AMXA5VB+wIbY5nUvDIzwFsnR4Cqxo4Yq4SKFxROQAeP1ub5hVst+z GN2flBQ1bLv6EphiR/6DsfTPKEeel0CoTw+3/gZ9+UxDD62x8on5XXWs6VNmYEBdpiCJ aYawj0Et5Uo7sITo3iHgdMYeNQPpSGGQKjX3zk9SANy6kejqjTXJ5NJVeMgL90lKsE/7 K0bj6U2NZR4ZwU7y5npZNfh7Yv0ax1+g2PuKoU/wyHuXI4JqgEU0LWAez5JmFh+zm3Qa hwpQ== X-Gm-Message-State: AOAM5320IsUohRNnsFxc9AHs3bsaVvge1kfPj6VIqKlzVjFpNdSJslGW HPuUYbSoUse/Z90IcOFDOPem+AfStlFb8g== X-Google-Smtp-Source: ABdhPJyBpB2WuxInhCXem/xJkoDGUzyvq9l6KqDLRd9R6u4evqcEh1yTvJRoy+NfhMna1g+xq4oaqg== X-Received: by 2002:a17:906:d0cf:b0:708:ad9f:8e88 with SMTP id bq15-20020a170906d0cf00b00708ad9f8e88mr4259601ejb.735.1654178278970; Thu, 02 Jun 2022 06:57:58 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id i12-20020a1709064ecc00b00704b196e59bsm1688705ejv.185.2022.06.02.06.57.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:57:58 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 05/22] microblaze: Switch absolute branches to relative Date: Thu, 2 Jun 2022 15:57:29 +0200 Message-Id: <437ea3a92ea050b0f7d1c11b10950496774af5eb.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean There is no reason to use absolute branches and use just relative. This change helps with moving binary to different location and start it from there. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 645f7cb0389d..9e00eef1f4b6 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -29,7 +29,7 @@ _start: /* Call board_init_f_alloc_reserve with the current stack pointer as * parameter. */ add r5, r0, r1 - bralid r15, board_init_f_alloc_reserve + brlid r15, board_init_f_alloc_reserve nop /* board_init_f_alloc_reserve returns a pointer to the allocated area @@ -41,20 +41,20 @@ _start: /* Call board_init_f_init_reserve with the address returned by * board_init_f_alloc_reserve as parameter. */ add r5, r0, r3 - bralid r15, board_init_f_init_reserve + brlid r15, board_init_f_init_reserve nop #if !defined(CONFIG_SPL_BUILD) /* Setup vectors with pre-relocation symbols */ or r5, r0, r0 - bralid r15, __setup_exceptions + brlid r15, __setup_exceptions nop #endif /* Flush cache before enable cache */ addik r5, r0, 0 addik r6, r0, XILINX_DCACHE_BYTE_SIZE - bralid r15, flush_cache + brlid r15, flush_cache nop /* enable instruction and data cache */ @@ -75,14 +75,14 @@ clear_bss: bnei r6, 2b 3: /* jumping to board_init */ #ifdef CONFIG_DEBUG_UART - bralid r15, debug_uart_init + brlid r15, debug_uart_init nop #endif #ifndef CONFIG_SPL_BUILD or r5, r0, r0 /* flags - empty */ - brai board_init_f + bri board_init_f #else - brai board_init_r + bri board_init_r #endif 1: bri 1b @@ -289,7 +289,7 @@ relocate_code: /* Setup vectors with post-relocation symbols */ add r5, r0, r23 /* load gd->reloc_off to r5 */ - bralid r15, __setup_exceptions + brlid r15, __setup_exceptions nop /* Check if GOT exist */ @@ -318,7 +318,7 @@ relocate_code: /* Flush caches to ensure consistency */ addik r5, r0, 0 addik r6, r0, XILINX_DCACHE_BYTE_SIZE - bralid r15, flush_cache + brlid r15, flush_cache nop 2: addi r5, r31, 0 /* gd is initialized in board_r.c */ From patchwork Thu Jun 2 13:57:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638364 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=1NdTYWsD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSLY55S0z9sFr for ; Thu, 2 Jun 2022 23:59:33 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C0D6F84388; Thu, 2 Jun 2022 15:58:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="1NdTYWsD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B53208432E; Thu, 2 Jun 2022 15:58:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (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 0BB738431A for ; Thu, 2 Jun 2022 15:58:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x530.google.com with SMTP id er5so6359993edb.12 for ; Thu, 02 Jun 2022 06:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9mzemrwUb3D2m3sKdmhvPcZbsnHm0xJQQBSDiq0IfiI=; b=1NdTYWsDi8wuZ7+VYGjzamcjqfUfIY6QCiq4XIl4Nxwpc/KSC1R1XaM04i/zX/UTL6 3gLVlfArWqVfwhM2HokD3TW18vKg7U/ihjzXBBFEV4Um/eYjynAT+r4IHxz2eHIU0vJ3 RXY2qxijYLBbZZTO5u8s85jWjBUFs7ztRuKk7kA6KIhFQU3D5W5e46jKzdbFAn6RbSyh U6DXHDt/kXOEOSvmYe00gWpt1otWCEcANt3crbyOwnc64sckydsN+kt5U7Zlq67U7H6o NaDItjtzYrTfGXDVYSwHwp0fasIhwblYZOF8uxw4vFgrifmQR00fSl3FmJJFECi8OUrF hHgA== 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=9mzemrwUb3D2m3sKdmhvPcZbsnHm0xJQQBSDiq0IfiI=; b=CUMJb22zHEbs3RRdciJuseblr9opW/pcrP1sq0y+yXTdoPMnrXLP10QvvHpHUBSUaY 6kl7vEb9Rhjpx7asUOEsMc3YqNF1dXN6rJRnghakTJKUiA2VRHt3dBMLDZyvdCLF5c4a wP9+MVV68X/b1wz0lxv77Q6/GWdpIWybYtBfyA6/5FkcTJ+mucit3rk2knDZWyuuAruh AIgXLisT0P4BbQQgfk67e0gCnBD8QOzZS0V9QCK2/SKmHK5EHjLwWlNYkjPcuAGF0eQJ L5sEN/hPaQq2gnvfTQYLzphvdbFkzsiKgXQWzv+n7wQrRq0xM+slcVByN2xxXGLifH3O WhIw== X-Gm-Message-State: AOAM530TDWwLXSrrYY07DozKSEZLAq3vNsgbz5MHQtqIjc7V+K66/Uil uGCgE9Nqjw0phCYxGwhN0m8MhKSSf/SsjA== X-Google-Smtp-Source: ABdhPJzWc84uTCrlzJMdhp2jpNk/Fpj3hZo5WhyhBLRja7EJMIIW8uvxW1jmFFhjsC7EBaqfkxRA6g== X-Received: by 2002:a05:6402:510a:b0:42b:66c3:d4fd with SMTP id m10-20020a056402510a00b0042b66c3d4fdmr5659726edd.260.1654178280359; Thu, 02 Jun 2022 06:58:00 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id u15-20020a05640207cf00b0042dd60352d1sm2524842edy.35.2022.06.02.06.57.59 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:00 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 06/22] microblaze: Fix stack protection behavior Date: Thu, 2 Jun 2022 15:57:30 +0200 Message-Id: <61da823d3e9db42cd1543644de559dd83e392adb.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean When U-Boot starts stack protection can be already enabled that's why setup the lowest possible SLR value which is address 0. And the highest possible stack in front of U-Boot. That's why you should never load U-Boot to the beginning of DDR. There must be some space reserved. Code is using this location for early malloc space, early global data and stack. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 9e00eef1f4b6..715ef37b39d9 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -15,8 +15,9 @@ _start: mts rmsr, r0 /* disable cache */ - addi r8, r0, _end - mts rslr, r8 + mts rslr, r0 + addi r8, r0, _start + mts rshr, r8 #if defined(CONFIG_SPL_BUILD) addi r1, r0, CONFIG_SPL_STACK_ADDR From patchwork Thu Jun 2 13:57:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638365 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=0i3x3O/s; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSLn3yW9z9sFr for ; Thu, 2 Jun 2022 23:59:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A91008434D; Thu, 2 Jun 2022 15:58:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="0i3x3O/s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C6918431A; Thu, 2 Jun 2022 15:58:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (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 2277384339 for ; Thu, 2 Jun 2022 15:58:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52d.google.com with SMTP id h19so6422973edj.0 for ; Thu, 02 Jun 2022 06:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/ij4EbdIiMMP/rZ8nd+UoxFAca+KGuNH3Ys3+FwuCIM=; b=0i3x3O/sBPegsbJlp2vk5fxbn1pyV/BdbwJWzFL1Gx56I0xcLbn4j4MbaCCNgAQ8o1 7KjbhP8l0Df96cGIT5ETJh+Mz4OFPzadxmbS8pBCwXEtvFUgiLLpdsPIcUfkp3ebdIAz v+UcozAPFqics2PsFsIrZA6iZPC0t74XQZCj9pi+jP80ifRQPsymYiKgrZ9hLczMVbWn mvNawYOzQExr0mpQSpN8Lo/32+TjNh4rL6Cwe0MC2LxL4VI9shS66PHEypKJpP2dITy4 n0vYmaDfSKqbfC/LpTClYH1+EREHVEjJCJgnFbNa4QdR8GlL0L9oO5igwk0LMHEWbrpL eujw== 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=/ij4EbdIiMMP/rZ8nd+UoxFAca+KGuNH3Ys3+FwuCIM=; b=Iy11g83yrP8mNUk7oJxKgL06MOs8GNxIkBvWWItau7++gl3UlgUgW2dwhL4TDHCGFX fHqsuDU4vsZ35onpC3vIkcpNNSKCQo4yY4NHfdWwjE1zYMDUof6nJwfLsZlHJOvnjQHt Q3utS5U9JlX6J2KmLc49jDhNYLyVaXBb/NOaUhNb6ulzHf17A9+r3qMaldY7qRrNhVVz hopN26507N77ovyGwx588xMDYBCgisep4gKuupX6N+vtnJuNVyeJRnRFcIBNGB7PBlXf RY2EaGpmRjtm1TuPB4yP1h578gMmGYMe8qqfkGxY2u9OA8KBMXuKJ+RvVqyO05HZXqxG qVkw== X-Gm-Message-State: AOAM532Xf3OyC0kn1aK6Vewi4bqEhzGrvrIcLIr7RDpUDcxRlQYjtxuF u2odI9p1KVcotjPLgq9dUlu4pj7z7jns9w== X-Google-Smtp-Source: ABdhPJyaYNA2WYS40UR797L8ybBEFFtmpl0hWsqM3Z1qhzC+Nd4OwNmZxsdKCUEcseU+WHd/je2S7Q== X-Received: by 2002:a05:6402:2399:b0:42e:1400:818b with SMTP id j25-20020a056402239900b0042e1400818bmr3080229eda.159.1654178281698; Thu, 02 Jun 2022 06:58:01 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id c22-20020a17090654d600b0070587f81bcfsm1784656ejp.19.2022.06.02.06.58.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:01 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 07/22] microblaze: Fix early stack allocation Date: Thu, 2 Jun 2022 15:57:31 +0200 Message-Id: <44512ba5d77e0658d52b269884630935c89d5729.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean CONFIG_SYS_INIT_SP_OFFSET macro place stack to TEXT_BASE - SYS_MALLOC_F_LEN but there is no reason to do it now because board_init_f_alloc_reserve() returns exact location where stack should be. That's why stack location is calculated at run time and there is no need to hardcode it via macro. This change will help with placing U-Boot to any address. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 2 +- include/configs/microblaze-generic.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 715ef37b39d9..1acac5faf428 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -22,7 +22,7 @@ _start: #if defined(CONFIG_SPL_BUILD) addi r1, r0, CONFIG_SPL_STACK_ADDR #else - addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET + add r1, r0, r8 #endif addi r1, r1, -4 /* Decrement SP to top of memory */ diff --git a/include/configs/microblaze-generic.h b/include/configs/microblaze-generic.h index 663837f33dc4..60ceb2c817e9 100644 --- a/include/configs/microblaze-generic.h +++ b/include/configs/microblaze-generic.h @@ -18,10 +18,6 @@ # define CONFIG_SYS_BAUDRATE_TABLE \ {300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400} -/* Stack location before relocation */ -#define CONFIG_SYS_INIT_SP_OFFSET (CONFIG_SYS_TEXT_BASE - \ - CONFIG_SYS_MALLOC_F_LEN) - #ifdef CONFIG_CFI_FLASH /* ?empty sector */ # define CONFIG_SYS_FLASH_EMPTY_INFO 1 From patchwork Thu Jun 2 13:57:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638367 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=6kiPgBsP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSML3vqGz9sFr for ; Fri, 3 Jun 2022 00:00:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2EE6184346; Thu, 2 Jun 2022 15:59:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="6kiPgBsP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8C7588432C; Thu, 2 Jun 2022 15:58:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 4055B84327 for ; Thu, 2 Jun 2022 15:58:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52c.google.com with SMTP id o10so6383935edi.1 for ; Thu, 02 Jun 2022 06:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NRfPiJUUCvVrseVrkfi+Y3PxK9vTtDcg6KiZKStTpkg=; b=6kiPgBsPRLyTXjfxuUw2B3gMy2D8TJdnhQD+Gw4ept/fywOoJjxGn5U4TNTLTtzwck LBr/+7mJ01ck2XcCgwxjsEArGZXRcts8ujlHBjH3cYhQoA+GCmEslqnUjn+ZBya6Wil5 QPKu3eXP39krQhBOvJNt+S+9FCOgH7lKwQIJF3GeoqaVjj/s7NOXU2EbOpc6M/KasRsY cdLg/yZP9hmi5gcXBgvwxGenmf9MpnO9NDBkpwsngS304A9EHmecRLUZri8P9k3s4l+G et8Hapc++sqrCEPkLb8A962ZdK8+7eUaRTtjnEgCJZv2jqpsQdc4TzhxYrkUlT6h/SNy PD3g== 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=NRfPiJUUCvVrseVrkfi+Y3PxK9vTtDcg6KiZKStTpkg=; b=4mOep/cAbzeQPgVIFopk2VwBelyJKzFwC/nPN20fYDISrePN3DpuDMxvurstPTzMje C0nPKuyoR76DQsx85IphhzWJZdX06+yplRWiJa1U8m0tBMFzZxkrqfkTAt0LhmkIfJuv xD313l6y5e8GF8QDjXBdFB+iltBXxlNiwTHzLIqpUeU2/klZjiS83psHbbD95ZpTsky3 YpCEFklOmIiUo0s8J9IVcWllR5/9EX1OcnWIr1yk7LY8IHDN6oFm9L20KswnrYcRbd+w PiyNOQGGnXx7HtUJgbS9vsR1c6Z9/2hZOTIj+T93LwJDoMZqndCfTRmKqkRNzynV1uwB ky/w== X-Gm-Message-State: AOAM530oc4Bh5LkxjKatP6/xYwhwm72dt39hllr1DwUmy+qyqv2YQ7DC Lm605QxnV8IoOgyuIlkFCW6E+kZlHmRw5g== X-Google-Smtp-Source: ABdhPJztuy9/yeCo7sMifP+twFV/q5/LZmV//pcLIEGNrKpEaSrFJ5IINOYj8RgXP7dxkDcNn6arzQ== X-Received: by 2002:aa7:c55a:0:b0:42a:adfa:9150 with SMTP id s26-20020aa7c55a000000b0042aadfa9150mr5592914edr.57.1654178283282; Thu, 02 Jun 2022 06:58:03 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id w3-20020a1709064a0300b006ff0b457cdasm1791920eju.53.2022.06.02.06.58.02 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:02 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 08/22] microblaze: Remove CONFIG_TEXT_BASE from code Date: Thu, 2 Jun 2022 15:57:32 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Use symbol instead macro to find where U-Boot starts. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 1acac5faf428..205d5f384c38 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -142,7 +142,7 @@ __setup_exceptions: swi r2, r4, 0x0 /* reset address - imm opcode */ swi r3, r4, 0x4 /* reset address - brai opcode */ - addik r6, r0, CONFIG_SYS_TEXT_BASE + addik r6, r0, _start sw r6, r1, r0 lhu r7, r1, r10 rsubi r8, r10, 0x2 @@ -285,7 +285,7 @@ relocate_code: /* R23 points to the base address. */ add r23, r0, r7 /* Move reloc addr to r23 */ - addi r24, r0, CONFIG_SYS_TEXT_BASE /* Get reloc offset */ + addi r24, r0, _start /* Get reloc offset */ rsub r23, r24, r23 /* keep - this is already here gd->reloc_off */ /* Setup vectors with post-relocation symbols */ @@ -323,7 +323,7 @@ relocate_code: nop 2: addi r5, r31, 0 /* gd is initialized in board_r.c */ - addi r6, r0, CONFIG_SYS_TEXT_BASE + addi r6, r0, _start addi r12, r23, board_init_r bra r12 /* Jump to relocated code */ From patchwork Thu Jun 2 13:57:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638366 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=DUOFn4CH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSM10wlSz9sG6 for ; Thu, 2 Jun 2022 23:59:57 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E6D6A84395; Thu, 2 Jun 2022 15:58:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="DUOFn4CH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 29DCC84339; Thu, 2 Jun 2022 15:58:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (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 3A4BB8432F for ; Thu, 2 Jun 2022 15:58:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62d.google.com with SMTP id f9so10241755ejc.0 for ; Thu, 02 Jun 2022 06:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pQoMGxw8mCf/756B4FKkDcQ0GTtv6jzAMHTRJa9B/rs=; b=DUOFn4CHVqF2lqcHFmxczqdveGy8iUAn6LkHJmaxa2Mhy1+9l7Op0h2jbFZIJ14LCu Ee3CyGJiL8WSxCjPdegCQd+hPqzOaDIesgsbO+tn2Xu17a+4Y1RYwnhwuzCh2MwIl7oE 6AqEuXh6fN87QyxVy3afD4woiqSq5uI1RIP/vnitWhko1kA2pylZP4lPaYVBQVI9Z1pJ oL7IySxMZPywGpSwIEoKj47Do5RhTHMXgFroAt14A7coZulHOIpCtqcOIDCybVUkNDDw VeTiTGH0D+c2elkSA/yzibyZhu2JS4Q5GL1Xoe7HHQyjbUk8MoHNyPhw59O2d+ZCtmzm yPRw== 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=pQoMGxw8mCf/756B4FKkDcQ0GTtv6jzAMHTRJa9B/rs=; b=r4T40WKdxg9LlK5R99PKg2SKVQSGv+eDC4HmTQPHW1ssSbX60jp/mBUmllc0KdyVqR hUAJhaCVct9KG+lB+zVCK9m44/4QFO1zQ+hL7aluZvlc0l0jqfD+CGC8++Q9P6vZ+4JO X5jZtF8ZNYvi6PQ4C40ppFmuVqaZzrM8SjWzj7D7k8MComUb3NLLPcTezJcDEvq8US60 wyF7piM0LQS9jE7wripR8TRGvnUjTHw3oYhMyFnALh93jEG3RUnrgrCYku/KWNIpFcgN bymGC/59bVlyBcht1xRREsVWWOVFmWZ6e+mhLVqPbrK3xu2rbyO3Cn+vm9OjJt86xY8b fr/A== X-Gm-Message-State: AOAM531hHodTKAWzEaV3gQy5DEgHQWbsrcGhf6+BFMuBPjksn2kAv9JE oCGxQ8D3WULIoEwrJYSKu4Yi/+W/VElltQ== X-Google-Smtp-Source: ABdhPJwy+6HCpNmLF1eKRfyfNXrJ5fEfJ2uY6hFQwjMIQn6y28EhyBF4d9uG+O+wJpFvOjbq+drH8A== X-Received: by 2002:a17:907:8a17:b0:6ff:160:b9d9 with SMTP id sc23-20020a1709078a1700b006ff0160b9d9mr4283111ejc.726.1654178284629; Thu, 02 Jun 2022 06:58:04 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id y21-20020a056402135500b0042aa5a74598sm2660865edw.52.2022.06.02.06.58.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:04 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 09/22] microblaze: Fix typo in exception.c Date: Thu, 2 Jun 2022 15:57:33 +0200 Message-Id: <6175363ed14ffdd3b56a14534feeb77b8fb46d15.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Trivial fix. Signed-off-by: Michal Simek --- arch/microblaze/cpu/exception.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/microblaze/cpu/exception.c b/arch/microblaze/cpu/exception.c index d3640d3903b8..9414776afa7f 100644 --- a/arch/microblaze/cpu/exception.c +++ b/arch/microblaze/cpu/exception.c @@ -16,7 +16,7 @@ void _hw_exception_handler (void) /* loading address of exception EAR */ MFS(address, rear); - /* loading excetpion state register ESR */ + /* loading exception state register ESR */ MFS(state, resr); printf("Hardware exception at 0x%x address\n", address); R17(address); From patchwork Thu Jun 2 13:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638368 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=MxzXAuwH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSMb0XBVz9sFr for ; Fri, 3 Jun 2022 00:00:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 017FF8439A; Thu, 2 Jun 2022 15:59:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="MxzXAuwH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8C0718432C; Thu, 2 Jun 2022 15:58:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 90ED680179 for ; Thu, 2 Jun 2022 15:58:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x531.google.com with SMTP id fd25so6386120edb.3 for ; Thu, 02 Jun 2022 06:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hWBseo48M6XffmloE6aEmcd6yt1V94Nx3Bt3PsczHfE=; b=MxzXAuwHffpuAS8433f93IUQS3wu72dgaSKQceA0hAgzVTYdG3v4csnxQYwTlPy71P ZmPL0SrbKCRds7mfMTbLFC9O8/yCQCBjbX3QKCCT+vQTVXJ+gPwDK1IqgDHxSXbe1ZNF GOayoiomMPRV2iawt7H1AbHiHZIh7Und2Nmktw0vktopBwRLrBVYJfchpEScES0sb+Z1 tYAcICtnHRypAflDhpudf6KNiZkoO7s2cbgx3DxCGfwaXuK1FjgudxFgMyX5b2yZUmAe bpEsQnLiy2Cw93b3fjo8osvaFh4ryec5Nn3eXcriCE8w40P2gscfTGgWlu57KbeR4SZk NkBw== 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=hWBseo48M6XffmloE6aEmcd6yt1V94Nx3Bt3PsczHfE=; b=JYwNwZ+CJQyxYdYgdZblbv6EYyXHc3nuFcUph0WeOq447kqGxCrxWefu6hxSrJ8Vvj BNpwEWn09tmQFKBwjP+ZQ5YsRvm1cI4cTpDxT9D+nyFGOMgxZaLu4rAcYAN8aMX97Nua ekZJ+DtRHD5qtF+BvwjzDWTKdIZrGwunuIMCdtzzJoEsHy8xqkREZTYSY/KJHWabDUdQ BTrGgSpqxWv4dCGyvCh783W+A3h7PsXSrXBrranJxVNUP7yVs/IBMlnFFU5Reps/gtXK E1ZDu6WaUp17dnRS+MQwMGZhqql6NPbuc2HMEFvXqt21xZ/XwwAYDNcPkve8/lb9Z+e3 mGzA== X-Gm-Message-State: AOAM531Op8XcWUNvki+EEYGZvYyW9QE379GgfHnVMOYm91vUWZFRRhew HsX+r6nlwBeHKSr3YIctl8hOps6fttGKeQ== X-Google-Smtp-Source: ABdhPJz+J1RD0TRSvHlqJVLVg17MtG+XukvQV6lkc8PzrQ86JlBBvOfOdtiBT0kujd2ugwUDA58Lkw== X-Received: by 2002:a05:6402:2548:b0:42d:dd95:5bfe with SMTP id l8-20020a056402254800b0042ddd955bfemr5576299edb.285.1654178286128; Thu, 02 Jun 2022 06:58:06 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id p19-20020a056402155300b0042617ba638esm2510181edx.24.2022.06.02.06.58.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:05 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek Subject: [PATCH 10/22] microblaze: Enable REMAKE_ELF Date: Thu, 2 Jun 2022 15:57:34 +0200 Message-Id: <26af8d7195c86b4535bbabfbb460085580e763b0.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Enable u-boot.elf recreation from u-boot.bin to prepare for removing manul relocation. Enable option for big endian configuration but it is not used too much that's why it is completely untested. By supporting this system there is a need to define LITTLE/BIG endian Kconfig options to pass -EL/-EB flags. Full command line for u-boot.elf recreation looks like this: microblazeel-xilinx-linux-gnu-objcopy -I binary -B microblaze \ -O elf32-microblazeel u-boot.bin u-boot-elf.o Signed-off-by: Michal Simek --- There are two Kconfig warnings and don't know how to fix it now. arch/mips/Kconfig:192:warning: choice value used outside its choice group arch/mips/Kconfig:196:warning: choice value used outside its choice group --- arch/microblaze/Kconfig | 16 ++++++++++++++++ arch/microblaze/config.mk | 6 ++++++ configs/microblaze-generic_defconfig | 1 + 3 files changed, 23 insertions(+) diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig index d7d1b219704e..f1fc46e774e5 100644 --- a/arch/microblaze/Kconfig +++ b/arch/microblaze/Kconfig @@ -4,6 +4,22 @@ menu "MicroBlaze architecture" config SYS_ARCH default "microblaze" +# Endianness selection +choice + prompt "Endianness selection" + default SYS_LITTLE_ENDIAN + help + Microblaze architectures can be configured for either little or + big endian formats. Be sure to select the appropriate mode. + +config SYS_BIG_ENDIAN + bool "Big endian" + +config SYS_LITTLE_ENDIAN + bool "Little endian" + +endchoice + choice prompt "Target select" optional diff --git a/arch/microblaze/config.mk b/arch/microblaze/config.mk index de5b97e719cc..3e84a832fc12 100644 --- a/arch/microblaze/config.mk +++ b/arch/microblaze/config.mk @@ -16,3 +16,9 @@ LDFLAGS_FINAL += --gc-sections ifeq ($(CONFIG_SPL_BUILD),) PLATFORM_CPPFLAGS += -fPIC endif + +ifeq ($(CONFIG_SYS_LITTLE_ENDIAN),y) +PLATFORM_ELFFLAGS += -B microblaze $(OBJCOPYFLAGS) -O elf32-microblazeel +else +PLATFORM_ELFFLAGS += -B microblaze $(OBJCOPYFLAGS) -O elf32-microblaze +endif diff --git a/configs/microblaze-generic_defconfig b/configs/microblaze-generic_defconfig index c0f5d4c9a1cf..c2d25ea460b2 100644 --- a/configs/microblaze-generic_defconfig +++ b/configs/microblaze-generic_defconfig @@ -18,6 +18,7 @@ CONFIG_XILINX_MICROBLAZE0_USE_DIV=1 CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL=2 CONFIG_DEBUG_UART=y CONFIG_DISTRO_DEFAULTS=y +CONFIG_REMAKE_ELF=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_BOOTDELAY=-1 From patchwork Thu Jun 2 13:57:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638371 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=C7qK4c5Q; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSNH2r4nz9sFr for ; Fri, 3 Jun 2022 00:01:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 44EB184394; Thu, 2 Jun 2022 15:59:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="C7qK4c5Q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DE2E8434E; Thu, 2 Jun 2022 15:58:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (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 0110884330 for ; Thu, 2 Jun 2022 15:58:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62e.google.com with SMTP id m20so10110598ejj.10 for ; Thu, 02 Jun 2022 06:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1CMrFwxekvxqr0XXhdrNCjIJsaNIsUx5iF1FOpDo3LI=; b=C7qK4c5QOKyTv+u1e60BaffK4F9/ZVAqmok+9+GQDm3FTaXIBt0EwZ9z79W4xcwj3i iOZAU7iqigwzJh1bh4n05G03cMfniDRCuFJwaF4vrhCuehUd+o8sHwyIlOVv5p0lpceD c1aL3EBr26FqI2wJWJQXHSQw1EmHgwFyOeOPwMYLOMwu22zrLsqjfR6HJWffYPFsviyz DIuMDEwHZWsPvRKHRypCFkDm/L/axwhCl8PQuaLHyb6XluMVrDj6AdKmdUSjK0d8PtKJ anKPgimVWLrAlWuAK5QauRy7m+zfnbajMN7dcaWJDnRj+jDAfGfvNWjx4/dtPKkb1oOR JoPQ== 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=1CMrFwxekvxqr0XXhdrNCjIJsaNIsUx5iF1FOpDo3LI=; b=hSk7Pgd2h23hx9S0VqR0ROGwLidTeYD6DFu2cDZbhcIuP0VCQs7GtHK+t+4OZyP8x7 vx83qJZICB05byut7NaGlK6rxabSNffp5h6ekoW3kZu9drjfAEDpnexlDpVwx4fcCLWS bsGBMPQcxJM9uzL/tNaVC6wLnoY+ynxGsFYprwNAk9C4KZeSEVQn89M9zqAlucPgGX4F fGloILSvjgfW9Ijl0NeyF7jgr984BiiaZRYZb1YMImGGRnVTRuhMyeC/TQQHnsSIhBhT fMhdVfKdR+2qtdFIDQcr5xutZciaTi0m0cAIlh4oJ2PDiqMjlQREIMFLWOxeFzNA4CV0 IWLg== X-Gm-Message-State: AOAM531J0pGnJdlbNxm6D9lGYFcsL/wzg2nLXrpDCvT/4+gG4SS02JC3 xsd+tk60gqmcUnd1QyWqE7KlyY9865vizQ== X-Google-Smtp-Source: ABdhPJyhpBomtNJ35is23o0TOKPmn2qIDP3pA5wqWZICuTNcH2PvpMWRNveBJ32RRuX7kAQN6vlnFQ== X-Received: by 2002:a17:907:c21:b0:70b:735f:55aa with SMTP id ga33-20020a1709070c2100b0070b735f55aamr2222571ejc.332.1654178287515; Thu, 02 Jun 2022 06:58:07 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id f24-20020a05640214d800b0042617ba63basm2516134edx.68.2022.06.02.06.58.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:07 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 11/22] microblaze: Separate code end substraction Date: Thu, 2 Jun 2022 15:57:35 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Follow up patch will convert symbol handling that's why it is necessary to separate logic around symbols to special instruction. It adds 4B for new instruction but it is worth to do it to have code ready for for full relocation. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 205d5f384c38..a35d8d8ea29a 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -273,7 +273,8 @@ relocate_code: add r23, r0, r7 /* Move reloc addr to r23 */ /* Relocate text and data - r12 temp value */ addi r21, r0, _start - addi r22, r0, _end - 4 /* Include BSS too */ + addi r22, r0, _end /* Include BSS too */ + addi r22, r22, -4 rsub r6, r21, r22 or r5, r0, r0 From patchwork Thu Jun 2 13:57:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638372 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=W+VE0ICl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSNW28x7z9sFr for ; Fri, 3 Jun 2022 00:01:15 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 897AB843AE; Thu, 2 Jun 2022 15:59:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="W+VE0ICl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 559EA8431A; Thu, 2 Jun 2022 15:58:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 A8F848433D for ; Thu, 2 Jun 2022 15:58:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62a.google.com with SMTP id q21so10173602ejm.1 for ; Thu, 02 Jun 2022 06:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LIoIN/wUCqrWFBS9/on+wZBnyPVYYSHQmojo1b15Br8=; b=W+VE0IClHD08z3DU4mM1FcMCidY4AlCiIRqPlYIjydaDUbwcn4P54NP/DMDmNPNZRU QzpEFwUFkwDkwprWatWmplCDnsoulKIXFcOaa02mOVFBD9aI9h8/rugiqkRvNs7+774x 665azxLt+zkyrMw1beKaobBwtQPexuo5wRICYNjOSa0dGaQDKR/oJ+DMz6AG1woOKqAD Aly5Paud8ahzs/KP9FkZLDWN+ayVFkxb9MsJ82LOme4IFqOYE6FyB1EIGWZ/kBhV6D2n HC6XXtAJjh6Yj27N3ugj1jHsQYVX0o4Xm3qgivqrH7afsGR7Ta1IUHqmjvrm0gU5AdwL PhTg== 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=LIoIN/wUCqrWFBS9/on+wZBnyPVYYSHQmojo1b15Br8=; b=Xm06D0dy9EthDLDV4V919tam7hCNuDQJDFnU3HnRMWfeCw5lrlSweJrV2uzFtOYa1P UT+UXfs3gG/Vqtv/J0XUFVcO1FojrE7LYm+y6zMbbxqz0A9nWnqHnBsIH6QSCl7xs/p9 nB9ylMz7w8dC38MJcJzxm1ifiF1CSACs8v8NIhkbu7Vcr1cJ7MAZrNP+mGvIwaTTCtMy EfQ5NfUGPK9DOervgxK8Dx5H9aNNnu8zJbXh57hKGQS+XxW2r+6UlCmG1sfLrGI3tpvY nL6EiUUG+n/veYazW4fNyG3dymTzlbaeeKofwDTmhFpGdf8j9ju9eJYoH91BdK76PO32 r6MQ== X-Gm-Message-State: AOAM530Gfv45R7kippt6m3QoB/PDrChTH25kt5xJce7sqCi5sQRZe70r Nt0YFndvttDS8hZ/rhv7QcjKWvkFhLTnOw== X-Google-Smtp-Source: ABdhPJwX/aMkNX5IhSPpkVnCQ5GhZUsm1ta0ydhAJyFlmBxUMksXOHKZkZaUHt6nEBYFUl98RwK8ag== X-Received: by 2002:a17:906:358a:b0:6f4:2903:417e with SMTP id o10-20020a170906358a00b006f42903417emr4487746ejb.592.1654178289053; Thu, 02 Jun 2022 06:58:09 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id mj4-20020a170906af8400b006ff0fe78cb7sm1788995ejb.133.2022.06.02.06.58.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:08 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 12/22] microblaze: Change stack protection address to new stack address Date: Thu, 2 Jun 2022 15:57:36 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean SLR low address is still setup to 0 that's why only high limit should be updated. STACK_SIZE macro is present and could be possible used for low address alignment but it is not done by this patch. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index a35d8d8ea29a..2aae4a0b7ccb 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -268,6 +268,7 @@ relocate_code: * r7 - reloc_addr */ addi r1, r5, 0 /* Start to use new SP */ + mts rshr, r1 addi r31, r6, 0 /* Start to use new GD */ add r23, r0, r7 /* Move reloc addr to r23 */ From patchwork Thu Jun 2 13:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638370 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=Gkuq0Dzf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSN30PPHz9sG6 for ; Fri, 3 Jun 2022 00:00:50 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C0DD84392; Thu, 2 Jun 2022 15:59:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="Gkuq0Dzf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6F18F84361; Thu, 2 Jun 2022 15:58:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) (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 1D42F84342 for ; Thu, 2 Jun 2022 15:58:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52d.google.com with SMTP id h19so6422973edj.0 for ; Thu, 02 Jun 2022 06:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9PbwXYDJMBOd2QiPr42OPhM8f73ett4xRLVzy30MHbA=; b=Gkuq0DzfHF/v/G+ujVzHOtU/YnjA4mz9AwM/swO/9xO6U1/RmnWheqlM6F2GKQ8JJ6 jLcVkw8ci6tGFhZtp18n3FlsWpLDFIMnhdeHNuDZ4BtaS38iNEbN2t4OtVVPV0rD0p4l 6+HJzo418OhxxKQrc0cu5eUagNyCNqAvEaFVT9nFtRTG86Zk0cAODbOISGwwUBc0iT9I Daoovs8W3r8vY5mMIZ5X2tDiuFA8i6cwU/Bvgh9E3JZVrxP8EfjF8CTy5Ogk6YPCOtLN zwdq6rNX6OU+4qGaL7YaEnpjenSneTTjVW4rnNy4g4DqYSvzsyPD36f7WNHRCyYg24l6 385A== 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=9PbwXYDJMBOd2QiPr42OPhM8f73ett4xRLVzy30MHbA=; b=6gfyra2MKER9lmQvO80fBBLNYo5DhinD6gddtH++2jpQ8N0uTZ0WG23DWaOjUi8zLH VBgbqbWzw8guhb8/zVkuweb8YLq5vwfLEdHvBMqrIbkR1bd/whapXygqhIp1jOZxAvH2 DOzp6Pefh41WZoVx6VXWdoZgb5AM6qYu2KHRaxrfhUbxveZvi4ulOzrGEgdnZV4Q8WP5 wbSMMNcRSuVkwK+Wml2qAqKNAhQ004QX7CMsmRLcWdd0JHLi6ocCRxjKPdlSWq3Q4M6R JjgYVYSmuZ+/xqY0Exthz7OZGRQxoGz4wezwGcBxwucMQhMbMQYzxLa12bomz5tM0hMX lpnQ== X-Gm-Message-State: AOAM5337vmt0x0xAbfdq6iZDIDtcveRsXxgHZDrrytMQZw3+xKe2IVOs t2dCptcLg876gPwrkZwAvWSPut90ikrZlw== X-Google-Smtp-Source: ABdhPJxP2bet03hHDnSyQCT07YW/4tCToz7/pBAsyM8PMWvSxBTQtDr+uaP5PbFfJ034d4b3Kz6zuA== X-Received: by 2002:a50:ed12:0:b0:42d:d1d3:493c with SMTP id j18-20020a50ed12000000b0042dd1d3493cmr5520937eds.174.1654178290646; Thu, 02 Jun 2022 06:58:10 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id j3-20020a170906050300b006fed99e1143sm1738888eja.61.2022.06.02.06.58.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:10 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 13/22] microblaze: Optimize register usage in relocate_code Date: Thu, 2 Jun 2022 15:57:37 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean There are additional operations which can be done simpler that's why improve logic around relocation address r7 handling and _start symbol. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 2aae4a0b7ccb..f2d6d12deb73 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -271,7 +271,6 @@ relocate_code: mts rshr, r1 addi r31, r6, 0 /* Start to use new GD */ - add r23, r0, r7 /* Move reloc addr to r23 */ /* Relocate text and data - r12 temp value */ addi r21, r0, _start addi r22, r0, _end /* Include BSS too */ @@ -280,15 +279,13 @@ relocate_code: rsub r6, r21, r22 or r5, r0, r0 1: lw r12, r21, r5 /* Load u-boot data */ - sw r12, r23, r5 /* Write zero to loc */ + sw r12, r7, r5 /* Write zero to loc */ cmp r12, r5, r6 /* Check if we have reach the end */ bneid r12, 1b addi r5, r5, 4 /* Increment to next loc - relocate code */ /* R23 points to the base address. */ - add r23, r0, r7 /* Move reloc addr to r23 */ - addi r24, r0, _start /* Get reloc offset */ - rsub r23, r24, r23 /* keep - this is already here gd->reloc_off */ + rsub r23, r21, r7 /* keep - this is already here gd->reloc_off */ /* Setup vectors with post-relocation symbols */ add r5, r0, r23 /* load gd->reloc_off to r5 */ From patchwork Thu Jun 2 13:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638369 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=Am96ikHM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSMq1BNhz9sFr for ; Fri, 3 Jun 2022 00:00:39 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D24308436C; Thu, 2 Jun 2022 15:59:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="Am96ikHM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1BECA8432E; Thu, 2 Jun 2022 15:58:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (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 75F2B8431A for ; Thu, 2 Jun 2022 15:58:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x632.google.com with SMTP id u12so10135997eja.8 for ; Thu, 02 Jun 2022 06:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ekn6bzUOrrASA4815ar06i7A48daoiM5aPsV8bkJEHo=; b=Am96ikHMH0poXYWWHUcjPjZOcWaF47pki47M5AoJl2N9Hn2f/J+QAr8eh4JuSVZ6zl wwixfVrPTI2UGk2aLtbmOsWEbxpUpzoWz6t/mIgs/w338wX1Fhgs+R/jm8aWi/oaakdw tydrnF4NderKDuPgCyoD0ksWE1VH2d8W13Gt96pzL3V4+2N5Syh31Jka6yYPkhp6R2WP mO40R2gY2g6qw6pqOAyqH1EuFOKWt9Yd/2tFQmZRJ452j9kxwS3BX8ZAYQ7G00LV346H 6ZSS4ugVbpArvFSMF3qRGHtM2+M4bWQTVboGHrNPKWZB487dDAPPp5Jsi4zONYbGx9U8 z+Kg== 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=ekn6bzUOrrASA4815ar06i7A48daoiM5aPsV8bkJEHo=; b=Brh4Jvbhw+l41TbqV8p39u+FtF43lMYgBb9/bWx2DyLs+oWMTkLzHcReg5OyrS0gir jhh03QRJrSbK3DunuqbwAHxnOK9hHRwyyncpoEgtg2zvBE4V5OiwU2bBj+oXtzcIFWYo ty2l+dIX2bVTZnDnZYpbPO2HzHKaon6vGf6lvTjmTvGDemygUpSoWA42fy40Atj7so8G OrA6lAsH603q7XzbDX1ZGf7q3gXYKqQErqbShDh1pooFBqBT30ypXg7MB1z8uef9ofwp tzXRORu0oscPErnelBzCYkHJ4J2uVwothJKRIU88vrzJUeoxaRc6x+Uh2ZCnN88yqpY7 Cxiw== X-Gm-Message-State: AOAM533v+Ls49DR1AVqy16Chrpw36OASCAlG/wuUofN2FcbPWkHcUkQx vJ92KF7eLlsGYNliKX3ItOSycK5koLGypg== X-Google-Smtp-Source: ABdhPJzWROuQFDqkwe1trgs28mZJUJElgPyUXc+xkLkhiY/Gba39CRIBck0rVfktEJmINtYn7R/DiQ== X-Received: by 2002:a17:907:3e14:b0:6fe:8d7e:26fe with SMTP id hp20-20020a1709073e1400b006fe8d7e26femr4414381ejc.499.1654178291998; Thu, 02 Jun 2022 06:58:11 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id y22-20020aa7ca16000000b0042dcbc3f302sm2495406eds.36.2022.06.02.06.58.11 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:11 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 14/22] microblaze: Remove code around r20 in relocate_code() Date: Thu, 2 Jun 2022 15:57:38 +0200 Message-Id: <8282fb144c65035913009d7991bb2a4c56f3a5ca.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean r20 is not used that's why remove logic around it. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index f2d6d12deb73..c3d925c1d151 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -310,11 +310,6 @@ relocate_code: bneid r12, 3b addik r21. r21, 4 - /* Update pointer to GOT */ - mfs r20, rpc - addik r20, r20, _GLOBAL_OFFSET_TABLE_ + 8 - addk r20, r20, r23 - /* Flush caches to ensure consistency */ addik r5, r0, 0 addik r6, r0, XILINX_DCACHE_BYTE_SIZE From patchwork Thu Jun 2 13:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638374 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=tmCwTYMj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSP11PdXz9sFr for ; Fri, 3 Jun 2022 00:01:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 863AE843C5; Thu, 2 Jun 2022 15:59:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="tmCwTYMj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 51FEF8437D; Thu, 2 Jun 2022 15:58:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) (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 97F5E84358 for ; Thu, 2 Jun 2022 15:58:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52a.google.com with SMTP id v25so6382629eda.6 for ; Thu, 02 Jun 2022 06:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YYBOhOsCSjmCZt4nP/Ucdnddaiz4xwaM4v7W33vHrB4=; b=tmCwTYMjBMr5pc8An3WRCr05sPZ34aLk0cmYvV5iEV2pVn2mQYNn1SJtcluLScjWHp z+TPjAW2Un59YrdfPCnPWPUM6YGY3OwyRSnqe89Xy2poJdYCt0VAL1Y1wYzjUBwI+kdC JUqWyEd7IPFgc5yqLbImXSwcH4VN63UhZkMqwn6iso/mTbISI885EqL0WpJ8B2jhFFbm b1ircg1c6xcaW9sxp/ZqldldSoWHsB8Emt4V8wRSSPL15bKTPTROo5xhuTv6KnxiPf5X GWSpyOxzhfBP/KnaAJyRXP1wkOPgsZuqqB/PazOx+SbVabug8+PD0iaESG+tIK5tA9dy Fbhw== 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=YYBOhOsCSjmCZt4nP/Ucdnddaiz4xwaM4v7W33vHrB4=; b=0+cmXpB1iVEIZsBQ3T6P8G/hzwkvtz+izNyce4CqcgnwG49tf1FY3/ixA447OpYavk Hv29FbWehy1RfNFMqG6GBCZJkMTKsWX3j622DomuulaJHDIst3hDcgOd1PDcPljkuyWv jWX8y5fEEg45nYPjCYJnG2g5rwKzyO+jN7PGBpfANLVyRMHBogQ9Uatc+qY+T/l9JZUC /SBwKTiArI5+UtlF2igFZx658B8B3jveX3aHTwpE5Ekd6Z5eRWAkLFF4fEBLZrQ7q3iA IrapZx3mAAjczx9gz5n39HRKDyXqiFJX5a3Ofk5KGetEPA9cPxPo34n0kzwSoB+VfHHg PvLQ== X-Gm-Message-State: AOAM530WwOGhKUUQZkOI7vXKNrMBlnnTDiBEDnPZYnwJ3XStmrjsDjzo DNsaW86yM6ekxjQKrasRpFiZOv+IPywDpg== X-Google-Smtp-Source: ABdhPJwoZ9HciEIICrsU2qb9oCgswcmck4FukwUKaUoCPwOOjMB8BOPSiIhEzeRVITw5Bq9fRGmVrA== X-Received: by 2002:a05:6402:1914:b0:42b:73ae:e082 with SMTP id e20-20020a056402191400b0042b73aee082mr5644346edz.31.1654178293439; Thu, 02 Jun 2022 06:58:13 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id i23-20020a1709061e5700b00708a2ae7620sm1398593ejj.67.2022.06.02.06.58.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:13 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 15/22] microblaze: Remove _start symbol handling at U-Boot start Date: Thu, 2 Jun 2022 15:57:39 +0200 Message-Id: <1cf6cc4d5289a4c068b22ddeaf6e5550776342df.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Right now U-Boot runs all the time from the same address where it is loaded but going to full relocation code starting address doesn't need to be fixed and can be simply discovered from reading PC register. That's why use r20 to get PC address and subtract offset from the beginning to get starting address. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index c3d925c1d151..db3998f54505 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -14,15 +14,16 @@ .global _start _start: mts rmsr, r0 /* disable cache */ + mfs r20, rpc + addi r20, r20, -4 mts rslr, r0 - addi r8, r0, _start - mts rshr, r8 + mts rshr, r20 #if defined(CONFIG_SPL_BUILD) addi r1, r0, CONFIG_SPL_STACK_ADDR #else - add r1, r0, r8 + add r1, r0, r20 #endif addi r1, r1, -4 /* Decrement SP to top of memory */ From patchwork Thu Jun 2 13:57:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638373 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=WGqi4nW1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSNl5fsMz9sFr for ; Fri, 3 Jun 2022 00:01:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F09A18439F; Thu, 2 Jun 2022 15:59:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="WGqi4nW1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B92258431A; Thu, 2 Jun 2022 15:58:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 53E9784346 for ; Thu, 2 Jun 2022 15:58:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ej1-x62f.google.com with SMTP id f21so10111025ejh.11 for ; Thu, 02 Jun 2022 06:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wVqpGodXBClsDdPkK1TN8qlczFFfaOzHCvDxY0vyQeI=; b=WGqi4nW1lSUanHBL3o3WSwNK4xzHt0HatT+t65cixQSD0W9IXAKNqXU7hta28WKsTs hLHouxF93F0IP/FTaGHNnu7UWOelzc2j4od+ZuesPyNLSUtcgiG+zOnTqWRp7uqMfl92 I6gO8LKGEyw4U26bEfACSQKLspEJIER1vvJGFFD41+vGj5OZVIPITqurk1AXmGRcA+KT /heBgiTuVbl1L6+9sMSACz0BqKT2zjYeq15MN2DTu6zoUyiZpyC5X4cEpUdY5vQCHDPV B96gPg9YbuRG1comwnhTIBqAOxW8YFu2aTQvIO1wQsHe4MOAIjYRASj5aNd9/ahT9FuF HmRg== 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=wVqpGodXBClsDdPkK1TN8qlczFFfaOzHCvDxY0vyQeI=; b=PDvLkk57PNiIspKYQ2jH0v/GWNuPaZ2jNEN5ry7dx7aRNYSiLXeDuBz3en2n9U+RPw BK8bBxrLvh1M4BugDfes5Ze0TdYPNGIAAa4CMKU27bRlq3EMNnYUOemBySXzZS3PbLyD 225gQLvxd/yyJIsdC0vx5pzV1yT/gwMckPd2GffYgnlrL8q1pQxya65AESd2TzXpReVx OG97gavhZAa/UqL54Kxb3oqEXhkOhI3P6qMzD1lpRPLQveeEXCxIkEgv0fEel7YdewRL XQzE4u7b+7Yw+5HH+AA2nXUAW7+cWGeQt/DbvNMNFFEmpaSb6dZqm08yqDqV4kjTKFkI H1Yw== X-Gm-Message-State: AOAM5316BcNRsL/pFgsPlzKTCV5c0P0nN2/+nzCp0HC4B2axHbueVH73 Wqk5pwPf3wIAp6rX/+GFOEBcUcq5gJe2Qw== X-Google-Smtp-Source: ABdhPJxNnRxGGfqWOacWYacK5UYNdH+4gc1GdHuCYIf/QRAs7wNQaeIzcjQ2IZ4A+8ZOsno501NNlA== X-Received: by 2002:a17:906:54c3:b0:6ef:d07b:c8ec with SMTP id c3-20020a17090654c300b006efd07bc8ecmr4366188ejp.687.1654178294870; Thu, 02 Jun 2022 06:58:14 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id w7-20020a056402070700b0042aa153e73esm2496882edx.12.2022.06.02.06.58.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:14 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 16/22] microblaze: Add comment about reset location Date: Thu, 2 Jun 2022 15:57:40 +0200 Message-Id: <680597d51955bcede82c5e0ecdf9d04a4bf1054d.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Better to add comment to explain why reset vector points all the time to origin U-Boot location. If reset happens U-Boot should start from it's origin location. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index db3998f54505..9aa5fd099361 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -144,6 +144,7 @@ __setup_exceptions: swi r3, r4, 0x4 /* reset address - brai opcode */ addik r6, r0, _start + /* Intentionally keep reset vector back to origin u-boot location */ sw r6, r1, r0 lhu r7, r1, r10 rsubi r8, r10, 0x2 From patchwork Thu Jun 2 13:57:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638376 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=zKrKCf8g; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSPS74T2z9sFr for ; Fri, 3 Jun 2022 00:02:04 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EAA94843BC; Thu, 2 Jun 2022 16:00:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="zKrKCf8g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA16E8431A; Thu, 2 Jun 2022 15:58:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 4533A84362 for ; Thu, 2 Jun 2022 15:58:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52c.google.com with SMTP id w27so6370617edl.7 for ; Thu, 02 Jun 2022 06:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vjgVi2nKY2+YVfnIpK6M97bJp2I4DQ5WnG/8Gj26pfk=; b=zKrKCf8gXTOuaifUiI4cspdvOK24jylsnCkK5VFD/rawT60zbhjxRSAISOHklMlS8B /rXce9yMD+eq3ISJBLLcOuoSNWcagGaFStZTyjjZcT44yPZSTyuxP88YLq71zxapRYaL iUbxb9p9N01JJBKcf2LM3+kHSHy+uqsPxUWlFJGi9rhK0w5RzyRoGnRRQ92ANFk7Mb2l YKE72gETmhgzuTayhqpluzi6+mKLFTW2AfyMEfq9Sli7pieUkc7mhaPNHgvJ/xvXF3Iy E2W/dVZnBnKXiXaNFRg1IC/r6AyFBiIy+RhSpaqWkoRl0DMX6588Zd7hNeQYBnDZ6zQc taqg== 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=vjgVi2nKY2+YVfnIpK6M97bJp2I4DQ5WnG/8Gj26pfk=; b=SLMVmVn36IC8rmIISk/n7/1aIgzkZcQJqpUqnWbcwECtW8sG6/PzqGa/Z8mtpOcJ4m m7fAHuwWyQ8mZSgUXUYskPp9qmhgha0G5YDRrPLZLV7UUZgeHKad6Ve4pzC77NS1dgPx K3+YMIjZqK2FZRWwogbAdlhAjJM0UhULu2D8KE6Pbr2YrFCMGlfLYoVkg8Hpne4qqfU6 jeUy4zQEs9PGwMs1E4m9dMSFw2fe3Y9qjFpX5koKYoNr/jm+jHOFKJGBfKCs6psHLya3 SMQf/R9nD6tuR6/QOnaN/5/NvL4KGue7Ka5L2yYnm9k2qe5V9lcZhTpNYQ6B+KE/9FBI 177g== X-Gm-Message-State: AOAM5303DZWW7w/K83AyU22pUSibRboSz11UafLbINtu8SYp9OR6xFDE Xt/wwDL3PqUazS5bW6OsWbPrvAV0s2AwEA== X-Google-Smtp-Source: ABdhPJyDhT9jTZVN3JG/K+ObFSZ5VMlZiAEd1kMSd7FtHxP7gAheH7nx5SLcIR7rOeOilV9QcPhbug== X-Received: by 2002:a05:6402:1393:b0:42a:c36d:67a6 with SMTP id b19-20020a056402139300b0042ac36d67a6mr5757733edv.158.1654178296263; Thu, 02 Jun 2022 06:58:16 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id b17-20020a50e791000000b0042ac2705444sm2576793edn.58.2022.06.02.06.58.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:16 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Michal Simek , Ovidiu Panait Subject: [PATCH 17/22] microblaze: Create SYM_ADDR macro to deal with symbols Date: Thu, 2 Jun 2022 15:57:41 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Symbol handling depends on compilation flags. Right now manual relocation is used that's why symbols can be referenced just by name and there is no need to find them out. But when position independent code (PIC) is used symbols need to be described differently. That's why having one macro change is easier than changing the whole code. Signed-off-by: Michal Simek --- arch/microblaze/cpu/start.S | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 9aa5fd099361..72b0f3354731 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -10,6 +10,9 @@ #include #include +#define SYM_ADDR(reg, reg_add, symbol) \ + addi reg, reg_add, symbol + .text .global _start _start: @@ -66,8 +69,8 @@ _start: clear_bss: /* clear BSS segments */ - addi r5, r0, __bss_start - addi r4, r0, __bss_end + SYM_ADDR(r5, r0, __bss_start) + SYM_ADDR(r4, r0, __bss_end) cmp r6, r5, r4 beqi r6, 3f 2: @@ -143,7 +146,7 @@ __setup_exceptions: swi r2, r4, 0x0 /* reset address - imm opcode */ swi r3, r4, 0x4 /* reset address - brai opcode */ - addik r6, r0, _start + SYM_ADDR(r6, r0, _start) /* Intentionally keep reset vector back to origin u-boot location */ sw r6, r1, r0 lhu r7, r1, r10 @@ -157,7 +160,7 @@ __setup_exceptions: swi r2, r4, 0x8 /* user vector exception - imm opcode */ swi r3, r4, 0xC /* user vector exception - brai opcode */ - addik r6, r5, _exception_handler + SYM_ADDR(r6, r5, _exception_handler) sw r6, r1, r0 /* * BIG ENDIAN memory map for user exception @@ -190,7 +193,7 @@ __setup_exceptions: swi r2, r4, 0x10 /* interrupt - imm opcode */ swi r3, r4, 0x14 /* interrupt - brai opcode */ - addik r6, r5, _interrupt_handler + SYM_ADDR(r6, r5, _interrupt_handler) sw r6, r1, r0 lhu r7, r1, r10 rsubi r8, r10, 0x12 @@ -202,7 +205,7 @@ __setup_exceptions: swi r2, r4, 0x20 /* hardware exception - imm opcode */ swi r3, r4, 0x24 /* hardware exception - brai opcode */ - addik r6, r5, _hw_exception_handler + SYM_ADDR(r6, r5, _hw_exception_handler) sw r6, r1, r0 lhu r7, r1, r10 rsubi r8, r10, 0x22 @@ -274,8 +277,8 @@ relocate_code: addi r31, r6, 0 /* Start to use new GD */ /* Relocate text and data - r12 temp value */ - addi r21, r0, _start - addi r22, r0, _end /* Include BSS too */ + SYM_ADDR(r21, r0, _start) + SYM_ADDR(r22, r0, _end) /* Include BSS too */ addi r22, r22, -4 rsub r6, r21, r22 @@ -319,8 +322,8 @@ relocate_code: nop 2: addi r5, r31, 0 /* gd is initialized in board_r.c */ - addi r6, r0, _start - addi r12, r23, board_init_r + SYM_ADDR(r6, r0, _start) + SYM_ADDR(r12, r23, board_init_r) bra r12 /* Jump to relocated code */ .end relocate_code From patchwork Thu Jun 2 13:57:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638375 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=cjtYkdnX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSPF4ZsRz9sFr for ; Fri, 3 Jun 2022 00:01:53 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A540D84368; Thu, 2 Jun 2022 15:59:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="cjtYkdnX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C8A558431A; Thu, 2 Jun 2022 15:58:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (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 81FE28432C for ; Thu, 2 Jun 2022 15:58:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x530.google.com with SMTP id v19so6384550edd.4 for ; Thu, 02 Jun 2022 06:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=70D3oSUKj2qKckyQP2yxqxvZvrAOmcmd51x5zIpD+Ms=; b=cjtYkdnXkNprzprguMZ2ZgDul1jx8X3q8Xx9hhYCJSVhEaIbwymYbAsYIGGrcI64WU OE0a99Y5XAfXDRlybqXQDra6AKyhXK7JsXXbMernW4rpGw9MCl7CTxHpdybuAjSsPziz vDUqu7h5kvaeAa01tRXXfhJu8msDI93xirlpKsY8d9vVSKlTE8bD9VrDgxp58DoKI9o0 WvF8b4hJjPnIde+WJMCIWB4f2JHkM52ORYd2e1+McY5hbBDUdORkcCzJdP7SmqlilZWC 2AkSpxauF6RQoQRwgNc7wb2JJ/NbTikHPJF/gVHdTyyigrlKY3djUm4QTCYy6UD34F29 sB2Q== 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=70D3oSUKj2qKckyQP2yxqxvZvrAOmcmd51x5zIpD+Ms=; b=s5stk+SK6Pm0+pmCfPVxcPH/a4eNbPgQIyeZ/cFc8jiCzHGmppM7tCQbJ4ko4w5Qxc r7QQaqn+TBHHOstW5OB88MnJ9HNm+4J/uzNXiT4ePf869XGVf3OA6tebyu2Ag1/kBFfy rtgd4fGpt8ZFzAj6JhW+SqGA//dhGJGSJLvB+oLAa5ADt8CYR4CIuGYMywfo4TTq/r1/ 6u8wReSK+a0ecmdpMGF1q21y7ZxiEbg1Kvqny8U4DDuoBsPVWEIQNpAPOYqRYCvVSB+j XPIIyS8UM+ORZucUhUqLt//oc/WaK0soOJVMnLdPMNaCX0UCmjTRXJ5xrDrEYYW3e4wS u5SA== X-Gm-Message-State: AOAM5300ISJCjJsBCoRSOnH+cGiuknh1bsygcRaIEePi7TXvtef9qaMW 5VozpC4oTYFYSmzh8EeM9pjVKokWhMp6tA== X-Google-Smtp-Source: ABdhPJx6kzSEPWwVoWnO59sn/fvQylN/4sphr6cNFpZ06Jop/Y6qNr6wmwbyExvVMLHiUC9N0eeR9Q== X-Received: by 2002:a05:6402:1907:b0:42d:e90e:337 with SMTP id e7-20020a056402190700b0042de90e0337mr5657356edz.405.1654178297640; Thu, 02 Jun 2022 06:58:17 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id p19-20020a056402155300b0042617ba638esm2510395edx.24.2022.06.02.06.58.17 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:17 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH 18/22] tools: relocate-rela: Extract elf64 reloc to special function Date: Thu, 2 Jun 2022 15:57:42 +0200 Message-Id: <3682788f013c2d3a77b556833cb452caedd270fa.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Adding support for new type requires to change code layout that's why move elf64 code to own function for easier maintenance. It also solves the problem with not calling fclose in case of error. Return value from rela_elf64 is saved to variable that's why fclose() is called all the time. Signed-off-by: Michal Simek --- tools/relocate-rela.c | 96 ++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index 36065edb3f01..e62247d51e2a 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -216,49 +216,9 @@ static int decode_elf(char **argv) return 1; } -int main(int argc, char **argv) +static int rela_elf64(char **argv, FILE *f) { - FILE *f; - int i, num, ret; - uint64_t file_size; - - if (argc != 3) { - fprintf(stderr, "Statically apply ELF rela relocations\n"); - fprintf(stderr, "Usage: %s \n", - argv[0]); - return 1; - } - - ret = decode_elf(argv); - if (ret) { - fprintf(stderr, "ELF decoding failed\n"); - return ret; - } - - if (rela_start > rela_end || rela_start < text_base) { - fprintf(stderr, "%s: bad rela bounds\n", argv[0]); - return 3; - } - - rela_start -= text_base; - rela_end -= text_base; - - f = fopen(argv[1], "r+b"); - if (!f) { - fprintf(stderr, "%s: Cannot open %s: %s\n", - argv[0], argv[1], strerror(errno)); - return 2; - } - - fseek(f, 0, SEEK_END); - file_size = ftell(f); - rewind(f); - - if (rela_end > file_size) { - // Most likely compiler inserted some section that didn't get - // objcopy-ed into the final binary - rela_end = file_size; - } + int i, num; if ((rela_end - rela_start) % sizeof(Elf64_Rela)) { fprintf(stderr, "%s: rela size isn't a multiple of Elf64_Rela\n", argv[0]); @@ -316,11 +276,61 @@ int main(int argc, char **argv) } } + return 0; +} + +int main(int argc, char **argv) +{ + FILE *f; + int ret; + uint64_t file_size; + + if (argc != 3) { + fprintf(stderr, "Statically apply ELF rela relocations\n"); + fprintf(stderr, "Usage: %s \n", + argv[0]); + return 1; + } + + ret = decode_elf(argv); + if (ret) { + fprintf(stderr, "ELF decoding failed\n"); + return ret; + } + + if (rela_start > rela_end || rela_start < text_base) { + fprintf(stderr, "%s: bad rela bounds\n", argv[0]); + return 3; + } + + rela_start -= text_base; + rela_end -= text_base; + + f = fopen(argv[1], "r+b"); + if (!f) { + fprintf(stderr, "%s: Cannot open %s: %s\n", + argv[0], argv[1], strerror(errno)); + return 2; + } + + fseek(f, 0, SEEK_END); + file_size = ftell(f); + rewind(f); + + if (rela_end > file_size) { + // Most likely compiler inserted some section that didn't get + // objcopy-ed into the final binary + rela_end = file_size; + } + + if (ei_class == 2) + ret = rela_elf64(argv, f); + if (fclose(f) < 0) { fprintf(stderr, "%s: %s: close failed: %s\n", argv[0], argv[1], strerror(errno)); return 4; } - return 0; + return ret; } From patchwork Thu Jun 2 13:57:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638379 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=1Be7eRTr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSQB64stz9sFr for ; Fri, 3 Jun 2022 00:02:42 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 098E9843AF; Thu, 2 Jun 2022 16:00:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="1Be7eRTr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4049E84388; Thu, 2 Jun 2022 15:58:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (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 866338433D for ; Thu, 2 Jun 2022 15:58:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x530.google.com with SMTP id v19so6384550edd.4 for ; Thu, 02 Jun 2022 06:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gdvi5Rvq3hjZIRKJNH2mCOQkLHdosnkx0DUdUFg1DLU=; b=1Be7eRTr2hDv2tt1xbOshcitGydolTX25a3zrFomFQNRfpqJ0QXyYoc3hrnBwlVtWp K9OPzZl+nXiSm2La1K1TsGruo2BIgXDCj3y5veCKDJ8ATCAp3kBhfRQDR3si0yRqAs16 A2RusB1Im9aVhb3vDByUvAcUnYTbg95QchGFSE5DBEKIGXfnFPdwmq+mXeTrOVDhN2kn jgyuGPjlQqVitCgs0tH+zZZnAnoTQPzW4tkMEa+x0nBXbzI3ZT89w1fF3xcm6L89qRGP UBGH+1sUFeEc1tDRl7xO4a55Cd1yvWUe3QTKXMmVlPC2LtEjzbqsjSAboleeAPX6NWBK XF4Q== 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=gdvi5Rvq3hjZIRKJNH2mCOQkLHdosnkx0DUdUFg1DLU=; b=Zz/ulMO9hqOW6hlNLnp122yd3yuer11IbutlGuu+ryXu/fdYvV3jcuSq+oph1SOjaW uVjwH7UxD5lOcDsGR18sNSfLqM4zMOjJ1+sZYxGc5sLbsTWKqYeJ8EWeadgCAR61H09A Mej3oT1RXJtg1M5PCTVDcD24Oq3Mdpg52j3Yk+hNRgFlGHFmDW5sKPRawjcaRF/SlSwe mgzbmf7wElJ6+eJiOL25sbL3EnpNs3bQq/NKkftNGlHzuz/VB/93Pw6N3o13e2FEVq47 r/au5cjDFMBxCyGjMpgXDTouLMPsuY5gaGLv/n9D30NmtVKC/1WF0Ga3FA9iCTEGusSA RuyQ== X-Gm-Message-State: AOAM530ob47BHfYjwo+NuwLzIOnmYxPmKKOWRUamHYeIbOtLueIYGuDi D+E+L4bz7XHxFaVAwCP89G9cx0r49/VLhw== X-Google-Smtp-Source: ABdhPJzSxY5H4s7f5Xs77wUPaq1V9VnAB7jFh/HXmtIH4FbhF5l859RIcFpTHjAl5/nbrzh4uV5I4g== X-Received: by 2002:a05:6402:c0c:b0:42d:c7b8:dff5 with SMTP id co12-20020a0564020c0c00b0042dc7b8dff5mr5657884edb.251.1654178299063; Thu, 02 Jun 2022 06:58:19 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id p18-20020a17090628d200b006f3ef214dbesm1759114ejd.36.2022.06.02.06.58.18 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:18 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH 19/22] tools: relocate-rela: Check that relocation works only for EM_AARCH64 Date: Thu, 2 Jun 2022 15:57:43 +0200 Message-Id: <5196b98748115efc440507824d4087e2c5d7aef3.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Relocation support is only for EM_AARCH64 that's why check machine type to make sure that the code will never run on any unsupported one. Signed-off-by: Michal Simek --- tools/relocate-rela.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index e62247d51e2a..2f7f1796a0ef 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -79,6 +79,11 @@ static int decode_elf64(FILE *felf, char **argv) machine = header.e_machine; debug("Machine\t%d\n", machine); + if (machine != EM_AARCH64) { + fprintf(stderr, "%s: Not supported machine type\n", argv[0]); + return 30; + } + text_base = header.e_entry; section_header_base = header.e_shoff; section_header_size = header.e_shentsize * header.e_shnum; From patchwork Thu Jun 2 13:57:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638377 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=MqLmhZNP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSPk30dVz9sFr for ; Fri, 3 Jun 2022 00:02:18 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0A837843D1; Thu, 2 Jun 2022 16:00:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="MqLmhZNP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 168198433D; Thu, 2 Jun 2022 15:58:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 0433484373 for ; Thu, 2 Jun 2022 15:58:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x52c.google.com with SMTP id o10so6383935edi.1 for ; Thu, 02 Jun 2022 06:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EqSuLK/MCheH+CwYY3iIOalPFSDS4JGVbO7vqZFPOuU=; b=MqLmhZNP6FSkJb1bOP/EDCHH4Yo0iEprRxwLkUHbqIlCmzkpvUCK3tl18S4Xl7IPKk iITB1UycGw9QEIc6Z2n5ZUVtf69pBxdMCveDmy8QySKaybSfsxskio72jVjJ75sfJu45 h2fE+5o8iA8gl+35/2ndGxwkMqAxZMK/6PqxXqjG/Kh8jpquZB7vft4nEAVCOsk85pUA EsxMukXgefkIi+HA9Z8i3gQ1k6rV/QFA8X8T0YaDJVBCCKZeVz0CrHBlwb4xVKPq4Mn9 rcwzzfCgEEqBd3qOTORSHFSBk/6qbPWr+JMybNn88v0MwcLEKCsZ6GxCrEQ2xg4K3amn WG0A== 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=EqSuLK/MCheH+CwYY3iIOalPFSDS4JGVbO7vqZFPOuU=; b=xyv4rscMs83RVuKRuWZWqFrTWXfR1lk+0f2/8CZwF9l0Ht0sFv+yJvdBCKapqguvEI PzYwammPewfpa0/EtaSOlhnW2Nbgf8UQXTlwKUiO/bZrZu2orSNicSCJwznWBc+uF5IH TJrg8WQf+MBCP674aWA7HY30WP+6mTxl1gTqFF/5w2Zyn75kme3/mHRCUkqqW1A8UIsP 6ZXLevKA5UnbskXJuIq3rmdzAgtSLKILRM6qwymJd5okPM4mc9/GHZp+UNXZlXobqm2I SNuRH6f2h8RxK5sGtVxX6sPXaG2jyH8EZvx5vfm4aWbOhy40+Nm0OkUeNhD/CXojOyCY AW7A== X-Gm-Message-State: AOAM531cSRmBr+7jvCor0RYxumsY2qirTQ3TlRn77FezZlCZ+gZmcaUi J6e8C3lTbh7cKEKTUh2ebdqreFcNQI3NmA== X-Google-Smtp-Source: ABdhPJzxWa4znO+oOFw/6eiJUW60rpsepoJrrsE0rk3nYp4okdoMAnuPfFkTI3PAfT0m6wPeLcatDA== X-Received: by 2002:a05:6402:3207:b0:42d:dba6:8ef0 with SMTP id g7-20020a056402320700b0042ddba68ef0mr5763597eda.410.1654178300564; Thu, 02 Jun 2022 06:58:20 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id e2-20020a1709062d4200b006fec2097d53sm1763509eji.118.2022.06.02.06.58.20 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:20 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH 20/22] tools: relocate-rela: Add support for elf32 decoding Date: Thu, 2 Jun 2022 15:57:44 +0200 Message-Id: <525ebe2f7d730afb1db4f48f324f08a3caf8c114.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Add support for 32bit ELF format which is used by Microblaze. Also check that code runs only for Microblaze. Function finds information about rela.dyn and dynsym which will be used later for relocation. Signed-off-by: Michal Simek --- tools/relocate-rela.c | 141 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 2 deletions(-) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index 2f7f1796a0ef..7c2a441a8e91 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -22,7 +22,7 @@ static int ei_class; -static uint64_t rela_start, rela_end, text_base; +static uint64_t rela_start, rela_end, text_base, dyn_start; static const bool debug_en; @@ -184,6 +184,142 @@ static int decode_elf64(FILE *felf, char **argv) return 0; } +static int decode_elf32(FILE *felf, char **argv) +{ + size_t size; + Elf32_Ehdr header; + uint64_t section_header_base, section_header_size, sh_offset, sh_size; + Elf32_Shdr *sh_table; /* Elf symbol table */ + int ret, i, machine; + char *sh_str; + + debug("32bit version\n"); + + /* Make sure we are at start */ + rewind(felf); + + size = fread(&header, 1, sizeof(header), felf); + if (size != sizeof(header)) { + fclose(felf); + return 25; + } + + machine = header.e_machine; + debug("Machine %d\n", machine); + + if (machine != EM_MICROBLAZE) { + fprintf(stderr, "%s: Not supported machine type\n", argv[0]); + return 30; + } + + text_base = header.e_entry; + section_header_base = header.e_shoff; + + debug("Section header base %x\n", section_header_base); + + section_header_size = header.e_shentsize * header.e_shnum; + + debug("Section header size %d\n", section_header_size); + + sh_table = malloc(section_header_size); + if (!sh_table) { + fprintf(stderr, "%s: Cannot allocate space for section header\n", + argv[0]); + fclose(felf); + return 26; + } + + ret = fseek(felf, section_header_base, SEEK_SET); + if (ret) { + fprintf(stderr, "%s: Can't set pointer to section header: %x/%lx\n", + argv[0], ret, section_header_base); + free(sh_table); + fclose(felf); + return 26; + } + + size = fread(sh_table, 1, section_header_size, felf); + if (size != section_header_size) { + fprintf(stderr, "%s: Can't read section header: %lx/%lx\n", + argv[0], size, section_header_size); + free(sh_table); + fclose(felf); + return 27; + } + + sh_size = sh_table[header.e_shstrndx].sh_size; + debug("e_shstrndx %x, sh_size %lx\n", header.e_shstrndx, sh_size); + + sh_str = malloc(sh_size); + if (!sh_str) { + fprintf(stderr, "malloc failed\n"); + free(sh_table); + fclose(felf); + return 28; + } + + /* + * Specifies the byte offset from the beginning of the file + * to the first byte in the section. + */ + sh_offset = sh_table[header.e_shstrndx].sh_offset; + + debug("sh_offset %x\n", header.e_shnum); + + ret = fseek(felf, sh_offset, SEEK_SET); + if (ret) { + fprintf(stderr, "Setting up sh_offset failed\n"); + free(sh_str); + free(sh_table); + fclose(felf); + return 29; + } + + size = fread(sh_str, 1, sh_size, felf); + if (size != sh_size) { + fprintf(stderr, "%s: Can't read section: %lx/%lx\n", + argv[0], size, sh_size); + free(sh_str); + free(sh_table); + fclose(felf); + return 30; + } + + for (i = 0; i < header.e_shnum; i++) { + debug("%s\n", sh_str + sh_table[i].sh_name); + if (!strcmp(".rela.dyn", (sh_str + sh_table[i].sh_name))) { + debug("Found section\t\".rela_dyn\"\n"); + debug(" at addr\t0x%08x\n", (unsigned int)sh_table[i].sh_addr); + debug(" at offset\t0x%08x\n", (unsigned int)sh_table[i].sh_offset); + debug(" of size\t0x%08x\n", (unsigned int)sh_table[i].sh_size); + rela_start = sh_table[i].sh_addr; + rela_end = rela_start + sh_table[i].sh_size; + } + if (!strcmp(".dynsym", (sh_str + sh_table[i].sh_name))) { + debug("Found section\t\".dynsym\"\n"); + debug(" at addr\t0x%08x\n", (unsigned int)sh_table[i].sh_addr); + debug(" at offset\t0x%08x\n", (unsigned int)sh_table[i].sh_offset); + debug(" of size\t0x%08x\n", (unsigned int)sh_table[i].sh_size); + dyn_start = sh_table[i].sh_addr; + } + } + + /* Clean up */ + free(sh_str); + free(sh_table); + fclose(felf); + + debug("text_base\t0x%08lx\n", text_base); + debug("rela_start\t0x%08lx\n", rela_start); + debug("rela_end\t0x%08lx\n", rela_end); + debug("dyn_start\t0x%08lx\n", dyn_start); + + if (!rela_start) + return 1; + + return 0; +} + static int decode_elf(char **argv) { FILE *felf; @@ -218,7 +354,7 @@ static int decode_elf(char **argv) if (ei_class == 2) return decode_elf64(felf, argv); - return 1; + return decode_elf32(felf, argv); } static int rela_elf64(char **argv, FILE *f) @@ -310,6 +446,7 @@ int main(int argc, char **argv) rela_start -= text_base; rela_end -= text_base; + dyn_start -= text_base; f = fopen(argv[1], "r+b"); if (!f) { From patchwork Thu Jun 2 13:57:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638378 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=bWSEoAX1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSPy5WH0z9sFr for ; Fri, 3 Jun 2022 00:02:30 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E6F96843D5; Thu, 2 Jun 2022 16:00:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="bWSEoAX1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D9B588438E; Thu, 2 Jun 2022 15:58:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) (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 6CA688433F for ; Thu, 2 Jun 2022 15:58:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x530.google.com with SMTP id v19so6384550edd.4 for ; Thu, 02 Jun 2022 06:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hUN6Rh64aVJ9OIdkmBDfZM+qxuCFaO3wGI0I2GUdxw8=; b=bWSEoAX14INIZVFzg2xHENs/Gc1oJIuiniJ5O+PwjWSWEFUzabZ8/Ibm0jHANK/zYC iGNuXOCOrihtwRg05UlnFE2tIt1CPCXBzOlXXzrJQnY7kzx8VR0+yI2yGD0H3tWEzgkw MhFKtLVfmBz+795GY8j+ls9P028A8tOzd77JXL3k8nPKnh0ZLpJKl0gVPgo1d+FbJ1jo MOi0WNz4G+vtefMlqU1uaCLRC2XBm1zZMnt8k+Grz2I76lYDsB946oKoaml4cdG1JPm+ 1Y+OabQxFTru8qcBR5nWf15NG9ymHJVBLRMRUeRn7A3fJfkEl1Q4crqKiRJTIZKEzlRk /mgQ== 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=hUN6Rh64aVJ9OIdkmBDfZM+qxuCFaO3wGI0I2GUdxw8=; b=Pfhv+TUA3aFL+zh/VnrGhn/N310VIkab96A+VGSz3G0H3PyCvGnLmH00BJUsIwqSEs aV1w9lQLDigR3TgPpSaKUdNhbm/SusxdnLEeCokDOu833/6lc6FXCPKFUDL1Hy6UVoK+ DefC5uSWVnELpgSU5ijawgMWA7ja8SwIpT1mj1ZUCxgUWLHkgstBzLVItDHLP95NF5uP 9R6yP8fCCWon6Um21IV5xJ+iqbNRQfRem1kHef+08odzmaNZNRCH5S2Ig0zjCbA95kgv CYk8mDaSoOWlpI17jjevePYLlC6Kz16JVCLYP+CMJ5Vpvvgxal1I9/1ePEwO6ht7/3ZL Ok4g== X-Gm-Message-State: AOAM533yizJwJQHCKTbFBELFAQWK0uh9rdgxf/WPO3YXblOOXhy/ffLP fFQJzWb2TRxIB8ltQ7dIKuNTNfiYbMq6Vg== X-Google-Smtp-Source: ABdhPJw/KrWGoZkvJ25r6oOmZx+7GCuP+qiQGLuBeOJFX0kxlBU14TstX/qxDWkB8JJrFwHHpRvTQQ== X-Received: by 2002:a05:6402:2815:b0:420:c32e:ebe2 with SMTP id h21-20020a056402281500b00420c32eebe2mr5697966ede.1.1654178301973; Thu, 02 Jun 2022 06:58:21 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id ay25-20020a056402203900b0042cf43e1937sm2558008edb.75.2022.06.02.06.58.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:21 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Alistair Delva Subject: [PATCH 21/22] tools: relocate-rela: Add support for 32bit Microblaze relocation Date: Thu, 2 Jun 2022 15:57:45 +0200 Message-Id: <99096416c079178296f4645f425991742f3fd975.1654178252.git.michal.simek@amd.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Microblaze is 32bit that's why it is using elf32 format. Relocation code requires to get information about rela and dynsym senctions and also text base which was used for compilation. Code build with -fPIC and linked with -pic generates 4 relocation types. R_MICROBLAZE_NONE is the easiest one which doesn't require any action. R_MICROBLAZE_REL only requires write addend to r_offset address. R_MICROBLAZE_32/R_MICROBLAZE_GLOB_DAT are the most complicated. There is a need to find out symbol value with adding symbol value and write it to address pointed by r_offset. Calculation with addend is also added but only 0 addend values are generated now. Signed-off-by: Michal Simek --- tools/relocate-rela.c | 166 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c index 7c2a441a8e91..090fb1acb20c 100644 --- a/tools/relocate-rela.c +++ b/tools/relocate-rela.c @@ -420,6 +420,170 @@ static int rela_elf64(char **argv, FILE *f) return 0; } +static bool supported_rela32(Elf32_Rela *rela, uint32_t *type) +{ + uint32_t mask = 0xffULL; /* would be different on 32-bit */ + *type = rela->r_info & mask; + + debug("Type:\t"); + + switch (*type) { + case R_MICROBLAZE_32: + debug("R_MICROBLAZE_32\n"); + return true; + case R_MICROBLAZE_GLOB_DAT: + debug("R_MICROBLAZE_GLOB_DAT\n"); + return true; + case R_MICROBLAZE_NONE: + debug("R_MICROBLAZE_NONE - ignoring - do nothing\n"); + return false; + case R_MICROBLAZE_REL: + debug("R_MICROBLAZE_REL\n"); + return true; + default: + fprintf(stderr, "warning: unsupported relocation type %" + PRIu32 " at %" PRIx32 "\n", *type, rela->r_offset); + + return false; + } +} + +static int rela_elf32(char **argv, FILE *f) +{ + int i, num, index; + uint32_t value, type; + + if ((rela_end - rela_start) % sizeof(Elf32_Rela)) { + fprintf(stderr, "%s: rela size isn't a multiple of Elf32_Rela\n", argv[0]); + return 3; + } + + num = (rela_end - rela_start) / sizeof(Elf32_Rela); + + debug("Number of entries: %u\n", num); + + for (i = 0; i < num; i++) { + Elf32_Rela rela, swrela; + Elf32_Sym symbols; + uint32_t pos = rela_start + sizeof(Elf32_Rela) * i; + uint32_t addr, pos_dyn; + + debug("\nPossition:\t%d/0x%x\n", i, pos); + + if (fseek(f, pos, SEEK_SET) < 0) { + fprintf(stderr, "%s: %s: seek to %" PRIx32 + " failed: %s\n", + argv[0], argv[1], pos, strerror(errno)); + } + + if (fread(&rela, sizeof(rela), 1, f) != 1) { + fprintf(stderr, "%s: %s: read rela failed at %" + PRIx32 "\n", + argv[0], argv[1], pos); + return 4; + } + + debug("Rela:\toffset:\t%" PRIx32 " r_info:\t%" + PRIu32 " r_addend:\t%" PRIx32 "\n", + rela.r_offset, rela.r_info, rela.r_addend); + + swrela.r_offset = cpu_to_le32(rela.r_offset); + swrela.r_info = cpu_to_le32(rela.r_info); + swrela.r_addend = cpu_to_le32(rela.r_addend); + + debug("SWRela:\toffset:\t%" PRIx32 " r_info:\t%" + PRIu32 " r_addend:\t%" PRIx32 "\n", + swrela.r_offset, swrela.r_info, swrela.r_addend); + + if (!supported_rela32(&swrela, &type)) + continue; + + if (swrela.r_offset < text_base) { + fprintf(stderr, "%s: %s: bad rela at %" PRIx32 "\n", + argv[0], argv[1], pos); + return 4; + } + + addr = swrela.r_offset - text_base; + + debug("Addr:\t0x%" PRIx32 "\n", addr); + + switch (type) { + case R_MICROBLAZE_REL: + if (fseek(f, addr, SEEK_SET) < 0) { + fprintf(stderr, "%s: %s: seek to %" + PRIx32 " failed: %s\n", + argv[0], argv[1], addr, strerror(errno)); + return 5; + } + + debug("Write addend\n"); + + if (fwrite(&rela.r_addend, sizeof(rela.r_addend), 1, f) != 1) { + fprintf(stderr, "%s: %s: write failed at %" PRIx32 "\n", + argv[0], argv[1], addr); + return 4; + } + break; + case R_MICROBLAZE_32: + case R_MICROBLAZE_GLOB_DAT: + /* global symbols read it and add reloc offset */ + index = swrela.r_info >> 8; + pos_dyn = dyn_start + sizeof(Elf32_Sym) * index; + + debug("Index:\t%d\n", index); + debug("Pos_dyn:\t0x%x\n", pos_dyn); + + if (fseek(f, pos_dyn, SEEK_SET) < 0) { + fprintf(stderr, "%s: %s: seek to %" + PRIx32 " failed: %s\n", + argv[0], argv[1], pos_dyn, strerror(errno)); + return 5; + } + + if (fread(&symbols, sizeof(symbols), 1, f) != 1) { + fprintf(stderr, "%s: %s: read symbols failed at %" + PRIx32 "\n", + argv[0], argv[1], pos_dyn); + return 4; + } + + debug("Symbol description:\n"); + debug(" st_name:\t0x%x\n", symbols.st_name); + debug(" st_value:\t0x%x\n", symbols.st_value); + debug(" st_size:\t0x%x\n", symbols.st_size); + + value = swrela.r_addend + symbols.st_value; + + debug("Value:\t0x%x\n", value); + + if (fseek(f, addr, SEEK_SET) < 0) { + fprintf(stderr, "%s: %s: seek to %" + PRIx32 " failed: %s\n", + argv[0], argv[1], addr, strerror(errno)); + return 5; + } + + if (fwrite(&value, sizeof(rela.r_addend), 1, f) != 1) { + fprintf(stderr, "%s: %s: write failed at %" PRIx32 "\n", + argv[0], argv[1], addr); + return 4; + } + + break; + case R_MICROBLAZE_NONE: + debug("R_MICROBLAZE_NONE - skip\n"); + break; + default: + fprintf(stderr, "warning: unsupported relocation type %" + PRIu32 " at %" PRIx32 "\n", + type, rela.r_offset); + } + } + + return 0; +} + int main(int argc, char **argv) { FILE *f; @@ -467,6 +631,8 @@ int main(int argc, char **argv) if (ei_class == 2) ret = rela_elf64(argv, f); + else + ret = rela_elf32(argv, f); if (fclose(f) < 0) { fprintf(stderr, "%s: %s: close failed: %s\n", From patchwork Thu Jun 2 13:57:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1638380 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=nzMEPVv6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LDSQR3X50z9sFr for ; Fri, 3 Jun 2022 00:02:55 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7A3E6843E3; Thu, 2 Jun 2022 16:00:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu 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=monstr-eu.20210112.gappssmtp.com header.i=@monstr-eu.20210112.gappssmtp.com header.b="nzMEPVv6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 28C4D84362; Thu, 2 Jun 2022 15:58:48 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 044A68436F for ; Thu, 2 Jun 2022 15:58:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=monstr.eu Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x531.google.com with SMTP id fd25so6386120edb.3 for ; Thu, 02 Jun 2022 06:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ay/slLsbeBR64MYO5G3wfh3lzmaQPaq8zwmyyNljrfw=; b=nzMEPVv63d2M+sM9Y0i2UsQV2O6cPF6+uW0UKNj50JA1LF0R9ejpO8xFbapXLHoBcq zLyifmJaEEf2V6UejNtHxH7a/FGTi3QWK9XKSWcWQZ/J6Wy/gJBQqwWEK55vF0OCKU9B iJ+7nDU28gTUuMPanxCgXq8q8FUBGiPa+pwfDYcVUuydD8AMXv9yq/kOj8IZpR0q5CLB vaTxNhdBk/KdxEewfixg+6FMC/2vwFveIf35SBVfyBqsMmewo/Do3YjbyXk1el71dhuw sUqq0lQ6IlIVH6vDZWpM1qlJfLqRXt6wITO42oPpclMEVn7aMoOpfk9zzvxQ6zM63bYb 9kqg== 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=ay/slLsbeBR64MYO5G3wfh3lzmaQPaq8zwmyyNljrfw=; b=Tom5WiZMWJtV/B5+7DEbc1wfeWQ22dkCk1CtcEt77WQYBhqa4jyyE2YNoHPDQzzh14 L5yAwxfNHyr7KjHIskRpmDBv2yJKjJ6B6fKKOIqnTpxpiZ16bJZboimnPTIVAqK6d49b WcM901fqox9j2lwaQUKBEnm1Y/KOOPdFStdcY9MLB3hIz2qFOeSSwvF3jORaHR6pt9om Zc6MXLaYCbwAvZZBAxnCsjvv4XORshYqQL7hvrkl0kMmC93wIMADDIDWkE0byc8Jc4R/ WWCMRj25Xlh9fgHJtUjyZP2nJkADNArO5j8+UO0wBJJfRv5GIHvMy/uTsaGuEYzKWsV4 Btsg== X-Gm-Message-State: AOAM530JRYgO4CF2cGAgJeB5pYkeVIEOzIy7hK94tGFd/l9CdkcPaeYC 6bilq0EbBFLggnGTqjIB/3bhAOq1oicNFg== X-Google-Smtp-Source: ABdhPJzAswQNVaSCimhJVk2pvaUhMgkgFjvZKKBEBcWwexUFdMyFdO4K5waIckj54jU7QvgVzVBUIA== X-Received: by 2002:a05:6402:2155:b0:42c:297b:76b8 with SMTP id bq21-20020a056402215500b0042c297b76b8mr5702278edb.190.1654178303396; Thu, 02 Jun 2022 06:58:23 -0700 (PDT) Received: from localhost ([2a02:768:2307:40d6::f9e]) by smtp.gmail.com with ESMTPSA id l1-20020a1709060e0100b006fec4ee28d0sm354443eji.189.2022.06.02.06.58.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Jun 2022 06:58:23 -0700 (PDT) From: Michal Simek X-Google-Original-From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Heiko Schocher , Heinrich Schuchardt , Marek Vasut , Michal Simek , Ovidiu Panait , Rick Chen , Sean Anderson , Simon Glass Subject: [PATCH 22/22] microblaze: Add support for run time relocation Date: Thu, 2 Jun 2022 15:57:46 +0200 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean Microblaze is using NEEDS_MANUAL_RELOC from the beginnging. This is causing issues with function pointer arrays which need to be updated manually after relocation. Building code with -fPIC and linking with -pic will remove this limitation and there is no longer need to run manual update. By default still old option is enabled but by disabling NEEDS_MANUAL_RELOC code will be compiled for full relocation. The patch does couple of things which are connected to each other. - Define STATIC_RELA dependency to call relocate-rela to fill sections. - REMAKE_ELF was already enabled but u-boot file can't be used because sections are empty. relocate-rela will fill them and output file is u-boot.elf which should be used. - Add support for full relocation (u-boot.elf) - Add support for early relocation when u-boot.bin is loaded to different address then CONFIG_SYS_TEXT_BASE - Add rela.dyn and dynsym sections Disabling NEEDS_MANUAL_RELOC U-Boot size increased by 10% of it's original size (550kB to 608kB). Signed-off-by: Michal Simek --- arch/Kconfig | 1 - arch/microblaze/Kconfig | 14 +++++ arch/microblaze/config.mk | 5 ++ arch/microblaze/cpu/Makefile | 1 + arch/microblaze/cpu/relocate.c | 111 +++++++++++++++++++++++++++++++++ arch/microblaze/cpu/start.S | 66 ++++++++++++++++++++ arch/microblaze/cpu/u-boot.lds | 14 +++++ common/board_f.c | 2 + 8 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 arch/microblaze/cpu/relocate.c diff --git a/arch/Kconfig b/arch/Kconfig index 12de8a11650d..a653583894c2 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -76,7 +76,6 @@ config M68K config MICROBLAZE bool "MicroBlaze architecture" - select NEEDS_MANUAL_RELOC select SUPPORT_OF_CONTROL imply CMD_IRQ diff --git a/arch/microblaze/Kconfig b/arch/microblaze/Kconfig index f1fc46e774e5..b01c587b1c7b 100644 --- a/arch/microblaze/Kconfig +++ b/arch/microblaze/Kconfig @@ -20,6 +20,20 @@ config SYS_LITTLE_ENDIAN endchoice +config NEEDS_MANUAL_RELOC + bool "Disable position-independent pre-relocation code" + default y + help + U-Boot expects to be linked to a specific hard-coded address, and to + be loaded to and run from that address. This option lifts that + restriction, thus allowing the code to be loaded to and executed from + almost any 4K aligned address. This logic relies on the relocation + information that is embedded in the binary to support U-Boot + relocating itself to the top-of-RAM later during execution. + +config STATIC_RELA + def_bool y if !NEEDS_MANUAL_RELOC + choice prompt "Target select" optional diff --git a/arch/microblaze/config.mk b/arch/microblaze/config.mk index 3e84a832fc12..d35b4f6db7a1 100644 --- a/arch/microblaze/config.mk +++ b/arch/microblaze/config.mk @@ -17,6 +17,11 @@ ifeq ($(CONFIG_SPL_BUILD),) PLATFORM_CPPFLAGS += -fPIC endif +ifeq ($(CONFIG_STATIC_RELA),y) +PLATFORM_CPPFLAGS += -fPIC +LDFLAGS_u-boot += -pic +endif + ifeq ($(CONFIG_SYS_LITTLE_ENDIAN),y) PLATFORM_ELFFLAGS += -B microblaze $(OBJCOPYFLAGS) -O elf32-microblazeel else diff --git a/arch/microblaze/cpu/Makefile b/arch/microblaze/cpu/Makefile index f7a83d07b6f6..1feffc6a97c0 100644 --- a/arch/microblaze/cpu/Makefile +++ b/arch/microblaze/cpu/Makefile @@ -6,4 +6,5 @@ extra-y = start.o obj-y = irq.o obj-y += interrupts.o cache.o exception.o timer.o +obj-$(CONFIG_STATIC_RELA) += relocate.o obj-$(CONFIG_SPL_BUILD) += spl.o diff --git a/arch/microblaze/cpu/relocate.c b/arch/microblaze/cpu/relocate.c new file mode 100644 index 000000000000..b00d02b1dfcc --- /dev/null +++ b/arch/microblaze/cpu/relocate.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) Copyright 2022 Advanced Micro Devices, Inc + * Michal Simek + */ + +#include +#include + +#define R_MICROBLAZE_NONE 0 +#define R_MICROBLAZE_32 1 +#define R_MICROBLAZE_REL 16 +#define R_MICROBLAZE_GLOB_DAT 18 + +/** + * mb_fix_rela - update relocation to new address + * @reloc_addr: new relocation address + * @verbose: enable version messages + * @rela_start: rela section start + * @rela_end: rela section end + * @dyn_start: dynamic section start + * @origin_addr: address where u-boot starts(doesn't need to be CONFIG_SYS_TEXT_BASE) + */ +void mb_fix_rela(u32 reloc_addr, u32 verbose, u32 rela_start, + u32 rela_end, u32 dyn_start, u32 origin_addr) +{ + u32 num, type, mask, i, reloc_off; + + /* + * Return in case u-boot.elf is used directly. + * Skip it when u-boot.bin is loaded to different address than + * CONFIG_SYS_TEXT_BASE. In this case relocation is necessary to run. + */ + if (reloc_addr == CONFIG_SYS_TEXT_BASE) { + debug_cond(verbose, + "Relocation address is the same - skip relocation\n"); + return; + } + + reloc_off = reloc_addr - origin_addr; + + debug_cond(verbose, "Relocation address:\t0x%08x\n", reloc_addr); + debug_cond(verbose, "Relocation offset:\t0x%08x\n", reloc_off); + debug_cond(verbose, "Origin address:\t0x%08x\n", origin_addr); + debug_cond(verbose, "Rela start:\t0x%08x\n", rela_start); + debug_cond(verbose, "Rela end:\t0x%08x\n", rela_end); + debug_cond(verbose, "Dynsym start:\t0x%08x\n", dyn_start); + + num = (rela_end - rela_start) / sizeof(Elf32_Rela); + + debug_cond(verbose, "Number of entries:\t%u\n", num); + + for (i = 0; i < num; i++) { + Elf32_Rela *rela; + u32 temp; + + rela = (Elf32_Rela *)(rela_start + sizeof(Elf32_Rela) * i); + + mask = 0xffULL; /* would be different on 32-bit */ + type = rela->r_info & mask; + + debug_cond(verbose, "\nRela possition:\t%d/0x%x\n", + i, (u32)rela); + + switch (type) { + case R_MICROBLAZE_REL: + temp = *(u32 *)rela->r_offset; + + debug_cond(verbose, "Type:\tREL\n"); + debug_cond(verbose, "Rela r_offset:\t\t0x%x\n", rela->r_offset); + debug_cond(verbose, "Rela r_info:\t\t0x%x\n", rela->r_info); + debug_cond(verbose, "Rela r_addend:\t\t0x%x\n", rela->r_addend); + debug_cond(verbose, "Value at r_offset:\t0x%x\n", temp); + + rela->r_offset += reloc_off; + rela->r_addend += reloc_off; + + temp = *(u32 *)rela->r_offset; + temp += reloc_off; + *(u32 *)rela->r_offset = temp; + + debug_cond(verbose, "New:Rela r_offset:\t0x%x\n", rela->r_offset); + debug_cond(verbose, "New:Rela r_addend:\t0x%x\n", rela->r_addend); + debug_cond(verbose, "New:Value at r_offset:\t0x%x\n", temp); + break; + case R_MICROBLAZE_32: + case R_MICROBLAZE_GLOB_DAT: + debug_cond(verbose, "Type:\t(32/GLOB) %u\n", type); + debug_cond(verbose, "Rela r_offset:\t\t0x%x\n", rela->r_offset); + debug_cond(verbose, "Rela r_info:\t\t0x%x\n", rela->r_info); + debug_cond(verbose, "Rela r_addend:\t\t0x%x\n", rela->r_addend); + debug_cond(verbose, "Value at r_offset:\t0x%x\n", temp); + + rela->r_offset += reloc_off; + + temp = *(u32 *)rela->r_offset; + temp += reloc_off; + *(u32 *)rela->r_offset = temp; + + debug_cond(verbose, "New:Rela r_offset:\t0x%x\n", rela->r_offset); + debug_cond(verbose, "New:Value at r_offset:\t0x%x\n", temp); + break; + case R_MICROBLAZE_NONE: + debug_cond(verbose, "R_MICROBLAZE_NONE - skip\n"); + break; + default: + debug_cond(verbose, "warning: unsupported relocation type %d at %x\n", + type, rela->r_offset); + } + } +} diff --git a/arch/microblaze/cpu/start.S b/arch/microblaze/cpu/start.S index 72b0f3354731..9a661e785f6d 100644 --- a/arch/microblaze/cpu/start.S +++ b/arch/microblaze/cpu/start.S @@ -10,8 +10,16 @@ #include #include +#if defined(CONFIG_STATIC_RELA) +#define SYM_ADDR(reg, reg_add, symbol) \ + mfs r20, rpc; \ + addik r20, r20, _GLOBAL_OFFSET_TABLE_ + 8; \ + lwi reg, r20, symbol@GOT; \ + addk reg, reg reg_add; +#else #define SYM_ADDR(reg, reg_add, symbol) \ addi reg, reg_add, symbol +#endif .text .global _start @@ -27,6 +35,39 @@ _start: addi r1, r0, CONFIG_SPL_STACK_ADDR #else add r1, r0, r20 +#if defined(CONFIG_STATIC_RELA) + bri 1f + + /* Force alignment for easier ASM code below */ +#define ALIGNMENT_ADDR 0x20 + .align 4 +uboot_dyn_start: + .word __rel_dyn_start + +uboot_dyn_end: + .word __rel_dyn_end + +uboot_sym_start: + .word __dyn_sym_start +1: + + addi r5, r20, 0 + add r6, r0, r0 + + lwi r7, r20, ALIGNMENT_ADDR + addi r7, r7, -CONFIG_SYS_TEXT_BASE + add r7, r7, r5 + lwi r8, r20, ALIGNMENT_ADDR + 0x4 + addi r8, r8, -CONFIG_SYS_TEXT_BASE + add r8, r8, r5 + lwi r9, r20, ALIGNMENT_ADDR + 0x8 + addi r9, r9, -CONFIG_SYS_TEXT_BASE + add r9, r9, r5 + addi r10, r0, CONFIG_SYS_TEXT_BASE + + brlid r15, mb_fix_rela + nop +#endif #endif addi r1, r1, -4 /* Decrement SP to top of memory */ @@ -297,6 +338,30 @@ relocate_code: brlid r15, __setup_exceptions nop +#if defined(CONFIG_STATIC_RELA) + /* reloc_offset is current location */ + SYM_ADDR(r10, r0, _start) + + /* r5 new address where I should copy code */ + add r5, r0, r7 /* Move reloc addr to r5 */ + + /* Verbose message */ + addi r6, r0, 0 + + SYM_ADDR(r7, r0, __rel_dyn_start) + rsub r7, r10, r7 + add r7, r7, r5 + SYM_ADDR(r8, r0, __rel_dyn_end) + rsub r8, r10, r8 + add r8, r8, r5 + SYM_ADDR(r9, r0, __dyn_sym_start) + rsub r9, r10, r9 + add r9, r9, r5 + brlid r15, mb_fix_rela + nop + + /* end of code which does relocation */ +#else /* Check if GOT exist */ addik r21, r23, _got_start addik r22, r23, _got_end @@ -314,6 +379,7 @@ relocate_code: cmpu r12, r21, r22 /* Check if this cross boundary */ bneid r12, 3b addik r21. r21, 4 +#endif /* Flush caches to ensure consistency */ addik r5, r0, 0 diff --git a/arch/microblaze/cpu/u-boot.lds b/arch/microblaze/cpu/u-boot.lds index 2b316cc7f5a5..821cc55d7b30 100644 --- a/arch/microblaze/cpu/u-boot.lds +++ b/arch/microblaze/cpu/u-boot.lds @@ -46,6 +46,20 @@ SECTIONS } __init_end = . ; + . = ALIGN(4); + __rel_dyn_start = .; + .rela.dyn : { + *(.rela.dyn) + } + __rel_dyn_end = .; + + . = ALIGN(4); + __dyn_sym_start = .; + .dynsym : { + *(.dynsym) + } + __dyn_sym_end = .; + .bss ALIGN(0x4): { __bss_start = .; diff --git a/common/board_f.c b/common/board_f.c index 51d2f3c365e9..a5666ca77c24 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -684,6 +684,8 @@ static int setup_reloc(void) #ifdef CONFIG_SYS_TEXT_BASE #ifdef ARM gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start; +#elif defined(CONFIG_MICROBLAZE) + gd->reloc_off = gd->relocaddr - (u32)_start; #elif defined(CONFIG_M68K) /* * On all ColdFire arch cpu, monitor code starts always