From 4f10474794d4aea061461c4ac05573d7cade1766 Mon Sep 17 00:00:00 2001 From: Joel16 Date: Tue, 31 May 2022 10:57:03 -0400 Subject: [PATCH] app: Load kernel plugins from memory --- .github/workflows/c-cpp.yml | 12 ------------ app/Makefile | 28 +++++++++++++++------------ app/source/utils.cpp | 38 +++++++++++++++++++++++++++++++++---- audio_driver/Makefile | 1 + display_driver/Makefile | 1 + fs_driver/Makefile | 1 + 6 files changed, 53 insertions(+), 28 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 93d964c..1931d54 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -20,18 +20,6 @@ jobs: - name: Compile project run: make - - uses: actions/upload-artifact@v2 - with: - path: audio_driver/audio_driver.prx - - - uses: actions/upload-artifact@v2 - with: - path: display_driver/display_driver.prx - - - uses: actions/upload-artifact@v2 - with: - path: fs_driver/fs_driver.prx - - uses: actions/upload-artifact@v2 with: path: app/EBOOT.PBP diff --git a/app/Makefile b/app/Makefile index 1ad93f1..7a795a4 100644 --- a/app/Makefile +++ b/app/Makefile @@ -1,14 +1,15 @@ TARGET = CMFileManager SOURCES := data drivers source source/audio source/gui ../libs/libnsbmp ../libs/libnsgif -CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c)) -SFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.S)) -CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp)) -GFXFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.png)) -FONTFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.pgf)) +CFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.c)) +SFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.S)) +CPPFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.cpp)) +FONTFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.pgf)) +GFXFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.png)) +PRXFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.prx)) -OBJS := $(addsuffix .o,$(BINFILES)) \ - $(CFILES:.c=.o) $(SFILES:.S=.o) $(CPPFILES:.cpp=.o) $(GFXFILES:.png=.o) $(FONTFILES:.pgf=.o) +OBJS := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(SFILES:.S=.o) $(CPPFILES:.cpp=.o) \ + $(FONTFILES:.pgf=.o) $(GFXFILES:.png=.o) $(PRXFILES:.prx=.o) VERSION_MAJOR := 4 VERSION_MINOR := 1 @@ -30,15 +31,18 @@ LIBS = -lintrafont -lglib2d -lxmp -lmpg123 -lvorbisfile -lvorbis -lopusfile - -lpspkubridge -lpspsystemctrl_user -lpspusbdevice \ -lpspgu -lpspvram -lpspaudio -lpsppower -lpspreg -lpspusb -lpspusbstor -lpspumd -EXTRA_TARGETS = EBOOT.PBP -PSP_EBOOT_TITLE = CM File Manager PSP v$(VERSION_MAJOR).$(VERSION_MINOR)$(VERSION_MICRO) -PSP_EBOOT_ICON = ../ICON0.PNG +EXTRA_TARGETS = EBOOT.PBP +PSP_EBOOT_TITLE = CM File Manager PSP v$(VERSION_MAJOR).$(VERSION_MINOR)$(VERSION_MICRO) +PSP_EBOOT_ICON = ../ICON0.PNG PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak +%.o: %.pgf + bin2o -i $< $@ $(addsuffix _pgf, $(basename $(notdir $<) )) + %.o: %.png bin2o -i $< $@ $(addsuffix _png, $(basename $(notdir $<) )) -%.o: %.pgf - bin2o -i $< $@ $(addsuffix _pgf, $(basename $(notdir $<) )) +%.o: %.prx + bin2o -i $< $@ $(addsuffix _prx, $(basename $(notdir $<) )) \ No newline at end of file diff --git a/app/source/utils.cpp b/app/source/utils.cpp index 6b2e1eb..9e72f8c 100644 --- a/app/source/utils.cpp +++ b/app/source/utils.cpp @@ -21,6 +21,9 @@ enum PspCtrlButtons PSP_CTRL_ENTER, PSP_CTRL_CANCEL; BROWSE_STATE device = BROWSE_STATE_EXTERNAL; int g_psp_language = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH; +extern unsigned char audio_driver_prx_start[], display_driver_prx_start[], fs_driver_prx_start[]; +extern unsigned int audio_driver_prx_size, display_driver_prx_size, fs_driver_prx_size; + namespace Utils { constexpr unsigned int CTRL_DEADZONE_DELAY = 500000; constexpr unsigned int CTRL_DELAY = 100000; @@ -34,12 +37,14 @@ namespace Utils { typedef struct { const char *path = nullptr; int id = 0; + unsigned char *data = nullptr; + unsigned int size = 0; } Module; static std::vector kernel_modules { - { "audio_driver.prx", -1, }, - { "display_driver.prx", -1, }, - { "fs_driver.prx", -1, } + { "audio_driver.prx", -1, audio_driver_prx_start, audio_driver_prx_size }, + { "display_driver.prx", -1, display_driver_prx_start, display_driver_prx_size }, + { "fs_driver.prx", -1, fs_driver_prx_start, fs_driver_prx_size } }; static std::vector usb_modules { @@ -110,6 +115,31 @@ namespace Utils { return ret; } + // Basically removes and re-creates prx from memory -> then remove it after inital load + static int LoadStartModuleMem(const char *path, const void *buf, SceSize size) { + int ret = 0; + SceUID modID = 0; + + // Don't care if this passes or fails + sceIoRemove(path); + SceUID file = sceIoOpen(path, PSP_O_WRONLY | PSP_O_CREAT, 0777); + sceIoWrite(file, buf, size); + sceIoClose(file); + + if (R_FAILED(ret = modID = kuKernelLoadModule(path, 0, nullptr))) { + Log::Error("kuKernelLoadModule(%s) failed: 0x%08x\n", path, ret); + return ret; + } + + if (R_FAILED(ret = sceKernelStartModule(modID, 0, nullptr, nullptr, nullptr))) { + Log::Error("sceKernelStartModule(%s) failed: 0x%08x\n", path, ret); + return ret; + } + + sceIoRemove(path); + return 0; + } + static void StopUnloadModules(SceUID modID) { sceKernelStopModule(modID, 0, nullptr, nullptr, nullptr); sceKernelUnloadModule(modID); @@ -216,7 +246,7 @@ namespace Utils { void InitKernelDrivers(void) { for (unsigned int i = 0; i < kernel_modules.size(); ++i) - kernel_modules[i].id = Utils::LoadStartModule(kernel_modules[i].path); + kernel_modules[i].id = Utils::LoadStartModuleMem(kernel_modules[i].path, kernel_modules[i].data, kernel_modules[i].size); Utils::InitUSB(); } diff --git a/audio_driver/Makefile b/audio_driver/Makefile index 28da760..3fe1165 100644 --- a/audio_driver/Makefile +++ b/audio_driver/Makefile @@ -24,3 +24,4 @@ include $(PSPSDK)/lib/build_prx.mak all: psp-build-exports -s $(PRX_EXPORTS) mv audio_driver.S "../app/drivers/" + mv audio_driver.prx "../app/data/" diff --git a/display_driver/Makefile b/display_driver/Makefile index 114ee89..7f7a8f5 100644 --- a/display_driver/Makefile +++ b/display_driver/Makefile @@ -24,3 +24,4 @@ include $(PSPSDK)/lib/build_prx.mak all: psp-build-exports -s $(PRX_EXPORTS) mv display_driver.S "../app/drivers/" + mv display_driver.prx "../app/data/" diff --git a/fs_driver/Makefile b/fs_driver/Makefile index 99aae19..b92f25e 100644 --- a/fs_driver/Makefile +++ b/fs_driver/Makefile @@ -24,3 +24,4 @@ include $(PSPSDK)/lib/build_prx.mak all: psp-build-exports -s $(PRX_EXPORTS) mv fs_driver.S "../app/drivers/" + mv fs_driver.prx "../app/data/"