19 #define FLASH_BASE 0x10000000
20 #define PAU_BASE 0x40000000
21 #define SCU_BASE 0x40010000
22 #define NVM_BASE 0x40050000
24 #define FLASH_CS0 (FLASH_BASE + 0xf00)
26 #define PAU_FLSIZE (PAU_BASE + 0x404)
28 #define SCU_IDCHIP (SCU_BASE + 0x004)
30 #define NVMSTATUS (NVM_BASE + 0x00)
31 #define NVMPROG (NVM_BASE + 0x04)
32 #define NVMCONF (NVM_BASE + 0x08)
34 #define NVMSTATUS_BUSY (1 << 0)
35 #define NVMSTATUS_VERR_MASK (0x3 << 2)
37 #define NVMPROG_ACTION_OPTYPE_IDLE_VERIFY (0 << 0)
38 #define NVMPROG_ACTION_OPTYPE_WRITE (1 << 0)
39 #define NVMPROG_ACTION_OPTYPE_PAGE_ERASE (2 << 0)
41 #define NVMPROG_ACTION_ONE_SHOT_ONCE (1 << 4)
42 #define NVMPROG_ACTION_ONE_SHOT_CONTINUOUS (2 << 4)
44 #define NVMPROG_ACTION_VERIFY_EACH (1 << 6)
45 #define NVMPROG_ACTION_VERIFY_NO (2 << 6)
46 #define NVMPROG_ACTION_VERIFY_ARRAY (3 << 6)
48 #define NVMPROG_ACTION_IDLE 0x00
49 #define NVMPROG_ACTION_MASK 0xff
51 #define NVM_WORD_SIZE 4
52 #define NVM_BLOCK_SIZE (4 * NVM_WORD_SIZE)
53 #define NVM_PAGE_SIZE (16 * NVM_BLOCK_SIZE)
89 const uint8_t erase_code[] = {
90 #include "../../../contrib/loaders/flash/xmc1xxx/erase.inc"
93 LOG_DEBUG(
"Infineon XMC1000 erase sectors %u to %u", first, last);
96 LOG_WARNING(
"Cannot communicate... target not halted.");
112 sizeof(erase_code), erase_code);
125 bank->sectors[first].offset);
127 bank->sectors[last].offset +
bank->sectors[last].size);
135 LOG_ERROR(
"Error executing flash sector erase "
136 "programming algorithm");
164 const uint8_t erase_check_code[] = {
165 #include "../../../contrib/loaders/flash/xmc1xxx/erase_check.inc"
169 LOG_WARNING(
"Cannot communicate... target not halted.");
181 sizeof(erase_check_code), erase_check_code);
194 for (
unsigned int sector = 0; sector <
bank->num_sectors; sector++) {
210 LOG_ERROR(
"Error executing flash sector erase check "
211 "programming algorithm");
241 uint32_t
offset, uint32_t byte_count)
251 #include "../../../contrib/loaders/flash/xmc1xxx/write.inc"
254 LOG_DEBUG(
"Infineon XMC1000 write at 0x%08" PRIx32
" (%" PRIu32
" bytes)",
258 LOG_ERROR(
"offset 0x%" PRIx32
" breaks required block alignment",
263 LOG_WARNING(
"length %" PRIu32
" is not block aligned, rounding up",
268 LOG_WARNING(
"Cannot communicate... target not halted.");
275 LOG_ERROR(
"No working area available for write code.");
288 LOG_ERROR(
"No working area available for write data.");
303 while (byte_count > 0) {
320 data_workarea->
address + byte_count, 1,
322 &
bank->default_padded_value);
330 LOG_DEBUG(
"writing 0x%08" PRIx32
"-0x%08" PRIx32
" (%" PRIu32
"x)",
345 5 * 60 * 1000, &armv7m_algo);
348 "programming algorithm");
356 block_count -= blocks;
381 unsigned int num_protected;
385 LOG_WARNING(
"Cannot communicate... target not halted.");
391 LOG_ERROR(
"Cannot read NVMCONF register.");
394 LOG_DEBUG(
"NVMCONF = %08" PRIx32, nvmconf);
396 num_protected = (nvmconf >> 4) & 0xff;
398 for (
unsigned int i = 0; i <
bank->num_sectors; i++)
399 bank->sectors[i].is_protected = (i < num_protected) ? 1 : 0;
410 LOG_WARNING(
"Cannot communicate... target not halted.");
415 for (i = 0; i < 7; i++) {
418 LOG_ERROR(
"Cannot read CS0 register %i.", i);
421 LOG_DEBUG(
"ID[%d] = %08" PRIX32, i, chipid[i]);
425 LOG_ERROR(
"Cannot read DBGROMID register.");
428 LOG_DEBUG(
"ID[7] = %08" PRIX32, chipid[7]);
431 "XMC%" PRIx32
"00 %" PRIX32
" flash %" PRIu32
"KB ROM %" PRIu32
"KB SRAM %" PRIu32
"KB",
432 (chipid[0] >> 12) & 0xff,
433 0xAA + (chipid[7] >> 28) - 1,
434 (((chipid[6] >> 12) & 0x3f) - 1) * 4,
435 (((chipid[4] >> 8) & 0x3f) * 256) / 1024,
436 (((chipid[5] >> 8) & 0x1f) * 256 * 4) / 1024);
444 uint32_t flash_addr =
bank->base;
445 uint32_t idchip, flsize;
452 LOG_WARNING(
"Cannot communicate... target not halted.");
458 LOG_ERROR(
"Cannot read IDCHIP register.");
462 if ((idchip & 0xffff0000) != 0x10000) {
463 LOG_ERROR(
"IDCHIP register does not match XMC1xxx.");
467 LOG_DEBUG(
"IDCHIP = %08" PRIx32, idchip);
471 LOG_ERROR(
"Cannot read FLSIZE register.");
475 bank->num_sectors = 1 + ((flsize >> 12) & 0x3f) - 1;
476 bank->size =
bank->num_sectors * 4 * 1024;
477 bank->sectors = calloc(
bank->num_sectors,
479 for (
unsigned int i = 0; i <
bank->num_sectors; i++) {
481 bank->sectors[i].size = 0x200;
482 bank->sectors[i].offset = 0xE00;
483 flash_addr += 0x1000;
485 bank->sectors[i].size = 4 * 1024;
486 bank->sectors[i].offset = flash_addr -
bank->base;
487 flash_addr +=
bank->sectors[i].size;
489 bank->sectors[i].is_erased = -1;
490 bank->sectors[i].is_protected = -1;
518 bank->driver_priv = xmc_bank;
525 .flash_bank_command = xmc1xxx_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 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 ERROR_FLASH_OPERATION_FAILED
#define ERROR_FLASH_DST_BREAKS_ALIGNMENT
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_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
static const uint8_t write_code[]
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 target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int target_write_u16(struct target *target, target_addr_t address, uint16_t value)
int target_write_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Write count items of size bytes to the memory of target at the address given.
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_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_u16(struct target *target, target_addr_t address, uint16_t *value)
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.
const struct flash_driver xmc1xxx_flash
static int xmc1xxx_nvm_set_idle(struct target *target)
static int xmc1xxx_get_info_command(struct flash_bank *bank, struct command_invocation *cmd)
#define NVMSTATUS_VERR_MASK
static int xmc1xxx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
FLASH_BANK_COMMAND_HANDLER(xmc1xxx_flash_bank_command)
#define NVMPROG_ACTION_IDLE
static int xmc1xxx_probe(struct flash_bank *bank)
static int xmc1xxx_erase_check(struct flash_bank *bank)
static int xmc1xxx_nvm_check_idle(struct target *target)
#define NVMPROG_ACTION_MASK
static int xmc1xxx_protect_check(struct flash_bank *bank)
static int xmc1xxx_auto_probe(struct flash_bank *bank)
static int xmc1xxx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t byte_count)