forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange flash0 write access problem

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Sun Nov 04, 2007 3:05 pm    Post subject: Strange flash0 write access problem Reply with quote

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 :)
Back to top
View user's profile Send private message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Sat Nov 10, 2007 9:44 am    Post subject: Reply with quote

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 ?


Code:

#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(&param, 0, sizeof(param));
         
   param.key = "game";
   param.size = sizeof(param);
   param.args = strlen(target)+1;
   param.argp = target;

   sctrlKernelLoadExecVSHMs2(target, &param);   

}

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:

# 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
Back to top
View user's profile Send private message
.::Albandu51::.



Joined: 04 Oct 2007
Posts: 12

PostPosted: Mon Nov 12, 2007 9:11 pm    Post subject: Reply with quote

Hi,
Yes this is annoying, a flash how to get a file in the flash0 in kernel user? Thanks

PS: Sorry my English i am english
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Mon Nov 12, 2007 9:24 pm    Post subject: Reply with quote

.::Albandu51::. wrote:
PS: Sorry my English i am english


LOL
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Mon Nov 12, 2007 9:27 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Tue Nov 13, 2007 3:46 am    Post subject: Reply with quote

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 :)
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Sat Nov 17, 2007 11:43 am    Post subject: Reply with quote

Try to use vsh mode instead of user mode, this is:

PSP_MODULE_INFO("blahblah", 0x800, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VSH)

You could even reassign the flashes from it directly. M33-2 and 3 updaters do that, and they don't have any piece of kernel code.
Back to top
View user's profile Send private message
SPITFIR3



Joined: 21 Oct 2007
Posts: 16

PostPosted: Fri Jan 18, 2008 3:00 am    Post subject: Reply with quote

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

Code:

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);
}


Thanks
Back to top
View user's profile Send private message
hibbyware



Joined: 28 Mar 2007
Posts: 78

PostPosted: Fri Jan 18, 2008 3:29 am    Post subject: Reply with quote

@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,
Back to top
View user's profile Send private message
SPITFIR3



Joined: 21 Oct 2007
Posts: 16

PostPosted: Fri Jan 18, 2008 1:59 pm    Post subject: Reply with quote

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 did try your code, but it seemed to have the same effect with the prx, it wrote the text file fine though.

I am using the prx in header format using the code I posted.

For the prx my write_buffer is this.
Code:
char write_buffer[1024];

and this installs fine to ms.

Instead of
Code:

char write_buffer[128*1024];


I'll try again with you code and see what happens.

Thanks
Back to top
View user's profile Send private message
hibbyware



Joined: 28 Mar 2007
Posts: 78

PostPosted: Sat Jan 19, 2008 12:54 pm    Post subject: Reply with quote

Over writing a prx in flash sometimes fails depending on the file permissions set for that file,

So you would have to change the file permission to allow it to over write it,

Other option which is not really a safe option is to delete the prx thats in flash before replacing it,
Back to top
View user's profile Send private message
SPITFIR3



Joined: 21 Oct 2007
Posts: 16

PostPosted: Sat Jan 19, 2008 2:51 pm    Post subject: Reply with quote

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.
Code:

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);
}

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
Back to top
View user's profile Send private message
SPITFIR3



Joined: 21 Oct 2007
Posts: 16

PostPosted: Mon Jan 21, 2008 8:59 am    Post subject: Reply with quote

Sorted it out, I can now write, copy, remove files from flash0.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group