Skip to content

Commit 599138c

Browse files
jongwuretrage
authored andcommitted
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 <[email protected]>
1 parent 9308ff7 commit 599138c

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

aarch64-unknown-none.ld

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ ENTRY(ram64_start)
44
DRAM: [0x4000_0000-0xfc00_0000]
55
FDT: [0x4000_0000-0x401f_ffff)
66
ACPI: [0x4020_0000-0x403f_ffff)
7-
kernel: [0x4048_0000-]
8-
The stack start is at the end of the DRAM region. */
9-
ram_min = 0x40480000;
7+
payload:[0x4040_0000-0x405f_ffff)
8+
RHF: [0x40600000-]
9+
Assuming 2MB is enough to load payload.
10+
The stack start is at the end of the RHF region. */
11+
ram_min = 0x40600000;
12+
13+
/* This value must be identical with arch::aarch64::layout::map::dram::KERNEL_START. */
14+
PAYLOAD_START = 0x40400000;
15+
16+
efi_image_size = rhf_end - ram_min;
17+
efi_image_offset = ram_min - PAYLOAD_START;
1018

1119
SECTIONS
1220
{
@@ -41,4 +49,7 @@ SECTIONS
4149
*(.symtab)
4250
*(.strtab)
4351
}
52+
53+
. = ALIGN(4K);
54+
rhf_end = .;
4455
}

src/arch/aarch64/ram64.s

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
.section .text.boot, "ax"
55
.global ram64_start
6+
.global efi_image_size
7+
.global efi_image_offset
68

79
ram64_start:
810
/*
@@ -11,18 +13,18 @@ ram64_start:
1113
*
1214
* [1] https://docs.kernel.org/arm64/booting.html#call-the-kernel-image
1315
*/
14-
add x13, x18, #0x16 /* code0: UEFI "MZ" signature magic instruction */
15-
b jump_to_rust /* code1 */
16+
add x13, x18, #0x16 /* code0: UEFI "MZ" signature magic instruction */
17+
b jump_to_rust /* code1 */
1618

17-
.quad 0 /* text_offset */
18-
.quad 0 /* image_size */
19-
.quad 0 /* flags */
20-
.quad 0 /* res2 */
21-
.quad 0 /* res3 */
22-
.quad 0 /* res4 */
19+
.quad efi_image_offset /* text_offset */
20+
.quad efi_image_size /* image_size */
21+
.quad 0 /* flags */
22+
.quad 0 /* res2 */
23+
.quad 0 /* res3 */
24+
.quad 0 /* res4 */
2325

24-
.long 0x644d5241 /* "ARM\x64" magic number */
25-
.long 0 /* res5 */
26+
.long 0x644d5241 /* "ARM\x64" magic number */
27+
.long 0 /* res5 */
2628
.align 3
2729

2830
jump_to_rust:
@@ -34,4 +36,4 @@ jump_to_rust:
3436
mov sp, x30
3537

3638
/* x0: pointer to device tree */
37-
b rust64_start
39+
b rust64_start

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use core::panic::PanicInfo;
1616
#[cfg(target_arch = "x86_64")]
1717
use x86_64::instructions::hlt;
1818

19+
#[cfg(target_arch = "aarch64")]
20+
use crate::arch::aarch64::layout::code_range;
21+
1922
#[macro_use]
2023
mod serial;
2124

@@ -132,6 +135,12 @@ fn boot_from_device(device: &mut block::VirtioBlockDevice, info: &dyn bootinfo::
132135
}
133136
};
134137

138+
#[cfg(target_arch = "aarch64")]
139+
if code_range().start < (info.kernel_load_addr() + size) as usize {
140+
log!("Error Boot Image is too large");
141+
return false;
142+
}
143+
135144
log!("Executable loaded");
136145
efi::efi_exec(entry_addr, load_addr, size, info, &f, device);
137146
true

0 commit comments

Comments
 (0)