From d49520e48477d34364fb2c8943caba63e283b80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Tue, 13 Dec 2022 19:38:38 -0300 Subject: [PATCH 1/9] Update main.c --- launcher-hdd/payload/main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 65f5202..667159e 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -99,6 +99,11 @@ char ROMVersionNumStr[5]; u32 bios_version = 0; +int HDDCheckSMARTStatus(void) +{ + return (fileXioDevctl("hdd0:", APA_DEVCTL_SMART_STAT, NULL, 0, NULL, 0) != 0); +} + void ResetIOP() { @@ -253,6 +258,17 @@ int main(int argc, char *argv[]) if ((romver_region_char[0] == 'J') && (bios_version <= 0x120)) isEarlyJap = 1; + if (HDDCheckSMARTStatus()) + { + if (fileXioMount("pfs0:", hddosd_party, FIO_MT_RDONLY) == 0) + { + if (file_exists("pfs0:/fsck/fsck.elf")) + LoadElf( "pfs0:/fsck/fsck.elf", hddosd_party); + if (file_exists("pfs0:/fsck100/fsck.elf")) + LoadElf( "pfs0:/fsck100/fsck.elf", hddosd_party); + } + } + if (fileXioMount("pfs0:", party, FIO_MT_RDONLY) == 0) { From a5256fc8e3bee9bda60c705a940b48c7a0b39480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Tue, 13 Dec 2022 20:08:00 -0300 Subject: [PATCH 2/9] Update main.c --- launcher-hdd/payload/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 667159e..8a84aab 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -99,6 +99,13 @@ char ROMVersionNumStr[5]; u32 bios_version = 0; +void BootError(void) +{ + char *args[1]; + args[0] = "BootBrowser"; + ExecOSD(1, args); +} + int HDDCheckSMARTStatus(void) { return (fileXioDevctl("hdd0:", APA_DEVCTL_SMART_STAT, NULL, 0, NULL, 0) != 0); @@ -266,6 +273,7 @@ int main(int argc, char *argv[]) LoadElf( "pfs0:/fsck/fsck.elf", hddosd_party); if (file_exists("pfs0:/fsck100/fsck.elf")) LoadElf( "pfs0:/fsck100/fsck.elf", hddosd_party); + BootError(); } } From e2e6ca6a9ba71602fee021f2d98f8d25dea2c1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Tue, 13 Dec 2022 20:12:37 -0300 Subject: [PATCH 3/9] Fix git/GitHub ownership issue --- .github/workflows/compile.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 3914cd6..770803a 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -14,8 +14,10 @@ jobs: - name: Install dependencies run: | apk add build-base git zip + - uses: actions/checkout@v2 - run: | + git config --global --add safe.directory "$GITHUB_WORKSPACE" git fetch --prune --unshallow - name: Compile From f235bf878d21cb2d24109195a5b9e3d492b22cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Wed, 14 Dec 2022 21:31:23 -0300 Subject: [PATCH 4/9] Add needed headers? --- launcher-hdd/payload/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 8a84aab..6fdba43 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -1,4 +1,3 @@ - #include #include #include @@ -20,8 +19,12 @@ #include #include #include +#include #include "pad.h" +#define NEWLIB_PORT_AWARE +#include + #define NTSC 2 #define PAL 3 From fd83fa6615ecc32ca7e13a86fce2b51a44dd5fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Wed, 14 Dec 2022 21:50:29 -0300 Subject: [PATCH 5/9] Add part check and move FSCK runner to other func --- launcher-hdd/payload/main.c | 40 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 6fdba43..7bda54a 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -108,12 +108,35 @@ void BootError(void) args[0] = "BootBrowser"; ExecOSD(1, args); } - +/* Integrity checks for HDD + * Under Sony design for MBR programs, the MBR was in charge of checking if S.M.A.R.T and HDD format are ok + * If one of these checks fail, the MBR program task is simply looking for a FSCK program on __sysrem and running it + * WARNING: FreeHdBoot FSCK (Special build of SP193 HDDChecker) usage is heavily encouraged + */ int HDDCheckSMARTStatus(void) { return (fileXioDevctl("hdd0:", APA_DEVCTL_SMART_STAT, NULL, 0, NULL, 0) != 0); } +int HDDCheckPartErrorStatus(void) +{ + return (fileXioDevctl("hdd0:", APA_DEVCTL_GET_ERROR_PART_NAME, NULL, 0, NULL, 0) != 0); +} + +static void RunFSCK(void) +{ + if (fileXioMount("pfs0:", hddosd_party, FIO_MT_RDONLY) == 0) + { + if (file_exists("pfs0:/fsck/fsck.elf")) + LoadElf( "pfs0:/fsck/fsck.elf", hddosd_party); + if (file_exists("pfs0:/fsck100/fsck.elf")) + LoadElf( "pfs0:/fsck100/fsck.elf", hddosd_party); + + } + BootError(); // Go to OSDSYS memcard browser if FSCK can't be found or if __system can't be mounted +} +//-------- + void ResetIOP() { @@ -268,16 +291,15 @@ int main(int argc, char *argv[]) if ((romver_region_char[0] == 'J') && (bios_version <= 0x120)) isEarlyJap = 1; +// Perform the checks in order, SMART first. why bother with filesystem damage if HDD is about to die? if (HDDCheckSMARTStatus()) { - if (fileXioMount("pfs0:", hddosd_party, FIO_MT_RDONLY) == 0) - { - if (file_exists("pfs0:/fsck/fsck.elf")) - LoadElf( "pfs0:/fsck/fsck.elf", hddosd_party); - if (file_exists("pfs0:/fsck100/fsck.elf")) - LoadElf( "pfs0:/fsck100/fsck.elf", hddosd_party); - BootError(); - } + RunFSCK(); + } + + if (HDDCheckPartErrorStatus()) + { + RunFSCK(); } if (fileXioMount("pfs0:", party, FIO_MT_RDONLY) == 0) From f9dd398a70a0654c5f4649f82a2bb1103b8f85bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Israelson?= <57065102+israpps@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:00:38 -0300 Subject: [PATCH 6/9] Update main.c --- launcher-hdd/payload/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 7bda54a..be1495e 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -95,6 +95,8 @@ typedef struct u32 flags; u32 align; } elf_pheader_t; +void LoadElf(char *filename, char *party); + u8 romver[16]; char romver_region_char[1]; From afbb7794357691e24009d60792a0bbae2f566e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20L=C3=B3pez-Parrado?= Date: Fri, 16 Dec 2022 11:49:36 -0500 Subject: [PATCH 7/9] Update main.c --- launcher-hdd/payload/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index be1495e..6ea9a72 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -125,7 +125,7 @@ int HDDCheckPartErrorStatus(void) return (fileXioDevctl("hdd0:", APA_DEVCTL_GET_ERROR_PART_NAME, NULL, 0, NULL, 0) != 0); } -static void RunFSCK(void) +static void RunFSCK(char *hddosd_party) { if (fileXioMount("pfs0:", hddosd_party, FIO_MT_RDONLY) == 0) { @@ -296,12 +296,12 @@ int main(int argc, char *argv[]) // Perform the checks in order, SMART first. why bother with filesystem damage if HDD is about to die? if (HDDCheckSMARTStatus()) { - RunFSCK(); + RunFSCK(hddosd_party); } if (HDDCheckPartErrorStatus()) { - RunFSCK(); + RunFSCK(hddosd_party); } if (fileXioMount("pfs0:", party, FIO_MT_RDONLY) == 0) From de2048b85fb821d0da82397243a08f1300d14a67 Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Wed, 22 Mar 2023 13:21:20 -0300 Subject: [PATCH 8/9] update code to reflect checks performed by FHDB MBR FreeHdBoot MBR was disclosed. so we can make this behave EXACTLY as it should! --- launcher-hdd/payload/main.c | 68 ++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 6ea9a72..91c843d 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -104,27 +104,53 @@ char ROMVersionNumStr[5]; u32 bios_version = 0; -void BootError(void) -{ - char *args[1]; - args[0] = "BootBrowser"; - ExecOSD(1, args); +static void BootError(int argc, char **argv){ + static char *argv_BootBrowser[2]={ + "BootBrowser", + NULL + }; + + fileXioDevctl("hdd:", HDIOC_DEV9OFF, NULL, 0, NULL, 0); + + if(argc<2){ + ExecOSD(1, argv_BootBrowser); + } + else{ + ExecOSD(argc, argv); + } } + /* Integrity checks for HDD * Under Sony design for MBR programs, the MBR was in charge of checking if S.M.A.R.T and HDD format are ok - * If one of these checks fail, the MBR program task is simply looking for a FSCK program on __sysrem and running it + * If one of these checks fail, the MBR program task is simply looking for a FSCK program on __system and running it * WARNING: FreeHdBoot FSCK (Special build of SP193 HDDChecker) usage is heavily encouraged */ -int HDDCheckSMARTStatus(void) +static int HDDCheckSMARTStatus(void) { return (fileXioDevctl("hdd0:", APA_DEVCTL_SMART_STAT, NULL, 0, NULL, 0) != 0); } -int HDDCheckPartErrorStatus(void) +static int HDDCheckPartErrorStatus(void) +{ + if(fileXioDevctl("hdd0:", HDIOC_GETERRORPARTNAME, NULL, 0, ErrorPartName, sizeof(ErrorPartName))!=0){ + if(strcmp(ErrorPartName, "__system")==0) /* Do not continue if it is `__system` that has the error, since fsck is stored there. */ + BootError(argc, argv); + return 1; + } +} + +/// @return true if HDD is not connected, formatted and ready to use +static int HDDCheckHDIOCIssues(void) { - return (fileXioDevctl("hdd0:", APA_DEVCTL_GET_ERROR_PART_NAME, NULL, 0, NULL, 0) != 0); + return (fileXioDevctl("hdd0:", HDIOC_STATUS, NULL, 0, NULL, 0)!=0); } +static int HDDCheckSectorError(void) +{ + return (fileXioDevctl("hdd0:", HDIOC_GETSECTORERROR, NULL, 0, NULL, 0)!=0); +} + + static void RunFSCK(char *hddosd_party) { if (fileXioMount("pfs0:", hddosd_party, FIO_MT_RDONLY) == 0) @@ -133,7 +159,6 @@ static void RunFSCK(char *hddosd_party) LoadElf( "pfs0:/fsck/fsck.elf", hddosd_party); if (file_exists("pfs0:/fsck100/fsck.elf")) LoadElf( "pfs0:/fsck100/fsck.elf", hddosd_party); - } BootError(); // Go to OSDSYS memcard browser if FSCK can't be found or if __system can't be mounted } @@ -293,16 +318,20 @@ int main(int argc, char *argv[]) if ((romver_region_char[0] == 'J') && (bios_version <= 0x120)) isEarlyJap = 1; -// Perform the checks in order, SMART first. why bother with filesystem damage if HDD is about to die? - if (HDDCheckSMARTStatus()) - { +// Perform the checks in order + + if (HDDCheckHDIOCIssues()) // HDD has connection isues or it's not formatted? + BootError(argc, argv); + + if (HDDCheckSMARTStatus()) // S.M.A.R.T first. who cares of filesystem is HDD is nearly dead? + RunFSCK(hddosd_party); + + if (HDDCheckSectorError()) // sector damage second... RunFSCK(hddosd_party); - } - if (HDDCheckPartErrorStatus()) - { + if (HDDCheckPartErrorStatus()) // Check for partition error. will boot FSCK unless the damaged partition is the one wich holds FSCK RunFSCK(hddosd_party); - } + if (fileXioMount("pfs0:", party, FIO_MT_RDONLY) == 0) { @@ -387,8 +416,7 @@ int main(int argc, char *argv[]) fileXioUmount("pfs0:"); } - //If no HDD-OSD was found, then launch ROM OSD - LoadElf("rom0:OSDSYS", "hdd0:"); - + //If no HDD-OSD was found, then launch ROM OSD with error argumment, to prevent endles loop + BootError(argc, argv); return 0; } From 9f48f9e1979257f66d1b2d030da26e5190d1767c Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Wed, 22 Mar 2023 13:23:03 -0300 Subject: [PATCH 9/9] compact IRX extern --- launcher-hdd/payload/main.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/launcher-hdd/payload/main.c b/launcher-hdd/payload/main.c index 91c843d..98030eb 100755 --- a/launcher-hdd/payload/main.c +++ b/launcher-hdd/payload/main.c @@ -34,33 +34,21 @@ #define ELF_MAGIC 0x464c457f #define ELF_PT_LOAD 1 +#define IMPORT_IRX(_IRX) \ + extern unsigned char _IRX[]; \ + extern unsigned int size_#_IRX + //Extern references to embedded IRX/loaders. extern u8 elf_loader_elf[]; extern int elf_size_loader_elf; - -extern unsigned char IOMANX_irx[]; -extern unsigned int size_IOMANX_irx; - -extern unsigned char FILEXIO_irx[]; -extern unsigned int size_FILEXIO_irx; - -extern unsigned char SIO2MAN_irx[]; -extern unsigned int size_SIO2MAN_irx; - -extern unsigned char PADMAN_irx[]; -extern unsigned int size_PADMAN_irx; - -extern unsigned char DEV9_irx[]; -extern unsigned int size_DEV9_irx; - -extern unsigned char ATAD_irx[]; -extern unsigned int size_ATAD_irx; - -extern unsigned char HDD_irx[]; -extern unsigned int size_HDD_irx; - -extern unsigned char PFS_irx[]; -extern unsigned int size_PFS_irx; +IMPORT_IRX(IOMANX_irx); +IMPORT_IRX(FILEXIO_irx); +IMPORT_IRX(SIO2MAN_irx); +IMPORT_IRX(PADMAN_irx); +IMPORT_IRX(DEV9_irx); +IMPORT_IRX(ATAD_irx); +IMPORT_IRX(HDD_irx); +IMPORT_IRX(PFS_irx); int VMode = NTSC; extern void *_gp;