Skip to contentSkip to conversation

xen:arm: Populate arm64 image header

PATCH Superseded Amit Singh Tomar 2 participants 4 messages Sep 4, 2018 – Sep 5, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen:arm: Populate arm64 image header

This patch adds image size and flags to XEN image header. It uses those fields according to the updated Linux kernel image definition.

With this patch bootloader can now place XEN image anywhere in system RAM at 2MB aligned address without to worry about relocation.
For instance, it fixes the XEN boot on Amlogic SoC where bootloader(U-BOOT) always relocates the XEN image to an address range reserved for firmware data.

---
Changes since v1:
* Updated commit message
* Removed endianess code

---
 xen/arch/arm/arm64/head.S          | 5 +++--
 xen/arch/arm/arm64/lib/assembler.h | 9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/arm64/head.S +3 -2
index d63734f..8e35968 100644
@@ -25,6 +25,7 @@
 #include <asm/early_printk.h>
 #include <efi/efierr.h>
 #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
 
 #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */
 #define PT_MEM    0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */
@@ -120,8 +121,8 @@ efi_head:
         add     x13, x18, #0x16
         b       real_start           /* branch to kernel start */
         .quad   0                    /* Image load offset from start of RAM */
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */
+        .quad   __KERNEL_SIZE        /* Effective size of kernel image, little-endian */
+        .quad   __HEAD_FLAGS         /* Informative flags, little-endian */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
xen/arch/arm/arm64/lib/assembler.h +9 -0
index 3f9c0dc..7239c19 100644
@@ -9,4 +9,13 @@
 #define CPU_BE(x...)
 #define CPU_LE(x...) x
 
+#define __HEAD_FLAG_PAGE_SIZE   1 /* 4K hard-coded */
+
+#define __HEAD_FLAG_PHYS_BASE   1
+
+#define __HEAD_FLAGS            ((__HEAD_FLAG_PAGE_SIZE << 1) |  \
+                                (__HEAD_FLAG_PHYS_BASE << 3))
+
+#define __KERNEL_SIZE           (_end - start)
+
 #endif /* __ASM_ASSEMBLER_H__ */
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

Hi,

Quoted 7 lines · Amit Singh Tomar

This patch adds image size and flags to XEN image header. It uses those fields according to the updated Linux kernel image definition.

With this patch bootloader can now place XEN image anywhere in system RAM at 2MB aligned address without to worry about relocation.
For instance, it fixes the XEN boot on Amlogic SoC where bootloader(U-BOOT) always relocates the XEN image to an address range reserved for firmware data.

This message looks good to me now.

Quoted 23 lines

---
Changes since v1:
* Updated commit message
* Removed endianess code

---
 xen/arch/arm/arm64/head.S          | 5 +++--
 xen/arch/arm/arm64/lib/assembler.h | 9 +++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/arm64/head.S +1 -0
index d63734f..8e35968 100644
@@ -25,6 +25,7 @@
 #include <asm/early_printk.h>
 #include <efi/efierr.h>
 #include <asm/arm64/efibind.h>
+#include "lib/assembler.h"
 
 #define PT_PT     0xf7f /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=1 P=1 */
 #define PT_MEM    0xf7d /* nG=1 AF=1 SH=11 AP=01 NS=1 ATTR=111 T=0 P=1 */

xen/arch/arm/arm64/head.S efi_head: · line 124

Quoted 6 lines
xen/arch/arm/arm64/head.S +1 -2
@@ -120,8 +121,8 @@ efi_head:
         add     x13, x18, #0x16
         b       real_start           /* branch to kernel start */
         .quad   0                    /* Image load offset from start of RAM */
-        .quad   0                    /* reserved */
-        .quad   0                    /* reserved */
+        .quad   __KERNEL_SIZE        /* Effective size of kernel image, little-endian */

I don't think it's helpful to hide that KERNEL_SIZE definition in another file. Please just put "_end - start" here.

xen/arch/arm/arm64/head.S efi_head: · line 125

Quoted 1 line
xen/arch/arm/arm64/head.S +1 -0
+        .quad   __HEAD_FLAGS         /* Informative flags, little-endian */

and I don't see much sense either in having those defined in assembler.h, since it is only useful in this very file. So just have the definitions somewhere at the top of head.S.

xen/arch/arm/arm64/lib/assembler.h line 12

Quoted 12 lines
xen/arch/arm/arm64/head.S +0 -0
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
         .quad   0                    /* reserved */
xen/arch/arm/arm64/lib/assembler.h +1 -0
index 3f9c0dc..7239c19 100644
@@ -9,4 +9,13 @@
 #define CPU_BE(x...)
 #define CPU_LE(x...) x
 
+#define __HEAD_FLAG_PAGE_SIZE   1 /* 4K hard-coded */

Either you call this __HEAD_FLAG_PAGE_SIZE_4K, or, even better, copy the Linux definition, which would make it obvious where this comes from and would alert any developer of the PAGE_SIZE dependency.

Plus move those into head.S, as mentioned above.

Cheers,
Andre.

xen/arch/arm/arm64/lib/assembler.h line 21

Quoted 10 lines
xen/arch/arm/arm64/lib/assembler.h +8 -0
+
+#define __HEAD_FLAG_PHYS_BASE   1
+
+#define __HEAD_FLAGS            ((__HEAD_FLAG_PAGE_SIZE << 1) |  \
+                                (__HEAD_FLAG_PHYS_BASE << 3))
+
+#define __KERNEL_SIZE           (_end - start)
+
 #endif /* __ASM_ASSEMBLER_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw

Hello,

Thanks for having a look.

Quoted 5 lines · Andre Przywara

Hi,

I don't think it's helpful to hide that KERNEL_SIZE definition in another file. Please just put "_end - start" here.

Yeah, I thought about it and felt that it would be cleaner and more readable if we use macros here.

Also, wanted to have minimal changes in head.S and that is the reason for using assemble.h.

Quoted 5 lines

Either you call this __HEAD_FLAG_PAGE_SIZE_4K, or, even better, copy the Linux definition, which would make it obvious where this comes from and would alert any developer of the PAGE_SIZE dependency.

Plus move those into head.S, as mentioned above.

Ok.

Quoted 5 lines

xen/arch/arm/arm64/lib/assembler.h line 21

Quoted 5 lines
xen/arch/arm/arm64/lib/assembler.h +3 -0
+
+#define __KERNEL_SIZE           (_end - start)
+
 #endif /* __ASM_ASSEMBLER_H__ */

Thanks
-Amit

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Hi,

Quoted 6 lines · Amit Tomer

Hello,

Thanks for having a look.

Quoted 1 line · Andre Przywara
Quoted 7 lines
Quoted 4 lines

Hi,

I don't think it's helpful to hide that KERNEL_SIZE definition in another file. Please just put "_end - start" here.

Yeah, I thought about it and felt that it would be cleaner and more readable if we use macros here.

I don't see how this improves readability.
The point is that this line as is:

.quad __KERNEL_SIZE /* Effective size of kernel image, little-endian */

conveys only little information, basically you say that "kernel size is kernel size". I would rather see the actual definition of kernel size here, since the comment explains the meaning already.

Quoted 2 lines

Also, wanted to have minimal changes in head.S and that is the reason for using assemble.h.

assembler.h wouldn't be the right place anyway. AFAICT it's only there to make those files in lib/ happy, which are mostly copied from Linux.

Cheers,
Andre.

Quoted 7 lines
Quoted 5 lines

Either you call this __HEAD_FLAG_PAGE_SIZE_4K, or, even better, copy the Linux definition, which would make it obvious where this comes from and would alert any developer of the PAGE_SIZE dependency.

Plus move those into head.S, as mentioned above.

Ok.

Quoted 9 lines
Quoted 5 lines

xen/arch/arm/arm64/lib/assembler.h line 21

Quoted 5 lines
xen/arch/arm/arm64/lib/assembler.h +3 -0
+
+#define __KERNEL_SIZE           (_end - start)
+
 #endif /* __ASM_ASSEMBLER_H__ */

Thanks
-Amit

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel