From: bones@secretlab.ca (John Bonesio)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] ARM:boot:device tree: Allow the device tree binary to be appended to zImage
Date: Mon, 28 Feb 2011 15:33:27 -0800 [thread overview]
Message-ID: <20110228233327.24836.94530.stgit@riker> (raw)
In-Reply-To: <20110228233153.24836.24176.stgit@riker>
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 | 93 ++++++++++++++++++++++++++++++++++++---
2 files changed, 94 insertions(+), 6 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d8a330f..68fc640 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1593,6 +1593,13 @@ config USE_OF
help
Include support for flattened device tree machine descriptions.
+config ARM_APPENDED_DTB
+ bool "Use appended device tree blob" if OF
+ default n
+ help
+ With this option, the boot code will look for a dtb bianry
+ appended to zImage.
+
# Compressed boot loader in ROM. Yes, we really want to ask about
# TEXT and BSS so we preserve their values in the config files.
config ZBOOT_ROM_TEXT
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 200625c..ae9f8c6 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -210,6 +210,46 @@ restart: adr r0, LC0
*/
mov r10, r6
#endif
+#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 r12, [r6, #0]
+ ldr r1, =0xedfe0dd0 @ sig is 0xdoodfeed big endian
+ cmp r12, r1
+ bne dtb_check_done
+
+ /* Get the dtb's size */
+ ldr r12, [r6, #4] @ device tree size
+
+ /* convert r12 (dtb size) to little endian */
+ eor r1, r12, r12, ror #16
+ bic r1, r1, #0x00ff0000
+ mov r12, r12, ror #8
+ eor r12, r12, r1, lsr #8
+
+ add r10, r10, r12
+ add r6, r6, r12
+
+dtb_check_done:
+ adr r1, LC0
+ ldr r12, [r1, #28] @ restore r12 (GOT end)
+#endif
/*
* Check to see if we will overwrite ourselves.
@@ -223,8 +263,8 @@ restart: adr r0, LC0
*/
cmp r4, r10
bhs wont_overwrite
- add r10, r4, r9
- cmp r10, r5
+ add r1, r4, r9
+ cmp r1, r5
bls wont_overwrite
/*
@@ -272,8 +312,10 @@ wont_overwrite:
* r12 = GOT end
* sp = stack pointer
*/
- teq r0, #0
- beq not_relocated
+ adr r1, LC0
+ ldr r6, [r1, #16] @ reload _edata value
+
+ add r6, r6, r0
add r11, r11, r0
add r12, r12, r0
@@ -288,12 +330,34 @@ wont_overwrite:
/*
* Relocate all entries in the GOT table.
+ * Bump bss entries to past image end (r10)
*/
+ sub r5, r10, r6 @ delta of image end and _edata
+ add r5, r5, #7 @ ... rounded up to a multiple
+ bic r5, r5, #7 @ ... of 8 bytes, so misaligned
+ @ ... GOT entry doesn't
+ @ ... overwrite end of image
+
1: ldr r1, [r11, #0] @ relocate entries in the GOT
add r1, r1, r0 @ table. This fixes up the
+ cmp r1, r2
+ movcc r9, #0 @ r9 = entry < bss_start ? 0 :
+ movcs r9, #1 @ 1;
+ cmp r1, r3
+ movcs r9, #0 @ r9 = entry >= end ? 0 : t1;
+ cmp r9, #0
+ addne r1, r5 @ entry += r9 ? bss delta : 0;
str r1, [r11], #4 @ C references.
cmp r11, r12
blo 1b
+
+ /* bump our bss registers too */
+ add r2, r2, r5
+ add r3, r3, r5
+
+ /* bump the stack pinter, if at or above _edata */
+ cmp sp, r6
+ addcs sp, sp, r5
#else
/*
@@ -309,7 +373,7 @@ wont_overwrite:
blo 1b
#endif
-not_relocated: mov r0, #0
+ mov r0, #0
1: str r0, [r2], #4 @ clear bss
str r0, [r2], #4
str r0, [r2], #4
@@ -317,8 +381,25 @@ not_relocated: mov r0, #0
cmp r2, r3
blo 1b
+#ifdef CONFIG_ARM_APPENDED_DTB
+/*
+ * The C runtime environment should now be set up sufficiently.
+ * r4 = kernel execution address
+ * r6 = _edata
+ * r7 = architecture ID
+ * r8 = atags pointer
+ *
+ * if there is a device tree (dtb) appended to zImage, set up to use this dtb.
+ */
+ ldr r0, [r6, #0]
+ ldr r1, =0xedfe0dd0 @ sig is 0xdoodfeed big endian
+ cmp r0, r1
+ bne keep_atags
+
+ mov r8, r6 @ use the appended device tree
+keep_atags:
+#endif
/*
- * The C runtime environment should now be setup sufficiently.
* Set up some pointers, and start decompressing.
* r4 = kernel execution address
* r7 = architecture ID
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
Cc: glikely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org
Subject: [PATCH 1/4] ARM:boot:device tree: Allow the device tree binary to be appended to zImage
Date: Mon, 28 Feb 2011 15:33:27 -0800 [thread overview]
Message-ID: <20110228233327.24836.94530.stgit@riker> (raw)
In-Reply-To: <20110228233153.24836.24176.stgit@riker>
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 | 93 ++++++++++++++++++++++++++++++++++++---
2 files changed, 94 insertions(+), 6 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d8a330f..68fc640 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1593,6 +1593,13 @@ config USE_OF
help
Include support for flattened device tree machine descriptions.
+config ARM_APPENDED_DTB
+ bool "Use appended device tree blob" if OF
+ default n
+ help
+ With this option, the boot code will look for a dtb bianry
+ appended to zImage.
+
# Compressed boot loader in ROM. Yes, we really want to ask about
# TEXT and BSS so we preserve their values in the config files.
config ZBOOT_ROM_TEXT
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 200625c..ae9f8c6 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -210,6 +210,46 @@ restart: adr r0, LC0
*/
mov r10, r6
#endif
+#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 r12, [r6, #0]
+ ldr r1, =0xedfe0dd0 @ sig is 0xdoodfeed big endian
+ cmp r12, r1
+ bne dtb_check_done
+
+ /* Get the dtb's size */
+ ldr r12, [r6, #4] @ device tree size
+
+ /* convert r12 (dtb size) to little endian */
+ eor r1, r12, r12, ror #16
+ bic r1, r1, #0x00ff0000
+ mov r12, r12, ror #8
+ eor r12, r12, r1, lsr #8
+
+ add r10, r10, r12
+ add r6, r6, r12
+
+dtb_check_done:
+ adr r1, LC0
+ ldr r12, [r1, #28] @ restore r12 (GOT end)
+#endif
/*
* Check to see if we will overwrite ourselves.
@@ -223,8 +263,8 @@ restart: adr r0, LC0
*/
cmp r4, r10
bhs wont_overwrite
- add r10, r4, r9
- cmp r10, r5
+ add r1, r4, r9
+ cmp r1, r5
bls wont_overwrite
/*
@@ -272,8 +312,10 @@ wont_overwrite:
* r12 = GOT end
* sp = stack pointer
*/
- teq r0, #0
- beq not_relocated
+ adr r1, LC0
+ ldr r6, [r1, #16] @ reload _edata value
+
+ add r6, r6, r0
add r11, r11, r0
add r12, r12, r0
@@ -288,12 +330,34 @@ wont_overwrite:
/*
* Relocate all entries in the GOT table.
+ * Bump bss entries to past image end (r10)
*/
+ sub r5, r10, r6 @ delta of image end and _edata
+ add r5, r5, #7 @ ... rounded up to a multiple
+ bic r5, r5, #7 @ ... of 8 bytes, so misaligned
+ @ ... GOT entry doesn't
+ @ ... overwrite end of image
+
1: ldr r1, [r11, #0] @ relocate entries in the GOT
add r1, r1, r0 @ table. This fixes up the
+ cmp r1, r2
+ movcc r9, #0 @ r9 = entry < bss_start ? 0 :
+ movcs r9, #1 @ 1;
+ cmp r1, r3
+ movcs r9, #0 @ r9 = entry >= end ? 0 : t1;
+ cmp r9, #0
+ addne r1, r5 @ entry += r9 ? bss delta : 0;
str r1, [r11], #4 @ C references.
cmp r11, r12
blo 1b
+
+ /* bump our bss registers too */
+ add r2, r2, r5
+ add r3, r3, r5
+
+ /* bump the stack pinter, if at or above _edata */
+ cmp sp, r6
+ addcs sp, sp, r5
#else
/*
@@ -309,7 +373,7 @@ wont_overwrite:
blo 1b
#endif
-not_relocated: mov r0, #0
+ mov r0, #0
1: str r0, [r2], #4 @ clear bss
str r0, [r2], #4
str r0, [r2], #4
@@ -317,8 +381,25 @@ not_relocated: mov r0, #0
cmp r2, r3
blo 1b
+#ifdef CONFIG_ARM_APPENDED_DTB
+/*
+ * The C runtime environment should now be set up sufficiently.
+ * r4 = kernel execution address
+ * r6 = _edata
+ * r7 = architecture ID
+ * r8 = atags pointer
+ *
+ * if there is a device tree (dtb) appended to zImage, set up to use this dtb.
+ */
+ ldr r0, [r6, #0]
+ ldr r1, =0xedfe0dd0 @ sig is 0xdoodfeed big endian
+ cmp r0, r1
+ bne keep_atags
+
+ mov r8, r6 @ use the appended device tree
+keep_atags:
+#endif
/*
- * The C runtime environment should now be setup sufficiently.
* Set up some pointers, and start decompressing.
* r4 = kernel execution address
* r7 = architecture ID
next prev parent reply other threads:[~2011-02-28 23:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-28 23:33 [PATCH 0/4] Support for device-tree appended to zImage John Bonesio
2011-02-28 23:33 ` John Bonesio
2011-02-28 23:33 ` John Bonesio [this message]
2011-02-28 23:33 ` [PATCH 1/4] ARM:boot:device tree: Allow the device tree binary to be " John Bonesio
2011-03-01 6:39 ` Nicolas Pitre
2011-03-01 6:39 ` Nicolas Pitre
2011-03-02 1:41 ` John Bonesio
2011-03-02 1:41 ` John Bonesio
2011-03-02 2:37 ` Nicolas Pitre
2011-03-02 2:37 ` Nicolas Pitre
2011-03-02 2:13 ` John Bonesio
2011-03-02 2:13 ` John Bonesio
2011-03-02 2:57 ` Nicolas Pitre
2011-03-02 2:57 ` Nicolas Pitre
2011-02-28 23:33 ` [PATCH 2/4] ARM:boot:device tree: Merge specific atags into the device tree John Bonesio
2011-02-28 23:33 ` John Bonesio
2011-03-01 6:45 ` Nicolas Pitre
2011-03-01 6:45 ` Nicolas Pitre
2011-03-01 14:56 ` Grant Likely
2011-03-01 14:56 ` Grant Likely
2011-02-28 23:33 ` [PATCH 3/4] ARM:boot:device tree: Add puthex routine for use in the boot wrapper John Bonesio
2011-02-28 23:33 ` John Bonesio
2011-02-28 23:33 ` [PATCH 4/4] ARM:boot:device tree: Allow multiple device trees to be appended to zImage John Bonesio
2011-02-28 23:33 ` John Bonesio
2011-03-01 6:48 ` Nicolas Pitre
2011-03-01 6:48 ` Nicolas Pitre
2011-03-01 2:58 ` [PATCH 0/4] Support for device-tree " Shawn Guo
2011-03-01 2:58 ` Shawn Guo
2011-03-01 3:25 ` John Bonesio
2011-03-01 3:25 ` John Bonesio
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=20110228233327.24836.94530.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.