Difference between revisions of "/dev/flash"

From WiiBrew
Jump to navigation Jump to search
Line 1: Line 1:
 
==Description==
 
==Description==
 
/dev/flash provides a raw interface to the NAND flash memory. No file system permissions restrict the access to the NAND memory, however, the contents are encrypted.
 
/dev/flash provides a raw interface to the NAND flash memory. No file system permissions restrict the access to the NAND memory, however, the contents are encrypted.
 +
 +
Be careful when using these interfaces! Calling the wrong ioctl (or calling write() instead of read() could have unfortunate results.
 +
 +
=== Reading ===
 +
/dev/flash may be read to get the raw, encrypted contents of the Wii NAND flash chip.  You must either read with a block size of 2048 or 2112 (2048 + 64); the former will give you the normal contents of one page, and the latter will give you the same data plus the 64 bytes of OOB / spare / ECC data.  If you hope to use this to eventually restore the contents of your Wii, you MUST back up the spare data.
 +
 +
In between each read, you should seek() to the page number you are trying to read; for example, seeking to 0x200 would put you at page 0x200, the start of the encrypted filesystem.  That is to say, you must seek before every access, and the "file position" is in terms of pages, not bytes.  There are 256K (262,144) total pages.
 +
 +
 +
=== Ioctls ===
 +
Ioctl 1: get_flash_stats.  Input: 0 bytes. Output: 0x1c bytes.
 +
 +
Ioctl 4: check_bad_block.  No input or output.  If return value is -13, indicates that the block at the current fpos is bad.
 +
 +
=== Return Codes ===
 +
(These names were taken from a NAND flash diagnostic program scraped from flash)
 +
 +
* -1: NAND_RESULT_ACCESS
 +
* -3: NAND_RESULT_ECC_CRIT
 +
* -4: NAND_RESULT_CORRUPT
 +
* -5: NAND_RESULT_BUSY
 +
* -6: NAND_RESULT_EXISTS
 +
* -8: NAND_RESULT_INVALID
 +
* -9: NAND_RESULT_MAXBLOCKS
 +
* -10: NAND_RESULT_MAXFD
 +
* -11: NAND_RESULT_MAXFILES
 +
* -12: NAND_RESULT_NOEXISTS
 +
* -13: NAND_RESULT_NOTEMPTY
 +
* -14: NAND_RESULT_OPENFD
 +
* -64: NAND_RESULT_UNKNOWN
 +
* -128: NAND_RESULT_FATALERROR
 
[[Category:Wii Filesystem]]
 
[[Category:Wii Filesystem]]

Revision as of 11:21, 1 July 2008

Description

/dev/flash provides a raw interface to the NAND flash memory. No file system permissions restrict the access to the NAND memory, however, the contents are encrypted.

Be careful when using these interfaces! Calling the wrong ioctl (or calling write() instead of read() could have unfortunate results.

Reading

/dev/flash may be read to get the raw, encrypted contents of the Wii NAND flash chip. You must either read with a block size of 2048 or 2112 (2048 + 64); the former will give you the normal contents of one page, and the latter will give you the same data plus the 64 bytes of OOB / spare / ECC data. If you hope to use this to eventually restore the contents of your Wii, you MUST back up the spare data.

In between each read, you should seek() to the page number you are trying to read; for example, seeking to 0x200 would put you at page 0x200, the start of the encrypted filesystem. That is to say, you must seek before every access, and the "file position" is in terms of pages, not bytes. There are 256K (262,144) total pages.


Ioctls

Ioctl 1: get_flash_stats. Input: 0 bytes. Output: 0x1c bytes.

Ioctl 4: check_bad_block. No input or output. If return value is -13, indicates that the block at the current fpos is bad.

Return Codes

(These names were taken from a NAND flash diagnostic program scraped from flash)

  • -1: NAND_RESULT_ACCESS
  • -3: NAND_RESULT_ECC_CRIT
  • -4: NAND_RESULT_CORRUPT
  • -5: NAND_RESULT_BUSY
  • -6: NAND_RESULT_EXISTS
  • -8: NAND_RESULT_INVALID
  • -9: NAND_RESULT_MAXBLOCKS
  • -10: NAND_RESULT_MAXFD
  • -11: NAND_RESULT_MAXFILES
  • -12: NAND_RESULT_NOEXISTS
  • -13: NAND_RESULT_NOTEMPTY
  • -14: NAND_RESULT_OPENFD
  • -64: NAND_RESULT_UNKNOWN
  • -128: NAND_RESULT_FATALERROR