36 "pagesize: %i, buswidth: %i,\n\t"
37 "blocksize: %i, blocks: %i",
90 "#%i: %s (%s) pagesize: %i, buswidth: %i, erasesize: %i",
98 for (j = first; j <= last; j++) {
99 char *erase_state, *bad_state;
102 erase_state =
"not erased";
104 erase_state =
"erased";
106 erase_state =
"erase state unknown";
111 bad_state =
" (marked bad)";
113 bad_state =
" (block condition unknown)";
116 "\t#%i: 0x%8.8" PRIx32
" (%" PRIu32
"kB) %s%s",
182 "on NAND flash device #%s '%s'",
226 "use \"nand info\" command to list blocks");
241 uint32_t total_bytes = s.
size;
244 if (bytes_read <= 0) {
249 s.
size -= bytes_read;
255 "to NAND flash %s at offset 0x%8.8" PRIx32,
265 "offset 0x%8.8" PRIx32
" in %fs (%0.3f KiB/s)",
290 while (file.
size > 0) {
301 if (bytes_read <= 0) {
311 "at 0x%8.8" PRIx32, dev.
address);
317 file.
size -= bytes_read;
323 "up to offset 0x%8.8" PRIx32
" in %fs (%0.3f KiB/s)",
391 const char *msg = p->
use_raw ?
"enabled" :
"disabled";
400 .handler = handle_nand_list_command,
402 .help =
"list configured NAND flash devices",
407 .handler = handle_nand_info_command,
409 .usage =
"[banknum | first_bank_num last_bank_num]",
410 .help =
"print info about one or more NAND flash devices",
414 .handler = handle_nand_probe_command,
417 .help =
"identify NAND flash device",
420 .name =
"check_bad_blocks",
421 .handler = handle_nand_check_bad_blocks_command,
423 .usage =
"bank_id [offset length]",
424 .help =
"check all or part of NAND flash device for bad blocks",
428 .handler = handle_nand_erase_command,
430 .usage =
"bank_id [offset length]",
431 .help =
"erase all or subset of blocks on NAND flash device",
435 .handler = handle_nand_dump_command,
437 .usage =
"bank_id filename offset length "
438 "['oob_raw'|'oob_only']",
439 .help =
"dump from NAND flash device",
443 .handler = handle_nand_verify_command,
445 .usage =
"bank_id filename offset "
446 "['oob_raw'|'oob_only'|'oob_softecc'|'oob_softecc_kw']",
447 .help =
"verify NAND flash device",
451 .handler = handle_nand_write_command,
453 .usage =
"bank_id filename offset "
454 "['oob_raw'|'oob_only'|'oob_softecc'|'oob_softecc_kw']",
455 .help =
"write to NAND flash device",
458 .name =
"raw_access",
459 .handler = handle_nand_raw_access_command,
461 .usage =
"bank_id ['enable'|'disable']",
462 .help =
"raw access to NAND flash device",
480 static bool nand_initialized;
481 if (nand_initialized) {
482 LOG_INFO(
"'nand init' has already been called");
485 nand_initialized =
true;
487 LOG_DEBUG(
"Initializing NAND devices...");
530 c->
name = strdup(bank_name);
544 LOG_ERROR(
"'%s' driver rejected nand flash. Usage: %s",
551 if (!controller->
usage)
552 LOG_DEBUG(
"'%s' driver usage field missing", controller->
name);
565 const char *bank_name = *
CMD_ARGV++;
568 const char *driver_name =
CMD_ARGV[0];
572 LOG_ERROR(
"No valid NAND flash driver found (%s)", driver_name);
581 .handler = &handle_nand_device_command,
583 .help =
"defines a new NAND bank",
584 .usage =
"bank_id driver target [driver_options ...]",
588 .handler = &handle_nand_list_drivers,
590 .help =
"lists available NAND drivers",
596 .handler = &handle_nand_init_command,
597 .help =
"initialize NAND devices",
607 .help =
"NAND flash command group",
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 CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#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_ENABLE(in, out)
parses an enable/disable command argument
#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 CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
int nand_probe(struct nand_device *nand)
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)
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)
void nand_device_add(struct nand_device *c)
int nand_driver_walk(nand_driver_walker_t f, void *x)
Walk the list of drivers, encapsulating the data structure type.
struct nand_flash_controller * nand_driver_find_by_name(const char *name)
Find a NAND flash controller by name.
int nand_fileio_cleanup(struct nand_fileio_state *state)
int nand_fileio_start(struct command_invocation *cmd, struct nand_device *nand, const char *filename, int filemode, struct nand_fileio_state *state)
void nand_fileio_init(struct nand_fileio_state *state)
int nand_fileio_read(struct nand_device *nand, struct nand_fileio_state *s)
int nand_fileio_finish(struct nand_fileio_state *state)
static COMMAND_HELPER(create_nand_device, const char *bank_name, struct nand_flash_controller *controller)
struct nand_device * nand_devices
COMMAND_HANDLER(handle_nand_list_command)
static int nand_init(struct command_context *cmd_ctx)
static const struct command_registration nand_exec_command_handlers[]
static int nand_list_walker(struct nand_flash_controller *c, void *x)
static const struct command_registration nand_config_command_handlers[]
static const struct command_registration nand_command_handlers[]
int nand_register_commands(struct command_context *cmd_ctx)
int fileio_write(struct fileio *fileio, size_t size, const void *buffer, size_t *size_written)
int fileio_size(struct fileio *fileio, size_t *size)
FIX!!!!
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
Upper level NOR flash interfaces.
size_t size
Size of the control block search area.
When run_command is called, a new instance will be created on the stack, filled with the proper value...
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
enum oob_formats oob_format
Interface for NAND flash controllers.
const char * usage
Usage of flash command registration.
const struct command_registration * commands
const char * name
Driver name that is used to select it from configuration files.
struct target * get_target(const char *id)
float duration_elapsed(const struct duration *duration)
float duration_kbps(const struct duration *duration, size_t count)