Skip to content

Commit 53dcc8f

Browse files
authored
Make IOP Reset configurable (#93)
* [config] simplify config draw with ternary ops halves the ammount of sprintf in these config draws * make ELF loader IOP reboot configurable
1 parent 94628ca commit 53dcc8f

File tree

4 files changed

+46
-50
lines changed

4 files changed

+46
-50
lines changed

include/launchelf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ typedef struct
187187
int Popup_Opaque;
188188
int Init_Delay;
189189
int usbkbd_used;
190+
int reboot_iop_elf_load;
190191
int Show_Titles;
191192
int PathPad_Lock;
192193
int JpgView_Timer;

loader/loader.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,29 @@ int main(int argc, char *argv[])
6767
static t_ExecData elfdata;
6868
char *target, *path;
6969
char *args[1];
70-
int ret;
70+
int ret, rebootiop = 0;
7171

7272
// Initialize
7373
SifInitRpc(0);
7474
wipeUserMem();
7575

76-
if (argc != 2) { // arg1=path to ELF, arg2=partition to mount
76+
if (argc < 2) { // arg1=path to ELF, arg2=partition to mount
77+
sio_putsn("# wle: argc < 2\n");
7778
SifExitRpc();
7879
return -EINVAL;
7980
}
8081

8182
target = argv[0];
8283
path = argv[1];
83-
84+
if (argc > 2) {
85+
rebootiop = (!strcmp("-r", argv[2]));
86+
}
8487
//Writeback data cache before loading ELF.
8588
FlushCache(0);
8689
ret = SifLoadElf(target, &elfdata);
8790
if (ret == 0) {
8891
args[0] = path;
89-
///ISRA: reboot the IOP always, lots of apps dont have error handling on the RPC modules
92+
///ISRA: based on config
9093
/*if (strncmp(path, "hdd", 3) == 0 && (path[3] >= '0' && path[3] <= ':')) { /* Final IOP reset, to fill the IOP with the default modules.
9194
It appears that it was once a thing for the booting software to leave the IOP with the required IOP modules.
9295
This can be seen in OSDSYS v1.0x (no IOP reboot) and the mechanism to boot DVD player updates (OSDSYS will get LoadExecPS2 to load SIO2 modules).
@@ -95,17 +98,22 @@ int main(int argc, char *argv[])
9598
Reboot the IOP, to leave it in a clean & consistent state.
9699
But do not do that for boot targets on other devices, for backward-compatibility with older (homebrew) software.
97100
}*/
98-
while (!SifIopReset("", 0));
99-
while (!SifIopSync());
101+
if (rebootiop) {
102+
sio_putsn("# wle: rst iop\n");
103+
while (!SifIopReset("", 0));
104+
while (!SifIopSync());
105+
}
100106

101107
SifExitRpc();
102108

103109
FlushCache(0);
104110
FlushCache(2);
105111

106112
ExecPS2((void *)elfdata.epc, (void *)elfdata.gp, 1, args);
113+
sio_putsn("# wle: post ExecPS2\n");
107114
return 0;
108115
} else {
116+
sio_putsn("# wle: SifLoadElf fail\n");
109117
SifExitRpc();
110118
return -ENOENT;
111119
}

src/config.c

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum {
3939
DEF_POPUP_OPAQUE = FALSE,
4040
DEF_INIT_DELAY = 0,
4141
DEF_USBKBD_USED = 1,
42+
DEF_STARTUP_RESET_IOP_ELFOAD = 0,
4243
DEF_SHOW_TITLES = 1,
4344
DEF_PATHPAD_LOCK = 0,
4445
DEF_JPGVIEW_TIMER = 5,
@@ -493,6 +494,7 @@ void saveConfig(char *mainMsg, char *CNF)
493494
"Menu_Title = %s\r\n"
494495
"Init_Delay = %d\r\n"
495496
"USBKBD_USED = %d\r\n"
497+
"REBOOT_IOP_ELFLOAD = %d\r\n"
496498
"USBKBD_FILE = %s\r\n"
497499
"KBDMAP_FILE = %s\r\n"
498500
"Menu_Show_Titles = %d\r\n"
@@ -516,6 +518,7 @@ void saveConfig(char *mainMsg, char *CNF)
516518
setting->Menu_Title, //Menu_Title
517519
setting->Init_Delay, //Init_Delay
518520
setting->usbkbd_used, //USBKBD_USED
521+
setting->reboot_iop_elf_load,
519522
setting->usbkbd_file, //USBKBD_FILE
520523
setting->kbdmap_file, //KBDMAP_FILE
521524
setting->Show_Titles, //Menu_Show_Titles
@@ -686,6 +689,7 @@ void initConfig(void)
686689
setting->Popup_Opaque = DEF_POPUP_OPAQUE;
687690
setting->Init_Delay = DEF_INIT_DELAY;
688691
setting->usbkbd_used = DEF_USBKBD_USED;
692+
setting->reboot_iop_elf_load = DEF_STARTUP_RESET_IOP_ELFOAD;
689693
setting->Show_Titles = DEF_SHOW_TITLES;
690694
setting->PathPad_Lock = DEF_PATHPAD_LOCK;
691695
setting->JpgView_Timer = -1; //only used to detect missing variable
@@ -847,6 +851,8 @@ int loadConfig(char *mainMsg, char *CNF)
847851
setting->Init_Delay = atoi(value);
848852
else if (!strcmp(name, "USBKBD_USED"))
849853
setting->usbkbd_used = atoi(value);
854+
else if (!strcmp(name, "REBOOT_IOP_ELFLOAD"))
855+
setting->reboot_iop_elf_load = atoi(value);
850856
else if (!strcmp(name, "USBKBD_FILE"))
851857
strcpy(setting->usbkbd_file, value);
852858
else if (!strcmp(name, "KBDMAP_FILE"))
@@ -1581,6 +1587,7 @@ enum CONFIG_STARTUP {
15811587
CONFIG_STARTUP_SELECT_BTN,
15821588
CONFIG_STARTUP_INIT_DELAY,
15831589
CONFIG_STARTUP_TIMEOUT,
1590+
CONFIG_STARTUP_RESET_IOP_ELFOAD,
15841591
CONFIG_STARTUP_KEYBOARD,
15851592
CONFIG_STARTUP_USBKBD,
15861593
CONFIG_STARTUP_KBDMAP,
@@ -1672,6 +1679,8 @@ static void Config_Startup(void)
16721679
setting->timeout++;
16731680
else if (s == CONFIG_STARTUP_KEYBOARD)
16741681
setting->usbkbd_used = !setting->usbkbd_used;
1682+
else if (s == CONFIG_STARTUP_RESET_IOP_ELFOAD)
1683+
setting->reboot_iop_elf_load = !setting->reboot_iop_elf_load;
16751684
else if (s == CONFIG_STARTUP_USBKBD)
16761685
getFilePath(setting->usbkbd_file, USBKBD_IRX_CNF);
16771686
else if (s == CONFIG_STARTUP_KBDMAP)
@@ -1749,59 +1758,41 @@ static void Config_Startup(void)
17491758
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17501759
y += FONT_HEIGHT;
17511760

1752-
if (setting->usbkbd_used)
1753-
sprintf(c, " %s: %s", LNG(USB_Keyboard_Used), LNG(ON));
1754-
else
1755-
sprintf(c, " %s: %s", LNG(USB_Keyboard_Used), LNG(OFF));
1761+
sprintf(c, " %s: %s", "Reboot IOP when loading ELF", (setting->reboot_iop_elf_load) ? LNG(ON): LNG(OFF));
1762+
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
1763+
y += FONT_HEIGHT;
1764+
1765+
sprintf(c, " %s: %s", LNG(USB_Keyboard_Used), (setting->usbkbd_used) ? LNG(ON): LNG(OFF));
17561766
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17571767
y += FONT_HEIGHT;
17581768

1759-
if (strlen(setting->usbkbd_file) == 0)
1760-
sprintf(c, " %s: %s", LNG(USB_Keyboard_IRX), LNG(DEFAULT));
1761-
else
1762-
sprintf(c, " %s: %s", LNG(USB_Keyboard_IRX), setting->usbkbd_file);
1769+
sprintf(c, " %s: %s", LNG(USB_Keyboard_IRX), (strlen(setting->usbkbd_file) == 0) ? LNG(DEFAULT) : setting->usbkbd_file);
17631770
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17641771
y += FONT_HEIGHT;
17651772

1766-
if (strlen(setting->kbdmap_file) == 0)
1767-
sprintf(c, " %s: %s", LNG(USB_Keyboard_Map), LNG(DEFAULT));
1768-
else
1769-
sprintf(c, " %s: %s", LNG(USB_Keyboard_Map), setting->kbdmap_file);
1773+
sprintf(c, " %s: %s", LNG(USB_Keyboard_Map), (strlen(setting->kbdmap_file) == 0)? LNG(DEFAULT) : setting->kbdmap_file);
17701774
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17711775
y += FONT_HEIGHT;
17721776

1773-
if (strlen(setting->CNF_Path) == 0)
1774-
sprintf(c, " %s: %s", LNG(CNF_Path_override), LNG(NONE));
1775-
else
1776-
sprintf(c, " %s: %s", LNG(CNF_Path_override), setting->CNF_Path);
1777+
sprintf(c, " %s: %s", LNG(CNF_Path_override), (strlen(setting->CNF_Path) == 0) ? LNG(NONE) : setting->CNF_Path);
17771778
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17781779
y += FONT_HEIGHT;
17791780

1780-
if (strlen(setting->lang_file) == 0)
1781-
sprintf(c, " %s: %s", LNG(Language_File), LNG(DEFAULT));
1782-
else
1783-
sprintf(c, " %s: %s", LNG(Language_File), setting->lang_file);
1781+
sprintf(c, " %s: %s", LNG(Language_File), (strlen(setting->lang_file) == 0)? LNG(DEFAULT) : setting->lang_file);
17841782
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17851783
y += FONT_HEIGHT;
17861784

1787-
if (strlen(setting->font_file) == 0)
1788-
sprintf(c, " %s: %s", LNG(Font_File), LNG(DEFAULT));
1789-
else
1790-
sprintf(c, " %s: %s", LNG(Font_File), setting->font_file);
1785+
sprintf(c, " %s: %s", LNG(Font_File), (strlen(setting->font_file) == 0)? LNG(DEFAULT):setting->font_file);
17911786
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17921787
y += FONT_HEIGHT;
17931788

1794-
if (strlen(setting->LK_Path[SETTING_LK_ESR]) == 0)
1795-
sprintf(c, " ESR elf: %s", LNG(DEFAULT));
1796-
else
1797-
sprintf(c, " ESR elf: %s", setting->LK_Path[SETTING_LK_ESR]);
1789+
sprintf(c, " ESR elf: %s",
1790+
(strlen(setting->LK_Path[SETTING_LK_ESR]) == 0) ? LNG(DEFAULT) : setting->LK_Path[SETTING_LK_ESR]);
17981791
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
17991792
y += FONT_HEIGHT;
18001793

1801-
if (strlen(setting->LK_Path[SETTING_LK_OSDSYS]) == 0)
1802-
sprintf(c, " OSDSYS kelf: %s", LNG(DEFAULT));
1803-
else
1804-
sprintf(c, " OSDSYS kelf: %s", setting->LK_Path[SETTING_LK_OSDSYS]);
1794+
sprintf(c, " OSDSYS kelf: %s", (strlen(setting->LK_Path[SETTING_LK_OSDSYS]) == 0)?
1795+
LNG(DEFAULT) : setting->LK_Path[SETTING_LK_OSDSYS]);
18051796
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
18061797
y += FONT_HEIGHT;
18071798

@@ -1817,8 +1808,9 @@ static void Config_Startup(void)
18171808
y += FONT_HEIGHT / 2;
18181809
drawChar(LEFT_CUR, x, y, setting->color[COLOR_TEXT]);
18191810

1811+
18201812
//Tooltip section
1821-
if ((s == CONFIG_STARTUP_SELECT_BTN) || (s == CONFIG_STARTUP_KEYBOARD)) { //usbkbd_used
1813+
if ((s == CONFIG_STARTUP_SELECT_BTN) || (s == CONFIG_STARTUP_KEYBOARD) || (s == CONFIG_STARTUP_RESET_IOP_ELFOAD)) { //usbkbd_used
18221814
if (swapKeys)
18231815
len = sprintf(c, "\xFF"
18241816
"1:%s",
@@ -2408,17 +2400,11 @@ void config(char *mainMsg, char *CNF)
24082400

24092401
y += FONT_HEIGHT / 2;
24102402

2411-
if (setting->Show_Titles)
2412-
sprintf(c, " %s: %s", LNG(Show_launch_titles), LNG(ON));
2413-
else
2414-
sprintf(c, " %s: %s", LNG(Show_launch_titles), LNG(OFF));
2403+
sprintf(c, " %s: %s", LNG(Show_launch_titles), (setting->Show_Titles)? LNG(ON) : LNG(OFF));
24152404
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
24162405
y += FONT_HEIGHT;
24172406

2418-
if (setting->Hide_Paths)
2419-
sprintf(c, " %s: %s", LNG(Hide_full_ELF_paths), LNG(ON));
2420-
else
2421-
sprintf(c, " %s: %s", LNG(Hide_full_ELF_paths), LNG(OFF));
2407+
sprintf(c, " %s: %s", LNG(Hide_full_ELF_paths), (setting->Hide_Paths)?LNG(ON): LNG(OFF));
24222408
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
24232409
y += FONT_HEIGHT;
24242410

src/elf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ int checkELFheader(char *path)
133133
//------------------------------
134134
void RunLoaderElf(char *filename, char *party)
135135
{
136+
#define ELFLOAD_ARGC 3
136137
u8 *boot_elf;
137138
elf_header_t *eh;
138139
elf_pheader_t *eph;
139140
void *pdata;
140141
int i;
141-
char *argv[2], bootpath[256];
142+
char *argv[ELFLOAD_ARGC], bootpath[256];
142143

143144
if ((!strncmp(party, "hdd0:", 5)) && (!strncmp(filename, "pfs0:", 5))) {
144145
if (0 > fileXioMount("pfs0:", party, FIO_MT_RDONLY)) {
@@ -203,13 +204,13 @@ void RunLoaderElf(char *filename, char *party)
203204
memset(eph[i].vaddr + eph[i].filesz, 0,
204205
eph[i].memsz - eph[i].filesz);
205206
}
206-
207+
argv[2] = (setting->reboot_iop_elf_load) ? "-r" : "-nr";
207208
/* Let's go. */
208209
SifExitRpc();
209210
FlushCache(0);
210211
FlushCache(2);
211212

212-
ExecPS2((void *)eh->entry, NULL, 2, argv);
213+
ExecPS2((void *)eh->entry, NULL, ELFLOAD_ARGC, argv);
213214
}
214215
//------------------------------
215216
//End of func: void RunLoaderElf(char *filename, char *party)

0 commit comments

Comments
 (0)