Strange flash0 write access problem
Strange flash0 write access problem
Hi.
I have a strange problem to write to the flash0 device on 3.71 firmware. In my new project, i have a little file manager and would like to be able to write to the flash.
I have a kernel module that export some functions to my user module, one of the function reassign the flash0 device in write mode. But it don't work. To find the problem i loaded my project with psplink, and saw that the device was correctly reassigned because i can copy a file with psplink to the flash0 device after executing my unlocking kernel function.
So i tought i would have to execute the copy function in my kernel prx to reproduce the same thing, but it wont work too. It's really strange i don't see where the problem is.
If someone have an idea it would be very cool because this make me silly :)
I have a strange problem to write to the flash0 device on 3.71 firmware. In my new project, i have a little file manager and would like to be able to write to the flash.
I have a kernel module that export some functions to my user module, one of the function reassign the flash0 device in write mode. But it don't work. To find the problem i loaded my project with psplink, and saw that the device was correctly reassigned because i can copy a file with psplink to the flash0 device after executing my unlocking kernel function.
So i tought i would have to execute the copy function in my kernel prx to reproduce the same thing, but it wont work too. It's really strange i don't see where the problem is.
If someone have an idea it would be very cool because this make me silly :)
Maybe i will have some answer with an exemple.
In this kernel module (build for exporting functions), if i uncomment the "copyFileKernel" line in the module start, the function work.
If i call the function from my usermode eboot, the function do not work (of course my exports are working, the "execEboot" function is working fine, also the "copyFileKernel" function is working while writing on flash1).
Its seems to be a new sony syscall protection ?
In this kernel module (build for exporting functions), if i uncomment the "copyFileKernel" line in the module start, the function work.
If i call the function from my usermode eboot, the function do not work (of course my exports are working, the "execEboot" function is working fine, also the "copyFileKernel" function is working while writing on flash1).
Its seems to be a new sony syscall protection ?
Code: Select all
#include <psptypes.h>
#include <pspkernel.h>
#include <stdio.h>
#include <string.h>
#include <pspiofilemgr.h>
#include <psptypes.h>
#include "../include/systemctrl.h"
PSP_MODULE_INFO("kernelExports", 0x1000, 0, 1);
PSP_NO_CREATE_MAIN_THREAD();
void copyFileKernel(const char *readpath, const char *writepath)
{
int fdin;
int fdout;
char write_buffer[1024];
printf("Writing %s\n", writepath);
fdin = sceIoOpen(readpath, PSP_O_RDONLY, 0777);
if(fdin >= 0)
{
int bytesRead = 1;
fdout = sceIoOpen(writepath, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
if(fdout < 0)
{
printf("Couldn't open %s\n", writepath);
}
bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
while((bytesRead > 0) && (fdout >= 0))
{
sceIoWrite(fdout, write_buffer, bytesRead);
bytesRead = sceIoRead(fdin, write_buffer, sizeof(write_buffer));
}
if(fdout >= 0)
{
sceIoClose(fdout);
}
if(fdin >= 0)
{
sceIoClose(fdin);
}
}
else
{
printf("Couldn't open %s\n", readpath);
}
}
void execEboot(char *target)
{
struct SceKernelLoadExecVSHParam param;
memset(¶m, 0, sizeof(param));
param.key = "game";
param.size = sizeof(param);
param.args = strlen(target)+1;
param.argp = target;
sctrlKernelLoadExecVSHMs2(target, ¶m);
}
int module_start(int argc, char* argv[])
{
sceIoUnassign("flash0:");
sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
// copyFileKernel("ms0:/test.txt", "flash0:/test.txt");
return 0;
}
int module_stop(int argc, char* argv[])
{
return 0;
}
Code: Select all
# Define the exports for the prx
PSP_BEGIN_EXPORTS
# These four lines are mandatory (although you can add other functions like module_stop)
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC_HASH(module_start)
PSP_EXPORT_VAR_HASH(module_info)
PSP_EXPORT_END
PSP_EXPORT_START(kernelExports, 0, 0x4001)
PSP_EXPORT_FUNC_HASH(copyFileKernel)
PSP_EXPORT_FUNC_HASH(execEboot)
PSP_EXPORT_END
PSP_END_EXPORTS
-
- Posts: 12
- Joined: Thu Oct 04, 2007 12:33 am
Cpasjuste, you are forgetting to put the code of your function exported to user between "int k1 = pspSdkSetK1(0)" and pspSdkSetK1(k1). Never forget to put those in a function you export for user mode, except in some cases of "inocent code" such as int func { return 1; }
The firmware is full of k1 shit checks.
The firmware is full of k1 shit checks.
Many thanks for the tips moonlight.
It's very strange because even with the setK1 function it doesn't work.
I launch psplink, i load my hombrew with psplink, but i cant write to the flash0 device with my user mode filer while it's possible in the brackground with psplink (after having reassigned the flash0 device in write mode with my kernel prx).
I am loosing my head :)
It's very strange because even with the setK1 function it doesn't work.
I launch psplink, i load my hombrew with psplink, but i cant write to the flash0 device with my user mode filer while it's possible in the brackground with psplink (after having reassigned the flash0 device in write mode with my kernel prx).
I am loosing my head :)
Hi moonlight, I'm trying the same thing for writing a file to flash0, but the files size always comes out 0 bytes.
FW = 3.71M33
Kernel = 3.71
If I change the write path to ms0 the file is written with the correct file size, i'm using vsh mode.
This is the code i'm using to write the file
Thanks
FW = 3.71M33
Kernel = 3.71
If I change the write path to ms0 the file is written with the correct file size, i'm using vsh mode.
This is the code i'm using to write the file
Code: Select all
void flashTest(const char *writepath)
{
SceUID fd;
sceIoUnassign("flash0:");
sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
fd = sceIoOpen(writepath, PSP_O_WRONLY | PSP_O_CREAT, 0777);
if(fd < 0)
{
printf("\n Cannot open file for writing.\n");
sceKernelExitGame();
}
int flashfile = sceIoWrite(fd, test_prx, size_test_prx);
if(flashfile != size_test_prx)
{
sceIoClose(fd);
printf("\n Cannot write file.\n");
sceKernelExitGame();
}
printf(" Writing file: %s\n",writepath);
sceKernelDelayThread(300000);
sceIoClose(fd);
}
@SPITFIR3
Have a look at my last post here...
http://forums.ps2dev.org/viewtopic.php?t=9648
The code will flash a test.txt but I use the same type of code to flash prx's aswell,
Have a look at my last post here...
http://forums.ps2dev.org/viewtopic.php?t=9648
The code will flash a test.txt but I use the same type of code to flash prx's aswell,
I did try your code, but it seemed to have the same effect with the prx, it wrote the text file fine though.hibbyware wrote:@SPITFIR3
Have a look at my last post here...
http://forums.ps2dev.org/viewtopic.php?t=9648
The code will flash a test.txt but I use the same type of code to flash prx's aswell,
I am using the prx in header format using the code I posted.
For the prx my write_buffer is this.
Code: Select all
char write_buffer[1024];
Instead of
Code: Select all
char write_buffer[128*1024];
Thanks
Thanks hibbyware, didn't think about the file permissions, I'll give it another go with either deleting the file or changing it's permissions.
The prx i'm trying to write to flash0 don't exist there, it just seems whatever I try and that includes your direct code, it always results in a file size of 0 bytes, but the same code writing the same file to the memory stick works with the correct file size.
I just can't figure out why it's writing 0 bytes.
UPDATE:
The code below works on 3.52M33, give the correct bytes.
So could it be different write permissions, if so how would I set these's for 3.71M33 or 3.80M33.
Thanks again.
UPDATE:
I have managed to get this to work now on 1 of my 3.80M33 psp's.
I've also found out why the files don't write. If the folder your writing to has it's hidden attribute set.
I've never had to set a files attribute before so don't know how to do it any help appreciated.
Thanks
The prx i'm trying to write to flash0 don't exist there, it just seems whatever I try and that includes your direct code, it always results in a file size of 0 bytes, but the same code writing the same file to the memory stick works with the correct file size.
I just can't figure out why it's writing 0 bytes.
UPDATE:
The code below works on 3.52M33, give the correct bytes.
Code: Select all
void flashmyprx(const char *writepath)
{
SceUID fd;
fd = sceIoOpen(writepath, PSP_O_WRONLY | PSP_O_CREAT, 0777);
if(fd < 0)
{
printf("\n Cannot open for writing.\n");
sceKernelDelayThread(300000);
sceKernelExitGame();
}
int myprx = sceIoWrite(fd, test_prx, size_test_prx);
if(myprx != size_test_prx)
{
sceIoClose(fd);
printf("\n Cannot write file.\n");
sceKernelDelayThread(300000);
sceKernelExitGame();
}
printf(" Writing file: %s\n",writepath);
sceKernelDelayThread(300000);
sceIoClose(fd);
}
Thanks again.
UPDATE:
I have managed to get this to work now on 1 of my 3.80M33 psp's.
I've also found out why the files don't write. If the folder your writing to has it's hidden attribute set.
I've never had to set a files attribute before so don't know how to do it any help appreciated.
Thanks