33 "pagesize: %i, buswidth: %i,\n\t"
34 "blocksize: %i, blocks: %i",
87 "#%i: %s (%s) pagesize: %i, buswidth: %i, erasesize: %i",
95 for (j = first; j <= last; j++) {
96 char *erase_state, *bad_state;
99 erase_state =
"not erased";
101 erase_state =
"erased";
103 erase_state =
"erase state unknown";
108 bad_state =
" (marked bad)";
110 bad_state =
" (block condition unknown)";
113 "\t#%i: 0x%8.8" PRIx32
" (%" PRIu32
"kB) %s%s",
179 "on NAND flash device #%s '%s'",
223 "use \"nand info\" command to list blocks");
238 uint32_t total_bytes = s.
size;
241 if (bytes_read <= 0) {
246 s.
size -= bytes_read;
252 "to NAND flash %s at offset 0x%8.8" PRIx32,
262 "offset 0x%8.8" PRIx32
" in %fs (%0.3f KiB/s)",
287 while (file.
size > 0) {
298 if (bytes_read <= 0) {
308 "at 0x%8.8" PRIx32, dev.
address);
314 file.
size -= bytes_read;
320 "up to offset 0x%8.8" PRIx32
" in %fs (%0.3f KiB/s)",
388 const char *msg = p->
use_raw ?
"enabled" :
"disabled";
397 .handler = handle_nand_list_command,
399 .help =
"list configured NAND flash devices",
404 .handler = handle_nand_info_command,
406 .usage =
"[banknum | first_bank_num last_bank_num]",
407 .help =
"print info about one or more NAND flash devices",
411 .handler = handle_nand_probe_command,
414 .help =
"identify NAND flash device",
417 .name =
"check_bad_blocks",
418 .handler = handle_nand_check_bad_blocks_command,
420 .usage =
"bank_id [offset length]",
421 .help =
"check all or part of NAND flash device for bad blocks",
425 .handler = handle_nand_erase_command,
427 .usage =
"bank_id [offset length]",
428 .help =
"erase all or subset of blocks on NAND flash device",
432 .handler = handle_nand_dump_command,
434 .usage =
"bank_id filename offset length "
435 "['oob_raw'|'oob_only']",
436 .help =
"dump from NAND flash device",
440 .handler = handle_nand_verify_command,
442 .usage =
"bank_id filename offset "
443 "['oob_raw'|'oob_only'|'oob_softecc'|'oob_softecc_kw']",
444 .help =
"verify NAND flash device",
448 .handler = handle_nand_write_command,
450 .usage =
"bank_id filename offset "
451 "['oob_raw'|'oob_only'|'oob_softecc'|'oob_softecc_kw']",
452 .help =
"write to NAND flash device",
455 .name =
"raw_access",
456 .handler = handle_nand_raw_access_command,
458 .usage =
"bank_id ['enable'|'disable']",
459 .help =
"raw access to NAND flash device",
477 static bool nand_initialized;
478 if (nand_initialized) {
479 LOG_INFO(
"'nand init' has already been called");
482 nand_initialized =
true;
484 LOG_DEBUG(
"Initializing NAND devices...");
527 c->
name = strdup(bank_name);
541 LOG_ERROR(
"'%s' driver rejected nand flash. Usage: %s",
548 if (!controller->
usage)
549 LOG_DEBUG(
"'%s' driver usage field missing", controller->
name);
562 const char *bank_name = *
CMD_ARGV++;
565 const char *driver_name =
CMD_ARGV[0];
569 LOG_ERROR(
"No valid NAND flash driver found (%s)", driver_name);
578 .handler = &handle_nand_device_command,
580 .help =
"defines a new NAND bank",
581 .usage =
"bank_id driver target [driver_options ...]",
585 .handler = &handle_nand_list_drivers,
587 .help =
"lists available NAND drivers",
593 .handler = &handle_nand_init_command,
594 .help =
"initialize NAND devices",
604 .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)
struct nand_device * nand_devices
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)
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)