Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7C58C4332F for ; Thu, 22 Dec 2022 15:50:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 08229851FC; Thu, 22 Dec 2022 16:50:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="rgxdvubS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 45226851D8; Thu, 22 Dec 2022 16:50:07 +0100 (CET) Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) (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 92879851FC for ; Thu, 22 Dec 2022 16:50:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-vs1-xe2b.google.com with SMTP id q14so1454185vsr.1 for ; Thu, 22 Dec 2022 07:50:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=X3mfvzq+AFsGZpFTBWdM0br2rdpFrnN/1D2MTPaPg3o=; b=rgxdvubScFRQZZmytC6FZ3JudGU0QPhDV/Nl54leHGTJIKRDR8osOhqBKbnTx//gTq +S950bXcX6Qr096RWxdqa855qW4Q/rr93mCWmqh+bL8KUMgAIUiJ72YH8Lhe+HzexzmV /oxufwZFGbt9CUztB9buW37iOrIOcIGLXzlSg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=X3mfvzq+AFsGZpFTBWdM0br2rdpFrnN/1D2MTPaPg3o=; b=UcyVau34bH16lInvesB2pJqv2Vx1oiuZ0C4/q6NrXQ7YrebLuFkt/FKmuo6cADyrE+ CFsx5b/ICT/gkRVFDs7UJzGltGyWUJ5RX0ZFVQ28p9QPoPL1f7i/W3P7IuZlTnt7OG8M Huv2ltV4siy9UF/4VDiNkc7HO9MorbLOSVAR6m+c2PZbDu91dP/FbcgVMnGYDbALFPVr Z+HyrF5WHGq/aAwPF6mRqMdfOjO2AmdwsA9o7EEovj5fCMVG4/+5PXjOXbxUMAoGMCbM I5j12aYU9MchtdpdwAZQVcfnvT59WwK+8rdHgG26ZxJNBsBp+utDIRQ/kusiNKzoHMue Bq/g== X-Gm-Message-State: AFqh2ko/ev/DcdQiUR8GgvrUNU2eW4/Q85w5sE68/7kX+xrslGCzMNbq IwsdU2PEfJFr/iJvpS9TLuryvw== X-Google-Smtp-Source: AMrXdXuDYaZXrkn5YNtvdhDeHUpJ0kICO20+Qj6n7CXgamP9BAHmemFIWFIe5DV7mUoMi0Fr3RUqQg== X-Received: by 2002:a67:fdc8:0:b0:3b1:4975:c177 with SMTP id l8-20020a67fdc8000000b003b14975c177mr2723572vsq.4.1671724200218; Thu, 22 Dec 2022 07:50:00 -0800 (PST) Received: from bill-the-cat (2603-6081-7b00-6400-0489-d0bf-dcad-62f5.res6.spectrum.com. [2603:6081:7b00:6400:489:d0bf:dcad:62f5]) by smtp.gmail.com with ESMTPSA id k2-20020a05620a414200b006fc2cee4486sm522886qko.62.2022.12.22.07.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 07:49:59 -0800 (PST) Date: Thu, 22 Dec 2022 10:49:58 -0500 From: Tom Rini To: Pali =?iso-8859-1?Q?Roh=E1r?= Cc: Simon Glass , Eugen Hristev , u-boot@lists.denx.de, xypron.glpk@gmx.de, michal.simek@amd.com, daniel.schwierzeck@gmail.com, marex@denx.de, alpernebiyasak@gmail.com Subject: Re: [PATCH] lds: align u-boot-nodtb with 8 bytes boundary Message-ID: <20221222154958.GL3787616@bill-the-cat> References: <20221215115825.827111-1-eugen.hristev@microchip.com> <20221216001307.f5boephkfrb3cfpo@pali> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Ksutf3L6hV1WOIdx" Content-Disposition: inline In-Reply-To: <20221216001307.f5boephkfrb3cfpo@pali> X-Clacks-Overhead: GNU Terry Pratchett X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean --Ksutf3L6hV1WOIdx Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 16, 2022 at 01:13:07AM +0100, Pali Roh=E1r wrote: > On Thursday 15 December 2022 06:24:16 Simon Glass wrote: > > Hi Eugen, > >=20 > > On Thu, 15 Dec 2022 at 03:58, Eugen Hristev wrote: > > > > > > Newer DTC require that the DTB start address is aligned at 8 bytes. > > > In the u-boot.bin case, the u-boot-nodtb.bin is concatenated with the > > > DTB, but there is no alignment/padding to the next 8byte aligned addr= ess. > > > This causes the board to fail booting, because the FDT will claim > > > that the DTB inside u-boot.bin is not a valid DTB, it will fail with > > > -FDT_ERR_ALIGNMENT. > > > To solve this, have the u-boot binary `_end` aligned with 8 bytes. > > > The objcopy in the Makefile will create the u-boot-nodtb.bin and it h= as to > > > be truncated to 8 bytes to correspond to the u-boot.map file which wi= ll > > > have the `_end` aligned to 8 bytes. > > > The lds files which use devicetrees have been changed to align the `_= end` > > > tag with 8 bytes. > > > > > > This patch is also a prerequisite to have the possibility to update t= he > > > dtc inside u-boot to newer versions (1.6.1+) > > > > > > Signed-off-by: Eugen Hristev > > > --- > > > Hi, > > > > > > I could not test all affected boards, it's an impossible task. > > > I tried this on at91 boards which I have, and ran the CI on denx. > > > I cannot guarantee that no other boards are affected, so this patch i= s a bit > > > of an RFC. > > > If the u-boot-nodtb.bin does not have the size equal with the corresp= onding > > > one in u-boot.map, the binary_size_check will fail at build time with > > > something like this: > > > > > > u-boot.map shows a binary size of 502684 > > > but u-boot-nodtb.bin shows 502688 > > > > > > Thanks, > > > Eugen > > > > > > Makefile | 2 ++ > > > arch/arm/cpu/armv8/u-boot.lds | 4 ++-- > > > arch/arm/cpu/u-boot-spl.lds | 1 + > > > arch/arm/cpu/u-boot.lds | 1 + > > > arch/arm/lib/elf_arm_efi.lds | 5 +++++ > > > arch/arm/mach-at91/arm926ejs/u-boot-spl.lds | 2 +- > > > arch/arm/mach-at91/armv7/u-boot-spl.lds | 2 +- > > > arch/arm/mach-zynq/u-boot-spl.lds | 2 +- > > > arch/mips/cpu/u-boot.lds | 2 +- > > > arch/sandbox/cpu/u-boot.lds | 6 ++++++ > > > arch/sh/cpu/u-boot.lds | 2 ++ > > > board/ti/am335x/u-boot.lds | 1 + > > > tools/binman/test/u_boot_binman_embed.lds | 2 +- > > > 13 files changed, 25 insertions(+), 7 deletions(-) > > > > > > diff --git a/Makefile b/Makefile > > > index 9d84f96481..b4d387bcce 100644 > > > --- a/Makefile > > > +++ b/Makefile > > > @@ -1317,6 +1317,8 @@ endif > > > > > > u-boot-nodtb.bin: u-boot FORCE > > > $(call if_changed,objcopy_uboot) > > > +# Make sure the size is 8 byte-aligned. > > > + @truncate -s %8 $@ > > > $(BOARD_SIZE_CHECK) > >=20 > > I agree this line is needed, since otherwise we will only get 4-byte > > alignment. >=20 > Hello! I do not fully agree that this line is needed. >=20 > The whole issue is about DTB binary and its offset. So code/Makefile > which construct u-boot.bin should be fixed and not u-boot-nodtb.bin. We should indeed not force u-boot-nodtb.bin itself to be an 8 byte aligned size, yes. > > But it would be better if we could have the linker scripts > > fill bytes out to the required alignment. Is that possible? >=20 > I already investigated this. LD linker and objcopy (at least older > version in Debian 10) drops trailing zero bytes in raw binary output. >=20 > You can specify zero bytes in the linker script and they are filled in > ELF or COFF output. But not in raw binary, which u-boot.bin is. >=20 > So it could be possible to extract "correct" size from ELF binary and > call truncate on raw binary generated from objcopy. >=20 >=20 >=20 > I already hit this trailing-zeros issue for powerpc and I fixed it in: > 7696b80ec5e9 powerpc: mpc85xx: Fix loading U-Boot proper from SD card in = SPL > b898f6a6db76 powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support for NOR boo= ting > e8c0e0064c8a powerpc: mpc85xx: Fix CONFIG_OF_SEPARATE support >=20 > All those commits re-align output to just 4 bytes, not more. This however needs a follow-up. By spec, device tree binaries must start at an 8 byte aligned address, not 4. Yes, 4 is clearly functional in this case, but when we update to a newer libdtc that finally enforces this check we'll have a problem. --=20 Tom --Ksutf3L6hV1WOIdx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmOkfKIACgkQFHw5/5Y0 tyxGEgv/c9oLUd9Mv5xQMLF5SGLZJbR5xatqYH3io++wKBv1SZcinb87FfctSWEF 63s8nlEQYsbwtDwmwBn5w7QRRi8m3O6Mjpf+twxwFaw7kM6uAfp3Fzuf+VWYqQ6q OtH4Vjbs6DQOrLEgzOUSJ7p6mBm2htXRKEyZbgT2CfHVeGiJXNWEYfUK3Uc7Rtop 1OV9c7uoSWIiZMBRNFAtbek+SZIh4kYwSCJ+ARCJnSq/dxpBCQFi8Y+3gX7Vt1x2 0FTwDIG0ltO/RcFgeKTSjtAUCyunnDD6DbhgF2Wd5ypha0aDZStJrL2iJzQ9utx5 I0CDzB/qj7T1NNgctwf5KZo1w2ivlzsByp/NrBwQtB880Wnj0Cx2l6ofwoRvN7hh VqBjF/WArg0AfvHM65EV7hKiASKkHopKIj5I6C9ecJ/IC7ZzEC0NdiPZP7dp5Duw NzmXdKjmjcZit0MJVKQ2P7QZcCcaFz2ifCqFGttYKUcnHIfKRo6wp5g5O6iOKt6r 13UwVMRU =agjH -----END PGP SIGNATURE----- --Ksutf3L6hV1WOIdx--