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 

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

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



Joined: 24 Jan 2007
Posts: 84

PostPosted: Wed Jul 30, 2008 10:09 pm    Post subject: Write access to flash2: (NOT via USB! ;)) Reply with quote

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:

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



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Wed Jul 30, 2008 11:39 pm    Post subject: Reply with quote

can you tell us more on hb mode ( kernel , vsh ?)and on cfw version?
_________________
--pspZorba--
NO to K1.5 !
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Thu Jul 31, 2008 12:32 am    Post subject: Reply with quote

Use vsh mode (flags 0x800), unless there is a reason not to.
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Thu Jul 31, 2008 12:59 am    Post subject: Reply with quote

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



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Thu Jul 31, 2008 2:12 am    Post subject: Reply with quote

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:


...

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



Joined: 26 Oct 2005
Posts: 567

PostPosted: Thu Jul 31, 2008 3:16 am    Post subject: Reply with quote

Are the main thread flags set to PSP_THREAD_ATTR_VSH aswell?
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Thu Jul 31, 2008 3:57 am    Post subject: Reply with quote

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



Joined: 26 Oct 2005
Posts: 567

PostPosted: Thu Jul 31, 2008 4:34 am    Post subject: Reply with quote

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



Joined: 24 Jan 2007
Posts: 84

PostPosted: Thu Jul 31, 2008 5:05 am    Post subject: Reply with quote

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



Joined: 28 May 2008
Posts: 842

PostPosted: Thu Jul 31, 2008 12:02 pm    Post subject: Reply with quote

Thank you very much for that module.
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Fri Aug 01, 2008 10:47 am    Post subject: Reply with quote

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



Joined: 24 Mar 2008
Posts: 25

PostPosted: Fri Aug 01, 2008 11:18 pm    Post subject: Reply with quote

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



Joined: 17 Feb 2008
Posts: 23

PostPosted: Sat Aug 02, 2008 12:18 am    Post subject: Reply with quote

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



Joined: 24 Jan 2007
Posts: 84

PostPosted: Sat Aug 02, 2008 5:27 am    Post subject: Reply with quote

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



Joined: 24 Mar 2008
Posts: 25

PostPosted: Sat Aug 02, 2008 10:59 am    Post subject: Reply with quote

thx. I will download the prx and source.
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