| View previous topic :: View next topic |
| Author |
Message |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Wed Oct 26, 2005 8:02 pm Post subject: sceNand functions and dumping the flash |
|
|
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 |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Wed Oct 26, 2005 8:07 pm Post subject: |
|
|
| 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 |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
Posted: Wed Oct 26, 2005 8:13 pm Post subject: |
|
|
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 |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Thu Oct 27, 2005 1:30 am Post subject: Re: sceNand functions and dumping the flash |
|
|
| 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 |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Thu Oct 27, 2005 7:47 am Post subject: Re: sceNand functions and dumping the flash |
|
|
| 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 |
|
 |
lS[UMD/2kdlSU]
Joined: 26 Oct 2005 Posts: 8 Location: Shiga, Japan
|
Posted: Fri Oct 28, 2005 10:25 pm Post subject: |
|
|
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 |
|
 |
mrbrown
Joined: 17 Jan 2004 Posts: 1536
|
Posted: Sat Oct 29, 2005 12:28 am Post subject: |
|
|
| 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 |
|
 |
|