memory-onfi¶
Read and program raw NAND Flash using the asynchronous, 8-bit ONFI-like interface. ONFI parameter pages provide the memory geometry automatically; non-ONFI devices can be used by specifying the page, spare, and block sizes explicitly.
Wiring¶
Connect I/O0 through I/O7 in order to --io, and connect CLE, ALE, RE#, WE#, R/B#, and the target CE# pins to their corresponding options. Tie all R/B# pins together and provide an external pull-up. The applet also enables an internal pull-up on R/B#. Connect every CE# pin or pull unused CE# pins high to prevent bus contention. Up to four CE# signals are supported; --chip selects one, numbered from 1 in the order given to --ce. All connected targets are reset during setup.
Supply the memory separately and set -V to its I/O voltage. WP# must be driven to the appropriate level externally; the applet does not control it.
Usage¶
For example, with eight data pins on port A and control pins on port B:
glasgow run memory-onfi -V 3.3 --io A0:7 --cle B0 --ale B1 \
--re B2 --we B3 --r_b B4 --ce B5 identify
Using the same wiring options, read 64 pages starting at page 0:
glasgow run memory-onfi -V 3.3 --io A0:7 --cle B0 --ale B1 \
--re B2 --we B3 --r_b B4 --ce B5 read 0 64 data.bin spare.bin
With two output files, data and spare bytes are stored separately. With only one output file, each page’s data bytes are immediately followed by its spare bytes. For non-ONFI devices, supply --page-size (data bytes per page), --spare-size (spare bytes per page), and --block-size (pages per erase block). Valid ONFI parameters take precedence over these options.
program PAGE COUNT DATA-FILE SPARE-FILE programs separate data and spare files. erase PAGE [COUNT] erases entire blocks. Use block-aligned page ranges to erase a specific set of blocks.
Warning
Operations access raw NAND contents. The applet does not generate or correct ECC, skip bad blocks, or enforce device-specific partial programming limits. Preserve spare data when making backups, and consult the device datasheet before programming. Programming requires erased pages and erasing destroys the contents of the whole block.
The interface uses two column address bytes and three row address bytes. Only 8-bit asynchronous devices compatible with the documented command sequence are supported; geometry detection does not adapt the address cycle count.
CLI reference¶
glasgow run memory-onfi¶
Identify, read and write memories compatible with ONFI NAND Flash memory. The applet roughly follows the ONFI 1.0 specification, but tolerates the very common non-ONFI-compliant memories by gracefully degrading autodetection of memory functionality.
Only the asynchronous NAND interface is supported. All R/B# pins should be tied together, and externally pulled up. All CE# pins must be either connected or pulled high to avoid bus contention; for unidentified devices, this means all 4 CE# pins available on the package.
The NAND Flash command set is not standardized in practice. This applet uses the following commands when identifying the memory:
Cmd 0xFF: Reset (all devices)
Cmd 0x90 Addr 0x00: Read ID, JEDEC Manufacturer and Device (all devices)
Cmd 0x90 Addr 0x20: Read ID, ONFI Signature (ONFI and some non-ONFI devices)
Cmd 0xEC: Read Parameter Page (ONFI only)
If the memory doesn’t respond or gives invalid response to ONFI commands, it can still be used, but the array parameters need to be specified explicitly.
The applet use the following commands while reading and writing data:
Cmd 0x70: Read Status (all devices)
Cmd 0x00 Addr Col1..2,Row1..3 Cmd 0x30: Read (all devices)
Cmd 0x60 Addr Row1..3 Cmd 0xD0: Erase (all devices)
Cmd 0x80 Addr Col1..2,Row1..3 [Cmd 0x85 Col1..2]+ Cmd 0x10: Page Program (all devices)
usage: glasgow run memory-onfi [-h] [-V SPEC] [--io PINS] [--cle PIN]
[--ale PIN] [--re PIN] [--we PIN] [--r-b PIN]
[--ce PINS] [-c CHIP] [-P SIZE] [-S SIZE]
[-B SIZE]
OPERATION ...
- -h, --help¶
show this help message and exit
- -V <spec>, --voltage <spec>¶
configure I/O port voltage to SPEC (e.g.: ‘3.3’, ‘A=5.0,B=3.3’, ‘A=SA’)
- --io <pins>¶
bind the applet I/O lines ‘io’ to PINS (default: ‘A0,A1,A2,A3,A4,A5,A6,A7’, optional)
- --cle <pin>¶
bind the applet I/O line ‘cle’ to PIN (default: ‘B0’, optional)
- --ale <pin>¶
bind the applet I/O line ‘ale’ to PIN (default: ‘B1’, optional)
- --re <pin>¶
bind the applet I/O line ‘re’ to PIN (default: ‘B2’, optional)
- --we <pin>¶
bind the applet I/O line ‘we’ to PIN (default: ‘B3’, optional)
- --r-b <pin>¶
bind the applet I/O line ‘r_b’ to PIN (default: ‘B4’, optional)
- --ce <pins>¶
bind the applet I/O lines ‘ce’ to PINS (default: ‘B5,B6’, optional)
- -c <chip>, --chip <chip>¶
select chip connected to CE# signal CHIP (one of: 1..4, default: 1)
- -P <size>, --page-size <size>¶
Flash page (without spare) size, in bytes (default: autodetect)
- -S <size>, --spare-size <size>¶
Flash spare size, in bytes (default: autodetect)
- -B <size>, --block-size <size>¶
Flash block size, in pages (default: autodetect)
glasgow run memory-onfi erase¶
usage: glasgow run memory-onfi erase [-h] PAGE [COUNT]
- page¶
erase starting at block containing page PAGE
- count¶
erase blocks containing the next COUNT pages
- -h, --help¶
show this help message and exit
glasgow run memory-onfi identify¶
usage: glasgow run memory-onfi identify [-h]
- -h, --help¶
show this help message and exit
glasgow run memory-onfi program¶
usage: glasgow run memory-onfi program [-h] PAGE COUNT DATA-FILE SPARE-FILE
- page¶
program starting at page PAGE
- count¶
program COUNT pages
- data-file¶
program bytes to data area from DATA-FILE
- spare-file¶
program bytes to spare area from SPARE-FILE
- -h, --help¶
show this help message and exit
glasgow run memory-onfi read¶
usage: glasgow run memory-onfi read [-h] PAGE COUNT DATA-FILE [SPARE-FILE]
- page¶
read starting at page PAGE
- count¶
read COUNT pages
- data-file¶
write bytes from data and possibly spare area to DATA-FILE
- spare-file¶
write bytes from spare area to SPARE-FILE instead of DATA-FILE
- -h, --help¶
show this help message and exit
API reference¶
- class glasgow.applet.memory.onfi.ONFIInterface(logger: Logger, assembly: AbstractAssembly, *, io: GlasgowPin, cle: GlasgowPin, ale: GlasgowPin, re: GlasgowPin, we: GlasgowPin, r_b: GlasgowPin, ce: GlasgowPin)¶
- async select(chip)¶
Select the zero-based chip index (0 through 3).
- async reset()¶
Reset the selected target and wait until it is ready.
- async read_jedec_id()¶
Return the manufacturer and device identification bytes.
- async read_signature()¶
Return the first four Read ID bytes.
- async read_onfi_signature()¶
Return the four-byte ONFI signature.
- async read_status()¶
Return the NAND status byte.
- async is_write_protected()¶
Return whether the selected target is write-protected.
- async read_parameter_page(copies=3)¶
Read
copiesconsecutive 256-byte ONFI parameter pages.
- async read_unique_id()¶
Read the 32-byte unique ID response.
- async read(row, column, length)¶
Read
lengthraw bytes at pagerowand byte offsetcolumn.
- async program(row, chunks)¶
Program page
rowfrom an iterable of(column, data)chunks.Wait for completion and return whether programming succeeded. No ECC is generated.
- async erase(row)¶
Erase the block containing page
rowand return whether erasure succeeded.