Skip to contentSkip to conversation

Support for device-tree appended to zImage

PATCH New John Bonesio 5 participants 15 messages Feb 28, 2011 – Mar 2, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

cover Support for device-tree appended to zImage

The following series support for device tree binary blobs (dtb) that are appended to the compressed kernel image (zImage).

Having appended dtb data is not required to boot with a device tree. If no dtb data is appended to zImage, the kernel will boot using prior methods.

---

John Bonesio (4):
ARM:boot:device tree: Allow the device tree binary to be appended to zImage ARM:boot:device tree: Merge specific atags into the device tree ARM:boot:device tree: Add puthex routine for use in the boot wrapper ARM:boot:device tree: Allow multiple device trees to be appended to zImage

 arch/arm/Kconfig                  |    7 ++
 arch/arm/boot/compressed/Makefile |   31 +++++++-
 arch/arm/boot/compressed/atags.c  |   70 +++++++++++++++++++
 arch/arm/boot/compressed/head.S   |  136 +++++++++++++++++++++++++++++++++++--
 arch/arm/boot/compressed/misc.c   |  134 ++++++++++++++++++++++++++++++++++++
 5 files changed, 365 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/boot/compressed/atags.c
Signature · 1 line
Signature
#1 lore raw

PATCH 1/4 ARM:boot:device tree: Allow the device tree binary to be appended to zImage

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).

---

 arch/arm/Kconfig                |    7 +++
 arch/arm/boot/compressed/head.S |   93 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 94 insertions(+), 6 deletions(-)
arch/arm/Kconfig +7 -0
index d8a330f..68fc640 100644
@@ -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
arch/arm/boot/compressed/head.S +87 -6

136 lines not on this page · raw message

#2 lore raw

PATCH 1/4 ARM:boot:device tree: Allow the device tree binary to be appended to zImage

Quoted 4 lines · John Bonesio

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).

Comments below.

Quoted 11 lines

---

 arch/arm/Kconfig                |    7 +++
 arch/arm/boot/compressed/head.S |   93 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 94 insertions(+), 6 deletions(-)
arch/arm/Kconfig +0 -0
index d8a330f..68fc640 100644

arch/arm/Kconfig config USE_OF · line 1598

Quoted 6 lines
arch/arm/Kconfig +3 -0
@@ -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

The default is n by default, so you don't need to mention it.

Also this should depend on OF (CONFIG_OF).

arch/arm/Kconfig config USE_OF · line 1600

Quoted 2 lines
arch/arm/Kconfig +2 -0
+       help
+         With this option, the boot code will look for a dtb bianry

s/bianry/binary/

Since this is an help text for people who might not have a clue about "dtb", it would be better to spell it out.

Quoted 43 lines
arch/arm/Kconfig +2 -0
+         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
arch/arm/boot/compressed/head.S +30 -0
index 200625c..ae9f8c6 100644
@@ -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

arch/arm/boot/compressed/head.S restart: adr r0, LC0 · line 252

Quoted 10 lines
arch/arm/boot/compressed/head.S +10 -0
+		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

Instead of clobbering r12, you could use lr instead.

The byte swap on the size should be done only if __ARMEB__ is not defined i.e. #ifndef __ARMEB__ ...

Also the DT signature should be endian aware.

Quoted 14 lines
arch/arm/boot/compressed/head.S +2 -2
 /*
  * 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
 
 /*

arch/arm/boot/compressed/head.S wont_overwrite: · line 316

Quoted 7 lines
arch/arm/boot/compressed/head.S +2 -2
@@ -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

Why?

Quoted 6 lines
arch/arm/boot/compressed/head.S +2 -0
+
+		add	r6, r6, r0
 		add	r11, r11, r0
 		add	r12, r12, r0
 

arch/arm/boot/compressed/head.S wont_overwrite: · line 339

Quoted 10 lines
arch/arm/boot/compressed/head.S +6 -0
@@ -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

This is wrong. You are going to displace the .bss pointers even if they don't need that in the case where no dtb was found. And if a dtb was found the displacement is going to be the size of the dtb _plus_ the size of the .bss_stack instead of only the dtb size.

At this point you should only keep track of the .bss displacement in addition to the delta offset in r0. And if both are equal to zero then skip over the fixup loop as before.

arch/arm/boot/compressed/head.S wont_overwrite: · line 349

Quoted 9 lines
arch/arm/boot/compressed/head.S +7 -0
 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;

The above would be much more elegant if written like this:

		cmp	r1, r2
		cmphs	r3, r1
		addhi	r1, r5

arch/arm/boot/compressed/head.S wont_overwrite: · line 360

Quoted 11 lines
arch/arm/boot/compressed/head.S +8 -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

This will always be true as this is within #ifndef CONFIG_ZBOOT_ROM.

Quoted 22 lines
arch/arm/boot/compressed/head.S +7 -1
 #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

arch/arm/boot/compressed/head.S not_relocated: mov r0, #0 · line 399

Quoted 10 lines
arch/arm/boot/compressed/head.S +10 -0
+ *   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

You should have updated r8 the moment you knew you have a valid dtb earlier instead of duplicating this test here.

Quoted 8 lines
arch/arm/boot/compressed/head.S +2 -1
+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
#3 lore raw

PATCH 1/4 ARM:boot:device tree: Allow the device tree binary to be appended to zImage

I have looked through, and I'm reworking the patch set. I have just one comment below.

- John

Quoted 166 lines · Nicolas Pitre
Quoted 4 lines · John Bonesio

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).

Comments below.

Quoted 11 lines

---

 arch/arm/Kconfig                |    7 +++
 arch/arm/boot/compressed/head.S |   93 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 94 insertions(+), 6 deletions(-)
arch/arm/Kconfig +0 -0
index d8a330f..68fc640 100644

arch/arm/Kconfig config USE_OF · line 1598

Quoted 6 lines
arch/arm/Kconfig +3 -0
@@ -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

The default is n by default, so you don't need to mention it.

Also this should depend on OF (CONFIG_OF).

arch/arm/Kconfig config USE_OF · line 1600

Quoted 2 lines
arch/arm/Kconfig +2 -0
+       help
+         With this option, the boot code will look for a dtb bianry

s/bianry/binary/

Since this is an help text for people who might not have a clue about "dtb", it would be better to spell it out.

Quoted 43 lines
arch/arm/Kconfig +2 -0
+         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
arch/arm/boot/compressed/head.S +30 -0
index 200625c..ae9f8c6 100644
@@ -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

arch/arm/boot/compressed/head.S restart: adr r0, LC0 · line 252

Quoted 10 lines
arch/arm/boot/compressed/head.S +10 -0
+		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

Instead of clobbering r12, you could use lr instead.

The byte swap on the size should be done only if __ARMEB__ is not defined i.e. #ifndef __ARMEB__ ...

Also the DT signature should be endian aware.

Quoted 14 lines
arch/arm/boot/compressed/head.S +2 -2
 /*
  * 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
 
 /*

arch/arm/boot/compressed/head.S wont_overwrite: · line 316

Quoted 7 lines
arch/arm/boot/compressed/head.S +2 -2
@@ -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

Why?

Quoted 6 lines
arch/arm/boot/compressed/head.S +2 -0
+
+		add	r6, r6, r0
 		add	r11, r11, r0
 		add	r12, r12, r0
 

arch/arm/boot/compressed/head.S wont_overwrite: · line 339

Quoted 10 lines
arch/arm/boot/compressed/head.S +6 -0
@@ -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

This is wrong. You are going to displace the .bss pointers even if they don't need that in the case where no dtb was found. And if a dtb was found the displacement is going to be the size of the dtb _plus_ the size of the .bss_stack instead of only the dtb size.

At this point you should only keep track of the .bss displacement in addition to the delta offset in r0. And if both are equal to zero then skip over the fixup loop as before.

arch/arm/boot/compressed/head.S wont_overwrite: · line 349

Quoted 9 lines
arch/arm/boot/compressed/head.S +7 -0
 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;

The above would be much more elegant if written like this:

		cmp	r1, r2
		cmphs	r3, r1
		addhi	r1, r5
Quoted 13 lines

arch/arm/boot/compressed/head.S wont_overwrite: · line 360

Quoted 11 lines
arch/arm/boot/compressed/head.S +8 -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

This will always be true as this is within #ifndef CONFIG_ZBOOT_ROM.

Right now sp will always be above r6. I thought it might be prudent to add the test in case the linker script changed and the stack was placed elsewhere. It might save someone a headache later.

Quoted 45 lines
Quoted 23 lines
arch/arm/boot/compressed/head.S +7 -1
 #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

arch/arm/boot/compressed/head.S not_relocated: mov r0, #0 · line 399

Quoted 10 lines
arch/arm/boot/compressed/head.S +10 -0
+ *   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

You should have updated r8 the moment you knew you have a valid dtb earlier instead of duplicating this test here.

Quoted 8 lines
arch/arm/boot/compressed/head.S +2 -1
+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
#4 lore raw

PATCH 1/4 ARM:boot:device tree: Allow the device tree binary to be appended to zImage

Quoted 8 lines · John Bonesio

I have looked through, and I'm reworking the patch set. I have just one comment below.

- John

Quoted 2 lines · Nicolas Pitre

On Mon, 28 Feb 2011, John Bonesio wrote:

[...]

Quoted 11 lines
Quoted 10 lines

arch/arm/boot/compressed/head.S wont_overwrite: · line 360

Quoted 8 lines
arch/arm/boot/compressed/head.S +8 -0
+
+		/* 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

This will always be true as this is within #ifndef CONFIG_ZBOOT_ROM.

Quoted 3 lines

Right now sp will always be above r6. I thought it might be prudent to add the test in case the linker script changed and the stack was placed elsewhere. It might save someone a headache later.

That's what comments are for. And if someone modifies the linker script without understanding the affected code then that someone deserves the pain.

Nicolas

#5 lore raw

PATCH 1/4 ARM:boot:device tree: Allow the device tree binary to be appended to zImage

In reply to Nicolas Pitre

Comment/question below.

Quoted 146 lines · Nicolas Pitre
Quoted 4 lines · John Bonesio

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).

Comments below.

Quoted 11 lines

---

 arch/arm/Kconfig                |    7 +++
 arch/arm/boot/compressed/head.S |   93 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 94 insertions(+), 6 deletions(-)
arch/arm/Kconfig +0 -0
index d8a330f..68fc640 100644

arch/arm/Kconfig config USE_OF · line 1598

Quoted 6 lines
arch/arm/Kconfig +3 -0
@@ -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

The default is n by default, so you don't need to mention it.

Also this should depend on OF (CONFIG_OF).

arch/arm/Kconfig config USE_OF · line 1600

Quoted 2 lines
arch/arm/Kconfig +2 -0
+       help
+         With this option, the boot code will look for a dtb bianry

s/bianry/binary/

Since this is an help text for people who might not have a clue about "dtb", it would be better to spell it out.

Quoted 43 lines
arch/arm/Kconfig +2 -0
+         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
arch/arm/boot/compressed/head.S +30 -0
index 200625c..ae9f8c6 100644
@@ -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

arch/arm/boot/compressed/head.S restart: adr r0, LC0 · line 252

Quoted 10 lines
arch/arm/boot/compressed/head.S +10 -0
+		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

Instead of clobbering r12, you could use lr instead.

The byte swap on the size should be done only if __ARMEB__ is not defined i.e. #ifndef __ARMEB__ ...

Also the DT signature should be endian aware.

Quoted 14 lines
arch/arm/boot/compressed/head.S +2 -2
 /*
  * 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
 
 /*

arch/arm/boot/compressed/head.S wont_overwrite: · line 316

Quoted 7 lines
arch/arm/boot/compressed/head.S +2 -2
@@ -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

Why?

Quoted 6 lines
arch/arm/boot/compressed/head.S +2 -0
+
+		add	r6, r6, r0
 		add	r11, r11, r0
 		add	r12, r12, r0
 

arch/arm/boot/compressed/head.S wont_overwrite: · line 339

Quoted 10 lines
arch/arm/boot/compressed/head.S +6 -0
@@ -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

This is wrong. You are going to displace the .bss pointers even if they don't need that in the case where no dtb was found. And if a dtb was found the displacement is going to be the size of the dtb _plus_ the size of the .bss_stack instead of only the dtb size.

Quoted 3 lines

At this point you should only keep track of the .bss displacement in addition to the delta offset in r0. And if both are equal to zero then skip over the fixup loop as before.

Maybe I'm not understanding correctly. I think that if there is an appended dtb, then there are sections like the code and data that needs to be adjusted by the old r0 value, while the bss and the stack need to be adjusted by the old r0 + dtb size.

If my understanding is right, then we can't just add the dtb size to r0 and adjust everything.

Am I missing something?

Quoted 75 lines

arch/arm/boot/compressed/head.S wont_overwrite: · line 349

Quoted 10 lines
arch/arm/boot/compressed/head.S +7 -0
 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;

The above would be much more elegant if written like this:

		cmp	r1, r2
		cmphs	r3, r1
		addhi	r1, r5

arch/arm/boot/compressed/head.S wont_overwrite: · line 360

Quoted 11 lines
arch/arm/boot/compressed/head.S +8 -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

This will always be true as this is within #ifndef CONFIG_ZBOOT_ROM.

Quoted 22 lines
arch/arm/boot/compressed/head.S +7 -1
 #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

arch/arm/boot/compressed/head.S not_relocated: mov r0, #0 · line 399

Quoted 10 lines
arch/arm/boot/compressed/head.S +10 -0
+ *   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

You should have updated r8 the moment you knew you have a valid dtb earlier instead of duplicating this test here.

Quoted 8 lines
arch/arm/boot/compressed/head.S +2 -1
+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
#6 lore raw

PATCH 1/4 ARM:boot:device tree: Allow the device tree binary to be appended to zImage

Quoted 22 lines · John Bonesio

Comment/question below.

Quoted 19 lines · Nicolas Pitre

arch/arm/boot/compressed/head.S wont_overwrite: · line 339

Quoted 11 lines · John Bonesio
arch/arm/boot/compressed/head.S +6 -0
@@ -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

This is wrong. You are going to displace the .bss pointers even if they don't need that in the case where no dtb was found. And if a dtb was found the displacement is going to be the size of the dtb _plus_ the size of the .bss_stack instead of only the dtb size.

Quoted 8 lines
Quoted 3 lines

At this point you should only keep track of the .bss displacement in addition to the delta offset in r0. And if both are equal to zero then skip over the fixup loop as before.

Maybe I'm not understanding correctly. I think that if there is an appended dtb, then there are sections like the code and data that needs to be adjusted by the old r0 value, while the bss and the stack need to be adjusted by the old r0 + dtb size.

Exact.

Quoted 2 lines

If my understanding is right, then we can't just add the dtb size to r0 and adjust everything.

indeed.

Quoted 1 line

Am I missing something?

Suppose that no dtb was found. In that case, r10 is still pointing to the top of the stack. So r5 will contain the size of .bss and the stack. Then you bump .bss pointers in the GOT by that size. If a dtb was found then r5 ends up with the size of the dtb plus .bss plus stack.

What I'm suggesting is that the size of the dtb be kept in a register of its own up to this point. That size can be 0 if none was found. If r0 == 0 and dtb_size == 0 then the whole GOT fixup can be skipped as it is done at the moment by branching to not_relocated.

Nicolas

#7 lore raw

PATCH 2/4 ARM:boot:device tree: Merge specific atags into the device tree

In reply to John Bonesio

This patch is to merge in key atags into the appended device tree. An appended device tree is where the zImage has a dtb binary appended at the end of it. The boot code looks for an appended device tree, then looks for a few key atags passed in by the bootloader.

The bootargs and memory size settings, if they exist, override existing values in the appended device tree. If these values don't currently exist in the appended device tree, they are added.

---

 arch/arm/boot/compressed/Makefile |   31 ++++++++++++++--
 arch/arm/boot/compressed/atags.c  |   70 +++++++++++++++++++++++++++++++++++++
 arch/arm/boot/compressed/head.S   |   15 ++++++++
 arch/arm/boot/compressed/misc.c   |   58 ++++++++++++++++++++++++++++++-
 4 files changed, 167 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/boot/compressed/atags.c
arch/arm/boot/compressed/Makefile +26 -5
index 9d328be..7a2fe22 100644
@@ -49,6 +49,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
 OBJS		+= head-shmobile.o
 endif
 
+ifeq ($(CONFIG_ARM_APPENDED_DTB),y)
+OBJS		+= atags.o libfdt.a 
+endif
+
 #
 # We now have a PIC decompressor implementation.  Decompressors running
 # from RAM should not define ZTEXTADDR.  Decompressors running directly
@@ -80,7 +84,9 @@ ORIG_CFLAGS := $(KBUILD_CFLAGS)
 KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
 endif
 
-EXTRA_CFLAGS  := -fpic -fno-builtin
+fdttree      := $(srctree)/scripts/dtc/libfdt
+
+EXTRA_CFLAGS  := -fpic -fno-builtin -I$(fdttree) -I$(obj)
 EXTRA_AFLAGS  := -Wa,-march=all
 
 # Provide size of uncompressed kernel to the decompressor via a linker symbol.
@@ -102,13 +108,28 @@ LDFLAGS_vmlinux += -X
 LDFLAGS_vmlinux += -T
 
 # For __aeabi_uidivmod
-lib1funcs = $(obj)/lib1funcs.o
+libfuncs = $(obj)/lib1funcs.o
 
-$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
-	$(call cmd,shipped)
+ifeq ($(CONFIG_ARM_APPENDED_DTB),y)
+# For memchr, memmove, etc
+libfuncs += $(obj)/memchr.o $(obj)/strchr.o $(obj)/memmove.o $(obj)/memzero.o
+endif
+
+
+libfdtheader := $(fdttree)/fdt.h $(fdttree)/libfdt.h $(fdttree)/libfdt_internal.h
+libfdtobj    := $(obj)/fdt.o $(obj)/fdt_ro.o $(obj)/fdt_wip.o $(obj)/fdt_sw.o $(obj)/fdt_rw.o $(obj)/fdt_strerror.o
+
+$(libfdtobj): $(obj)/%.o: $(srctree)/scripts/dtc/libfdt/%.c $(libfdtheader)
+	$(call cmd_cc_o_c)
+
+$(obj)/libfdt.a: $(libfdtobj)
+	$(AR) rcs $@ $^
+
+$(libfuncs): $(obj)/%.o: $(srctree)/arch/$(SRCARCH)/lib/%.S
+	$(call cmd_as_o_S)
 
 $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \
-	 	$(addprefix $(obj)/, $(OBJS)) $(lib1funcs) FORCE
+	 	$(addprefix $(obj)/, $(OBJS)) $(libfuncs) FORCE
 	$(call if_changed,ld)
 	@:
 
arch/arm/boot/compressed/atags.c new file +70 -0

70 lines not on this page · raw message

arch/arm/boot/compressed/head.S +15 -0
index ae9f8c6..c2cdc5f 100644
@@ -211,6 +211,7 @@ restart:	adr	r0, LC0
 		mov	r10, r6
 #endif
 #ifdef CONFIG_ARM_APPENDED_DTB
+#define MERGE_SPACE	1024
 /*
  *   r0  = delta
  *   r2  = BSS start
@@ -243,6 +244,8 @@ restart:	adr	r0, LC0
 		mov	r12, r12, ror #8
 		eor	r12, r12, r1, lsr #8
 
+		add	r12, r12, #MERGE_SPACE	@ extra space to merge in atags
+
 		add	r10, r10, r12
 		add	r6, r6, r12
 
@@ -338,6 +341,8 @@ wont_overwrite:
 		             	 		@ ... GOT entry doesn't
 		             	 		@ ... overwrite end of image
 
+		add	r5, r5, #MERGE_SPACE	@ extra space to merge in atags
+
 1:		ldr	r1, [r11, #0]		@ relocate entries in the GOT
 		add	r1, r1, r0		@ table.  This fixes up the
 		cmp	r1, r2
@@ -396,6 +401,16 @@ wont_overwrite:
 		cmp	r0, r1
 		bne	keep_atags
 
+#ifndef CONFIG_ZBOOT_ROM
+		ldr	r0, [r6, #4]
+		add	r0, r0, #MERGE_SPACE	
+		str	r0, [r6, #4]		@ increase device tree size
+
+		/* merge in some key atags into the dtb */
+		mov	r0, r6
+		mov	r1, r8
+		bl	dt_merge_atags
+#endif
 		mov	r8, r6			@ use the appended device tree
 keep_atags:
 #endif
arch/arm/boot/compressed/misc.c +56 -2

76 lines not on this page · raw message

#8 lore raw

PATCH 2/4 ARM:boot:device tree: Merge specific atags into the device tree

Quoted 10 lines · John Bonesio

This patch is to merge in key atags into the appended device tree. An appended device tree is where the zImage has a dtb binary appended at the end of it. The boot code looks for an appended device tree, then looks for a few key atags passed in by the bootloader.

The bootargs and memory size settings, if they exist, override existing values in the appended device tree. If these values don't currently exist in the appended device tree, they are added.

Is this really useful?

I understand this might be handy for testing purposes. But if your bootloader does ATAG only then your hardware is likely to have support in the kernel without device tree support just fine.

IOW I don't think this would be of much value in upstream.

Quoted 275 lines

---

 arch/arm/boot/compressed/Makefile |   31 ++++++++++++++--
 arch/arm/boot/compressed/atags.c  |   70 +++++++++++++++++++++++++++++++++++++
 arch/arm/boot/compressed/head.S   |   15 ++++++++
 arch/arm/boot/compressed/misc.c   |   58 ++++++++++++++++++++++++++++++-
 4 files changed, 167 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm/boot/compressed/atags.c
arch/arm/boot/compressed/Makefile +26 -5
index 9d328be..7a2fe22 100644
@@ -49,6 +49,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
 OBJS		+= head-shmobile.o
 endif
 
+ifeq ($(CONFIG_ARM_APPENDED_DTB),y)
+OBJS		+= atags.o libfdt.a 
+endif
+
 #
 # We now have a PIC decompressor implementation.  Decompressors running
 # from RAM should not define ZTEXTADDR.  Decompressors running directly
@@ -80,7 +84,9 @@ ORIG_CFLAGS := $(KBUILD_CFLAGS)
 KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
 endif
 
-EXTRA_CFLAGS  := -fpic -fno-builtin
+fdttree      := $(srctree)/scripts/dtc/libfdt
+
+EXTRA_CFLAGS  := -fpic -fno-builtin -I$(fdttree) -I$(obj)
 EXTRA_AFLAGS  := -Wa,-march=all
 
 # Provide size of uncompressed kernel to the decompressor via a linker symbol.
@@ -102,13 +108,28 @@ LDFLAGS_vmlinux += -X
 LDFLAGS_vmlinux += -T
 
 # For __aeabi_uidivmod
-lib1funcs = $(obj)/lib1funcs.o
+libfuncs = $(obj)/lib1funcs.o
 
-$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
-	$(call cmd,shipped)
+ifeq ($(CONFIG_ARM_APPENDED_DTB),y)
+# For memchr, memmove, etc
+libfuncs += $(obj)/memchr.o $(obj)/strchr.o $(obj)/memmove.o $(obj)/memzero.o
+endif
+
+
+libfdtheader := $(fdttree)/fdt.h $(fdttree)/libfdt.h $(fdttree)/libfdt_internal.h
+libfdtobj    := $(obj)/fdt.o $(obj)/fdt_ro.o $(obj)/fdt_wip.o $(obj)/fdt_sw.o $(obj)/fdt_rw.o $(obj)/fdt_strerror.o
+
+$(libfdtobj): $(obj)/%.o: $(srctree)/scripts/dtc/libfdt/%.c $(libfdtheader)
+	$(call cmd_cc_o_c)
+
+$(obj)/libfdt.a: $(libfdtobj)
+	$(AR) rcs $@ $^
+
+$(libfuncs): $(obj)/%.o: $(srctree)/arch/$(SRCARCH)/lib/%.S
+	$(call cmd_as_o_S)
 
 $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \
-	 	$(addprefix $(obj)/, $(OBJS)) $(lib1funcs) FORCE
+	 	$(addprefix $(obj)/, $(OBJS)) $(libfuncs) FORCE
 	$(call if_changed,ld)
 	@:
 
arch/arm/boot/compressed/atags.c new file +70 -0
new file mode 100644
index 0000000..d19d53d
@@ -0,0 +1,70 @@
+#include <stddef.h>
+#include <asm/byteorder.h>
+#include <asm/setup.h>
+#include <fdt.h>
+#include <libfdt.h>
+
+int dt_setprop(void *fdt, const char *node_path, const char *property,
+               uint32_t *val_array, int size)
+{
+	int offset;
+
+	offset = fdt_path_offset(fdt, node_path);
+	if (offset < 0)
+		return offset;
+
+	return fdt_setprop(fdt, offset, property, val_array, size);
+}
+
+int dt_setprop_string(void *fdt, const char *node_path,
+                      const char *property, const char *string)
+{
+	int offset;
+		
+	offset = fdt_path_offset(fdt, node_path);
+	if (offset < 0)
+		return offset;
+			
+	return fdt_setprop_string(fdt, offset, property, string);
+}
+
+int dt_setprop_cell(void *fdt, const char *node_path,
+                    const char *property, uint32_t val)
+{
+	int offset;
+
+	offset = fdt_path_offset(fdt, node_path);
+	if (offset < 0)
+		return offset;
+
+	return fdt_setprop_cell(fdt, offset, property, val);
+}
+
+void dt_merge_atags(void *dt,  void *ataglist)
+{
+	struct tag *atag = ataglist;
+	uint32_t mem_reg_property[2];
+	uint32_t initrd_start, initrd_size;
+	int rc;
+
+	while (atag && atag->hdr.tag != 0) {
+		if (atag->hdr.tag == ATAG_CMDLINE) {
+			dt_setprop_string(dt, "/chosen", "bootargs",
+			                  atag->u.cmdline.cmdline);
+		} else if (atag->hdr.tag == ATAG_MEM) {
+			mem_reg_property[0] = cpu_to_fdt32(atag->u.mem.start);
+			mem_reg_property[1] = cpu_to_fdt32(atag->u.mem.size);
+			dt_setprop(dt, "/memory", "reg", mem_reg_property,
+			           sizeof(mem_reg_property));
+		} else if (atag->hdr.tag == ATAG_INITRD2) {
+			initrd_start = atag->u.initrd.start;
+			initrd_size = atag->u.initrd.size;
+			dt_setprop_cell(dt, "/chosen", "linux,initrd-start",
+			                initrd_start);
+			dt_setprop_cell(dt, "/chosen", "linux,initrd-end",
+			                initrd_start + initrd_size);
+		}
+		atag = tag_next(atag);
+	}
+}
+
arch/arm/boot/compressed/head.S +15 -0
index ae9f8c6..c2cdc5f 100644
@@ -211,6 +211,7 @@ restart:	adr	r0, LC0
 		mov	r10, r6
 #endif
 #ifdef CONFIG_ARM_APPENDED_DTB
+#define MERGE_SPACE	1024
 /*
  *   r0  = delta
  *   r2  = BSS start
@@ -243,6 +244,8 @@ restart:	adr	r0, LC0
 		mov	r12, r12, ror #8
 		eor	r12, r12, r1, lsr #8
 
+		add	r12, r12, #MERGE_SPACE	@ extra space to merge in atags
+
 		add	r10, r10, r12
 		add	r6, r6, r12
 
@@ -338,6 +341,8 @@ wont_overwrite:
 		             	 		@ ... GOT entry doesn't
 		             	 		@ ... overwrite end of image
 
+		add	r5, r5, #MERGE_SPACE	@ extra space to merge in atags
+
 1:		ldr	r1, [r11, #0]		@ relocate entries in the GOT
 		add	r1, r1, r0		@ table.  This fixes up the
 		cmp	r1, r2
@@ -396,6 +401,16 @@ wont_overwrite:
 		cmp	r0, r1
 		bne	keep_atags
 
+#ifndef CONFIG_ZBOOT_ROM
+		ldr	r0, [r6, #4]
+		add	r0, r0, #MERGE_SPACE	
+		str	r0, [r6, #4]		@ increase device tree size
+
+		/* merge in some key atags into the dtb */
+		mov	r0, r6
+		mov	r1, r8
+		bl	dt_merge_atags
+#endif
 		mov	r8, r6			@ use the appended device tree
 keep_atags:
 #endif
arch/arm/boot/compressed/misc.c +56 -2
index e653a6d..2d4da4c 100644
@@ -29,7 +29,7 @@ unsigned int __machine_arch_type;
 #include <asm/unaligned.h>
 
 
-static void putstr(const char *ptr);
+void putstr(const char *ptr);
 extern void error(char *x);
 
 #include <mach/uncompress.h>
@@ -100,7 +100,7 @@ static void icedcc_putc(int ch)
 #define putc(ch)	icedcc_putc(ch)
 #endif
 
-static void putstr(const char *ptr)
+void putstr(const char *ptr)
 {
 	char c;
 
@@ -114,6 +114,60 @@ static void putstr(const char *ptr)
 }
 
 
+#ifdef CONFIG_ARM_APPENDED_DTB
+/**
+ * strlen - Find the length of a string
+ * @s: The string to be sized
+ */
+size_t strlen(const char *s)
+{
+        const char *sc;
+
+        for (sc = s; *sc != '\0'; ++sc)
+                /* nothing */;
+        return sc - s;
+}
+
+/**
+ * strcmp - Compare two strings
+ * @cs: One string
+ * @ct: Another string
+ */
+#undef strcmp
+int strcmp(const char *cs, const char *ct)
+{
+	unsigned char c1, c2;
+
+	while (1) {
+		c1 = *cs++;
+		c2 = *ct++;
+		if (c1 != c2)
+			return c1 < c2 ? -1 : 1;
+		if (!c1)
+			break;
+	}
+	return 0;
+}
+
+/**
+ * memcmp - Compare two areas of memory
+ * @cs: One area of memory
+ * @ct: Another area of memory
+ * @count: The size of the area.
+ */
+#undef memcmp
+int memcmp(const void *cs, const void *ct, size_t count)
+{
+	const unsigned char *su1, *su2;
+	int res = 0;
+
+	for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
+		if ((res = *su1 - *su2) != 0)
+			break;
+	return res;
+}
+#endif
+
 void *memcpy(void *__dest, __const void *__src, size_t __n)
 {
 	int i = 0;
#9 lore raw

PATCH 2/4 ARM:boot:device tree: Merge specific atags into the device tree

Quoted 13 lines · Nicolas Pitre
Quoted 10 lines · John Bonesio

This patch is to merge in key atags into the appended device tree. ?An appended device tree is where the zImage has a dtb binary appended at the end of it. The boot code looks for an appended device tree, then looks for a few key atags passed in by the bootloader.

The bootargs and memory size settings, if they exist, override existing values in the appended device tree. If these values don't currently exist in the appended device tree, they are added.

Quoted 7 lines

Is this really useful?

I understand this might be handy for testing purposes. ?But if your bootloader does ATAG only then your hardware is likely to have support in the kernel without device tree support just fine.

IOW I don't think this would be of much value in upstream.

That's fine. This feature was implemented to meet a client's requirement and to experiment with manipulating the .dtb in the zimage wrapper. We're posting it here for completeness if anyone else wants to play with it. Same for the last patch that allows appending multiple dtbs.

g.

#10 lore raw

PATCH 3/4 ARM:boot:device tree: Add puthex routine for use in the boot wrapper

In reply to John Bonesio

This patch adds a routine named 'puthex'. This allows the boot wraper code to display hex numbers.

---

 arch/arm/boot/compressed/misc.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
arch/arm/boot/compressed/misc.c +25 -0
index 2d4da4c..9af05ed 100644
@@ -113,6 +113,31 @@ void putstr(const char *ptr)
 	flush();
 }
 
+void puthex(unsigned i)
+{
+	unsigned rem;
+	char str[32];
+	int str_idx = sizeof(str) - 1;;
+
+	str[str_idx--] = '\0';
+	putstr("0x");
+	if (!i) {
+		putstr("0");
+	} else {
+		while (i) {
+			rem = i % 16;
+
+			if (rem < 10) {
+				str[str_idx--] = rem + '0';
+			} else {
+				str[str_idx--] = (rem - 10) + 'a';
+			}
+			i = i / 16;
+		}
+
+		putstr(&str[str_idx + 1]);
+	}
+}
 
 #ifdef CONFIG_ARM_APPENDED_DTB
 /**
#11 lore raw

PATCH 4/4 ARM:boot:device tree: Allow multiple device trees to be appended to zImage

In reply to John Bonesio

This patch allows mutliple device tree binaries to be appended to zImage. A device tree binary is selected when the 'machine_type' property in the root node in the dtb matches the machine type passed in by the boot loader.

If the device tree binary does not have the 'machine_type' property, the device tree is assumed to match the machine type. If no device tree binary matches, the kernel attempts to boot with out a device tree.

---

 arch/arm/boot/compressed/head.S |   30 ++++++++++++++++++++++-
 arch/arm/boot/compressed/misc.c |   51 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletions(-)
arch/arm/boot/compressed/head.S +29 -1
index c2cdc5f..f743431 100644
@@ -229,7 +229,7 @@ restart:	adr	r0, LC0
  * 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.
  */
-
+1:
 		ldr	r12, [r6, #0]
 		ldr	r1, =0xedfe0dd0		@ sig is 0xdoodfeed big endian
 		cmp	r12, r1
@@ -248,6 +248,7 @@ restart:	adr	r0, LC0
 
 		add	r10, r10, r12
 		add	r6, r6, r12
+		b	1b
 
 dtb_check_done:
 		adr	r1, LC0
@@ -396,11 +397,34 @@ wont_overwrite:
  *
  * if there is a device tree (dtb) appended to zImage, set up to use this dtb.
  */
+		mvn	r9, #0			@ r9 dtb search result
+		   	      			@ ... -1 = no appended dtb
+dt_search:
 		ldr	r0, [r6, #0]
 		ldr	r1, =0xedfe0dd0		@ sig is 0xdoodfeed big endian
 		cmp	r0, r1
 		bne	keep_atags
 
+		/* Get the dtb's size */
+		ldr	r5, [r6, #4]		@ device tree size
+
+		/* convert dtb size to little endian */
+		eor	r1, r5, r5, ror #16
+		bic	r1, r1, #0x00ff0000
+		mov	r5, r5, ror #8
+		eor	r5, r5, r1, lsr #8
+
+		mov	r0, r6
+		mov	r1, r7
+		bl	match_dt_machine_type
+		mov	r9, r0			@ save result
+		cmp	r0, #0
+		bne	dt_found
+
+		add	r6, r5
+		b	dt_search
+
+dt_found:
 #ifndef CONFIG_ZBOOT_ROM
 		ldr	r0, [r6, #4]
 		add	r0, r0, #MERGE_SPACE	
@@ -413,6 +437,10 @@ wont_overwrite:
 #endif
 		mov	r8, r6			@ use the appended device tree
 keep_atags:
+
+		mov	r0, r9
+		mov	r1, r7
+		bl	put_dt_match_str
 #endif
 /*
  * Set up some pointers, and start decompressing.
arch/arm/boot/compressed/misc.c +51 -0

63 lines not on this page · raw message

#12 lore raw

PATCH 4/4 ARM:boot:device tree: Allow multiple device trees to be appended to zImage

Quoted 1 line · John Bonesio

This patch allows mutliple device tree binaries to be appended to zImage.

Huh? Why would you do that?

Nicolas

#13 lore raw

cover Support for device-tree appended to zImage

In reply to John Bonesio

Hi John,

Quoted 15 lines · John Bonesio

The following series support for device tree binary blobs (dtb) that are appended to the compressed kernel image (zImage).

Having appended dtb data is not required to boot with a device tree. If no dtb data is appended to zImage, the kernel will boot using prior methods.

---

John Bonesio (4):
ARM:boot:device tree: Allow the device tree binary to be appended to zImage ARM:boot:device tree: Merge specific atags into the device tree ARM:boot:device tree: Add puthex routine for use in the boot wrapper ARM:boot:device tree: Allow multiple device trees to be appended to zImage

Quoted 8 lines
 arch/arm/Kconfig                  |    7 ++
 arch/arm/boot/compressed/Makefile |   31 +++++++-
 arch/arm/boot/compressed/atags.c  |   70 +++++++++++++++++++
 arch/arm/boot/compressed/head.S   |  136 +++++++++++++++++++++++++++++++++++--
 arch/arm/boot/compressed/misc.c   |  134 ++++++++++++++++++++++++++++++++++++
 5 files changed, 365 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/boot/compressed/atags.c

I'm trying to test and use it. But it does not apply against any tree that I can find, neither mainline nor Grant's tree. Need rebasing?

Signature · 2 lines
Regards,
Shawn
#14 lore raw

cover Support for device-tree appended to zImage

Hi Shawn,

I'm using Grant's tree with Nicolas Pitre's patch to the compressed image wrapper. His patches went out to the ARM list and I'm told they were accepted. These patches may not yet be in Grant's tree. These patches are titled:

[PATCH 1/2] ARM: improvements to compressed/head.S
[PATCH 2/2] ARM: remove the 4x expansion presumption while decompressing the kernel

Grant, is there a branch in your tree that people should be using, or should be they applying both sets of patches?

- John

Quoted 29 lines · Shawn Guo

Hi John,

Quoted 15 lines · John Bonesio

The following series support for device tree binary blobs (dtb) that are appended to the compressed kernel image (zImage).

Having appended dtb data is not required to boot with a device tree. If no dtb data is appended to zImage, the kernel will boot using prior methods.

---

John Bonesio (4):
ARM:boot:device tree: Allow the device tree binary to be appended to zImage ARM:boot:device tree: Merge specific atags into the device tree ARM:boot:device tree: Add puthex routine for use in the boot wrapper ARM:boot:device tree: Allow multiple device trees to be appended to zImage

Quoted 8 lines
 arch/arm/Kconfig                  |    7 ++
 arch/arm/boot/compressed/Makefile |   31 +++++++-
 arch/arm/boot/compressed/atags.c  |   70 +++++++++++++++++++
 arch/arm/boot/compressed/head.S   |  136 +++++++++++++++++++++++++++++++++++--
 arch/arm/boot/compressed/misc.c   |  134 ++++++++++++++++++++++++++++++++++++
 5 files changed, 365 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/boot/compressed/atags.c

I'm trying to test and use it. But it does not apply against any tree that I can find, neither mainline nor Grant's tree. Need rebasing?