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 

sceNand functions and dumping the flash

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



Joined: 26 Oct 2005
Posts: 567

PostPosted: Wed Oct 26, 2005 8:02 pm    Post subject: sceNand functions and dumping the flash Reply with quote

i've gladly seen that the sceNand functions have been recently added to the PSPSDK and also a good example dumping the IPL.

I've tried to create a program that dumps all the nand to a single binary file... but it doesn't work as expected.

Code:

nblocks = sceNandGetTotalBlocks();
   ppb = sceNandGetPagesPerBlock();
   cbBlock = ppb * sceNandGetPageSize();

   block = (u8 *)malloc(cbBlock);

   for (i = 0; i < nblocks; i++)
   {
      sceNandLock(0);

      if (!sceNandIsBadBlock(i))
      {

         memset(block, 0, cbBlock);
         goodb++;
      
         if (sceNandReadBlockWithRetry(i*ppb, block, NULL) < 0)
         {
            printf("Error reading block #%d\n", i);
            sceNandUnlock();
            continue;
         }

         writtenb++;
         printf("Dumping block #%d\n", i);
         sceIoWrite(fd, block, cbBlock);
      }
      
      else
      {
         printf("bad block :#%d\n", i);
      }

      sceNandUnlock();
   }

   printf("Done. good blocks: %d, written: %d\n", goodb, writtenb);



At the end, goodb (good blocks) = 64 and writtenb (written blocks) = 61, and the file is less than 1 MB when it should be exactly 32 MB if it had written the 2048 blocks.

What are exactly bad blocks? and why 3 of the good blocks are not read correctly? does the kernel block access to read them?
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Oct 26, 2005 8:04 pm    Post subject: Reply with quote

update your sdk....mrbrown (i think) added a sample that dumps the flash using scenand interface :)
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Wed Oct 26, 2005 8:07 pm    Post subject: Reply with quote

groepaz wrote:
update your sdk....mrbrown (i think) added a sample that dumps the flash using scenand interface :)


yes, i have it and i have read his code before making the mine. but it only dumps the ipl.
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Oct 26, 2005 8:13 pm    Post subject: Reply with quote

ah ok i see :)

about the bad blocks.... you maybe want to read up on NAND flash (get a datasheet on a simelar flash). in a nutshell, NAND flashes use EDC coding and "backup" blocks simelar to HDs do. i dont know how exactly this is handled by the sceNand driver though, i got distracted from reversing that one :=P
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Thu Oct 27, 2005 1:30 am    Post subject: Re: sceNand functions and dumping the flash Reply with quote

moonlight wrote:
Code:

nblocks = sceNandGetTotalBlocks();
   ppb = sceNandGetPagesPerBlock();
   cbBlock = ppb * sceNandGetPageSize();

   block = (u8 *)malloc(cbBlock);

   for (i = 0; i < nblocks; i++)
   {
      sceNandLock(0);

      if (!sceNandIsBadBlock(i))
      {


The problem is the argument to sceNandIsBadBlock(). All flash addresses are given in page offsets, so you have to pass the physical page number instead of the block number (you're already doing this in your call to sceNandReadBlockWithRetry()).
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Thu Oct 27, 2005 7:47 am    Post subject: Re: sceNand functions and dumping the flash Reply with quote

mrbrown wrote:

The problem is the argument to sceNandIsBadBlock(). All flash addresses are given in page offsets, so you have to pass the physical page number instead of the block number (you're already doing this in your call to sceNandReadBlockWithRetry()).


ok. i've solved that, what a stupid mistake of mine. now the result is:

good blocks: 2048 (i have the flash in perfect state... at the moment :P )
written blocks: 1947

The dump, ~30.4 MB. i wanted to fully backup every byte, every bit of the flash to a file, but i don't know why those 2048-1947 = 101 blocks cannot be read.

maybe there is another way?
Back to top
View user's profile Send private message
lS[UMD/2kdlSU]



Joined: 26 Oct 2005
Posts: 8
Location: Shiga, Japan

PostPosted: Fri Oct 28, 2005 10:25 pm    Post subject: Reply with quote

I've written a small program that reads flash with sceNandReadPages function.
As a result,
- Some of the page (could not read with sceNandReadBlockWithRetry) could read with sceNandReadPages function.
- Others (could read with sceNandReadBlockWithRetry) could not read...

What is the difference?

# Sorry for my bad English..
_________________
lS[UMD/2kdlSU] - now working as 67...
----------------------------------------------
site: jap | eng
jap blog: here
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Sat Oct 29, 2005 12:28 am    Post subject: Reply with quote

lS[UMD/2kdlSU] wrote:
What is the difference?

None, because sceNandReadBlockWithRetry() just calls sceNandReadPages() with a page count of 32. Check to make sure if you're reading a whole block with sceNandReadBlock/ReadPages that your page count is exactly 32, and that your PPN starts on a block boundary (divisible by 32).

Another restriction is that if you read pages within a block, the most pages you can read is 32 - (PPN & 0x1f).
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