45 uint8_t *
data, uint32_t data_size, uint8_t *oob, uint32_t oob_size);
47 uint8_t *
data, uint32_t data_size, uint8_t *oob, uint32_t oob_size);
53 #define NAND4BITECCLOAD 0xbc
54 #define NAND4BITECC 0xc0
55 #define NANDERRADDR 0xd0
56 #define NANDERRVAL 0xd8
63 LOG_ERROR(
"Target must be halted to use NAND controller (%s)",
label);
80 if (!(nandfcr & (1 <<
info->chipsel))) {
81 LOG_ERROR(
"chip address %08" PRIx32
" not NAND-enabled?",
info->data);
171 uint8_t *data,
int data_size)
175 uint32_t nfdata =
info->data;
181 while (data_size >= 4) {
193 while (data_size > 0) {
204 uint8_t *data,
int data_size)
208 uint32_t nfdata =
info->data;
221 while (data_size >= 4) {
229 while (data_size > 0) {
240 uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
243 uint8_t *ooballoc =
NULL;
253 LOG_ERROR(
"Missing NAND data; try 'nand raw_access enable'");
272 ooballoc = malloc(oob_size);
276 memset(oob, 0x0ff, oob_size);
285 status =
info->write_page(nand, page,
data, data_size, oob, oob_size);
291 uint8_t *
data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
300 return info->read_page(nand, page,
data, data_size, oob, oob_size);
348 uint8_t *oob, uint32_t oob_size)
380 uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
411 fcr |= 1 << (8 +
info->chipsel);
426 ecc1 = (ecc1 & 0x0fff) | ((ecc1 & 0x0fff0000) >> 4);
430 oob[oob_offset++] = (uint8_t)(ecc1);
431 oob[oob_offset++] = (uint8_t)(ecc1 >> 8);
432 oob[oob_offset++] = (uint8_t)(ecc1 >> 16);
447 uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
449 static const uint8_t ecc512[] = {
453 static const uint8_t ecc2048[] = {
454 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
455 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
456 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
457 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
459 static const uint8_t ecc4096[] = {
460 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
461 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
462 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
463 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
464 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
465 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
466 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
467 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
503 fcr |= (1 << 12) | (
info->chipsel << 4);
506 uint32_t raw_ecc[4], *p;
518 for (i = 0; i < 4; i++) {
520 raw_ecc[i] &= 0x03ff03ff;
522 for (i = 0, p = raw_ecc; i < 2; i++, p += 2) {
523 oob[*l++] = p[0] & 0xff;
524 oob[*l++] = ((p[0] >> 8) & 0x03) | ((p[0] >> 14) & 0xfc);
525 oob[*l++] = ((p[0] >> 22) & 0x0f) | ((p[1] << 4) & 0xf0);
526 oob[*l++] = ((p[1] >> 4) & 0x3f) | ((p[1] >> 10) & 0xc0);
527 oob[*l++] = (p[1] >> 18) & 0xff;
549 uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
564 fcr |= (1 << 12) | (
info->chipsel << 4);
567 uint32_t raw_ecc[4], *p;
580 for (i = 0; i < 4; i++) {
582 raw_ecc[i] &= 0x03ff03ff;
586 for (i = 0, l = oob + 6, p = raw_ecc; i < 2; i++, p += 2) {
588 *l++ = ((p[0] >> 8) & 0x03) | ((p[0] >> 14) & 0xfc);
589 *l++ = ((p[0] >> 22) & 0x0f) | ((p[1] << 4) & 0xf0);
590 *l++ = ((p[1] >> 4) & 0x3f) | ((p[1] >> 10) & 0xc0);
591 *l++ = (p[1] >> 18) & 0xff;
604 uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
607 int want_col, at_col;
623 while ((data && data_size) || (oob && oob_size)) {
625 if (data && data_size) {
626 if (want_col != at_col) {
634 read_size = data_size > 512 ? 512 : data_size;
637 data_size -= read_size;
642 if (oob && oob_size) {
643 if (want_col != at_col) {
650 read_size = oob_size > 16 ? 16 : oob_size;
653 oob_size -= read_size;
664 unsigned long chip,
aemif;
685 if (strcmp(
CMD_ARGV[3],
"hwecc1") == 0)
687 else if (strcmp(
CMD_ARGV[3],
"hwecc4") == 0)
689 else if (strcmp(
CMD_ARGV[3],
"hwecc4_infix") == 0)
706 if (
aemif == 0x01e00000
707 ||
aemif == 0x01e10000
708 ||
aemif == 0x01d10000
710 if (chip < 0x02000000 || chip >= 0x0a000000) {
711 LOG_ERROR(
"NAND address %08lx out of range?", chip);
714 chipsel = (chip - 0x02000000) >> 25;
728 info->cmd = chip | 0x10;
729 info->addr = chip | 0x08;
731 nand->controller_priv =
info;
733 info->io.target = nand->target;
767 .usage =
"chip_addr hwecc_mode aemif_addr",
768 .nand_device_command = davinci_nand_device_command,
int arm_nandwrite(struct arm_nand_data *nand, uint8_t *data, int size)
ARM-specific bulk write from buffer to address of 8-bit wide NAND.
@ ARM_NAND_NONE
No operation performed.
#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 CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#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...
static int davinci_read_block_data(struct nand_device *nand, uint8_t *data, int data_size)
static int davinci_read_data(struct nand_device *nand, void *data)
static int davinci_write_page_ecc4(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
static int davinci_address(struct nand_device *nand, uint8_t address)
static int davinci_seek_column(struct nand_device *nand, uint16_t column)
static int davinci_write_data(struct nand_device *nand, uint16_t data)
static void davinci_write_pagecmd(struct nand_device *nand, uint8_t cmd, uint32_t page)
static int davinci_write_page_ecc4infix(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
static int davinci_write_block_data(struct nand_device *nand, uint8_t *data, int data_size)
static int davinci_init(struct nand_device *nand)
static int davinci_reset(struct nand_device *nand)
static int davinci_write_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
NAND_DEVICE_COMMAND_HANDLER(davinci_nand_device_command)
static int davinci_write_page_ecc1(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
struct nand_flash_controller davinci_nand_controller
static int davinci_command(struct nand_device *nand, uint8_t command)
static int davinci_writepage_tail(struct nand_device *nand, uint8_t *oob, uint32_t oob_size)
static int davinci_read_page_ecc4infix(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
static int davinci_nand_ready(struct nand_device *nand, int timeout)
static int halted(struct target *target, const char *label)
static int davinci_read_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
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_read_status(struct nand_device *nand, uint8_t *status)
void alive_sleep(uint64_t ms)
#define LOG_ERROR(expr ...)
#define ERROR_NAND_NO_BUFFER
#define ERROR_NAND_OPERATION_TIMEOUT
#define ERROR_NAND_DEVICE_NOT_PROBED
#define ERROR_NAND_OPERATION_FAILED
The arm_nand_data struct is used for defining NAND I/O operations on an ARM core.
int(* write_page)(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
int(* read_page)(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
struct nand_info * device
Interface for NAND flash controllers.
const char * name
Driver name that is used to select it from configuration files.
int target_write_u8(struct target *target, target_addr_t address, uint8_t value)
int target_read_u8(struct target *target, target_addr_t address, uint8_t *value)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
static uint32_t le_to_h_u32(const uint8_t *buf)
static struct ublast_lowlevel_priv info