From: bones@secretlab.ca (John Bonesio)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv3] ARM:boot:device tree: Allow the device tree binary to be appended to zImage
Date: Thu, 24 Mar 2011 16:18:41 -0700 [thread overview]
Message-ID: <20110324231830.2586.7150.stgit@riker> (raw)
This patch provides the ability to boot using a device tree that is appended
to the raw binary zImage (e.g. cat zImage <filename>.dtb > zImage_w_dtb).
Signed-off-by: John Bonesio <bones@secretlab.ca>
---
arch/arm/Kconfig | 7 ++++
arch/arm/boot/compressed/head.S | 78 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 3 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 92bae09..3556aea 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1651,6 +1651,13 @@ config ZBOOT_ROM
Say Y here if you intend to execute your compressed kernel image
(zImage) directly from ROM or flash. If unsure, say N.
+config ARM_APPENDED_DTB
+ bool "Use appended device tree blob"
+ depends on OF && !ZBOOT_ROM
+ help
+ With this option, the boot code will look for a device tree binary
+ (dtb) appended to zImage.
+
config CMDLINE
string "Default kernel command string"
default ""
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 200625c..034a654 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -211,6 +211,61 @@ restart: adr r0, LC0
mov r10, r6
#endif
+ mov lr, #0 @ init lr (dtb size) to 0
+#ifdef CONFIG_ARM_APPENDED_DTB
+/*
+ * r0 = delta
+ * r2 = BSS start
+ * r3 = BSS end
+ * r4 = final kernel address
+ * r5 = start of this image
+ * r6 = _edata
+ * r7 = architecture ID
+ * r8 = atags/device tree pointer
+ * r9 = size of decompressed image
+ * r10 = end of this image, including bss/stack/malloc space if non XIP
+ * r11 = GOT start
+ * r12 = GOT end
+ *
+ * if there are device trees (dtb) appended to zImage, advance r10 so that the
+ * dtb data will get relocated along with the kernel if necessary.
+ */
+
+ ldr lr, [r6, #0]
+#ifndef __ARMEB__
+ ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
+#else
+ ldr r1, =0xd00dfeed
+#endif
+ cmp lr, r1
+ mov lr, #0 @ dtb not found, it's size is 0
+ bne dtb_check_done
+
+ mov r8, r6 @ use the appended device tree
+
+ /* Get the dtb's size */
+ ldr lr, [r6, #4]
+
+#ifndef __ARMEB__
+ /* convert lr (dtb size) to little endian */
+ eor r1, lr, lr, ror #16
+ bic r1, r1, #0x00ff0000
+ mov lr, lr, ror #8
+ eor lr, lr, r1, lsr #8
+#endif
+ /*
+ * dtb size rounded up to a multiple of 8 bytes so a
+ * misaligned GOT entry doesn't cause the end of the
+ * dtb binary to be overwritten.
+ */
+ add lr, lr, #7
+ bic lr, lr, #7
+
+ add r10, r10, lr
+ add r6, r6, lr
+dtb_check_done:
+#endif
+
/*
* Check to see if we will overwrite ourselves.
* r4 = final kernel address
@@ -271,8 +326,9 @@ wont_overwrite:
* r11 = GOT start
* r12 = GOT end
* sp = stack pointer
+ * lr = appended dtb size (0 if not present)
*/
- teq r0, #0
+ orrs r1, r0, lr
beq not_relocated
add r11, r11, r0
add r12, r12, r0
@@ -288,12 +344,28 @@ wont_overwrite:
/*
* Relocate all entries in the GOT table.
+ * Bump bss entries to _edata + dtb size
*/
1: ldr r1, [r11, #0] @ relocate entries in the GOT
- add r1, r1, r0 @ table. This fixes up the
- str r1, [r11], #4 @ C references.
+ add r1, r1, r0 @ This fixes up C references
+ cmp r1, r2 @ if entry >= bss_start &&
+ cmphs r3, r1 @ bss_end > entry
+ addhi r1, r1, lr @ entry += dtb size
+ str r1, [r11], #4 @ next entry
cmp r11, r12
blo 1b
+
+ /* bump our bss registers too */
+ add r2, r2, lr
+ add r3, r3, lr
+
+ /*
+ * bump the stack pinter
+ *
+ * If the linker script changes so the stack is not after
+ * the bss section, this code will be wrong.
+ */
+ add sp, sp, lr
#else
/*
WARNING: multiple messages have this Message-ID (diff)
From: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
nico-vtqb6HGKxmzR7s880joybQ@public.gmane.org
Cc: glikely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org
Subject: [PATCHv3] ARM:boot:device tree: Allow the device tree binary to be appended to zImage
Date: Thu, 24 Mar 2011 16:18:41 -0700 [thread overview]
Message-ID: <20110324231830.2586.7150.stgit@riker> (raw)
This patch provides the ability to boot using a device tree that is appended
to the raw binary zImage (e.g. cat zImage <filename>.dtb > zImage_w_dtb).
Signed-off-by: John Bonesio <bones-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
arch/arm/Kconfig | 7 ++++
arch/arm/boot/compressed/head.S | 78 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 3 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 92bae09..3556aea 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1651,6 +1651,13 @@ config ZBOOT_ROM
Say Y here if you intend to execute your compressed kernel image
(zImage) directly from ROM or flash. If unsure, say N.
+config ARM_APPENDED_DTB
+ bool "Use appended device tree blob"
+ depends on OF && !ZBOOT_ROM
+ help
+ With this option, the boot code will look for a device tree binary
+ (dtb) appended to zImage.
+
config CMDLINE
string "Default kernel command string"
default ""
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 200625c..034a654 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -211,6 +211,61 @@ restart: adr r0, LC0
mov r10, r6
#endif
+ mov lr, #0 @ init lr (dtb size) to 0
+#ifdef CONFIG_ARM_APPENDED_DTB
+/*
+ * r0 = delta
+ * r2 = BSS start
+ * r3 = BSS end
+ * r4 = final kernel address
+ * r5 = start of this image
+ * r6 = _edata
+ * r7 = architecture ID
+ * r8 = atags/device tree pointer
+ * r9 = size of decompressed image
+ * r10 = end of this image, including bss/stack/malloc space if non XIP
+ * r11 = GOT start
+ * r12 = GOT end
+ *
+ * if there are device trees (dtb) appended to zImage, advance r10 so that the
+ * dtb data will get relocated along with the kernel if necessary.
+ */
+
+ ldr lr, [r6, #0]
+#ifndef __ARMEB__
+ ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
+#else
+ ldr r1, =0xd00dfeed
+#endif
+ cmp lr, r1
+ mov lr, #0 @ dtb not found, it's size is 0
+ bne dtb_check_done
+
+ mov r8, r6 @ use the appended device tree
+
+ /* Get the dtb's size */
+ ldr lr, [r6, #4]
+
+#ifndef __ARMEB__
+ /* convert lr (dtb size) to little endian */
+ eor r1, lr, lr, ror #16
+ bic r1, r1, #0x00ff0000
+ mov lr, lr, ror #8
+ eor lr, lr, r1, lsr #8
+#endif
+ /*
+ * dtb size rounded up to a multiple of 8 bytes so a
+ * misaligned GOT entry doesn't cause the end of the
+ * dtb binary to be overwritten.
+ */
+ add lr, lr, #7
+ bic lr, lr, #7
+
+ add r10, r10, lr
+ add r6, r6, lr
+dtb_check_done:
+#endif
+
/*
* Check to see if we will overwrite ourselves.
* r4 = final kernel address
@@ -271,8 +326,9 @@ wont_overwrite:
* r11 = GOT start
* r12 = GOT end
* sp = stack pointer
+ * lr = appended dtb size (0 if not present)
*/
- teq r0, #0
+ orrs r1, r0, lr
beq not_relocated
add r11, r11, r0
add r12, r12, r0
@@ -288,12 +344,28 @@ wont_overwrite:
/*
* Relocate all entries in the GOT table.
+ * Bump bss entries to _edata + dtb size
*/
1: ldr r1, [r11, #0] @ relocate entries in the GOT
- add r1, r1, r0 @ table. This fixes up the
- str r1, [r11], #4 @ C references.
+ add r1, r1, r0 @ This fixes up C references
+ cmp r1, r2 @ if entry >= bss_start &&
+ cmphs r3, r1 @ bss_end > entry
+ addhi r1, r1, lr @ entry += dtb size
+ str r1, [r11], #4 @ next entry
cmp r11, r12
blo 1b
+
+ /* bump our bss registers too */
+ add r2, r2, lr
+ add r3, r3, lr
+
+ /*
+ * bump the stack pinter
+ *
+ * If the linker script changes so the stack is not after
+ * the bss section, this code will be wrong.
+ */
+ add sp, sp, lr
#else
/*
next reply other threads:[~2011-03-24 23:18 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-24 23:18 John Bonesio [this message]
2011-03-24 23:18 ` [PATCHv3] ARM:boot:device tree: Allow the device tree binary to be appended to zImage John Bonesio
2011-03-24 23:37 ` Nicolas Pitre
2011-03-24 23:37 ` Nicolas Pitre
2011-03-28 9:13 ` Shawn Guo
2011-03-28 9:13 ` Shawn Guo
2011-04-13 14:00 ` Tony Lindgren
2011-04-13 14:00 ` Tony Lindgren
2011-04-20 5:47 ` Shawn Guo
2011-04-20 5:47 ` Shawn Guo
2011-04-20 7:34 ` Shawn Guo
2011-04-20 7:34 ` Shawn Guo
2011-04-21 8:02 ` Tony Lindgren
2011-04-21 8:02 ` Tony Lindgren
2011-04-21 12:46 ` Tony Lindgren
2011-04-21 12:46 ` Tony Lindgren
2011-04-27 14:23 ` Tony Lindgren
2011-04-27 14:23 ` Tony Lindgren
2011-04-27 14:38 ` Tony Lindgren
2011-04-27 14:38 ` Tony Lindgren
2011-04-27 14:40 ` Nicolas Pitre
2011-04-27 14:40 ` Nicolas Pitre
2011-04-27 14:43 ` Tony Lindgren
2011-04-27 14:43 ` Tony Lindgren
2011-04-29 10:26 ` Tony Lindgren
2011-04-29 10:26 ` Tony Lindgren
2011-04-29 13:02 ` Grant Likely
2011-04-29 13:02 ` Grant Likely
2011-04-29 13:08 ` Grant Likely
2011-04-29 13:08 ` Grant Likely
2011-04-29 13:09 ` Tony Lindgren
2011-04-29 13:09 ` Tony Lindgren
2011-04-29 13:21 ` Nicolas Pitre
2011-04-29 13:21 ` Nicolas Pitre
2011-04-29 13:16 ` Nicolas Pitre
2011-04-29 13:16 ` Nicolas Pitre
2011-04-29 13:53 ` Russell King - ARM Linux
2011-04-29 13:53 ` Russell King - ARM Linux
2011-04-29 19:14 ` Nicolas Pitre
2011-04-29 19:14 ` Nicolas Pitre
2011-05-04 7:23 ` Tony Lindgren
2011-05-04 7:23 ` Tony Lindgren
2011-05-04 13:12 ` Tony Lindgren
2011-05-04 13:12 ` Tony Lindgren
2011-05-04 13:38 ` Nicolas Pitre
2011-05-04 13:38 ` Nicolas Pitre
2011-05-09 11:19 ` [PATCH] ARM: Make sure appended device tree data won't overlap kernel BSS Tony Lindgren
2011-05-09 11:19 ` Tony Lindgren
2011-05-09 14:49 ` Tony Lindgren
2011-05-09 14:49 ` Tony Lindgren
2011-05-12 12:59 ` Tony Lindgren
2011-05-12 12:59 ` Tony Lindgren
2011-05-13 7:39 ` Nicolas Pitre
2011-05-13 7:39 ` Nicolas Pitre
2011-05-13 11:21 ` Tony Lindgren
2011-05-13 11:21 ` Tony Lindgren
2011-05-13 13:09 ` Nicolas Pitre
2011-05-13 13:09 ` Nicolas Pitre
2011-05-13 13:28 ` Tony Lindgren
2011-05-13 13:28 ` Tony Lindgren
2011-06-07 12:43 ` Tony Lindgren
2011-06-07 12:43 ` Tony Lindgren
2011-06-07 13:14 ` Nicolas Pitre
2011-06-07 13:14 ` Nicolas Pitre
2011-06-07 13:22 ` Tony Lindgren
2011-06-07 13:22 ` Tony Lindgren
2011-06-12 6:14 ` Nicolas Pitre
2011-06-12 6:14 ` Nicolas Pitre
2011-06-13 10:49 ` Tony Lindgren
2011-06-13 10:49 ` Tony Lindgren
2011-05-09 11:23 ` [PATCHv3] ARM:boot:device tree: Allow the device tree binary to be appended to zImage Tony Lindgren
2011-05-09 11:23 ` Tony Lindgren
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=20110324231830.2586.7150.stgit@riker \
--to=bones@secretlab.ca \
--cc=linux-arm-kernel@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.