Write access to flash2: (NOT via USB! ;))

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Write access to flash2: (NOT via USB! ;))

Post by Hellcat »

Hi there :)

In my little app, I am currently finishing, I want to WRITE a file to flash2:/
(NO, not via USB, only from inside the app)
(NO, I am NOT trying to hack anything, only RESTORING the PSN activation data)

The usual unassing and reassign chain doesn't seem to work:

Code: Select all

sceIoUnassign( "flash2:" );
sceIoAssign("flash2:", "lflash0:0,2", "flashfat2:", IOASSIGN_RDWR, NULL, 0);
fd = sceIoOpen(file, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
I am getting a 0x8001000d (no access file permission) when trying to WRITE the file using the above.
Reading, when the file is present, works flawlessly.
Write access to flash0:/ is also working perfectly, so I'm not too dump for such stuff ;)

Performing everything from kernel mode (incl. SetK1) doesn't change a thing....

Searching dug up two threads with a similar question, answered with nothing but (semi)flames or "why do you want to do it anyway?" - so we can skip that part, it's already done ;)


Anyone any clue how to actually get WRITE access to flash2?

Thanx in advance :)
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

can you tell us more on hb mode ( kernel , vsh ?)and on cfw version?
--pspZorba--
NO to K1.5 !
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Use vsh mode (flags 0x800), unless there is a reason not to.
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Post by Hellcat »

pspZorba wrote:can you tell us more on hb mode ( kernel , vsh ?)and on cfw version?
The main binary is VSH (0x800), tried both, calling from there or from my kernel mode .PRX that get loaded/started by the main module (didn't forget the SetK1 as well).

FW I so far tried is 4.01-M33

moonlight wrote:Use vsh mode (flags 0x800), unless there is a reason not to.
I am already using those flags, as some other things wouldn't work without beeing in VSH mode as well.

Oh, and I am in updater mode, if that makes any difference....
(The app restarts itself to get there).
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

I am not sure that's the problem, but I had a a kind of same issue, and moonlight gave me the solution.
But as he didn't suggested it you I might be wrong, and I can't test it before tonight (EST).

try to put sctrlKernelSetUserLevel before and after your file access.
like :

Code: Select all


...

    u32 k1;
    int oldlevel = sctrlKernelSetUserLevel( 4);
    k1 = pspSdkSetK1(0);  

    YOUR ACCESS TO THE FILE Open/write etc 

    pspSdkSetK1(k1);
    sctrlKernelSetUserLevel(oldlevel); 

....

--pspZorba--
NO to K1.5 !
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Are the main thread flags set to PSP_THREAD_ATTR_VSH aswell?
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Post by Hellcat »

@pspZorba:
That's worth a try, will do once I get home.

However, I'd like to avoid M33 specific special functions, as my app might run on CFWs not containing them (older OEs, or such).

moonlight wrote:Are the main thread flags set to PSP_THREAD_ATTR_VSH aswell?
Aye! They are....

:-/
Weird thing.... Do I have to "tell" the FW something before it lets me write?
(Any special protection, 'cause it's the DRM data stored there?)
Anything else is working so nicely :)

I also checked, it's not the case that the file exists and is protected by file attributes, the file does not exist at the moment when I try to copy it back.
(it might be at some point, but if it isn't even working w/o....)
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Looked at old sources, sctrlKernelSetUserLevel is there since 2.71 SE-C :)

Here is a prx that I use to avoid those issues, iop.prx. It patches the system so most io functions (there are some missing like the async ones) set the user level to 8 (which is the user level of pure kernel thread). This prx should work in 3.02 OE-C and higher, because of the PatchSyscall function not available before. I doubt there are too many people with versions prior to that :)

Just load and start it before anything else.

EDIT: it was an incorrect version, it was psp-compressed. The correct file is:
http://www.sendspace.com/file/qp7h1h
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Post by Hellcat »

Oh, this is GREAT :)

Many, many thanks, I will give it a try as soon as possible and report back :)


Once this bit works, I can finally finish the first version of my app :)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Thank you very much for that module.
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Post by Hellcat »

Thanx again!

I just tried, and it works perfectly!
Didn't load the entire .PRX, just wrapped the SetUserlevel calls around my file IO, and everything is fine now!

Great that you put the source in the archive as well, so I can incorporate rge bits I need into my existing kernel module :)
homemister
Posts: 25
Joined: Mon Mar 24, 2008 12:16 pm

Post by homemister »

hey hellcat,
could i get a copy of what you did. I have been trying to get R/W acsess to the flash 2 for so long.
But surprisingly flash3 has no problems mounting in R/W mode using the assign and unassign functions.

Regards
Homemister
Gh0st-UPMS
Posts: 23
Joined: Sun Feb 17, 2008 12:32 am

Post by Gh0st-UPMS »

homemister wrote:hey hellcat,
could i get a copy of what you did. I have been trying to get R/W acsess to the flash 2 for so long.
But surprisingly flash3 has no problems mounting in R/W mode using the assign and unassign functions.

Regards
Homemister
Just dl the prx and load it before anything else or do as Hellcat has done and only use the bits you need to use, you don't need to call anything from the prx within your program and assign/unassign as usual. Either way you do it you must load it before other modules that your app uses.

Thanks for this Moonlight :)
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Post by Hellcat »

The archive of the .PRX also contains it's source.

So if you'd rather do stuff in your own code, than loading several .PRXs, you can look there how and what to do to achive the same result.

Anyway, if still wanted, I can post my WriteFile snipped, that uses the sctrlSetUserLeverl call to get the neccessary permissions.

And like I know myself, the source of my just finished app will be released in public anyway :D
(maybe a bit later, since it needs some cleanup, but it's most likely I'll release it :))
homemister
Posts: 25
Joined: Mon Mar 24, 2008 12:16 pm

Post by homemister »

thx. I will download the prx and source.
Post Reply