41 #define ADUCM360_FLASH_BASE 0x40002800
42 #define ADUCM360_FLASH_FEESTA 0x0000
43 #define ADUCM360_FLASH_FEECON0 0x0004
44 #define ADUCM360_FLASH_FEECMD 0x0008
45 #define ADUCM360_FLASH_FEEADR0L 0x0010
46 #define ADUCM360_FLASH_FEEADR0H 0x0014
47 #define ADUCM360_FLASH_FEEADR1L 0x0018
48 #define ADUCM360_FLASH_FEEADR1H 0x001C
49 #define ADUCM360_FLASH_FEEKEY 0x0020
50 #define ADUCM360_FLASH_FEEPROL 0x0028
51 #define ADUCM360_FLASH_FEEPROH 0x002C
52 #define ADUCM360_FLASH_FEESIGL 0x0030
53 #define ADUCM360_FLASH_FEESIGH 0x0034
54 #define ADUCM360_FLASH_FEECON1 0x0038
55 #define ADUCM360_FLASH_FEEADRAL 0x0048
56 #define ADUCM360_FLASH_FEEADRAH 0x004C
57 #define ADUCM360_FLASH_FEEAEN0 0x0078
58 #define ADUCM360_FLASH_FEEAEN1 0x007C
59 #define ADUCM360_FLASH_FEEAEN2 0x0080
64 bank->base = 0x00000000;
65 bank->size = 0x00020000;
72 #define FLASH_SECTOR_SIZE 512
82 for (
unsigned int i = 0; i <
bank->num_sectors; ++i) {
86 bank->sectors[i].is_erased = -1;
87 bank->sectors[i].is_protected = 0;
146 LOG_ERROR(
"page erase failed at 0x%08" PRIx32, padd);
164 if (((first | last) == 0) || ((first == 0) && (last >=
bank->num_sectors))) {
167 count = last - first + 1;
168 for (i = 0; i <
count; ++i) {
187 uint32_t target_buffer_size = 8192;
193 uint32_t entry_point = 0, exit_point = 0;
197 static const uint32_t aducm360_flash_write_code[] = {
199 0x88AF4D10, 0x0704F047, 0x682F80AF, 0x600E6806,
200 0xF017882F, 0xF43F0F08, 0xF851AFFB, 0x42B77B04,
201 0x800DF040, 0x0004F100, 0xF47F3A04, 0x686FAFEF,
202 0x0704F027, 0xF04F80AF, 0xF0000400, 0xF04FB802,
203 0xBE000480, 0x40002800, 0x00015000, 0x20000000,
207 LOG_DEBUG(
"'aducm360_write_block_sync' requested, dst:0x%08" PRIx32
", count:0x%08" PRIx32
"bytes.",
212 LOG_ERROR(
"write block must be multiple of four bytes in offset & length");
219 LOG_WARNING(
"no working area available, can't do block memory writes");
224 uint8_t code[
sizeof(aducm360_flash_write_code)];
226 aducm360_flash_write_code);
234 LOG_WARNING(
"couldn't allocate a buffer space of 0x%08" PRIx32
"bytes in the target's SRAM.",
236 target_buffer_size /= 2;
237 if (target_buffer_size <= 256) {
238 LOG_WARNING(
"no large enough working area available, can't do block memory writes");
256 uint32_t thisrun_count = (
count > target_buffer_size) ? target_buffer_size :
count;
265 buf_set_u32(reg_params[2].value, 0, 32, thisrun_count);
269 reg_params, entry_point, exit_point, 10000, &armv7m_algo);
271 LOG_ERROR(
"error executing aducm360 flash write algorithm");
277 LOG_ERROR(
"aducm360 fast sync algorithm reports an error (%02" PRIX32
")", res);
283 address += thisrun_count;
284 count -= thisrun_count;
307 uint32_t target_buffer_size = 1024;
313 uint32_t entry_point = 0, exit_point = 0;
318 static const uint32_t aducm360_flash_write_code[] = {
320 0x4050F8DF, 0xF04588A5, 0x80A50504, 0x8000F8D0,
321 0x0F00F1B8, 0x8016F000, 0x45476847, 0xAFF6F43F,
322 0x6B04F857, 0x6B04F842, 0xF0158825, 0xF43F0F08,
323 0x428FAFFB, 0xF100BF28, 0x60470708, 0xB10B3B01,
324 0xBFE4F7FF, 0xF02588A5, 0x80A50504, 0x0900F04F,
325 0xBE00BF00, 0x40002800, 0x20000000, 0x20000100,
329 LOG_DEBUG(
"'aducm360_write_block_async' requested, dst:0x%08" PRIx32
", count:0x%08" PRIx32
"bytes.",
334 LOG_ERROR(
"write block must be multiple of four bytes in offset & length");
342 LOG_WARNING(
"no working area available, can't do block memory writes");
347 uint8_t code[
sizeof(aducm360_flash_write_code)];
349 aducm360_flash_write_code);
357 LOG_WARNING(
"couldn't allocate a buffer space of 0x%08" PRIx32
"bytes in the target's SRAM.",
359 target_buffer_size /= 2;
360 if (target_buffer_size <= 256) {
361 LOG_WARNING(
"no large enough working area available, can't do block memory writes");
386 entry_point, exit_point,
389 LOG_ERROR(
"error executing aducm360 flash write algorithm");
393 LOG_ERROR(
"aducm360 fast async algorithm reports an error (%02" PRIX32
")", res);
429 LOG_ERROR(
"aducm360_write_block was cancelled (no writing method was chosen)!");
435 #define FEESTA_WRDONE 0x00000008
447 LOG_DEBUG(
"performing slow write (offset=0x%08" PRIx32
", count=0x%08" PRIx32
")...",
456 for (i = 0; i <
count; i += 4) {
458 for (j = 0; i < 4; i += 1)
459 *((uint8_t *)(&d) + j) =
buffer[i+j];
481 LOG_WARNING(
"couldn't use block writes, falling back to single memory accesses");
511 value &= ~0x00000004;
530 if ((v & 0x00000001) == 0)
537 if (!(v & 0x00000004))
546 .flash_bank_command = aducm360_flash_bank_command,
#define ADUCM360_FLASH_FEECON0
FLASH_BANK_COMMAND_HANDLER(aducm360_flash_bank_command)
#define ADUCM360_FLASH_FEEADR0H
static int aducm360_probe(struct flash_bank *bank)
static int aducm360_mass_erase(struct target *target)
#define ADUCM360_FLASH_FEEADR0L
static int aducm360_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
#define ADUCM360_FLASH_FEECMD
#define ADUCM360_FLASH_FEESTA
#define ADUCM360_FLASH_BASE
#define ADUCM360_FLASH_FEEKEY
static int aducm360_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int aducm360_write_block_async(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int aducm360_set_write_enable(struct target *target, int enable)
static int aducm360_page_erase(struct target *target, uint32_t padd)
const struct flash_driver aducm360_flash
static int aducm360_write_modified(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int aducm360_write_block_sync(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int aducm360_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
#define FLASH_SECTOR_SIZE
static int aducm360_check_flash_completion(struct target *target, unsigned int timeout_ms)
static int aducm360_build_sector_list(struct flash_bank *bank)
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 int first, unsigned int 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 int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
#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 alive_sleep(uint64_t ms)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
unsigned int common_magic
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_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, unsigned int timeout_ms, void *arch_info)
Downloads a target-specific native code algorithm to the target, and executes it.
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_alloc_working_area_try(struct target *target, uint32_t size, struct working_area **area)
int target_run_flash_async_algorithm(struct target *target, const uint8_t *buffer, uint32_t count, int block_size, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t buffer_start, uint32_t buffer_size, uint32_t entry_point, uint32_t exit_point, void *arch_info)
Streams data to a circular buffer on target intended for consumption by code running asynchronously o...
int target_read_u32(struct target *target, target_addr_t address, uint32_t *value)
void target_buffer_set_u32_array(struct target *target, uint8_t *buffer, uint32_t count, const uint32_t *srcbuf)
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.