Skip to contentSkip to conversation

ARM: verify size of zImage

PATCH New Russell King 4 participants 5 messages Nov 28, 2017 – Dec 12, 2017 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: verify size of zImage

The linker can sometimes add additional sections to the zImage ELF file which results in the zImage binary being larger than expected. This causes appended DT blobs to fail.

Verify that the zImage binary is the expected size, and fail the build if this is not the case.

---
As this patch is different, I've dropped Matthias' tested-by. I'd appreciate a replacement, thanks. Also, I seem to remember that Ard's toolchain was giving issues - maybe this alternative will finally resolve them.

 arch/arm/boot/compressed/vmlinux.lds.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/compressed/vmlinux.lds.S +7 -0
index e6bf6774c4bb..ed53ca9f482e 100644
@@ -101,6 +101,12 @@ SECTIONS
    * this symbol allows further debug in the near future.
    */
   .image_end (NOLOAD) : {
+    /*
+     * EFI requires that the image is aligned to 512 bytes, and appended
+     * DTB requires that we know where the end of the image is.  Ensure
+     * that both are satisfied by ensuring that there are no additional
+     * sections emitted into the decompressor image.
+     */
     _edata_real = .;
   }
 
@@ -128,3 +134,4 @@ SECTIONS
   .stab.indexstr 0	: { *(.stab.indexstr) }
   .comment 0		: { *(.comment) }
 }
+ASSERT(_edata_real == _edata, "error: zImage file size is incorrect");
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 ARM: verify size of zImage

(+ Gregory)

Quoted 7 lines · Russell King

The linker can sometimes add additional sections to the zImage ELF file which results in the zImage binary being larger than expected. This causes appended DT blobs to fail.

Verify that the zImage binary is the expected size, and fail the build if this is not the case.

Quoted 7 lines

---
As this patch is different, I've dropped Matthias' tested-by. I'd appreciate a replacement, thanks. Also, I seem to remember that Ard's toolchain was giving issues - maybe this alternative will finally resolve them.

$ nm arch/arm/boot/compressed/vmlinux |grep _edata
007b8200 D _edata
007b8200 D _edata_real

although I don't remember seeing this fail. It think it may have been Gregory who was having these issues?

Quoted 28 lines
 arch/arm/boot/compressed/vmlinux.lds.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/compressed/vmlinux.lds.S +7 -1
index e6bf6774c4bb..ed53ca9f482e 100644
@@ -101,6 +101,12 @@ SECTIONS
    * this symbol allows further debug in the near future.
    */
   .image_end (NOLOAD) : {
+    /*
+     * EFI requires that the image is aligned to 512 bytes, and appended
+     * DTB requires that we know where the end of the image is.  Ensure
+     * that both are satisfied by ensuring that there are no additional
+     * sections emitted into the decompressor image.
+     */
     _edata_real = .;
   }
 
@@ -128,3 +134,4 @@ SECTIONS
   .stab.indexstr 0     : { *(.stab.indexstr) }
   .comment 0           : { *(.comment) }
 }
+ASSERT(_edata_real == _edata, "error: zImage file size is incorrect");
--

2.7.4

#2 lore raw

PATCH 1/1 ARM: verify size of zImage

Quoted 18 lines · Ard Biesheuvel

(+ Gregory)

Quoted 7 lines · Russell King

The linker can sometimes add additional sections to the zImage ELF file which results in the zImage binary being larger than expected. This causes appended DT blobs to fail.

Verify that the zImage binary is the expected size, and fail the build if this is not the case.

Quoted 7 lines

---
As this patch is different, I've dropped Matthias' tested-by. I'd appreciate a replacement, thanks. Also, I seem to remember that Ard's toolchain was giving issues - maybe this alternative will finally resolve them.

Quoted 8 lines
$ nm arch/arm/boot/compressed/vmlinux |grep _edata
007b8200 D _edata
007b8200 D _edata_real

although I don't remember seeing this fail. It think it may have been Gregory who was having these issues?

The failing case was with a few ld versions when we had:

	ASSERT(. == _edata, "error: zImage file size is incorrect");

in place of the _edata_real assignment. Yet, those very same linkers have shown that they set _edata_real to the same value as _edata.

I forget who had the problem, sorry.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up
#3 lore raw

PATCH 1/1 ARM: verify size of zImage

In reply to Ard Biesheuvel

Hi Ard,

Quoted 18 lines · Ard Biesheuvel

(+ Gregory)

Quoted 7 lines · Russell King

The linker can sometimes add additional sections to the zImage ELF file which results in the zImage binary being larger than expected. This causes appended DT blobs to fail.

Verify that the zImage binary is the expected size, and fail the build if this is not the case.

Quoted 7 lines

---
As this patch is different, I've dropped Matthias' tested-by. I'd appreciate a replacement, thanks. Also, I seem to remember that Ard's toolchain was giving issues - maybe this alternative will finally resolve them.

Quoted 8 lines
$ nm arch/arm/boot/compressed/vmlinux |grep _edata
007b8200 D _edata
007b8200 D _edata_real

although I don't remember seeing this fail. It think it may have been Gregory who was having these issues?

Thanks to remember me, I finally find time to test it, and with my setup I didn't have anymore issue while building it for a dtb append zImage for Armada XP:

Gregory

Quoted 31 lines
Quoted 31 lines


 arch/arm/boot/compressed/vmlinux.lds.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/compressed/vmlinux.lds.S +7 -1
index e6bf6774c4bb..ed53ca9f482e 100644
@@ -101,6 +101,12 @@ SECTIONS
    * this symbol allows further debug in the near future.
    */
   .image_end (NOLOAD) : {
+    /*
+     * EFI requires that the image is aligned to 512 bytes, and appended
+     * DTB requires that we know where the end of the image is.  Ensure
+     * that both are satisfied by ensuring that there are no additional
+     * sections emitted into the decompressor image.
+     */
     _edata_real = .;
   }
 
@@ -128,3 +134,4 @@ SECTIONS
   .stab.indexstr 0     : { *(.stab.indexstr) }
   .comment 0           : { *(.comment) }
 }
+ASSERT(_edata_real == _edata, "error: zImage file size is incorrect");
--

2.7.4

Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#4 lore raw

PATCH 1/1 ARM: verify size of zImage

Quoted 28 lines · Gregory CLEMENT

Hi Ard,

Quoted 24 lines · Ard Biesheuvel

(+ Gregory)

Quoted 7 lines · Russell King

The linker can sometimes add additional sections to the zImage ELF file which results in the zImage binary being larger than expected. This causes appended DT blobs to fail.

Verify that the zImage binary is the expected size, and fail the build if this is not the case.

Quoted 7 lines

---
As this patch is different, I've dropped Matthias' tested-by. I'd appreciate a replacement, thanks. Also, I seem to remember that Ard's toolchain was giving issues - maybe this alternative will finally resolve them.

$ nm arch/arm/boot/compressed/vmlinux |grep _edata
007b8200 D _edata
007b8200 D _edata_real
Quoted 9 lines
Quoted 2 lines

although I don't remember seeing this fail. It think it may have been Gregory who was having these issues?

Thanks to remember me, I finally find time to test it, and with my setup I didn't have anymore issue while building it for a dtb append zImage for Armada XP:

Thanks for confirming.