Skip to content

Commit c6bfd16

Browse files
committed
Add support for chainloading an ELF file from the memory card with mininal initialization
1 parent 4f36cc1 commit c6bfd16

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export HEADER
1313
# ---{BUILD CFG}--- #
1414
HAS_EMBED_IRX = 1 # whether to embed or not non vital IRX (wich will be loaded from memcard files)
1515
DEBUG ?= 0
16+
CHAINLOAD ?= 0 # Only inits the system and boots CHAINLOAD_PATH from the memory card
17+
CHAINLOAD_PATH ?= "mc?:BOOT/PAYLOAD.ELF"
1618
PSX ?= 0 # PSX DESR support
1719
HDD ?= 0 #wether to add internal HDD support
1820
MMCE ?= 0
@@ -77,6 +79,12 @@ ifneq ($(VERBOSE), 1)
7779
.SILENT:
7880
endif
7981

82+
ifeq ($(CHAINLOAD), 1)
83+
HAS_EMBED_IRX = 1
84+
EE_CFLAGS += -DCHAINLOAD -DCHAINLOAD_PATH=\"$(CHAINLOAD_PATH)\"
85+
undefine EMBEDDED_STUFF
86+
endif
87+
8088
ifeq ($(MX4SIO), 1)
8189
HOMEBREW_IRX = 1
8290
FILEXIO_NEED = 1

src/main.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ int main(int argc, char *argv[])
2828
SifInitIopHeap(); // Initialize SIF services for loading modules and files.
2929
SifLoadFileInit();
3030
fioInit(); // NO scr_printf BEFORE here
31+
32+
#if !defined(CHAINLOAD) || !defined(NO_DPRINTF)
3133
init_scr();
3234
scr_setCursor(0); // get rid of annoying that cursor.
35+
scr_printf(".\n"); // GBS control does not detect image output with scr debug till the first char is printed
36+
#endif
37+
3338
DPRINTF_INIT()
3439
#ifndef NO_DPRINTF
3540
DPRINTF("PS2BBL: starting with %d argumments:\n", argc);
3641
for (x = 0; x < argc; x++)
3742
DPRINTF("\targv[%d] = [%s]\n", x, argv[x]);
3843
#endif
39-
scr_printf(".\n"); // GBS control does not detect image output with scr debug till the first char is printed
4044
// print a simple dot to allow gbs control to start displaying video before banner and pad timeout begins to run. othersiwe, users with timeout lower than 4000 will have issues to respond in time
4145
DPRINTF("enabling LoadModuleBuffer\n");
4246
sbv_patch_enable_lmb(); // The old IOP kernel has no support for LoadModuleBuffer. Apply the patch to enable it.
@@ -73,6 +77,8 @@ int main(int argc, char *argv[])
7377
DPRINTF(" [MCSERV]: ID=%d, ret=%d\n", j, x);
7478
mcInit(MC_TYPE_XMC);
7579
#endif
80+
81+
#ifndef CHAINLOAD
7682
#ifdef USE_ROM_PADMAN
7783
j = SifLoadStartModule("rom0:PADMAN", 0, NULL, &x);
7884
DPRINTF(" [PADMAN]: ID=%d, ret=%d\n", j, x);
@@ -90,6 +96,7 @@ int main(int argc, char *argv[])
9096
sleep(1);
9197
#endif
9298
}
99+
#endif
93100

94101
#ifdef FILEXIO
95102
if (LoadFIO() < 0) {
@@ -171,6 +178,22 @@ int main(int argc, char *argv[])
171178
// Remember to set the video output option (RGB or Y Cb/Pb Cr/Pr) accordingly, before SetGsCrt() is called.
172179
DPRINTF("Setting vmode\n");
173180
SetGsVParam(OSDConfigGetVideoOutput() == VIDEO_OUTPUT_RGB ? VIDEO_OUTPUT_RGB : VIDEO_OUTPUT_COMPONENT);
181+
182+
#ifdef CHAINLOAD
183+
char bootPath[] = CHAINLOAD_PATH;
184+
for (j = '0'; j <'2'; j++) {
185+
bootPath[2] = j;
186+
if (exist(bootPath)) {
187+
CleanUp();
188+
RunLoaderElf(bootPath, NULL);
189+
}
190+
}
191+
init_scr();
192+
scr_setCursor(0); // get rid of annoying that cursor.
193+
scr_printf("\n\n\n"CHAINLOAD_PATH" not found\n");
194+
while (1) {}
195+
#endif
196+
174197
DPRINTF("Init pads\n");
175198
PadInitPads();
176199
DPRINTF("Init timer and wait for rescue mode key\n");

0 commit comments

Comments
 (0)