Re: [PATCH 3/5] arm: decompressor: define a new zImage tag

From: Lukasz Stelmach
Date: Mon Jun 01 2020 - 12:20:08 EST


It was <2020-06-01 pon 15:55>, when Russell King - ARM Linux admin wrote:
> On Mon, Jun 01, 2020 at 04:27:52PM +0200, Åukasz Stelmach wrote:
>> Add DCSZ tag which holds dynamic memory (stack, bss, malloc pool)
>> requirements of the decompressor code.
>
> Why do we need to know the stack and BSS size, when the userspace
> kexec tool doesn't need to know this to perform the same function.


kexec-tools load zImage as low in DRAM as possible and rely on two
assumptions:

+ the zImage will copy itself to make enough room for the kernel,
+ sizeof(zImage+mem) < sizeof(kernel+mem), which is true because
of compression.

DRAM start
+ 0x8000

zImage |-----------|-----|-------|
text+data bss stack

text+data bss
kernel |---------------------|-------------------|


initrd |-initrd-|-dtb-|


My code on the other hand tries to load the zImage high enough to make
room for the kernel without copying the zImage.


text+data bss
kernel |-----------|-------------------|

zImage |-----------|-----|-------|
text+data bss stack

initrd |-initrd-|-dtb-|


In such case the second assumption would be

sizeof(zImage+mem) < sizeof(kernel bss)

and I can't tell for sure it would always be true. That is why we need
detailed information about decompressor memory requirements.


>>
>> Signed-off-by: Åukasz Stelmach <l.stelmach@xxxxxxxxxxx>
>> ---
>> arch/arm/boot/compressed/vmlinux.lds.S | 9 ++++++++-
>> arch/arm/include/asm/image.h | 13 +++++++++++++
>> 2 files changed, 21 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S
>> index 308e9cd6a897..dcfdb3209c90 100644
>> --- a/arch/arm/boot/compressed/vmlinux.lds.S
>> +++ b/arch/arm/boot/compressed/vmlinux.lds.S
>> @@ -39,6 +39,11 @@ SECTIONS
>> LONG(ARM_ZIMAGE_MAGIC3)
>> LONG(ZIMAGE_MAGIC(__piggy_size_addr - _start))
>> LONG(ZIMAGE_MAGIC(_kernel_bss_size))
>> + LONG(ZIMAGE_MAGIC(5))
>> + LONG(ARM_ZIMAGE_MAGIC4)
>> + LONG(ZIMAGE_MAGIC(_end - __bss_start))
>> + LONG(ZIMAGE_MAGIC(_stack_end - _stack_start))
>> + LONG(ZIMAGE_MAGIC(_malloc_size))
>> LONG(0)
>> _table_end = .;
>> }
>> @@ -108,10 +113,12 @@ SECTIONS
>> . = BSS_START;
>> __bss_start = .;
>> .bss : { *(.bss) }
>> + . = ALIGN(8); /* the stack must be 64-bit aligned and adjoin bss */
>> _end = .;
>>
>> - . = ALIGN(8); /* the stack must be 64-bit aligned */
>> + _stack_start = .;
>> .stack : { *(.stack) }
>> + _stack_end = .;
>>
>> PROVIDE(__pecoff_data_size = ALIGN(512) - ADDR(.data));
>> PROVIDE(__pecoff_end = ALIGN(512));
>> diff --git a/arch/arm/include/asm/image.h b/arch/arm/include/asm/image.h
>> index d5c18a0f6a34..624438740f23 100644
>> --- a/arch/arm/include/asm/image.h
>> +++ b/arch/arm/include/asm/image.h
>> @@ -15,6 +15,7 @@
>> #define ARM_ZIMAGE_MAGIC1 ZIMAGE_MAGIC(0x016f2818)
>> #define ARM_ZIMAGE_MAGIC2 (0x45454545)
>> #define ARM_ZIMAGE_MAGIC3 ZIMAGE_MAGIC(0x5a534c4b)
>> +#define ARM_ZIMAGE_MAGIC4 ZIMAGE_MAGIC(0x5a534344)
>>
>> #ifndef __ASSEMBLY__
>>
>> @@ -43,6 +44,18 @@ struct arm_zimage_tag {
>> } u;
>> };
>>
>> +struct arm_zimage_tag_dc {
>> + struct tag_header hdr;
>> + union {
>> +#define ZIMAGE_TAG_DECOMP_SIZE ARM_ZIMAGE_MAGIC4
>> + struct zimage_decomp_size {
>> + __le32 bss_size;
>> + __le32 stack_size;
>> + __le32 malloc_size;
>> + } decomp_size;
>> + } u;
>> +};
>> +
>> #endif /* __ASSEMBLY__ */
>>
>> #endif /* __ASM_IMAGE_H */
>> --
>> 2.26.2
>>
>>

--
Åukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

Attachment: signature.asc
Description: PGP signature