From 599138cf9e90876393b3609c144f85bf887b0e12 Mon Sep 17 00:00:00 2001 From: Jianyong Wu Date: Wed, 5 Jul 2023 09:49:30 +0000 Subject: [PATCH] aarch64: Increase size of EFI payload In order to support the requirements of a larger GRUB binary extend the size of the memory used for loading the payload. Since the payload address is hardcoded to a location in RAM below that of where the RHF binary is loaded increase adjust the ram_min constant to handle that. This does not require any VMM changes as the load address in the PE binary will reflect this change. Fixes: #261 Signed-off-by: Jianyong Wu --- aarch64-unknown-none.ld | 17 ++++++++++++++--- src/arch/aarch64/ram64.s | 24 +++++++++++++----------- src/main.rs | 9 +++++++++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/aarch64-unknown-none.ld b/aarch64-unknown-none.ld index 31d1b681..2cbab38c 100644 --- a/aarch64-unknown-none.ld +++ b/aarch64-unknown-none.ld @@ -4,9 +4,17 @@ ENTRY(ram64_start) DRAM: [0x4000_0000-0xfc00_0000] FDT: [0x4000_0000-0x401f_ffff) ACPI: [0x4020_0000-0x403f_ffff) - kernel: [0x4048_0000-] - The stack start is at the end of the DRAM region. */ -ram_min = 0x40480000; + payload:[0x4040_0000-0x405f_ffff) + RHF: [0x40600000-] + Assuming 2MB is enough to load payload. + The stack start is at the end of the RHF region. */ +ram_min = 0x40600000; + +/* This value must be identical with arch::aarch64::layout::map::dram::KERNEL_START. */ +PAYLOAD_START = 0x40400000; + +efi_image_size = rhf_end - ram_min; +efi_image_offset = ram_min - PAYLOAD_START; SECTIONS { @@ -41,4 +49,7 @@ SECTIONS *(.symtab) *(.strtab) } + + . = ALIGN(4K); + rhf_end = .; } diff --git a/src/arch/aarch64/ram64.s b/src/arch/aarch64/ram64.s index 93e28e63..53bc055a 100644 --- a/src/arch/aarch64/ram64.s +++ b/src/arch/aarch64/ram64.s @@ -3,6 +3,8 @@ .section .text.boot, "ax" .global ram64_start +.global efi_image_size +.global efi_image_offset ram64_start: /* @@ -11,18 +13,18 @@ ram64_start: * * [1] https://docs.kernel.org/arm64/booting.html#call-the-kernel-image */ - add x13, x18, #0x16 /* code0: UEFI "MZ" signature magic instruction */ - b jump_to_rust /* code1 */ + add x13, x18, #0x16 /* code0: UEFI "MZ" signature magic instruction */ + b jump_to_rust /* code1 */ - .quad 0 /* text_offset */ - .quad 0 /* image_size */ - .quad 0 /* flags */ - .quad 0 /* res2 */ - .quad 0 /* res3 */ - .quad 0 /* res4 */ + .quad efi_image_offset /* text_offset */ + .quad efi_image_size /* image_size */ + .quad 0 /* flags */ + .quad 0 /* res2 */ + .quad 0 /* res3 */ + .quad 0 /* res4 */ - .long 0x644d5241 /* "ARM\x64" magic number */ - .long 0 /* res5 */ + .long 0x644d5241 /* "ARM\x64" magic number */ + .long 0 /* res5 */ .align 3 jump_to_rust: @@ -34,4 +36,4 @@ jump_to_rust: mov sp, x30 /* x0: pointer to device tree */ - b rust64_start \ No newline at end of file + b rust64_start diff --git a/src/main.rs b/src/main.rs index ed37984f..4e0b2f05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,9 @@ use core::panic::PanicInfo; #[cfg(target_arch = "x86_64")] use x86_64::instructions::hlt; +#[cfg(target_arch = "aarch64")] +use crate::arch::aarch64::layout::code_range; + #[macro_use] mod serial; @@ -132,6 +135,12 @@ fn boot_from_device(device: &mut block::VirtioBlockDevice, info: &dyn bootinfo:: } }; + #[cfg(target_arch = "aarch64")] + if code_range().start < (info.kernel_load_addr() + size) as usize { + log!("Error Boot Image is too large"); + return false; + } + log!("Executable loaded"); efi::efi_exec(entry_addr, load_addr, size, info, &f, device); true