zImage-arm: get rid of static offset
Subsystems (2)
PATCH v2 1/1 zImage-arm: get rid of static offset
The code in arch/arm/kexec-zImage-arm.c currently enforces a hard limit on the maximum size a dtb blob can occupy. This limit is set to 32k, which is quite low for device tree blobs nowadays.
Get rid of this assumption, and calculate the added size dynamically. For this, we need to slurp in the dtb file earlier in order to determine its size, because the memory hole allocation for 'base' takes this size into account.
For ATAGs, we keep the current value of 32k, which should in fact be enough.
With this change in place, the 'DTB too large!' error message can go away. Successfully tested on a AM335x board.
---
v2 includes a fixup from Sven Neumann for ATAGs driven boards. The patch is in tested on a larger number of machines by now.
kexec/arch/arm/kexec-zImage-arm.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
kexec/arch/arm/kexec-zImage-arm.c +12 -11
@@ -282,7 +282,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, {unsigned long base;unsigned int atag_offset =0x1000 ;/* 4k offset from memory start */ -unsigned int offset =0x8000 ;/* 32k offset from memory start */ +unsigned int extra_size =0 ;const char *command_line;char *modified_cmdline =NULL ;off_t command_line_len;
@@ -360,6 +360,13 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, ramdisk_buf =slurp_file (ramdisk, &initrd_size); } +if (dtb_file) { + dtb_buf =slurp_file (dtb_file, &dtb_length); + extra_size =_ALIGN (dtb_length,getpagesize ()); + }else if (use_atags) { + extra_size =0x8000 ;/* 32k should be plenty for ATAGs */ + } +/* * If we are loading a dump capture kernel, we need to update kernel * command line and also add some additional segments.
@@ -398,7 +405,8 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, } base = start; }else { - base =locate_hole (info,len+offset,0 ,0 ,ULONG_MAX ,INT_MAX ); + base =locate_hole (info, len + extra_size,0 ,0 , +ULONG_MAX ,INT_MAX ); }if (base ==ULONG_MAX )
@@ -428,8 +436,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,* Read a user-specified DTB file. */ if (dtb_file) { - dtb_buf =slurp_file (dtb_file, &dtb_length); -if (fdt_check_header (dtb_buf) !=0 ) {fprintf (stderr,"Invalid FDT buffer.\n" );return -1 ;
@@ -452,11 +458,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,create_flatten_tree (&dtb_buf, &dtb_length, command_line); } -if (base + atag_offset + dtb_length > base + offset) { -fprintf (stderr,"DTB too large!\n" ); -return -1 ; - } -if (ramdisk) {add_segment (info, ramdisk_buf, initrd_size, initrd_base, initrd_size);
@@ -485,9 +486,9 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, dtb_offset, dtb_length); } -add_segment (info, buf, len, base + offset, len); +add_segment (info, buf, len, base + extra_size, len); - info->entry = (void *)base + offset; + info->entry = (void *)base + extra_size;return 0 ; }
Signature · 7 lines
1.9.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
AppliedQuoted 15 lines · Daniel Mack
The code in
arch/arm/kexec-zImage-arm.ccurrently enforces a hard limit on the maximum size a dtb blob can occupy. This limit is set to 32k, which is quite low for device tree blobs nowadays.Get rid of this assumption, and calculate the added size dynamically. For this, we need to slurp in the dtb file earlier in order to determine its size, because the memory hole allocation for 'base' takes this size into account.
For ATAGs, we keep the current value of 32k, which should in fact be enough.
With this change in place, the 'DTB too large!' error message can go away. Successfully tested on a AM335x board.
Quoted 6 lines
Signed-off-by Daniel Mack <[email protected]>[[email protected]: Fix ATAGs case]Reported-and-tested-by Sven Neumann <[email protected]>---
v2 includes a fixup from Sven Neumann for ATAGs driven boards. The patch is in tested on a larger number of machines by now.
Thanks, applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 16 lines · Simon Horman
Quoted 15 lines · Daniel Mack
The code in
arch/arm/kexec-zImage-arm.ccurrently enforces a hard limit on the maximum size a dtb blob can occupy. This limit is set to 32k, which is quite low for device tree blobs nowadays.Get rid of this assumption, and calculate the added size dynamically. For this, we need to slurp in the dtb file earlier in order to determine its size, because the memory hole allocation for 'base' takes this size into account.
For ATAGs, we keep the current value of 32k, which should in fact be enough.
With this change in place, the 'DTB too large!' error message can go away. Successfully tested on a AM335x board.
Quoted 9 lines
Quoted 6 lines
Signed-off-by Daniel Mack <[email protected]>[[email protected]: Fix ATAGs case]Reported-and-tested-by Sven Neumann <[email protected]>---
v2 includes a fixup from Sven Neumann for ATAGs driven boards. The patch is in tested on a larger number of machines by now.Thanks, applied.
After applying this patch, the second kernel on qemu never works. I have posted a patch on it to solve this problem:
[kexec-tools][PATCH] zImage-arm: bugfix: load kernel at TEXT_OFFSET
I think there must be some misunderstanding about "DTB too large!" problem. DTB is pasted after initrd by kexec, not before the kernel. See following figures:
When using DTB:
|<--- TEXT_OFFSET (0x8000) ------->| |<-- atags, DTB *is not here* ---->|<-- zImage -->|<-- initrd -->|<-- *DTB is here* -->|
When using ATAGS:
|<-- TEXT_OFFSET (0x8000) ->| |<-- 0x1000 --|<-- atags -->|<-- zImage -->|<-- initrd -->|
It seems the original code is incorrect:
if (base + atag_offset + dtb_length > base + offset) { // offset is TEXT_OFFSET
fprintf(stderr, "DTB too large!\n");
return -1;
}This code assumes dtb is loaded between atags_offset and zImage, can use only 28KiB memory, same as atags. However, dtb is loaded after initrd, no upper limit is taken place, so simply remove the above checking is enough. In my patch, I use locate_holes() to endure there is enough space for initrd and dtb.
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec