Skip to content

Commit bb492b0

Browse files
asdfugilSiguza
andcommitted
Load m1n1 at top of kernel data
m1n1 expects itself to be loaded below top of kernel data, so load it right at top of kernel data and then update top of kernel so that it is below top of kernel data. In particular, its memory allocator start at topOfKernelData and assumes all memory between that and physBase + memSize is free. More severely, the chainloading scripts will derive new topOfKernelData from the current m1n1, so the current approach of loading would actually cause chainloading to set topOfKernelData to near the end of memory, causing problems.m1n1 expects itself to be loaded below top of kernel data, so do it. Co-authored-by: Siguza <[email protected]> Signed-off-by: Nick Chan <[email protected]>
1 parent ce17354 commit bb492b0

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/drivers/xnu/xnu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,6 @@ void xnu_boot(void)
11271127
{
11281128
panic("Cannot boot XNU with TZ0 unlocked");
11291129
}*/
1130-
gBootArgs->topOfKernelData = gTopOfKernelData;
11311130
}
11321131

11331132
void xnu_init(void)

src/kernel/entry.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ __attribute__((noinline)) void pongo_entry_cached(void)
284284
screen_fill_basecolor();
285285
}
286286

287+
extern uint64_t gM1N1Base;
288+
287289
/*
288290
289291
Name: pongo_entry
@@ -309,25 +311,28 @@ _Noreturn void pongo_entry(uint64_t *kernel_args, void *entryp, void (*exit_to_e
309311
set_exception_stack_core0();
310312
gFramebuffer = (uint32_t*)gBootArgs->Video.v_baseAddr;
311313
lowlevel_cleanup();
314+
gBootArgs->topOfKernelData = gTopOfKernelData;
312315

313316
// Unused space above kernel static area
314317
void *boot_tramp = (void*)((gTopOfKernelData + 0x3fffULL) & ~0x3fffULL);
315318
if(gBootFlag == BOOT_FLAG_RAW || gBootFlag == BOOT_FLAG_M1N1)
316319
{
320+
uint64_t entry;
317321
// We're in EL1 here, but we might need to go back to EL3
318322
if((__builtin_arm_rsr64("id_aa64pfr0_el1") & 0xf000) != 0)
319323
{
320324
__asm__ volatile("smc 0"); // elevate to EL3
321325
}
322-
uint64_t entryOff = 0x800;
323326
if(gBootFlag == BOOT_FLAG_RAW)
324327
{
328+
entry = (uint64_t)loader_xfer_recv_data - kCacheableView + 0x800000000;
325329
boot_tramp = NULL;
326-
entryOff = 0;
327330
}
328-
// XXX: We should really replace loader_xfer_recv_data with something dedicated here.
329-
void *image = (void*)((uint64_t)loader_xfer_recv_data - kCacheableView + 0x800000000 + entryOff);
330-
jump_to_image_extended(image, gBootArgs, boot_tramp, gEntryPoint);
331+
else
332+
{
333+
entry = gM1N1Base + 0x800;
334+
}
335+
jump_to_image_extended((void*)entry, gBootArgs, boot_tramp, gEntryPoint);
331336
}
332337
else
333338
{

src/shell/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,22 @@ void pongo_boot_raw(const char *cmd, char *args) {
4646
task_yield();
4747
}
4848

49+
uint64_t gM1N1Base;
4950
extern char gFWVersion[256];
5051
void pongo_boot_m1n1(const char *cmd, char *args) {
5152
if (!loader_xfer_recv_count) {
5253
iprintf("please upload a raw m1n1.bin before issuing this command\n");
5354
return;
5455
}
5556

56-
loader_xfer_recv_count = 0;
5757
char *fwversion = dt_get_prop("/chosen", "firmware-version", NULL);
5858
strlcpy(fwversion, gFWVersion, 256);
5959

60+
void *m1n1 = alloc_static(loader_xfer_recv_count);
61+
memmove(m1n1, loader_xfer_recv_data, loader_xfer_recv_count);
62+
loader_xfer_recv_count = 0;
63+
gM1N1Base = vatophys_static(m1n1);
64+
6065
gBootFlag = BOOT_FLAG_M1N1;
6166
task_yield();
6267
}

0 commit comments

Comments
 (0)