Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IOP Reset configurable #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/launchelf.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ typedef struct
int Popup_Opaque;
int Init_Delay;
int usbkbd_used;
int reboot_iop_elf_load;
int Show_Titles;
int PathPad_Lock;
int JpgView_Timer;
Expand Down
20 changes: 14 additions & 6 deletions loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,29 @@ int main(int argc, char *argv[])
static t_ExecData elfdata;
char *target, *path;
char *args[1];
int ret;
int ret, rebootiop = 0;

// Initialize
SifInitRpc(0);
wipeUserMem();

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

target = argv[0];
path = argv[1];

if (argc > 2) {
rebootiop = (!strcmp("-r", argv[2]));
}
//Writeback data cache before loading ELF.
FlushCache(0);
ret = SifLoadElf(target, &elfdata);
if (ret == 0) {
args[0] = path;
///ISRA: reboot the IOP always, lots of apps dont have error handling on the RPC modules
///ISRA: based on config
/*if (strncmp(path, "hdd", 3) == 0 && (path[3] >= '0' && path[3] <= ':')) { /* Final IOP reset, to fill the IOP with the default modules.
It appears that it was once a thing for the booting software to leave the IOP with the required IOP modules.
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).
Expand All @@ -95,17 +98,22 @@ int main(int argc, char *argv[])
Reboot the IOP, to leave it in a clean & consistent state.
But do not do that for boot targets on other devices, for backward-compatibility with older (homebrew) software.
}*/
while (!SifIopReset("", 0));
while (!SifIopSync());
if (rebootiop) {
sio_putsn("# wle: rst iop\n");
while (!SifIopReset("", 0));
while (!SifIopSync());
}

SifExitRpc();

FlushCache(0);
FlushCache(2);

ExecPS2((void *)elfdata.epc, (void *)elfdata.gp, 1, args);
sio_putsn("# wle: post ExecPS2\n");
return 0;
} else {
sio_putsn("# wle: SifLoadElf fail\n");
SifExitRpc();
return -ENOENT;
}
Expand Down
68 changes: 27 additions & 41 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum {
DEF_POPUP_OPAQUE = FALSE,
DEF_INIT_DELAY = 0,
DEF_USBKBD_USED = 1,
DEF_STARTUP_RESET_IOP_ELFOAD = 0,
DEF_SHOW_TITLES = 1,
DEF_PATHPAD_LOCK = 0,
DEF_JPGVIEW_TIMER = 5,
Expand Down Expand Up @@ -493,6 +494,7 @@ void saveConfig(char *mainMsg, char *CNF)
"Menu_Title = %s\r\n"
"Init_Delay = %d\r\n"
"USBKBD_USED = %d\r\n"
"REBOOT_IOP_ELFLOAD = %d\r\n"
"USBKBD_FILE = %s\r\n"
"KBDMAP_FILE = %s\r\n"
"Menu_Show_Titles = %d\r\n"
Expand All @@ -516,6 +518,7 @@ void saveConfig(char *mainMsg, char *CNF)
setting->Menu_Title, //Menu_Title
setting->Init_Delay, //Init_Delay
setting->usbkbd_used, //USBKBD_USED
setting->reboot_iop_elf_load,
setting->usbkbd_file, //USBKBD_FILE
setting->kbdmap_file, //KBDMAP_FILE
setting->Show_Titles, //Menu_Show_Titles
Expand Down Expand Up @@ -686,6 +689,7 @@ void initConfig(void)
setting->Popup_Opaque = DEF_POPUP_OPAQUE;
setting->Init_Delay = DEF_INIT_DELAY;
setting->usbkbd_used = DEF_USBKBD_USED;
setting->reboot_iop_elf_load = DEF_STARTUP_RESET_IOP_ELFOAD;
setting->Show_Titles = DEF_SHOW_TITLES;
setting->PathPad_Lock = DEF_PATHPAD_LOCK;
setting->JpgView_Timer = -1; //only used to detect missing variable
Expand Down Expand Up @@ -847,6 +851,8 @@ int loadConfig(char *mainMsg, char *CNF)
setting->Init_Delay = atoi(value);
else if (!strcmp(name, "USBKBD_USED"))
setting->usbkbd_used = atoi(value);
else if (!strcmp(name, "REBOOT_IOP_ELFLOAD"))
setting->reboot_iop_elf_load = atoi(value);
else if (!strcmp(name, "USBKBD_FILE"))
strcpy(setting->usbkbd_file, value);
else if (!strcmp(name, "KBDMAP_FILE"))
Expand Down Expand Up @@ -1581,6 +1587,7 @@ enum CONFIG_STARTUP {
CONFIG_STARTUP_SELECT_BTN,
CONFIG_STARTUP_INIT_DELAY,
CONFIG_STARTUP_TIMEOUT,
CONFIG_STARTUP_RESET_IOP_ELFOAD,
CONFIG_STARTUP_KEYBOARD,
CONFIG_STARTUP_USBKBD,
CONFIG_STARTUP_KBDMAP,
Expand Down Expand Up @@ -1672,6 +1679,8 @@ static void Config_Startup(void)
setting->timeout++;
else if (s == CONFIG_STARTUP_KEYBOARD)
setting->usbkbd_used = !setting->usbkbd_used;
else if (s == CONFIG_STARTUP_RESET_IOP_ELFOAD)
setting->reboot_iop_elf_load = !setting->reboot_iop_elf_load;
else if (s == CONFIG_STARTUP_USBKBD)
getFilePath(setting->usbkbd_file, USBKBD_IRX_CNF);
else if (s == CONFIG_STARTUP_KBDMAP)
Expand Down Expand Up @@ -1749,59 +1758,41 @@ static void Config_Startup(void)
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;

if (setting->usbkbd_used)
sprintf(c, " %s: %s", LNG(USB_Keyboard_Used), LNG(ON));
else
sprintf(c, " %s: %s", LNG(USB_Keyboard_Used), LNG(OFF));
sprintf(c, " %s: %s", "Reboot IOP when loading ELF", (setting->reboot_iop_elf_load) ? LNG(ON): LNG(OFF));
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;

sprintf(c, " %s: %s", LNG(USB_Keyboard_Used), (setting->usbkbd_used) ? LNG(ON): LNG(OFF));
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;

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

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

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

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

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

if (strlen(setting->LK_Path[SETTING_LK_ESR]) == 0)
sprintf(c, " ESR elf: %s", LNG(DEFAULT));
else
sprintf(c, " ESR elf: %s", setting->LK_Path[SETTING_LK_ESR]);
sprintf(c, " ESR elf: %s",
(strlen(setting->LK_Path[SETTING_LK_ESR]) == 0) ? LNG(DEFAULT) : setting->LK_Path[SETTING_LK_ESR]);
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;

if (strlen(setting->LK_Path[SETTING_LK_OSDSYS]) == 0)
sprintf(c, " OSDSYS kelf: %s", LNG(DEFAULT));
else
sprintf(c, " OSDSYS kelf: %s", setting->LK_Path[SETTING_LK_OSDSYS]);
sprintf(c, " OSDSYS kelf: %s", (strlen(setting->LK_Path[SETTING_LK_OSDSYS]) == 0)?
LNG(DEFAULT) : setting->LK_Path[SETTING_LK_OSDSYS]);
printXY(c, x, y, setting->color[COLOR_TEXT], TRUE, 0);
y += FONT_HEIGHT;

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


//Tooltip section
if ((s == CONFIG_STARTUP_SELECT_BTN) || (s == CONFIG_STARTUP_KEYBOARD)) { //usbkbd_used
if ((s == CONFIG_STARTUP_SELECT_BTN) || (s == CONFIG_STARTUP_KEYBOARD) || (s == CONFIG_STARTUP_RESET_IOP_ELFOAD)) { //usbkbd_used
if (swapKeys)
len = sprintf(c, "\xFF"
"1:%s",
Expand Down Expand Up @@ -2408,17 +2400,11 @@ void config(char *mainMsg, char *CNF)

y += FONT_HEIGHT / 2;

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

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

Expand Down
7 changes: 4 additions & 3 deletions src/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ int checkELFheader(char *path)
//------------------------------
void RunLoaderElf(char *filename, char *party)
{
#define ELFLOAD_ARGC 3
u8 *boot_elf;
elf_header_t *eh;
elf_pheader_t *eph;
void *pdata;
int i;
char *argv[2], bootpath[256];
char *argv[ELFLOAD_ARGC], bootpath[256];

if ((!strncmp(party, "hdd0:", 5)) && (!strncmp(filename, "pfs0:", 5))) {
if (0 > fileXioMount("pfs0:", party, FIO_MT_RDONLY)) {
Expand Down Expand Up @@ -203,13 +204,13 @@ void RunLoaderElf(char *filename, char *party)
memset(eph[i].vaddr + eph[i].filesz, 0,
eph[i].memsz - eph[i].filesz);
}

argv[2] = (setting->reboot_iop_elf_load) ? "-r" : "-nr";
/* Let's go. */
SifExitRpc();
FlushCache(0);
FlushCache(2);

ExecPS2((void *)eh->entry, NULL, 2, argv);
ExecPS2((void *)eh->entry, NULL, ELFLOAD_ARGC, argv);
}
//------------------------------
//End of func: void RunLoaderElf(char *filename, char *party)
Expand Down