diff options
author | Zhaofeng Li <hello@zhaofeng.li> | 2021-09-13 20:51:39 -0700 |
---|---|---|
committer | Simon Horman <horms@verge.net.au> | 2021-09-14 13:21:47 +0200 |
commit | 4f8d667fc52375494db6d7413a0b15411d102e60 (patch) | |
tree | a8cbf182148fe7984564e727aeffe3c08d01a970 /kexec | |
parent | bfaebfb3ac740345eafda251a871638014983ba7 (diff) |
multiboot2: Correct MBI size calculation
tag_load_base_addr is dependent on rel_tag, and tag_framebuffer was
not accounted for.
Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
Signed-off-by: Simon Horman <horms@verge.net.au>
Diffstat (limited to 'kexec')
-rw-r--r-- | kexec/arch/i386/kexec-mb2-x86.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/kexec/arch/i386/kexec-mb2-x86.c b/kexec/arch/i386/kexec-mb2-x86.c index b4996bc..6bbe35e 100644 --- a/kexec/arch/i386/kexec-mb2-x86.c +++ b/kexec/arch/i386/kexec-mb2-x86.c @@ -115,17 +115,26 @@ void multiboot2_x86_usage(void) static size_t multiboot2_get_mbi_size(int ranges, int cmdline_size, int modcount, int modcmd_size) { - return (2 * sizeof (uint32_t) + sizeof (struct multiboot_tag) - + sizeof (struct multiboot_tag) + size_t mbi_size; + + mbi_size = (2 * sizeof (uint32_t) /* u32 total_size, u32 reserved */ + ALIGN_UP (sizeof (struct multiboot_tag_basic_meminfo), MULTIBOOT_TAG_ALIGN) + ALIGN_UP ((sizeof (struct multiboot_tag_mmap) + ranges * sizeof (struct multiboot_mmap_entry)), MULTIBOOT_TAG_ALIGN) - + ALIGN_UP (sizeof (struct multiboot_tag_load_base_addr), MULTIBOOT_TAG_ALIGN) + (sizeof (struct multiboot_tag_string) + ALIGN_UP (cmdline_size, MULTIBOOT_TAG_ALIGN)) + (sizeof (struct multiboot_tag_string) + ALIGN_UP (strlen(BOOTLOADER " " BOOTLOADER_VERSION) + 1, MULTIBOOT_TAG_ALIGN)) - + (modcount * sizeof (struct multiboot_tag_module) + modcmd_size)); + + (modcount * sizeof (struct multiboot_tag_module) + modcmd_size)) + + sizeof (struct multiboot_tag); /* end tag */ + + if (mhi.rel_tag) + mbi_size += ALIGN_UP (sizeof (struct multiboot_tag_load_base_addr), MULTIBOOT_TAG_ALIGN); + + if (mhi.fb_tag) + mbi_size += ALIGN_UP (sizeof (struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN); + + return mbi_size; } static void multiboot2_read_header_tags(void) |