From: "Bjørn Mork" <bjorn@mork.no>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
Frank Rowand <frowand.list@gmail.com>
Subject: Re: [PATCH] MIPS: vmlinux.lds.S: align raw appended dtb to 8 bytes
Date: Mon, 08 Mar 2021 14:45:57 +0100 [thread overview]
Message-ID: <878s6xbvxm.fsf@miraculix.mork.no> (raw)
In-Reply-To: <20210308125348.GA7976@alpha.franken.de> (Thomas Bogendoerfer's message of "Mon, 8 Mar 2021 13:53:49 +0100")
[-- Attachment #1: Type: text/plain, Size: 3014 bytes --]
Thomas Bogendoerfer <tsbogend@alpha.franken.de> writes:
> I see
>
> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> index c1c345be04ff..4b4e39b7c79b 100644
> --- a/arch/mips/kernel/vmlinux.lds.S
> +++ b/arch/mips/kernel/vmlinux.lds.S
> @@ -145,6 +145,7 @@ SECTIONS
> }
>
> #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
> + STRUCT_ALIGN();
> .appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
> *(.appended_dtb)
> KEEP(*(.appended_dtb))
> @@ -172,6 +173,7 @@ SECTIONS
> #endif
>
> #ifdef CONFIG_MIPS_RAW_APPENDED_DTB
> + STRUCT_ALIGN();
> __appended_dtb = .;
> /* leave space for appended DTB */
> . += 0x100000;
>
> in that patch, and IMHO this does align the appended_dtb. What do I miss ?
I'll not pretend I know anything about this subject, so feel free to
adjust as necessary.
The problem with that patch is that it doesn't pad the image to the
aligment. So you can't do
cat my.dtb >> arch/mips/boot/vmlinux.bin
anymore. This used to work before commit 79edff12060f.
This is an image build with that patch and an initramfs:
bjorn@canardo:/usr/local/src/build-tmp/linux$ ls -l arch/mips/boot/vmlinux.bin
-rwxr-xr-x 1 bjorn src 15724964 Mar 8 14:21 arch/mips/boot/vmlinux.bin
So that's aligned to 4 bytes, because it's terminated by the 32bit
length of the initramfs:
15724964/8
1965620.50000000000000000000
Building with the attached patch results in:
bjorn@canardo:/usr/local/src/build-tmp/linux$ ls -l arch/mips/boot/vmlinux.bin
-rwxr-xr-x 1 bjorn src 15724992 Mar 8 14:29 arch/mips/boot/vmlinux.bin
Which is aligned to the 32 bytes expected after STRUCT_ALIGN():
15724992/8
1965624.00000000000000000000
The tail of the image shows the cpio trailer and cpio length
(0x0061f400) followed by enough padding to align an appended DTB to 32
bytes:
bjorn@canardo:/usr/local/src/build-tmp/linux$ ls -l arch/mips/boot/vmlinux.bin
-rwxr-xr-x 1 bjorn src 15724992 Mar 8 14:29 arch/mips/boot/vmlinux.bin
bjorn@canardo:/usr/local/src/build-tmp/linux$ hexdump -C arch/mips/boot/vmlinux.bin|tail
00eff090 30 30 30 30 30 30 30 30 30 31 30 30 30 30 30 30 |0000000001000000|
00eff0a0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 |0000000000000000|
*
00eff0d0 30 42 30 30 30 30 30 30 30 30 54 52 41 49 4c 45 |0B00000000TRAILE|
00eff0e0 52 21 21 21 00 00 00 00 00 00 00 00 00 00 00 00 |R!!!............|
00eff0f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00eff1a0 00 61 f4 00 00 00 00 00 00 00 00 00 00 00 00 00 |.a..............|
00eff1b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00eff1c0
Yes, you can always pad the image yourself if you know about this
alignment requirement. But it gets more complicated. And it breaks my
home grown hackish build script. I know I'm not the only one...
Bjørn
[-- Attachment #2: 0001-MIPS-vmlinux.lds.S-fill-vmlinux.bin-to-DTB-alignment.patch --]
[-- Type: text/x-diff, Size: 1085 bytes --]
From c1bd611ae62db46db12d86196cade2613a291400 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= <bjorn@mork.no>
Date: Mon, 8 Mar 2021 14:24:17 +0100
Subject: [PATCH] MIPS: vmlinux.lds.S: fill vmlinux.bin to DTB alignment
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Padding the binary to the required alignment for raw appended
DTBs so that it is possible to append one without detailed
knowledge of this requirement.
Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
arch/mips/kernel/vmlinux.lds.S | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 4b4e39b7c79b..1f98947fe715 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -173,7 +173,11 @@ SECTIONS
#endif
#ifdef CONFIG_MIPS_RAW_APPENDED_DTB
- STRUCT_ALIGN();
+ .fill : {
+ FILL(0);
+ BYTE(0);
+ STRUCT_ALIGN();
+ }
__appended_dtb = .;
/* leave space for appended DTB */
. += 0x100000;
--
2.20.1
next prev parent reply other threads:[~2021-03-08 13:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-07 18:23 [PATCH] MIPS: vmlinux.lds.S: align raw appended dtb to 8 bytes Bjørn Mork
2021-03-08 10:55 ` Thomas Bogendoerfer
2021-03-08 11:10 ` Bjørn Mork
2021-03-08 12:53 ` Thomas Bogendoerfer
2021-03-08 13:45 ` Bjørn Mork [this message]
2021-03-08 17:47 ` Thomas Bogendoerfer
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=878s6xbvxm.fsf@miraculix.mork.no \
--to=bjorn@mork.no \
--cc=frowand.list@gmail.com \
--cc=linux-mips@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=tsbogend@alpha.franken.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