17 #define AT91C_PIOX_SODR (0x30)
18 #define AT91C_PIOX_CODR (0x34)
19 #define AT91C_PIOX_PDSR (0x3C)
20 #define AT91C_ECCX_CR (0x00)
21 #define AT91C_ECCX_SR (0x08)
22 #define AT91C_ECCX_PR (0x0C)
23 #define AT91C_ECCX_NPR (0x10)
74 LOG_ERROR(
"Target must be halted to use NAND controller (%s)",
label);
298 LOG_ERROR(
"ECC controller address must be set when not reading raw NAND data");
327 LOG_ERROR(
"Unable to allocate space for OOB");
331 memset(oob, 0xFF, *
size);
351 uint8_t *
data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
380 LOG_ERROR(
"Multiple errors encountered; unrecoverable!");
388 uint32_t word = (
parity & 0x0000FFF0) >> 4;
391 data[word] ^= (0x1) <<
bit;
392 LOG_INFO(
"Data word %d, bit %d corrected.",
400 LOG_ERROR(
"Error in ECC bytes detected");
426 uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
431 uint8_t *oob_data = oob;
445 LOG_ERROR(
"Unable to write data to NAND device");
457 oob_data[0] = (uint8_t)
parity;
458 oob_data[1] = (uint8_t) (
parity >> 8);
459 oob_data[2] = (uint8_t) nparity;
460 oob_data[3] = (uint8_t) (nparity >> 8);
469 LOG_ERROR(
"Unable to write OOB data to NAND");
485 unsigned long chip = 0,
ecc = 0;
488 LOG_DEBUG(
"AT91SAM9 NAND Device Command");
490 if (CMD_ARGC < 3 || CMD_ARGC > 4) {
511 LOG_ERROR(
"unable to allocate space for controller private data");
516 info->cmd = chip | (1 << 22);
517 info->addr = chip | (1 << 21);
520 nand->controller_priv =
info;
521 info->io.target = nand->target;
536 unsigned num, address_line;
539 command_print(
CMD,
"incorrect number of arguments for 'at91sam9 cle' command");
553 info->cmd =
info->data | (1 << address_line);
566 unsigned num, address_line;
581 info->addr =
info->data | (1 << address_line);
594 unsigned num, base_pioc, pin_num;
609 info->busy.pioc = base_pioc;
612 info->busy.num = pin_num;
625 unsigned num, base_pioc, pin_num;
640 info->ce.pioc = base_pioc;
643 info->ce.num = pin_num;
651 .handler = handle_at91sam9_cle_command,
653 .help =
"set command latch enable address line (default is 22)",
654 .usage =
"bank_id address_line",
658 .handler = handle_at91sam9_ale_command,
660 .help =
"set address latch enable address line (default is 21)",
661 .usage =
"bank_id address_line",
665 .handler = handle_at91sam9_rdy_busy_command,
667 .help =
"set the GPIO input pin connected to "
668 "the RDY/~BUSY signal (no default)",
669 .usage =
"bank_id pio_base_addr pin_num",
673 .handler = handle_at91sam9_ce_command,
675 .help =
"set the GPIO output pin connected to "
676 "the chip enable signal (no default)",
677 .usage =
"bank_id pio_base_addr pin_num",
686 .help =
"AT91SAM9 NAND flash controller commands",
698 .nand_device_command = at91sam9_nand_device_command,
Holds the interface to ARM cores.
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.
int arm_nandread(struct arm_nand_data *nand, uint8_t *data, uint32_t size)
Uses an on-chip algorithm for an ARM device to read from a NAND device and store the data into the ho...
@ ARM_NAND_NONE
No operation performed.
static int at91sam9_read_page(struct nand_device *nand, uint32_t page, uint8_t *data, uint32_t data_size, uint8_t *oob, uint32_t oob_size)
Reads a page from an AT91SAM9 NAND controller and verifies using 1-bit ECC controller on chip.
static int at91sam9_read_data(struct nand_device *nand, void *data)
Read data directly from the NAND device attached to an AT91SAM9 NAND controller.
static int at91sam9_nand_ready(struct nand_device *nand, int timeout)
Determine if the NAND device is ready by looking at the ready/~busy pin.
static int at91sam9_command(struct nand_device *nand, uint8_t command)
Send a command to the NAND device.
static int at91sam9_enable(struct nand_device *nand)
Enable NAND device attached to a controller.
COMMAND_HANDLER(handle_at91sam9_cle_command)
Handle the AT91SAM9 CLE command for specifying the address line to use for writing commands to a NAND...
struct nand_flash_controller at91sam9_nand_controller
Structure representing the AT91SAM9 NAND controller.
static int at91sam9_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 of data including 1-bit ECC information to a NAND device attached to an AT91SAM9 control...
static int at91sam9_read_block_data(struct nand_device *nand, uint8_t *data, int size)
Read a block of data from the NAND device attached to an AT91SAM9.
static int at91sam9_halted(struct target *target, const char *label)
Checks if the target is halted and prints an error message if it isn't.
static const struct command_registration at91sam9_sub_command_handlers[]
static int at91sam9_reset(struct nand_device *nand)
Reset the AT91SAM9 NAND controller.
#define AT91C_ECCX_SR
Offset to ECC SR.
static int at91sam9_disable(struct nand_device *nand)
Disable NAND device attached to a controller.
static uint8_t * at91sam9_oob_init(struct nand_device *nand, uint8_t *oob, uint32_t *size)
Initialize an area for the OOB based on whether a user is requesting the OOB data.
static const struct command_registration at91sam9_command_handler[]
static int at91sam9_ecc_init(struct target *target, struct at91sam9_nand *info)
Initialize the ECC controller on the AT91SAM9.
static int at91sam9_write_block_data(struct nand_device *nand, uint8_t *data, int size)
Write a block of data to a NAND device attached to an AT91SAM9.
static int at91sam9_write_data(struct nand_device *nand, uint16_t data)
Write data directly to the NAND device attached to an AT91SAM9 NAND controller.
#define AT91C_ECCX_PR
Offset to ECC PR.
static int at91sam9_address(struct nand_device *nand, uint8_t address)
Send an address to the NAND device attached to an AT91SAM9 NAND controller.
#define AT91C_ECCX_NPR
Offset to ECC NPR.
static int at91sam9_init(struct nand_device *nand)
Initialize the AT91SAM9 NAND controller.
#define AT91C_PIOX_SODR
Offset to PIO SODR.
NAND_DEVICE_COMMAND_HANDLER(at91sam9_nand_device_command)
Handle the initial NAND device command for AT91SAM9 controllers.
#define AT91C_ECCX_CR
Offset to ECC CR.
#define AT91C_PIOX_CODR
Offset to PIO CODR.
#define AT91C_PIOX_PDSR
Offset to PIO PDSR.
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 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...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
int nand_write_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
int nand_read_data_page(struct nand_device *nand, uint8_t *data, uint32_t size)
int nand_write_finish(struct nand_device *nand)
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_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
#define ERROR_NAND_OPERATION_FAILED
static uint32_t bit(uint32_t value, unsigned int b)
size_t size
Size of the control block search area.
The arm_nand_data struct is used for defining NAND I/O operations on an ARM core.
unsigned chunk_size
The chunk size is the page size or ECC chunk.
uint32_t data
Where data is read from or written to.
Private data for the controller that is stored in the NAND device structure.
struct at91sam9_pin ce
Pin representing the chip enable.
uint32_t data
Address data is written to.
uint32_t cmd
Address commands are written to.
uint32_t ecc
Address of the ECC controller for NAND.
struct at91sam9_pin busy
Pin representing the ready/~busy line.
uint32_t addr
Address addresses are written to.
struct arm_nand_data io
I/O structure for hosted reads/writes.
Representation of a pin on an AT91SAM9 chip.
uint32_t pioc
Address of the PIO controller.
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 struct ublast_lowlevel_priv info
static unsigned int parity(unsigned int v)