45 "K9GAG08 2GB NAND 3.3V x8 MLC 2b/cell"},
47 "K9LBG08 4GB NAND 3.3V x8 MLC 2b/cell"},
50 { 0x0, 0x6e, 256, 1, 0x1000, 0,
"NAND 1MiB 5V 8-bit"},
51 { 0x0, 0x64, 256, 2, 0x1000, 0,
"NAND 2MiB 5V 8-bit"},
52 { 0x0, 0x6b, 512, 4, 0x2000, 0,
"NAND 4MiB 5V 8-bit"},
53 { 0x0, 0xe8, 256, 1, 0x1000, 0,
"NAND 1MiB 3.3V 8-bit"},
54 { 0x0, 0xec, 256, 1, 0x1000, 0,
"NAND 1MiB 3.3V 8-bit"},
55 { 0x0, 0xea, 256, 2, 0x1000, 0,
"NAND 2MiB 3.3V 8-bit"},
56 { 0x0, 0xd5, 512, 4, 0x2000, 0,
"NAND 4MiB 3.3V 8-bit"},
57 { 0x0, 0xe3, 512, 4, 0x2000, 0,
"NAND 4MiB 3.3V 8-bit"},
58 { 0x0, 0xe5, 512, 4, 0x2000, 0,
"NAND 4MiB 3.3V 8-bit"},
59 { 0x0, 0xd6, 512, 8, 0x2000, 0,
"NAND 8MiB 3.3V 8-bit"},
61 { 0x0, 0x39, 512, 8, 0x2000, 0,
"NAND 8MiB 1.8V 8-bit"},
62 { 0x0, 0xe6, 512, 8, 0x2000, 0,
"NAND 8MiB 3.3V 8-bit"},
67 { 0x0, 0x33, 512, 16, 0x4000, 0,
"NAND 16MiB 1.8V 8-bit"},
68 { 0x0, 0x73, 512, 16, 0x4000, 0,
"NAND 16MiB 3.3V 8-bit"},
72 { 0x0, 0x35, 512, 32, 0x4000, 0,
"NAND 32MiB 1.8V 8-bit"},
73 { 0x0, 0x75, 512, 32, 0x4000, 0,
"NAND 32MiB 3.3V 8-bit"},
77 { 0x0, 0x36, 512, 64, 0x4000, 0,
"NAND 64MiB 1.8V 8-bit"},
78 { 0x0, 0x76, 512, 64, 0x4000, 0,
"NAND 64MiB 3.3V 8-bit"},
82 { 0x0, 0x78, 512, 128, 0x4000, 0,
"NAND 128MiB 1.8V 8-bit"},
83 { 0x0, 0x39, 512, 128, 0x4000, 0,
"NAND 128MiB 1.8V 8-bit"},
84 { 0x0, 0x79, 512, 128, 0x4000, 0,
"NAND 128MiB 3.3V 8-bit"},
90 { 0x0, 0x71, 512, 256, 0x4000, 0,
"NAND 256MiB 3.3V 8-bit"},
92 { 0x0, 0xA2, 0, 64, 0,
LP_OPTIONS,
"NAND 64MiB 1.8V 8-bit"},
93 { 0x0, 0xF2, 0, 64, 0,
LP_OPTIONS,
"NAND 64MiB 3.3V 8-bit"},
94 { 0x0, 0xB2, 0, 64, 0,
LP_OPTIONS16,
"NAND 64MiB 1.8V 16-bit"},
95 { 0x0, 0xC2, 0, 64, 0,
LP_OPTIONS16,
"NAND 64MiB 3.3V 16-bit"},
97 { 0x0, 0xA1, 0, 128, 0,
LP_OPTIONS,
"NAND 128MiB 1.8V 8-bit"},
98 { 0x0, 0xF1, 0, 128, 0,
LP_OPTIONS,
"NAND 128MiB 3.3V 8-bit"},
99 { 0x0, 0xB1, 0, 128, 0,
LP_OPTIONS16,
"NAND 128MiB 1.8V 16-bit"},
100 { 0x0, 0xC1, 0, 128, 0,
LP_OPTIONS16,
"NAND 128MiB 3.3V 16-bit"},
102 { 0x0, 0xAA, 0, 256, 0,
LP_OPTIONS,
"NAND 256MiB 1.8V 8-bit"},
103 { 0x0, 0xDA, 0, 256, 0,
LP_OPTIONS,
"NAND 256MiB 3.3V 8-bit"},
104 { 0x0, 0xBA, 0, 256, 0,
LP_OPTIONS16,
"NAND 256MiB 1.8V 16-bit"},
105 { 0x0, 0xCA, 0, 256, 0,
LP_OPTIONS16,
"NAND 256MiB 3.3V 16-bit"},
107 { 0x0, 0xAC, 0, 512, 0,
LP_OPTIONS,
"NAND 512MiB 1.8V 8-bit"},
108 { 0x0, 0xDC, 0, 512, 0,
LP_OPTIONS,
"NAND 512MiB 3.3V 8-bit"},
109 { 0x0, 0xBC, 0, 512, 0,
LP_OPTIONS16,
"NAND 512MiB 1.8V 16-bit"},
110 { 0x0, 0xCC, 0, 512, 0,
LP_OPTIONS16,
"NAND 512MiB 3.3V 16-bit"},
112 { 0x0, 0xA3, 0, 1024, 0,
LP_OPTIONS,
"NAND 1GiB 1.8V 8-bit"},
113 { 0x0, 0xD3, 0, 1024, 0,
LP_OPTIONS,
"NAND 1GiB 3.3V 8-bit"},
114 { 0x0, 0xB3, 0, 1024, 0,
LP_OPTIONS16,
"NAND 1GiB 1.8V 16-bit"},
115 { 0x0, 0xC3, 0, 1024, 0,
LP_OPTIONS16,
"NAND 1GiB 3.3V 16-bit"},
117 { 0x0, 0xA5, 0, 2048, 0,
LP_OPTIONS,
"NAND 2GiB 1.8V 8-bit"},
118 { 0x0, 0xD5, 0, 8192, 0,
LP_OPTIONS,
"NAND 2GiB 3.3V 8-bit"},
119 { 0x0, 0xB5, 0, 2048, 0,
LP_OPTIONS16,
"NAND 2GiB 1.8V 16-bit"},
120 { 0x0, 0xC5, 0, 2048, 0,
LP_OPTIONS16,
"NAND 2GiB 3.3V 16-bit"},
122 { 0x0, 0x48, 0, 2048, 0,
LP_OPTIONS,
"NAND 2GiB 3.3V 8-bit"},
124 {0, 0, 0, 0, 0, 0,
NULL}
177 if (++found < requested)
200 const char *str =
CMD_ARGV[name_index];
223 if ((first < 0) || (first >= nand->
num_blocks))
226 if ((last >= nand->
num_blocks) || (last == -1))
229 page = first * pages_per_block;
230 for (i = first; i <= last; i++) {
236 || (((nand->
page_size == 512) && (oob[5] != 0xff)) ||
237 ((nand->
page_size == 2048) && (oob[0] != 0xff)))) {
243 page += pages_per_block;
293 uint8_t manufacturer_id, device_id;
294 uint8_t id_buff[6] = { 0 };
314 LOG_DEBUG(
"controller initialization failed");
318 "BUG: controller reported that it doesn't support default parameters");
321 LOG_ERROR(
"BUG: unknown controller initialization failure");
338 manufacturer_id = data_buf & 0xff;
340 device_id = data_buf & 0xff;
366 "unknown NAND flash device found, manufacturer id: 0x%2.2x device id: 0x%2.2x",
404 id_buff[3] = data_buf;
409 id_buff[4] = data_buf;
414 id_buff[5] = data_buf >> 8;
420 nand->
page_size = 1 << (10 + (id_buff[4] & 3));
422 LOG_ERROR(
"NAND flashes with 256 byte pagesize are not supported");
435 LOG_ERROR(
"BUG: small page NAND device with more than 8 GiB encountered");
445 LOG_ERROR(
"BUG: large page NAND device with more than 32 GiB encountered");
452 switch ((id_buff[4] >> 4) & 3) {
474 LOG_DEBUG(
"controller initialization failed");
478 "controller doesn't support requested parameters (buswidth: %i, address cycles: %i, page size: %i)",
484 LOG_ERROR(
"BUG: unknown controller initialization failure");
512 if ((first_block < 0) || (last_block >= nand->
num_blocks))
516 for (i = first_block; i <= last_block; i++) {
523 for (i = first_block; i <= last_block; i++) {
559 LOG_ERROR(
"timeout waiting for NAND flash block erase to complete");
570 LOG_ERROR(
"didn't erase %sblock %d; status: 0x%2.2x",
584 static int nand_read_plain(
struct nand_device *nand,
595 LOG_ERROR(
"reads need to be page aligned");
601 while (data_size > 0) {
603 uint32_t page_address;
606 page_address = address / nand->
page_size;
610 memcpy(data, page, thisrun_size);
612 address += thisrun_size;
613 data += thisrun_size;
614 data_size -= thisrun_size;
622 static int nand_write_plain(
struct nand_device *nand,
633 LOG_ERROR(
"writes need to be page aligned");
639 while (data_size > 0) {
641 uint32_t page_address;
644 memcpy(page, data, thisrun_size);
646 page_address = address / nand->
page_size;
650 address += thisrun_size;
651 data += thisrun_size;
652 data_size -= thisrun_size;
662 uint8_t *data, uint32_t data_size,
663 uint8_t *oob, uint32_t oob_size)
681 uint8_t *data, uint32_t data_size,
682 uint8_t *oob, uint32_t oob_size)
694 uint8_t
cmd,
bool oob_only)
769 for (i = 0; retval ==
ERROR_OK && i <
size; i += incr) {
779 uint8_t *data, uint32_t data_size,
780 uint8_t *oob, uint32_t oob_size)
806 uint32_t incr = is16bit ? 2 : 1;
810 for (i = 0; i <
size; i += incr) {
847 LOG_ERROR(
"write operation didn't pass, status: 0x%2.2x",
856 uint8_t *data, uint32_t data_size,
857 uint8_t *oob, uint32_t oob_size)
868 LOG_ERROR(
"Unable to write data to NAND device");
876 LOG_ERROR(
"Unable to write OOB data to NAND device");
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
unsigned get_flash_name_index(const char *name)
Parses the optional '.index' portion of a flash bank identifier.
bool flash_driver_name_matches(const char *name, const char *expected)
Attempt to match the expected name with the name of a driver.
int nand_write_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
int nand_probe(struct nand_device *nand)
int nand_read_page_raw(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
int nand_build_bbt(struct nand_device *nand, int first, int last)
int nand_erase(struct nand_device *nand, int first_block, int last_block)
int nand_write_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
COMMAND_HELPER(nand_command_get_device, unsigned name_index, struct nand_device **nand)
helper for parsing a nand device command argument string
int nand_read_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
struct nand_device * nand_devices
static int nand_poll_ready(struct nand_device *nand, int timeout)
int nand_read_status(struct nand_device *nand, uint8_t *status)
int nand_read_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
static struct nand_info nand_flash_ids[]
int nand_write_finish(struct nand_device *nand)
static struct nand_device * get_nand_device_by_name(const char *name)
Returns the flash bank specified by name, which matches the driver name and a suffix (option) specify...
static struct nand_manufacturer nand_manuf_ids[]
int nand_write_page_raw(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
void nand_device_add(struct nand_device *c)
struct nand_device * get_nand_device_by_num(int num)
int nand_page_command(struct nand_device *nand, uint32_t page, uint8_t cmd, bool oob_only)
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
#define ERROR_NAND_NO_BUFFER
#define ERROR_NAND_OPERATION_TIMEOUT
#define ERROR_NAND_DEVICE_NOT_PROBED
#define ERROR_NAND_OPERATION_FAILED
#define ERROR_NAND_OPERATION_NOT_SUPPORTED
size_t size
Size of the control block search area.
Representation of a single NAND block in a NAND device.
int is_erased
True if the block has been erased.
uint32_t offset
Offset to the block.
int is_bad
True if the block is bad.
uint32_t size
Size of the block.
struct nand_flash_controller * controller
struct nand_device * next
struct nand_block * blocks
struct nand_manufacturer * manufacturer
struct nand_info * device
int(* read_data)(struct nand_device *nand, void *data)
Read word of data from the NAND device.
int(* nand_ready)(struct nand_device *nand, int timeout)
Check if the NAND device is ready for more instructions with timeout.
int(* write_block_data)(struct nand_device *nand, uint8_t *data, int size)
Write a block of data to the NAND device.
int(* read_page)(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Read a page from the NAND device.
int(* write_data)(struct nand_device *nand, uint16_t data)
Write word of data to the NAND device.
const char * name
Driver name that is used to select it from configuration files.
int(* command)(struct nand_device *nand, uint8_t command)
Issue a command to the NAND device.
int(* read_block_data)(struct nand_device *nand, uint8_t *data, int size)
Read a block of data from the NAND device.
int(* address)(struct nand_device *nand, uint8_t address)
Write an address to the NAND device.
int(* init)(struct nand_device *nand)
Initialize the NAND device.
int(* reset)(struct nand_device *nand)
Reset the NAND device.
int(* write_page)(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Write a page to the NAND device.
static void write_data(FILE *f, const void *data, size_t len)
static uint16_t le_to_h_u16(const uint8_t *buf)