u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: eugen.hristev@microchip.com, u-boot@lists.denx.de,
	sjg@chromium.org, 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
Date: Wed, 21 Dec 2022 18:44:12 -0500	[thread overview]
Message-ID: <20221221234412.GE3787616@bill-the-cat> (raw)
In-Reply-To: <87k02k2vku.fsf@bloch.sibelius.xs4all.nl>

[-- Attachment #1: Type: text/plain, Size: 5507 bytes --]

On Thu, Dec 22, 2022 at 12:20:01AM +0100, Mark Kettenis wrote:
> > Date: Wed, 21 Dec 2022 18:09:10 -0500
> > From: Tom Rini <trini@konsulko.com>
> > 
> > On Wed, Dec 21, 2022 at 11:42:56PM +0100, Mark Kettenis wrote:
> > > > Date: Wed, 21 Dec 2022 16:56:37 -0500
> > > > From: Tom Rini <trini@konsulko.com>
> > > > 
> > > > On Sat, Dec 17, 2022 at 11:14:41PM +0100, Mark Kettenis wrote:
> > > > > > From: Eugen Hristev <eugen.hristev@microchip.com>
> > > > > > Date: Thu, 15 Dec 2022 13:58:25 +0200
> > > > > > 
> > > > > > 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 address.
> > > > > > 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 will
> > > > > > 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 <eugen.hristev@microchip.com>
> > > > > > ---
> > > > > > 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 corresponding
> > > > > > 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 $@
> > > > > 
> > > > > $ truncate
> > > > > ksh: truncate: not found
> > > > > 
> > > > > In other words: truncate(1) isn't a standard UNIX utility and not
> > > > > present on OpenBSD for example.  It isn't part of POSIX and therefore
> > > > > its usage is unportable.
> > > > > 
> > > > > Please find a different solution.
> > > > 
> > > > Ah yes. Can this perhaps be done with dd? A bit of looking around
> > > > suggests that this might be a portable way to truncate a file to say 512
> > > > bytes:
> > > > dd if=/dev/urandom of=testfile bs=1 count=500
> > > > dd if=/dev/null of=testfile bs=1 count=512
> > > > 
> > > > And then hexdump or whatever to see that the last 12 bytes are zero. Can
> > > > you please test this on OpenBSD?  We'll need some shell work to get
> > > > current byte size and make it 8-byte aligned, but that should be
> > > > portable at least.  Thanks!
> > > 
> > > Hi Tom,
> > > 
> > > That results on a file with zero bytes on OpenBSD... but also on
> > > Linux.  Did you intend to write something different?  I can't
> > > immediately come up with a way to do this with dd(1).
> > 
> > Ah, I typod that, sorry!  I meant (and just re-checked):
> > dd if=/dev/urandom of=testfile bs=1 count=500
> > dd if=/dev/null of=testfile bs=1 seek=512
> > 
> > Which here does:
> > $ dd if=/dev/urandom of=testfile bs=1 count=500
> > 500+0 records in
> > 500+0 records out
> > 500 bytes copied, 0.00641125 s, 78.0 kB/s
> > $ dd if=/dev/null of=testfile bs=1 seek=512
> > 0+0 records in
> > 0+0 records out
> > 0 bytes copied, 0.000358246 s, 0.0 kB/s
> > $ ls -l testfile
> > -rw-rw-r-- 1 trini trini 512 Dec 21 18:07 testfile
> > $ hexdump testfile | tail -n2
> > 00001f0 8cdd 300e 0000 0000 0000 0000 0000 0000
> > 0000200
> 
> That works here as well.

Great, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

      reply	other threads:[~2022-12-21 23:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-15 11:58 [PATCH] lds: align u-boot-nodtb with 8 bytes boundary Eugen Hristev
2022-12-15 14:24 ` Simon Glass
2022-12-15 14:36   ` Eugen.Hristev
2022-12-15 15:00     ` Simon Glass
2022-12-15 15:57       ` Michal Simek
2022-12-21 21:49       ` Tom Rini
2022-12-16  0:13   ` Pali Rohár
2022-12-17 21:40     ` Simon Glass
2022-12-17 22:04       ` Pali Rohár
2022-12-17 22:54         ` Pali Rohár
2022-12-17 23:59           ` Pali Rohár
2022-12-21 14:47             ` Eugen.Hristev
2022-12-21 22:06               ` Pali Rohár
2022-12-22 15:49     ` Tom Rini
2022-12-30 15:31       ` Pali Rohár
2022-12-30 17:51         ` Simon Glass
2022-12-30 18:11           ` Mark Kettenis
2022-12-30 19:00             ` Simon Glass
2022-12-17 22:14 ` Mark Kettenis
2022-12-21 21:56   ` Tom Rini
2022-12-21 22:42     ` Mark Kettenis
2022-12-21 23:09       ` Tom Rini
2022-12-21 23:20         ` Mark Kettenis
2022-12-21 23:44           ` Tom Rini [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221221234412.GE3787616@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=alpernebiyasak@gmail.com \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=eugen.hristev@microchip.com \
    --cc=marex@denx.de \
    --cc=mark.kettenis@xs4all.nl \
    --cc=michal.simek@amd.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).