sleirsgoevy/ps4jb

Pullrequest

Closed this issue · 6 comments

I added a couple changes but wasn't sure how to best make a pull request so here there are.
Would be nice if you could merge:

Patch1: Add --no-dynamic-linker flag
src/payloads/linux/ps4-kexec/Makefile

-	-Os -Wall -Werror -Wl,--build-id=none,-T,kexec.ld,--nmagic \
+	-Os -Wall -Werror -Wl,--no-dynamic-linker,--build-id=none,-T,kexec.ld,--nmagic \


Patch2: Add -fno-stack-protector flag
src/payloads/lib/Makefile

-	gcc -c -isystem ../../8cc/freebsd-headers -nostdinc dl.c -o dl.o
+	gcc -c -isystem ../../8cc/freebsd-headers -nostdinc dl.c -o dl.o -fno-stack-protector

Patch3: 
	- Prefer USB over local config
	- make bootargs and vram configurable from file
src/payloads/linux/main.c

---------------------------------- PATCHFILE -----------------------------------------
diff --git a/src/payloads/linux/main.c b/src/payloads/linux/main.c
index 4e0db5a..eb1fd53 100644
--- a/src/payloads/linux/main.c
+++ b/src/payloads/linux/main.c
@@ -103,6 +103,15 @@ void alert(const char* msg)
 #define VRAM_GB 1
 #endif
 
+#ifndef VRAM_GB_MIN
+#define VRAM_GB_MIN 1
+#endif
+
+#ifndef VRAM_GB_MAX
+#define VRAM_GB_MAX 3
+#endif
+
+
 int main()
 {
     struct sigaction sa = {
@@ -113,23 +122,55 @@ int main()
     sigaction(SIGSTOP, &sa, NULL);
     sigaction(SIGTERM, &sa, NULL);
     sigaction(SIGKILL, &sa, NULL);
-    char* kernel;
-    unsigned long long kernel_size;
-    char* initrd;
-    unsigned long long initrd_size;
-#define L(name, where, wheresz)\
-    if(read_file("/user/system/boot/" name, where, wheresz)\
-    && read_file("/mnt/usb0/" name, where, wheresz)\
-    && read_file("/mnt/usb1/" name, where, wheresz))\
+    char* kernel = NULL;
+    unsigned long long kernel_size = 0;
+    char* initrd = NULL;
+    unsigned long long initrd_size = 0;
+    char* cmdline = NULL;
+    unsigned long long cmdline_size = 0;
+    char* vramstr = NULL;
+    unsigned long long vramstr_size = 0;
+    
+    int vramgb = 0;
+
+#define L(name, where, wheresz, is_fatal)\
+    if(read_file("/mnt/usb0/" name, where, wheresz)\
+    && read_file("/mnt/usb1/" name, where, wheresz)\
+    && read_file("/user/system/boot/" name, where, wheresz))\
     {\
         alert("Failed to load file: " name ".\nPaths checked:\n/user/system/boot/" name "\n/mnt/usb0/" name "\n/mnt/usb1/" name);\
-        return 1;\
+        if (is_fatal) return 1;\
     }
-    L("bzImage", &kernel, &kernel_size);
-    L("initramfs.cpio.gz", &initrd, &initrd_size);
-    char* cmdline = "panic=0 clocksource=tsc radeon.dpm=0 console=tty0 console=ttyS0,115200n8 "
-                    "console=uart8250,mmio32,0xd0340000 video=HDMI-A-1:1920x1080-24@60 "
-                    "consoleblank=0 net.ifnames=0 drm.debug=0";
+    L("bzImage", &kernel, &kernel_size, 1);
+    L("initramfs.cpio.gz", &initrd, &initrd_size, 1);
+        
+    L("bootargs.txt", &cmdline, &cmdline_size, 0);
+
+    if (cmdline && cmdline_size){
+	for (int i=0; i<cmdline_size; i++) {
+            if (cmdline[i] == '\n') {
+                cmdline[i] = '\0';
+                break;
+            }
+        }
+    }else{
+        cmdline = "panic=0 clocksource=tsc radeon.dpm=0 console=tty0 console=ttyS0,115200n8 "
+                  "console=uart8250,mmio32,0xd0340000 video=HDMI-A-1:1920x1080-24@60 "
+                  "consoleblank=0 net.ifnames=0 drm.debug=0";
+    }
+
+    L("vram.txt", &vramstr, &vramstr_size, 0);
+
+    if (vramstr && vramstr_size){
+        vramgb = atoi(vramstr);
+        if (vramgb < VRAM_GB_MIN || vramgb > VRAM_GB_MAX){
+            vramgb = VRAM_GB;
+        }
+    }else{
+        vramgb = VRAM_GB;
+    }
+
+
     kexec(kernel_main, (void*)0);
     long x, y;
     struct thr_param thr = {
     ```

i just realized that it is probably a good idea to make paraing the vram.txt optional with an ifdef so that it doesn't conflict with you current way of multiple payloads (3gb/1gb)

For example if VRAM_GB isn't defined then enable dynamic vram.txt parsing with the default value being hardcoded to 1gb

Also in case you'd want to rebuild linux payloads: the current payload will use the same kexec.bin binary for both 6.72 and 7.02 builds, and this is wrong. But I'm too lazy to fix ps4-kexec's build system to allow multi-fw builds.

To make a pull request: fork the repository, edit the files in your fork, then there will be a button to open a pull request. After it gets merged you can delete your repository.

I don't think i can fork the ps4-kexec repo (first patch) because it's technically not a repository that is embedded here.
That's why i opened this issue in first place.

For me to be able to fork your ps4-kexec state, you need to fork https://github.com/ethylamine/ps4-kexec
into a full own fork, then i could open a PR there to update the code, then i could open a PR her for you to update the submodule to match that.

For patch 2 and 3: yes i could open a pr here.
Can you do fork ps4-kexec properly so i can make PRs there too?

It's weird, seems like you do have a fork of ps4-kexec.
Altought if you go here:
https://github.com/sleirsgoevy/ps4jb/tree/master/src/payloads/linux
and click ps4-kexec it redirects you
here https://github.com/ethylamine/ps4-kexec
instead of here https://github.com/sleirsgoevy/ps4-kexec

Seems like you .gitmodules are configured incorrectly, see:
https://github.com/sleirsgoevy/ps4jb/blob/master/.gitmodules#L6

Could you fix that?

Alright, i made a couple pullrequests:
sleirsgoevy/ps4-kexec#1
#66
#67

we probabl should move furthere discussion there (if any).