37 #define CONTROL_SLM (1<<0)
38 #define CONTROL_WP (1<<1)
39 #define CONTROL_E (1<<3)
40 #define CONTROL_EP (1<<4)
41 #define CONTROL_P (1<<5)
42 #define CONTROL_ERC (1<<6)
43 #define CONTROL_R (1<<7)
44 #define CONTROL_AP (1<<8)
47 #define TIMING0_R(x) (((x) << 0) & 0x3f)
48 #define TIMING0_F(x) (((x) << 16) & 0xffff0000)
49 #define TIMING1_E(x) (((x) << 0) & 0xffffff)
50 #define TIMING2_P(x) (((x) << 0) & 0xffff)
51 #define TIMING2_H(x) (((x) << 16) & 0xff0000)
52 #define TIMING2_T(x) (((x) << 24) & 0xf000000)
55 #define STATUS_BUSY (1<<0)
56 #define STATUS_WER (1<<1)
57 #define STATUS_DR (1<<2)
58 #define STATUS_DIS (1<<3)
59 #define STATUS_BO (1<<4)
62 #define REDUN_R (1<<0)
63 #define REDUN_P(x) (((x) << 12) & 0x7f000)
72 #define TERASE 160000000
78 #define TERASE 40000000
83 #define CONTROL_TIMEOUT 5000
84 #define FLASH_PAGE_SIZE 4096
87 #define NUM_NS_PER_S 1000000000ULL
111 bank->driver_priv = esirisc_info;
230 LOG_ERROR(
"%s: control timed out: 0x%" PRIx32,
bank->name, control);
254 for (
unsigned int page = first; page < last; ++page) {
261 LOG_ERROR(
"%s: failed to erase address: 0x%" PRIx32,
bank->name, address);
337 uint32_t num_bytes =
MIN(
count, max_bytes);
374 uint32_t num_bytes =
MIN(
count, max_bytes);
399 uint64_t hz = (uint64_t)esirisc_info->
clock * 1000;
400 uint64_t num_cycles = ((hz /
NUM_NS_PER_S) * ns) / 1000;
464 esirisc_info->
probed =
true;
484 "%4s cfg at 0x%" PRIx32
", clock %" PRIu32
", wait_states %" PRIu32,
508 (retval ==
ERROR_OK) ?
"successful" :
"failed");
528 (retval ==
ERROR_OK) ?
"successful" :
"failed");
535 .
name =
"mass_erase",
536 .handler = handle_esirisc_flash_mass_erase_command,
538 .help =
"erase all pages in data memory",
543 .handler = handle_esirisc_flash_ref_erase_command,
545 .help =
"erase reference cell (uncommon)",
555 .help =
"eSi-TSMC Flash command group",
564 .usage =
"flash bank bank_id 'esirisc' base_address size_bytes 0 0 target "
565 "cfg_address clock_hz wait_states",
566 .flash_bank_command = esirisc_flash_bank_command,
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
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_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.
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,...
static struct esirisc_common * target_to_esirisc(const struct target *target)
static const struct command_registration esirisc_flash_exec_command_handlers[]
static int esirisc_flash_unlock(struct flash_bank *bank)
static int esirisc_flash_enable_protect(struct flash_bank *bank)
static int esirisc_flash_clear_status(struct flash_bank *bank)
static const struct command_registration esirisc_flash_command_handlers[]
static int esirisc_flash_check_status(struct flash_bank *bank)
FLASH_BANK_COMMAND_HANDLER(esirisc_flash_bank_command)
static int esirisc_flash_wait(struct flash_bank *bank, int ms)
static int esirisc_flash_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int esirisc_flash_info(struct flash_bank *bank, struct command_invocation *cmd)
static int esirisc_flash_fill_pb(struct flash_bank *bank, const uint8_t *buffer, uint32_t count)
COMMAND_HANDLER(handle_esirisc_flash_mass_erase_command)
static int esirisc_flash_ref_erase(struct flash_bank *bank)
static int esirisc_flash_disable_protect(struct flash_bank *bank)
static int esirisc_flash_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int esirisc_flash_probe(struct flash_bank *bank)
static int esirisc_flash_recall(struct flash_bank *bank)
static int esirisc_flash_init(struct flash_bank *bank)
const struct flash_driver esirisc_flash
static uint32_t esirisc_flash_num_cycles(struct flash_bank *bank, uint64_t ns)
static int esirisc_flash_mass_erase(struct flash_bank *bank)
static int esirisc_flash_control(struct flash_bank *bank, uint32_t control)
static int esirisc_flash_auto_probe(struct flash_bank *bank)
#define ERROR_FLASH_OPERATION_FAILED
struct flash_sector * alloc_block_array(uint32_t offset, uint32_t size, unsigned int num_blocks)
Allocate and fill an array of sectors or protection blocks.
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Provides details of a flash bank, available either on-chip or through a major interface.
Provides the implementation-independent structure that defines all of the callbacks required by OpenO...
const char * name
Gives a human-readable name of this flash driver, This field is used to select and initialize the dri...
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
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)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_TIMEOUT
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.