Skip to content

Commit

Permalink
aarch64: enlarge memory range for grub loading
Browse files Browse the repository at this point in the history
For now, 0x40400000 ~ 0x40480000 is used for loading grub. But it may not
be enough sometime. Enlarge this area by movnge the ram_min to 0x40600000.
Thus there is 2M range for loading grub that is enough.

As PE loader will get image offset and size in the header to put it in the
right place, image header should also be updated.

Fixes: cloud-hypervisor#261
Signed-off-by: Jianyong Wu <[email protected]>
  • Loading branch information
jongwu committed Jul 17, 2023
1 parent 180d1bd commit c7f8b08
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions aarch64-unknown-none.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -41,4 +49,7 @@ SECTIONS
*(.symtab)
*(.strtab)
}

. = ALIGN(4K);
rhf_end = .;
}
8 changes: 5 additions & 3 deletions src/arch/aarch64/ram64.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

.section .text.boot, "ax"
.global ram64_start
.global efi_image_size
.global efi_image_offset

ram64_start:
/*
Expand All @@ -14,8 +16,8 @@ ram64_start:
add x13, x18, #0x16 /* code0: UEFI "MZ" signature magic instruction */
b jump_to_rust /* code1 */

.quad 0 /* text_offset */
.quad 0 /* image_size */
.quad efi_image_offset /* text_offset */
.quad efi_image_size /* image_size */
.quad 0 /* flags */
.quad 0 /* res2 */
.quad 0 /* res3 */
Expand All @@ -34,4 +36,4 @@ jump_to_rust:
mov sp, x30

/* x0: pointer to device tree */
b rust64_start
b rust64_start
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7f8b08

Please sign in to comment.