Disposable Digital Camera Interfacing

Low Level Picture Flash Reading

[camera pic from pcworld.com article]

Introduction
The SPCA504B allows access to the picture Flash memory through two methods.

The usual method used routes the data through specialized hardware in to or out of the Flash. This is typically done when reading data out over USB and storing data from the compressed version stored in SDRAM. This method is fast, but has not been reverse-engineered yet.

The microcontroller can also access the Flash at a very low level through use of specific registers. This is typically used to erase the flash, to read the flash's size and manufacturer ID, and to access low volume non-picture metadata (such as the file directory, bad-block table, and wear-leveling info). This is the method we're going to use, and it is very slow because the camera's slow 8-bit processor must work hard. I averaged 544 bytes per second on a computer capable of saturating the USB bus, so transferring the whole 16 MB took about 10 hours.

SPCA504B Hardware Registers
The chip has four registers that we need to deal with. There are probably other registers that must be set up, but it seems that the firmware initializes them properly on boot.

7
6
5
4
3
2
1
0
x
x
x
x
CLE
ALE
WP*
CE*

'x' means not used; write a 0.  '*' means that the signal is inverted (as the FLASH expects).
To be found: there probably is a way to read the R/B* signal ("busy") signal from the flash, but I haven't decoded it yet. Due to the slow speed of the USB interface, we won't need to read this bit unless we're programming the part (in that case, we could probably just wait the maximum amount of time).


Samsung Flash Architecture
This flash is optimized for low-cost, high-density storage of data, not code.  The consequences of this is that it has two features not typically found in other flash memory:

Samsung Read Algorithm
The Samsung data sheet fully describes the algorithm for reading the FLASH data on page 21.  The reading method is a little funny - the read command (READ1 or READ2) describes the 8th address bit, but since we're reading blocks of 512, we won't need to specify this bit (nor A0-A7). After reading a block of 512 bytes, the FLASH's internal address pointer automatically moves to the spare area, and are read out as the following 16 bytes.

The general algorithm is:
  1. Issue a READ1 command (0x00) or a READ2 command (0x80), depending on A8.
  2. Send address A0-A7.
  3. Send address A9-A16.
  4. Send address A17-A23.
  5. Read 512 bytes of data.
  6. Read 16 spare bytes.
  7. Issue a RESET command.

Detailed Procedure
This is a summary of how the code in the flashdump.c program implements the Samsung FLASH read algorithm.  This description should match, but rely on the code because it has been tested.  This code could easily be changed to allow for writing or erasing the FLASH.

Set the mode configuration registers to access the Flash at a low level:
1. Register 0x2026 &= 0xFE (clear bit 0)
2. Register 0x2019 |= 0x02 (set bit 1)
3. Register 0x2423 = 0011b (not write protected, not enabled)
4. Register 0x2423 = 0010b (chip now enabled)

Issue the READ1 or READ2 command:
5a. Register 0x2423 = 0011b (not write protected, not enabled)
5b. Register 0x2423 = 0010b (chip now enabled)
5c. Register 0x2423 = 1010b (chip enabled, CLE high to indicate a command)
5d. Write READ1 or READ2 command to Register 0x2420. The hardware automatically generates the write strobe.
5e. Register 0x2423 = 0010b (CLE brought low)

6. Issue A0-A7, A9-A16, and A17-A23 in a similar fashion to the read command -- simply replace the value written in step 5d with the address subset.

7. Read 512 bytes of data from Register 0x2420. The hardware automatically generates the read strobe.
8. Read 16 bytes of data from Register 0x2420.

9. Issue a reset command (0xFF) in a similar fashion to the read command in steps 5a-5e.

10. Repeat steps 5-9 until all desired data is read.

Return the mode configuration registers to a normal mode:
11. Register 0x2423 = 0001b (write protected, not selected)
12. Register 0x2026 |= 0x01 (Set bit 0)
13. Register 0x2019 &= 0xFD (clear bit 1)

Download
I wrote a program called flashdump to dump the picture flash memory, including the main and ECC data areas (both are required to extract data stored in the Smart Media format). This provides the same results that you'd achieve by desoldering the picture flash from the board and reading it in a compatible memory reader.

I found that the camera's memory had no blocks marked as bad. I don't know if that's because Samsung's testing had determined that the flash was flawless, or if the bad-block-markers had been erased.



back to my dakota digital page
my homepage