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 4998AC4332F for ; Wed, 21 Dec 2022 21:49:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0E7BE85215; Wed, 21 Dec 2022 22:49:32 +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="sUBUzzjc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 57E60851EF; Wed, 21 Dec 2022 22:49:30 +0100 (CET) Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) (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 CC0DE8521D for ; Wed, 21 Dec 2022 22:49:25 +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-qv1-xf34.google.com with SMTP id mn15so34517qvb.13 for ; Wed, 21 Dec 2022 13:49:25 -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=4CWo4cqwGbgX4aqorra4/QqRhW+WQcJ/0GbQDJiY0eI=; b=sUBUzzjcJwBqNt96tvpixJK9HTNBMeJf9uh3/abIMY+JybwO9mgGSxYvfVrkcY01n7 6FqXmKNGM4J5L6x7LH5hbUAPFuxe+Ju4ePCB8llPJf1HMLRUFUw1r33QFhwneCFZRU3z wriem6soLy59foH6j6+AcJ7Tji+oJe+b3DvbI= 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=4CWo4cqwGbgX4aqorra4/QqRhW+WQcJ/0GbQDJiY0eI=; b=dT2claaBRvVuBj9mu6F51iMJ52PUipfHm7JFHzZX+pEFLWIJlxz1uiHcNDigtIvBo/ Zbez3Z8HoEFNf4+bq0eF40Fe4DkgXJaxC2or9pIjYD3dUki8SYWTqIzU3eoTn7GBCZ3z B+jBYw8wsEXP7eVjTi6vZ87g1G4v7DCsIrWrsN6MesfXN+FR/qANJtwH8aZEfl/ktKPS 74SOqdPFjoAgpehZf2im6+EimobPG24aDKOsGnjvCqDcbkcA7nsP2t+6NeUI32UHZHHt cu1Gf2YGQplqfiPWlDERdIECKnFP4iXETYPRRozDD/Qj9huDpdaR8Fgtc+bBA0olYPzi EZFw== X-Gm-Message-State: AFqh2krfJH+kP/e6Jox5Lo2bEdruTCWmZy5yYdtqDQD2bFydWLtJoydo +thkI1+0TIBhtrEdZ5pm1ODYWw== X-Google-Smtp-Source: AMrXdXtvN05I+2FilHvtGWGYYkSHyHjrfhDu8P1VbQWU4n2l/chsoinrK08sVWUQ7gnCWanNQoJlrw== X-Received: by 2002:a05:6214:c6c:b0:51e:4235:7ce6 with SMTP id t12-20020a0562140c6c00b0051e42357ce6mr6222119qvj.46.1671659364585; Wed, 21 Dec 2022 13:49:24 -0800 (PST) Received: from bill-the-cat (2603-6081-7b00-6400-24f0-bc4b-7894-230e.res6.spectrum.com. [2603:6081:7b00:6400:24f0:bc4b:7894:230e]) by smtp.gmail.com with ESMTPSA id 195-20020a370ccc000000b006fec1c0754csm11326627qkm.87.2022.12.21.13.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 13:49:24 -0800 (PST) Date: Wed, 21 Dec 2022 16:49:22 -0500 From: Tom Rini To: Simon Glass Cc: Eugen.Hristev@microchip.com, 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: <20221221214922.GZ3787616@bill-the-cat> References: <20221215115825.827111-1-eugen.hristev@microchip.com> <96fa811a-8810-01b0-c414-de852740bad8@microchip.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="A579NarwkBnoihWA" Content-Disposition: inline In-Reply-To: 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 --A579NarwkBnoihWA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Dec 15, 2022 at 07:00:51AM -0800, Simon Glass wrote: > Hi Eugen, >=20 > On Thu, 15 Dec 2022 at 06:37, wrote: > > > > On 12/15/22 16:24, Simon Glass wrote: > > > Hi Eugen, > > > > > > 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 add= ress. > > >> 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 = has to > > >> be truncated to 8 bytes to correspond to the u-boot.map file which w= ill > > >> 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 = the > > >> 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 = is a bit > > >> of an RFC. > > >> If the u-boot-nodtb.bin does not have the size equal with the corres= ponding > > >> 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) > > > > > > I agree this line is needed, since otherwise we will only get 4-byte > > > alignment. But it would be better if we could have the linker scripts > > > fill bytes out to the required alignment. Is that possible? > > > > > > Reviewed-by: Simon Glass > > > > > > Regards, > > > Simon > > > > > > Hi Simon, > > > > I tried to check the objcopy option --pad-to , to use it at the time of > > objcopy, but this requires a real number to be passed to it. > > And this number could only be found by inspecting the u-boot.map file, > > since u-boot-nodtb.bin still does not exist. > > And if we pad to the size specified in u-boot.map, then > > binary_size_check does not make much sense anymore, as we will basically > > use the same information to fit the file, and it will always pass with a > > success. (even if we would pad many more bytes than 4 ) > > Hence it would lose it's purpose ( binary_size_check ), which I think > > was created to make sure no objects were lost when doing objcopy and > > creating the u-boot-nodtb.bin file. >=20 > Yes, I was more thinking of something like: >=20 > fill { > . =3D ALIGN(8); > QUAD(0) > }; >=20 > in the link script, or something that actually writes the padding bytes. >=20 > > > > On a side note, do you think I covered all the implied lds files ? I > > would hate to break someone's boards. >=20 > If CI passes you should be able to rely on the binary size check. >=20 > > > > And also, P.S. : I would require to have the same change when building a > > FIT image with mkimage... all subimages inside a FIT must be aligned to > > 8 bytes. However mkimage only aligns the start address and header of the > > FIT (-B option). Out of your knowledge, is this possible and where could > > I have a look to do this change ? >=20 > I lean towards the view that this 8-byte alignment is a bad idea. I'm still working my way through this thread, but, the 8-byte requirement is hard, real, and has really been a forever-and-ever requirement. It wasn't enforced for a very long time and so various other problems cropped up over the years (the whole "dtb isn't aligned, so we need to do unaligned safe slow reads on everything" thread may ring a bell). So, please, this has been on my TODO-again list for a while, so I'm glad it was picked up by Eugen here, and whatever our final form here takes, it does need to start with "8-byte alignment is required". --=20 Tom --A579NarwkBnoihWA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmOjf14ACgkQFHw5/5Y0 tywEUAwAmKCU0PAA37e605Vw0CFW5pV4Df4E7hQm7t6ssQMNaJ+pHhMFhDZc0/KA sikLDa1OHjiMx0YwvgDDHSe9MqfvFmfOGB5TfO5HNr+GhHAYCrl2aXSW5ZEiEsAQ QHwyEzNtODDe0TA5PwV7J57skXGeHgTRnqqmJBrs+2evdL8g/SER+j4hfbPOofxV ZxfMkWUAG2mL2KT3+1paUpkt/q8iFzZdMFCeNGC8JYXfs6DMWTFBLxfV8L08t/bg Skuj7HphfPi6O7hcSMiN8eJd1FVKLX8Ub4Q65M/Ws6ABx+0xhJHfYARGAyc2Ws6n 6PIqUjwJE4HVtsO+TJVuK8LsaMyqf9chPxrfr9iVGk7W0tXisnHeiScnm2+ixOCY YD4PE3dA5598kfJ19wp/5FVLcxXvTA3qpWd9SUWBNN2PtV5ExZzkJA4rBvhoRs0j 2xIskClF1YdrWyrdQSDcRgQdQHcZmK/VttAXljkSyRec73vN1oPeY2vsKaCVZi40 qHsZh8II =Id1Z -----END PGP SIGNATURE----- --A579NarwkBnoihWA--