33 #define SMI_READ_REG(a) \
38 _ret = target_read_u32(target, io_base + (a), &_value); \
39 if (_ret != ERROR_OK) \
44 #define SMI_WRITE_REG(a, v) \
48 _retval = target_write_u32(target, io_base + (a), (v)); \
49 if (_retval != ERROR_OK) \
53 #define SMI_POLL_TFF(timeout) \
57 _retval = poll_tff(target, io_base, timeout); \
58 if (_retval != ERROR_OK) \
62 #define SMI_SET_SW_MODE() SMI_WRITE_REG(SMI_CR1, \
63 SMI_READ_REG(SMI_CR1) | SMI_SW_MODE)
64 #define SMI_SET_HWWB_MODE() SMI_WRITE_REG(SMI_CR1, \
65 (SMI_READ_REG(SMI_CR1) | SMI_WB_MODE) & ~SMI_SW_MODE)
66 #define SMI_SET_HW_MODE() SMI_WRITE_REG(SMI_CR1, \
67 SMI_READ_REG(SMI_CR1) & ~(SMI_SW_MODE | SMI_WB_MODE))
68 #define SMI_CLEAR_TFF() SMI_WRITE_REG(SMI_SR, ~SMI_TFF)
70 #define SMI_BANK_SIZE (0x01000000)
72 #define SMI_CR1 (0x00)
73 #define SMI_CR2 (0x04)
79 #define SMI_SW_MODE 0x10000000
80 #define SMI_WB_MODE 0x20000000
83 #define SMI_TX_LEN_1 0x00000001
84 #define SMI_TX_LEN_4 0x00000004
85 #define SMI_RX_LEN_3 0x00000030
86 #define SMI_SEND 0x00000080
87 #define SMI_RSR 0x00000400
88 #define SMI_WE 0x00000800
89 #define SMI_SEL_BANK0 0x00000000
90 #define SMI_SEL_BANK1 0x00001000
91 #define SMI_SEL_BANK2 0x00002000
92 #define SMI_SEL_BANK3 0x00003000
95 #define SMI_TFF 0x00000100
98 #define SMI_READ_ID 0x0000009F
101 #define SMI_CMD_TIMEOUT (100)
102 #define SMI_PROBE_TIMEOUT (100)
103 #define SMI_MAX_TIMEOUT (3000)
121 {
"SPEAr3xx/6xx", 0x07926041, 0xf8000000, 0xfc000000 },
122 {
"STR75x", 0x4f1f0041, 0x80000000, 0x90000000 },
141 bank->driver_priv = stmsmi_info;
142 stmsmi_info->
probed =
false;
250 LOG_ERROR(
"Cannot enable write to flash. Status=0x%08" PRIx32,
status);
260 uint8_t cmd_bytes[] = {
312 LOG_DEBUG(
"%s: from sector %u to sector %u", __func__, first, last);
319 if ((last < first) || (last >=
bank->num_sectors)) {
324 if (!(stmsmi_info->
probed)) {
329 for (
unsigned int sector = first; sector <= last; sector++) {
330 if (
bank->sectors[sector].is_protected) {
331 LOG_ERROR(
"Flash sector %u protected", sector);
339 for (
unsigned int sector = first; sector <= last; sector++) {
352 unsigned int first,
unsigned int last)
354 for (
unsigned int sector = first; sector <= last; sector++)
355 bank->sectors[sector].is_protected = set;
360 uint32_t address, uint32_t len)
367 LOG_DEBUG(
"%s: address=0x%08" PRIx32
" len=0x%08" PRIx32,
368 __func__, address, len);
390 uint32_t cur_count, page_size, page_offset;
393 LOG_DEBUG(
"%s: offset=0x%08" PRIx32
" count=0x%08" PRIx32,
402 LOG_WARNING(
"Write pasts end of flash. Extra data discarded.");
407 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
411 (
bank->sectors[sector].offset +
bank->sectors[sector].size))
413 &&
bank->sectors[sector].is_protected) {
414 LOG_ERROR(
"Flash sector %u protected", sector);
425 cur_count = 4 - (
offset & 3);
426 if (cur_count >
count)
437 page_offset =
offset % page_size;
441 if (page_offset +
count > page_size)
442 cur_count = page_size - page_offset;
444 cur_count =
count & ~3;
522 stmsmi_info->
probed =
false;
527 if (!target_device->
name) {
528 LOG_ERROR(
"Device ID 0x%" PRIx32
" is not known as SMI capable",
564 if (p->device_id ==
id) {
565 stmsmi_info->
dev = p;
569 if (!stmsmi_info->
dev) {
570 LOG_ERROR(
"Unknown flash device (ID 0x%08" PRIx32
")",
id);
574 LOG_INFO(
"Found flash device \'%s\' (ID 0x%08" PRIx32
")",
579 if (
bank->size <= (1UL << 16))
580 LOG_WARNING(
"device needs 2-byte addresses - not implemented");
581 if (
bank->size > (1UL << 24))
582 LOG_WARNING(
"device needs paging or 4-byte addresses - not implemented");
597 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
598 sectors[sector].
offset = sector * sectorsize;
599 sectors[sector].
size = sectorsize;
604 bank->sectors = sectors;
605 stmsmi_info->
probed =
true;
627 if (!(stmsmi_info->
probed)) {
633 " Device \'%s\' (ID 0x%08" PRIx32
")\n",
641 .flash_bank_command = stmsmi_flash_bank_command,
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
#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 ERROR_FLASH_OPER_UNSUPPORTED
#define ERROR_FLASH_SECTOR_INVALID
#define ERROR_FLASH_BANK_NOT_PROBED
#define ERROR_FLASH_OPERATION_FAILED
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.
The JTAG interface can be implemented with a software or hardware fifo.
void alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
const struct flash_device flash_devices[]
#define SPIFLASH_DEF_PAGESIZE
static int read_flash_id(struct flash_bank *bank, uint32_t *id)
static int stmsmi_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int stmsmi_auto_probe(struct flash_bank *bank)
#define SMI_PROBE_TIMEOUT
static const struct stmsmi_target target_devices[]
#define SMI_SET_HW_MODE()
static int stmsmi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define SMI_WRITE_REG(a, v)
static int smi_write_enable(struct flash_bank *bank)
const struct flash_driver stmsmi_flash
#define SMI_SET_HWWB_MODE()
static int read_status_reg(struct flash_bank *bank, uint32_t *status)
static int stmsmi_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
FLASH_BANK_COMMAND_HANDLER(stmsmi_flash_bank_command)
static int get_stmsmi_info(struct flash_bank *bank, struct command_invocation *cmd)
#define SMI_SET_SW_MODE()
static int wait_till_ready(struct flash_bank *bank, int timeout)
static int stmsmi_probe(struct flash_bank *bank)
static int poll_tff(struct target *target, uint32_t io_base, int timeout)
static int stmsmi_protect_check(struct flash_bank *bank)
static int smi_write_buffer(struct flash_bank *bank, const uint8_t *buffer, uint32_t address, uint32_t len)
static int smi_erase_sector(struct flash_bank *bank, int sector)
#define SMI_POLL_TFF(timeout)
static uint32_t erase_command(struct stmsmi_flash_bank *stmsmi_info, uint32_t offset)
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...
Describes the geometry and status of a single flash sector within a flash bank.
int is_erased
Indication of erasure status: 0 = not erased, 1 = erased, other = unknown.
uint32_t offset
Bus offset from start of the flash chip (in bytes).
int is_protected
Indication of protection status: 0 = unprotected/unlocked, 1 = protected/locked, other = unknown.
uint32_t size
Number of bytes in this flash sector.
uint32_t idcode
device identification code
const struct flash_device * dev
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
#define ERROR_TARGET_NOT_HALTED
static uint32_t le_to_h_u32(const uint8_t *buf)