Skip to content

Commit 5aca83c

Browse files
committed
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. Signed-off-by: Nick Chan <[email protected]>
1 parent ce17354 commit 5aca83c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/kernel/entry.c

Lines changed: 7 additions & 4 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
@@ -314,19 +316,20 @@ _Noreturn void pongo_entry(uint64_t *kernel_args, void *entryp, void (*exit_to_e
314316
void *boot_tramp = (void*)((gTopOfKernelData + 0x3fffULL) & ~0x3fffULL);
315317
if(gBootFlag == BOOT_FLAG_RAW || gBootFlag == BOOT_FLAG_M1N1)
316318
{
319+
uint64_t entry;
317320
// We're in EL1 here, but we might need to go back to EL3
318321
if((__builtin_arm_rsr64("id_aa64pfr0_el1") & 0xf000) != 0)
319322
{
320323
__asm__ volatile("smc 0"); // elevate to EL3
321324
}
322-
uint64_t entryOff = 0x800;
323325
if(gBootFlag == BOOT_FLAG_RAW)
324326
{
327+
entry = (uint64_t)loader_xfer_recv_data - kCacheableView + 0x800000000;
325328
boot_tramp = NULL;
326-
entryOff = 0;
329+
} else {
330+
entry = (uint64_t)gM1N1Base + 0x800;
327331
}
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);
332+
void *image = (void*)entry;
330333
jump_to_image_extended(image, gBootArgs, boot_tramp, gEntryPoint);
331334
}
332335
else

src/shell/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,23 @@ 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+
gM1N1Base = (gBootArgs->topOfKernelData + 0x3fff) & ~0x3fff;
61+
memmove((void*)(gM1N1Base - 0x800000000 + kCacheableView), loader_xfer_recv_data, loader_xfer_recv_count);
62+
gBootArgs->topOfKernelData = (gM1N1Base + loader_xfer_recv_count + 0x3fff) & ~0x3fff;
63+
gTopOfKernelData = gBootArgs->topOfKernelData;
64+
loader_xfer_recv_count = 0;
65+
6066
gBootFlag = BOOT_FLAG_M1N1;
6167
task_yield();
6268
}

0 commit comments

Comments
 (0)