Problem with sceLflashFatfmtStartFatfmt

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

Moderators: cheriff, TyRaNiD

Post Reply
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Problem with sceLflashFatfmtStartFatfmt

Post by JumpR »

Hey,

First of all, note that I'm trying to run this application from a DDCv4 stick using the ELF menu. Also, I already tried to search, and I can't seem to make up from that why it isn't working.
I need to format flash0, flash1 and flash2.
I did my best to write it as clean as possible with loops and stuff :) I reversed the modules to load from DDC.

Code: Select all

int sceLflashFatfmtStartFatfmt(int args_number,void* argv);

#define N_Modules 3
char* Modules [N_Modules] = { "ms0:/kd/nand_updater.prx", "ms0:/kd/lfatfs_updater.prx",  "ms0:/kd/lflash_fatfmt_updater.prx" };

int main(){

   char buf1[20];

   /* Loading modules */
   for&#40;i = 0; i < N_Modules; i++&#41;&#123;
      printf&#40;"Loading %s...", Modules&#91;i&#93;&#41;;
      
      mod = pspSdkLoadStartModule&#40;Modules&#91;i&#93;, PSP_MEMORY_PARTITION_KERNEL&#41;;      
      if &#40;mod < 0&#41;
         ErrorExit&#40;5, 1, "\nError 0x%08X loading/starting %s.", mod, Modules&#91;i&#93;&#41;;
      
      printf&#40;" done\n"&#41;;
   &#125;

   /* Unassigning Flashes */
   printf&#40;"Unassigning flashes..."&#41;;
   
   for&#40;i = 0; i < 2; i++&#41;&#123;
      sprintf&#40;buf1, "flash%i&#58;", i&#41;;
      if &#40;sceIoUnassign&#40;buf1&#41; < 0&#41;
         ErrorExit&#40;5, 1, "\nError&#58; Can't unassign flash%i.", i&#41;;
   &#125;
   
   printf&#40;" done\n"&#41;;

   /* Formatting flashes */
   char *argv&#91;2&#93;;
   argv&#91;0&#93; = "fatfmt";
   
   for&#40;i = 0; i < 3; i++&#41;&#123;
      printf&#40;"Formatting flash%i...", i&#41;;
      
      sprintf&#40;buf1, "lflash0&#58;0,%i", i&#41;;
      argv&#91;1&#93; = buf1;
   
      if &#40;sceLflashFatfmtStartFatfmt&#40;2, argv&#41; < 0&#41;
         ErrorExit&#40;5, 1, "\nError whilst formatting flash%i.", i&#41;;
      printf&#40;" done\n"&#41;;
   &#125;
&#125;
My stubs file:

Code: Select all

		.set noreorder

#include "pspstub.s"

	STUB_START "LflashFatfmt",0x40090000,0x00010005
	STUB_FUNC 0xB7A424A4,sceLflashFatfmtStartFatfmt
	STUB_END
Now, my problem is, that it simply freezes when it starts to format. I've been spending like 3 hours on this little bug now, and it's driving me crazy.
Is there a special trick needed because I'm loading it from the DDC stick or is there something wrong with my code?

Thanks,
JumpR :)
Last edited by JumpR on Thu Mar 13, 2008 4:12 pm, edited 2 times in total.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Does it shutdown itself? (the psp)
Image
Upgrade your PSP
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Post by JumpR »

Pirata Nervo wrote:Does it shutdown itself? (the psp)
Yes. Well, it hangs at "Formatting flash0..." for a few seconds, then it shuts itself down.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Are you running on usermode?
Image
Upgrade your PSP
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Post by JumpR »

Pirata Nervo wrote:Are you running on usermode?
Nope.

Code: Select all

PSP_MODULE_INFO&#40;"Test", 0x1000, 1, 0&#41;;
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

That might be the problem. Change it to 0.
Image
Upgrade your PSP
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Post by JumpR »

Pirata Nervo wrote:That might be the problem. Change it to 0.
That doesn't make sense.. How can I format the flashes, write files and other stuff in user mode? DDC is also kernel mode...
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Huh? That code can't even compile.
You reference buf1 before you declare it; you're missing a semicolon when you do declare it; etc.
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Post by JumpR »

jimparis wrote:Huh? That code can't even compile.
You reference buf1 before you declare it; you're missing a semicolon when you do declare it; etc.
I'm sorry, it was caused by the fact that this is only a snippet of the whole code, fixed ;) In the original code it was correct, so that wasn't the reason.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

You never fill "argv[0]" before calling sceLflashFatfmtStartFatfmt. (And if you answer is again just "Oh, but it's there in the real code".. then well, if you can't be bothered to post the proper code, then we can't be bothered to look at it).
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Post by JumpR »

jimparis wrote:You never fill "argv[0]" before calling sceLflashFatfmtStartFatfmt. (And if you answer is again just "Oh, but it's there in the real code".. then well, if you can't be bothered to post the proper code, then we can't be bothered to look at it).
Wait, that might be the problem :) I removed it accidently during my 3 hours of trying.. everything. However, I recompiled with the line (argv[0] = "fatfmt";), and it still doesn't work :(

I'm sorry that I won't post the full code, it's a little over 400 lines and I don't want to post it fully here, this snippet is a direct copy, however, the declaration of buf1[20]; was at the top of the code in the full code, so I forgot to move it before posting it here, sorry about that.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Try to unassign before loading the modules.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

@JumpR, create a kernel prx where you can load the function from (mode 0x1006) and then use usermode in your main application.
Image
Upgrade your PSP
JumpR
Posts: 25
Joined: Sun Feb 10, 2008 1:07 am

Post by JumpR »

moonlight wrote:Try to unassign before loading the modules.
Not working :( Do I need a little trick because I'm trying to format from the DDC memstick? Like disabling flashemu?
Pirata Nervo wrote:@JumpR, create a kernel prx where you can load the function from (mode 0x1006) and then use usermode in your main application.
Why... As I said, I'm running this from my DDC stick, using the 1.50 kernel, and in 1.50 you can load in kernel mode perfectly fine, even the original DDC resurrection.elf is kernel mode.

It gets worse, I reversed a patch from DDC:

Code: Select all

		if&#40;&#40;!bSlim&#41; && &#40;!strcmp&#40;Modules&#91;i&#93;, "ms0&#58;/kd/nand_updater.prx"&#41;&#41;&#41;&#123;
			sceKernelDelayThread&#40;4*1000*1000&#41;;
			u32 *mod = &#40;u32 *&#41;sceKernelFindModuleByName&#40;"sceNAND_Updater_Driver"&#41;;
			u32 text_addr = *&#40;mod+27&#41;;
			_sh&#40;0xac60, text_addr+0xE4E&#41;;
			sceKernelDcacheWritebackAll&#40;&#41;;
			sceKernelIcacheClearAll&#40;&#41;;
		&#125;
However, it can't find sceNAND_Updater_Driver, atleast, that's what I think, as it crashes at that line. It's executed right after loading ms0:/kd/nand_updater.prx ;)
Post Reply