Skip to content

Commit

Permalink
add IRX loading feature
Browse files Browse the repository at this point in the history
  • Loading branch information
israpps committed Feb 28, 2024
1 parent fba5e42 commit f41a676
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Lang/ENG.LNG
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,5 @@ lang(328, change_timestamp_of, "change timestamp of:")
lang(329, title_cfg, "create title.cfg")
lang(329, Build_Info, "BuildInfo")
lang(330, Loading_Flash_Modules, "Loading Flash Modules...")
lang(331, This_file_isnt_an_IRX, "This file isn't an IRX")
lang(331, confirm_irx_exec, "do you want to load this IRX driver?%c%s")
2 changes: 2 additions & 0 deletions Lang/SPA.LNG
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,5 @@ lang(328, change_timestamp_of, "cambiar fecha de:")
lang(329, title_cfg, "crear title.cfg")
lang(329, Build_Info, "BuildInfo")
lang(330, Loading_Flash_Modules, "Cargando modulos flash...")
lang(331, This_file_isnt_an_ELF, "Esto no es un driver IRX")
lang(331, confirm_irx_exec, "Desea cargar este driver IRX?%c%s")
6 changes: 5 additions & 1 deletion include/launchelf.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ int IsSupportedFileType(char *path);
void loadFlashModules(void);

/* elf.c */
int checkELFheader(char *filename);
#define TYPE_ELF 0
#define TYPE_IRX 1
#define ELF_HEADER_ID_EE 0x2
#define ELF_HEADER_ID_IRX 0xFF80
int checkELFheader(char *filename, int type);
void RunLoaderElf(char *filename, char *);

/* draw.c */
Expand Down
20 changes: 11 additions & 9 deletions src/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ typedef struct
//--------------------------------------------------------------
//End of data declarations
//--------------------------------------------------------------
//Start of function code
//--------------------------------------------------------------
// checkELFheader Tests for valid ELF file
// Modified version of loader from Independence
// (C) 2003 Marcus R. Brown <mrbrown@0xd6.org>
//--------------------------------------------------------------
int checkELFheader(char *path)

/**
* @brief open file and check for ELF header and ELF type
* @param path path
* @param type 0 for EE ELF, 1 for IOP IRX
* @return 0: unknown device, 1:check passed, -1: check failed
*/
int checkELFheader(char *path, int type)
{
u16 MAGICS[2] = {ELF_HEADER_ID_EE, ELF_HEADER_ID_IRX};
elf_header_t elf_head;
u8 *boot_elf = (u8 *)&elf_head;
elf_header_t *eh = (elf_header_t *)boot_elf;
Expand Down Expand Up @@ -108,8 +110,8 @@ int checkELFheader(char *path)
genLseek(fd, 0, SEEK_SET);
genRead(fd, boot_elf, sizeof(elf_header_t));
genClose(fd);

if ((_lw((u32)&eh->ident) != ELF_MAGIC) || eh->type != 2)
DPRINTF("%s: ELF magic 0x%x, ELF ident 0x%x\n", __FUNCTION__, _lw((u32)&eh->ident), eh->type);
if ((_lw((u32)&eh->ident) != ELF_MAGIC) || eh->type != MAGICS[type])
goto error;

return 1; //return 1 for successful check
Expand Down
4 changes: 2 additions & 2 deletions src/filer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3964,7 +3964,7 @@ int getFilePath(char *out, int cnfmode)
//pushed R3 for a file (treat as uLE-related)
sprintf(out, "%s%s", path, files[browser_sel].name);
// Must to include a function for check IRX Header
if (((cnfmode == LK_ELF_CNF) || (cnfmode == NON_CNF)) && (checkELFheader(out) < 0)) {
if (((cnfmode == LK_ELF_CNF) || (cnfmode == NON_CNF)) && (checkELFheader(out, TYPE_ELF) < 0)) {
browser_pushed = FALSE;
sprintf(msg0, "%s.", LNG(This_file_isnt_an_ELF));
out[0] = 0;
Expand Down Expand Up @@ -4469,7 +4469,7 @@ int getFilePath(char *out, int cnfmode)
iconcolr = COLOR_GRAPH1;
} else {
iconbase = ICON_FILE;
if (genCmpFileExt(files[top + i].name, "ELF"))
if (genCmpFileExt(files[top + i].name, "ELF") || genCmpFileExt(files[top + i].name, "IRX"))
iconcolr = COLOR_GRAPH2;
else if (
genCmpFileExt(files[top + i].name, "TXT") ||
Expand Down
85 changes: 56 additions & 29 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,14 +2030,16 @@ int IsSupportedFileType(char *path)
#ifdef SUPPORT_SYSTEM_2X6
if(strchr(path, ':') != NULL) {
if ((genCmpFileExt(path, "TXT") || genCmpFileExt(path, "CHT") || genCmpFileExt(path, "CFG") || genCmpFileExt(path, "INI") || genCmpFileExt(path, "CNF") ) || (genCmpFileExt(path, "JPG") || genCmpFileExt(path, "JPEG"))) return 1;
else if(genCmpFileExt(path, "IRX")) return 0;
else return(checkELFheader(path) >= 0);
else if((checkELFheader(path, TYPE_IRX) >= 0)) return 1;
else return(checkELFheader(path, TYPE_ELF) >= 0);
} else //No ':', hence no device name in path, which means it is a special action (e.g. MISC/*).
return 1;
#else
if (strchr(path, ':') != NULL) {
if (genCmpFileExt(path, "ELF")) {
return (checkELFheader(path) >= 0);
return (checkELFheader(path, TYPE_ELF) >= 0);
} else if(genCmpFileExt(path, "IRX")) {
return (checkELFheader(path, TYPE_IRX) >= 0);
} else if ((genCmpFileExt(path, "TXT") || genCmpFileExt(path, "CHT") || genCmpFileExt(path, "CFG") || genCmpFileExt(path, "INI") || genCmpFileExt(path, "CNF") ) || (genCmpFileExt(path, "JPG") || genCmpFileExt(path, "JPEG"))) {
return 1;
} else
Expand Down Expand Up @@ -2070,7 +2072,7 @@ static void Execute(char *pathin)
if (!uLE_related(path, pathin)) //1==uLE_rel 0==missing, -1==other dev
return;

Recurse_for_ESR: //Recurse here for PS2Disc command with ESR disc
Recurse_for_ESR: //Recurse here for PS2Disc command with ESR disc

pathSep = strchr(path, '/');

Expand All @@ -2080,7 +2082,7 @@ static void Execute(char *pathin)
goto CheckELF_path;
strcpy(fullpath, "mc0:");
strcat(fullpath, path + 3);
if (checkELFheader(fullpath) > 0)
if (checkELFheader(fullpath, TYPE_ELF) > 0)
goto ELFchecked;
fullpath[2] = '1';
goto CheckELF_fullpath;
Expand All @@ -2092,36 +2094,36 @@ static void Execute(char *pathin)
goto CheckELF_path;
} else if (!strncmp(path, "hdd0:/", 6)) {
loadHddModules();
if ((t = checkELFheader(path)) <= 0)
if ((t = checkELFheader(path, TYPE_ELF)) <= 0)
goto ELFnotFound;
//coming here means the ELF is fine
sprintf(party, "hdd0:%s", path + 6);
p = strchr(party, '/');
sprintf(fullpath, "pfs0:%s", p);
*p = 0;
goto ELFchecked;
#ifdef DVRP
} else if (!strncmp(path, "dvr_hdd0:/", 10)) {
loadDVRPHddModules();
if ((t = checkELFheader(path)) <= 0)
goto ELFnotFound;
//coming here means the ELF is fine
sprintf(party, "dvr_hdd0:%s", path + 10);
p = strchr(party, '/');
sprintf(fullpath, "dvr_pfs0:%s", p);
*p = 0;
goto ELFchecked;
#endif
#ifdef XFROM
#ifdef DVRP
} else if (!strncmp(path, "dvr_hdd0:/", 10)) {
loadDVRPHddModules();
if ((t = checkELFheader(path, TYPE_ELF)) <= 0)
goto ELFnotFound;
//coming here means the ELF is fine
sprintf(party, "dvr_hdd0:%s", path + 10);
p = strchr(party, '/');
sprintf(fullpath, "dvr_pfs0:%s", p);
*p = 0;
goto ELFchecked;
#endif
#ifdef XFROM
} else if (!strncmp(path, "xfrom:/", 7)) {
loadFlashModules();
if ((t = checkELFheader(path)) <= 0)
if ((t = checkELFheader(path, TYPE_ELF)) <= 0)
goto ELFnotFound;
strcpy(fullpath, path);
goto ELFchecked;
#endif
#endif
} else if (!strncmp(path, "mass", 4)) {
if ((t = checkELFheader(path)) <= 0)
if ((t = checkELFheader(path, TYPE_ELF)) <= 0)
goto ELFnotFound;
//coming here means the ELF is fine
party[0] = 0;
Expand All @@ -2130,7 +2132,7 @@ static void Execute(char *pathin)
if (pathSep && (pathSep - path < 7) && pathSep[-1] == ':')
strcpy(fullpath + (pathSep - path), pathSep + 1);
goto ELFchecked;
#ifdef ETH
#ifdef ETH
} else if (!strncmp(path, "host:", 5)) {
initHOST();
party[0] = 0;
Expand All @@ -2141,7 +2143,7 @@ static void Execute(char *pathin)
strcat(fullpath, path + 5);
makeHostPath(fullpath, fullpath);
goto CheckELF_fullpath;
#endif
#endif
} else if (!stricmp(path, setting->Misc_OSDSYS)) {
char arg0[20], arg1[20], arg2[20], arg3[40];
char *args[4] = {arg0, arg1, arg2, arg3};
Expand Down Expand Up @@ -2305,6 +2307,8 @@ static void Execute(char *pathin)
}

JpgViewer(tmp);
} else if (genCmpFileExt(tmp, "IRX")) {
goto IRXcheckheader;
} else
Execute(tmp);
}
Expand All @@ -2316,12 +2320,12 @@ static void Execute(char *pathin)
//The method below was used earlier, but causes reset with new ELF loader
//party[0]=0;
//strcpy(fullpath,"rom0:OSDSYS");
#ifdef ETH
#ifdef ETH
} else if (!stricmp(path, setting->Misc_PS2Net)) {
mainMsg[0] = 0;
loadNetModules();
return;
#endif
#endif
} else if (!stricmp(path, setting->Misc_PS2PowerOff)) {
mainMsg[0] = 0;
drawMsg(LNG(Powering_Off_Console));
Expand Down Expand Up @@ -2395,19 +2399,21 @@ static void Execute(char *pathin)
}
Show_build_info();
return;
#ifndef SUPPORT_SYSTEM_2X6
#ifndef SUPPORT_SYSTEM_2X6
} else if (!strncmp(path, "cdfs", 4)) {
CDVD_FlushCache();
CDVD_DiskReady(0);
party[0] = 0;
goto CheckELF_path;
#endif
#endif
} else if (!strncmp(path, "rom", 3)) {
party[0] = 0;
CheckELF_path:
strcpy(fullpath, path);
CheckELF_fullpath:
if ((t = checkELFheader(fullpath)) <= 0)
if (checkELFheader(fullpath, TYPE_IRX)>0)
goto IRXFound;
if ((t = checkELFheader(fullpath, TYPE_ELF)) <= 0)
goto ELFnotFound;
ELFchecked:
CleanUp();
Expand All @@ -2421,6 +2427,27 @@ static void Execute(char *pathin)
sprintf(mainMsg, "%s: %s.", LNG(This_file_isnt_an_ELF), fullpath);
return;
}
return;
IRXcheckheader:
if ((t = checkELFheader(fullpath, TYPE_IRX)) <= 0) {
if (t == 0)
sprintf(mainMsg, "%s %s.", fullpath, LNG(is_Not_Found));
else
sprintf(mainMsg, "%s: %s.", LNG(This_file_isnt_an_IRX), fullpath);
return;
}
IRXFound:
p = strrchr(fullpath, '/');
sprintf(mainMsg, LNG(confirm_irx_exec), '\n', (p!=NULL) ? p : "");
if (ynDialog(mainMsg)>0) {
int ret, id;
id = SifLoadStartModule(fullpath, 0, NULL, &ret);
sprintf(mainMsg, "%s: id:%d, ret:%d (%s)",
(p!=NULL) ? p+1 : "MODULE",
id, ret,
(id>0 && ret!=1) ? LNG(OK) : LNG(Failed));
DPRINTF("%s\n", mainMsg);
} else mainMsg[0] = 0;
}
//------------------------------
//endfunc Execute
Expand Down

0 comments on commit f41a676

Please sign in to comment.