23 #define FLASH_BASE 0x40000000
24 #define FASZR (FLASH_BASE + 0x000)
25 #define DFCTRLR (FLASH_BASE + 0x030)
26 #define DFCTRLR_DFE (1UL << 0)
28 #define WDG_BASE 0x40011000
29 #define WDG_CTL (WDG_BASE + 0x008)
30 #define WDG_LCK (WDG_BASE + 0xC00)
112 const uint8_t erase_sector_code[] = {
113 #include "../../../contrib/loaders/flash/fm4/erase.inc"
117 LOG_WARNING(
"Cannot communicate... target not halted.");
121 LOG_DEBUG(
"Spansion FM4 erase sectors %u to %u", first, last);
139 sizeof(erase_sector_code), erase_sector_code);
151 for (
unsigned int sector = first; sector <= last; sector++) {
152 uint32_t
addr =
bank->base +
bank->sectors[sector].offset;
165 LOG_ERROR(
"Error executing flash sector erase "
166 "programming algorithm");
173 LOG_ERROR(
"Timeout error from flash sector erase programming algorithm");
176 }
else if (result != 0) {
177 LOG_ERROR(
"Unexpected error %" PRIu32
" from flash sector erase programming algorithm", result);
202 uint32_t
offset, uint32_t byte_count)
212 const uint8_t write_block_code[] = {
213 #include "../../../contrib/loaders/flash/fm4/write.inc"
216 LOG_DEBUG(
"Spansion FM4 write at 0x%08" PRIx32
" (%" PRIu32
" bytes)",
220 LOG_ERROR(
"offset 0x%" PRIx32
" breaks required 2-byte alignment",
224 if (byte_count & 0x1) {
225 LOG_WARNING(
"length %" PRIu32
" is not 2-byte aligned, rounding up",
230 LOG_WARNING(
"Cannot communicate... target not halted.");
241 LOG_ERROR(
"No working area available for write code.");
245 sizeof(write_block_code), write_block_code);
253 LOG_ERROR(
"No working area available for write data.");
272 while (byte_count > 0) {
273 uint32_t halfwords =
MIN(halfword_count, data_workarea->
size / 2);
277 MIN(halfwords * 2, byte_count), data_workarea->
address);
287 LOG_DEBUG(
"writing 0x%08" PRIx32
"-0x%08" PRIx32
" (%" PRIu32
"x)",
288 addr,
addr + halfwords * 2 - 1, halfwords);
294 buf_set_u32(reg_params[4].value, 0, 32, halfwords);
300 5 * 60 * 1000, &armv7m_algo);
302 LOG_ERROR(
"Error executing flash sector erase "
303 "programming algorithm");
310 LOG_ERROR(
"Timeout error from flash write "
311 "programming algorithm");
314 }
else if (result != 0) {
315 LOG_ERROR(
"Unexpected error %" PRIu32
" from flash write "
316 "programming algorithm", result);
322 halfword_count -= halfwords;
325 byte_count -=
MIN(halfwords * 2, byte_count);
350 uint32_t flash_addr =
bank->base;
354 bank->num_sectors = 8;
357 bank->num_sectors = 10;
360 bank->num_sectors = 12;
363 bank->num_sectors = 16;
366 bank->num_sectors = 20;
373 bank->sectors = calloc(
bank->num_sectors,
375 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
377 bank->sectors[i].size = 8 * 1024;
379 bank->sectors[i].size = 32 * 1024;
381 bank->sectors[i].size = 64 * 1024;
382 bank->sectors[i].offset = flash_addr -
bank->base;
383 bank->sectors[i].is_erased = -1;
384 bank->sectors[i].is_protected = -1;
386 bank->size +=
bank->sectors[i].size;
387 flash_addr +=
bank->sectors[i].size;
396 sector->
size = 8 * 1024;
398 sector->
size = 32 * 1024;
400 sector->
size = 64 * 1024;
411 uint32_t flash_addr =
bank->base;
413 unsigned int i, num_extra_sectors, num_sectors;
419 LOG_WARNING(
"Dual Flash mode is not implemented.");
425 num_sectors = (fm4_bank->
macro_nr == 0) ? 20 : 0;
428 num_sectors = (fm4_bank->
macro_nr == 0) ? 20 : 12;
436 num_extra_sectors = (fm4_bank->
macro_nr == 0) ? 1 : 4;
437 bank->num_sectors = num_sectors + num_extra_sectors;
440 bank->sectors = calloc(
bank->num_sectors,
442 for (i = 0; i < num_sectors; i++) {
444 bank->sectors[i].offset = flash_addr -
bank->base;
447 bank->size +=
bank->sectors[i].size;
448 flash_addr +=
bank->sectors[i].size;
451 flash_addr = (fm4_bank->
macro_nr == 0) ? 0x00406000 : 0x00408000;
452 for (; i <
bank->num_sectors; i++) {
453 int sa = 4 - num_extra_sectors + (i - num_sectors);
454 bank->sectors[i].offset = flash_addr -
bank->base;
461 flash_addr +=
bank->sectors[i].size;
469 uint32_t flash_addr =
bank->base;
471 bank->num_sectors = 10;
472 bank->sectors = calloc(
bank->num_sectors,
474 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
476 bank->sectors[i].size = 8 * 1024;
478 bank->sectors[i].size = 32 * 1024;
480 bank->sectors[i].size = 64 * 1024;
481 bank->sectors[i].offset = flash_addr -
bank->base;
482 bank->sectors[i].is_erased = -1;
483 bank->sectors[i].is_protected = -1;
485 bank->size +=
bank->sectors[i].size;
486 flash_addr +=
bank->sectors[i].size;
501 LOG_WARNING(
"Cannot communicate... target not halted.");
548 LOG_WARNING(
"Cannot communicate... target not halted.");
608 if (pattern[i] !=
'x' && tolower(s[i]) != tolower(pattern[i]))
671 fm4_bank->
macro_nr = (
bank->base == 0x00000000) ? 0 : 1;
673 bank->driver_priv = fm4_bank;
693 .flash_bank_command = fm4_flash_bank_command,
void init_reg_param(struct reg_param *param, char *reg_name, uint32_t size, enum param_direction direction)
void destroy_reg_param(struct reg_param *param)
#define ARMV7M_COMMON_MAGIC
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
#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 ERROR_FLASH_OPER_UNSUPPORTED
#define ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
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.
static int s6e2dh_probe(struct flash_bank *bank)
static int mb9bf_probe(struct flash_bank *bank)
static int fm4_flash_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t byte_count)
static int fm4_enter_flash_cpu_programming_mode(struct target *target)
static int fm4_probe(struct flash_bank *bank)
static int fm4_enter_flash_cpu_rom_mode(struct target *target)
FLASH_BANK_COMMAND_HANDLER(fm4_flash_bank_command)
static int fm4_disable_hw_watchdog(struct target *target)
static int mb9bf_bank_setup(struct flash_bank *bank, const char *variant)
static bool fm4_name_match(const char *s, const char *pattern)
static void s6e2cc_init_sector(struct flash_sector *sector, int sa)
static int fm4_flash_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int s6e2cc_bank_setup(struct flash_bank *bank, const char *variant)
const struct flash_driver fm4_flash
static int fm4_auto_probe(struct flash_bank *bank)
static int fm4_get_info_command(struct flash_bank *bank, struct command_invocation *cmd)
static int s6e2cc_probe(struct flash_bank *bank)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
unsigned int common_magic
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.
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.
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
uint32_t target_get_working_area_avail(struct target *target)
int target_alloc_working_area(struct target *target, uint32_t size, struct working_area **area)
int target_write_u32(struct target *target, target_addr_t address, uint32_t value)
int target_free_working_area(struct target *target, struct working_area *area)
Free a working area.
int target_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_param, target_addr_t entry_point, target_addr_t exit_point, int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
#define ERROR_TARGET_NOT_HALTED
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.