Skip to content

Commit e023d73

Browse files
committed
flashalgo flags are introduced:
kAlgoVerifyReturnsAddress - Verify function returns address if this flag is set kAlgoSingleInitType - The Init/UnInit functions contain just return, so can be skipped kAlgoSkipChipErase - Skip region when erase.act action triggers. ChipErase on Some SPI Flash Memory take much more time that is allowed per drag-n-drop programming.
1 parent 300c820 commit e023d73

File tree

5 files changed

+72
-16
lines changed

5 files changed

+72
-16
lines changed

source/daplink/interface/swd_host.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* Copyright 2019, Cypress Semiconductor Corporation
8+
* or a subsidiary of Cypress Semiconductor Corporation.
79
* SPDX-License-Identifier: Apache-2.0
810
*
911
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -687,7 +689,7 @@ static uint8_t swd_wait_until_halted(void)
687689
return 0;
688690
}
689691

690-
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4)
692+
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, flash_algo_return_t return_type)
691693
{
692694
DEBUG_STATE state = {{0}, 0};
693695
// Call flash algorithm function on target and wait for result.
@@ -718,9 +720,17 @@ uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t e
718720
return 0;
719721
}
720722

721-
// Flash functions return 0 if successful.
722-
if (state.r[0] != 0) {
723-
return 0;
723+
if ( return_type == FLASHALGO_RETURN_POINTER ) {
724+
// Flash verify functions return pointer to byte following the buffer if successful.
725+
if (state.r[0] != (arg1 + arg2)) {
726+
return 0;
727+
}
728+
}
729+
else {
730+
// Flash functions return 0 if successful.
731+
if (state.r[0] != 0) {
732+
return 0;
733+
}
724734
}
725735

726736
return 1;

source/daplink/interface/swd_host.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* Copyright 2019, Cypress Semiconductor Corporation
8+
* or a subsidiary of Cypress Semiconductor Corporation.
79
* SPDX-License-Identifier: Apache-2.0
810
*
911
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -39,6 +41,11 @@ typedef enum {
3941
CONNECT_UNDER_RESET,
4042
} SWD_CONNECT_TYPE;
4143

44+
typedef enum {
45+
FLASHALGO_RETURN_BOOL,
46+
FLASHALGO_RETURN_POINTER
47+
} flash_algo_return_t;
48+
4249
uint8_t swd_init(void);
4350
uint8_t swd_off(void);
4451
uint8_t swd_init_debug(void);
@@ -55,7 +62,7 @@ uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size);
5562
uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size);
5663
uint8_t swd_read_core_register(uint32_t n, uint32_t *val);
5764
uint8_t swd_write_core_register(uint32_t n, uint32_t val);
58-
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
65+
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, flash_algo_return_t return_type);
5966
uint8_t swd_set_target_state_hw(target_state_t state);
6067
uint8_t swd_set_target_state_sw(target_state_t state);
6168
uint8_t swd_transfer_retry(uint32_t req, uint32_t *data);

source/daplink/interface/swd_host_ca.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* Copyright 2019, Cypress Semiconductor Corporation
8+
* or a subsidiary of Cypress Semiconductor Corporation.
79
* SPDX-License-Identifier: Apache-2.0
810
*
911
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -618,7 +620,7 @@ static uint8_t swd_wait_until_halted(void)
618620
return 0;
619621
}
620622

621-
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4)
623+
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, flash_algo_return_t return_type)
622624
{
623625
DEBUG_STATE state = {{0}, 0};
624626
// Call flash algorithm function on target and wait for result.
@@ -648,9 +650,17 @@ uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t e
648650
return 0;
649651
}
650652

651-
// Flash functions return 0 if successful.
652-
if (state.r[0] != 0) {
653-
return 0;
653+
if ( return_type == FLASHALGO_RETURN_POINTER ) {
654+
// Flash verify functions return pointer to byte following the buffer if successful.
655+
if (state.r[0] != (arg1 + arg2)) {
656+
return 0;
657+
}
658+
}
659+
else {
660+
// Flash functions return 0 if successful.
661+
if (state.r[0] != 0) {
662+
return 0;
663+
}
654664
}
655665

656666
return 1;

source/daplink/interface/target_flash.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7+
* Copyright 2019, Cypress Semiconductor Corporation
8+
* or a subsidiary of Cypress Semiconductor Corporation.
79
* SPDX-License-Identifier: Apache-2.0
810
*
911
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -32,6 +34,8 @@
3234
#include "target_family.h"
3335
#include "target_board.h"
3436

37+
#define DEFAULT_PROGRAM_PAGE_MIN_SIZE (256u)
38+
3539
typedef enum {
3640
STATE_CLOSED,
3741
STATE_OPEN,
@@ -107,13 +111,15 @@ static error_t flash_func_start(flash_func_t func)
107111
{
108112
// Finish the currently active function.
109113
if (FLASH_FUNC_NOP != last_flash_func &&
110-
0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->uninit, last_flash_func, 0, 0, 0)) {
114+
((flash->algo_flags & kAlgoSingleInitType) == 0 || FLASH_FUNC_NOP == func ) &&
115+
0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->uninit, last_flash_func, 0, 0, 0, FLASHALGO_RETURN_BOOL)) {
111116
return ERROR_UNINIT;
112117
}
113118

114119
// Start a new function.
115120
if (FLASH_FUNC_NOP != func &&
116-
0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->init, flash_start, 0, func, 0)) {
121+
((flash->algo_flags & kAlgoSingleInitType) == 0 || FLASH_FUNC_NOP == last_flash_func ) &&
122+
0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->init, flash_start, 0, func, 0, FLASHALGO_RETURN_BOOL)) {
117123
return ERROR_INIT;
118124
}
119125

@@ -237,7 +243,8 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
237243
addr,
238244
write_size,
239245
flash->program_buffer,
240-
0)) {
246+
0,
247+
FLASHALGO_RETURN_BOOL)) {
241248
return ERROR_WRITE;
242249
}
243250

@@ -248,12 +255,19 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
248255
if (status != ERROR_SUCCESS) {
249256
return status;
250257
}
258+
flash_algo_return_t return_type;
259+
if ((flash->algo_flags & kAlgoVerifyReturnsAddress) != 0) {
260+
return_type = FLASHALGO_RETURN_POINTER;
261+
} else {
262+
return_type = FLASHALGO_RETURN_BOOL;
263+
}
251264
if (!swd_flash_syscall_exec(&flash->sys_call_s,
252265
flash->verify,
253266
addr,
254267
write_size,
255268
flash->program_buffer,
256-
0)) {
269+
0,
270+
return_type)) {
257271
return ERROR_WRITE_VERIFY;
258272
}
259273
} else {
@@ -308,7 +322,7 @@ static error_t target_flash_erase_sector(uint32_t addr)
308322
return status;
309323
}
310324

311-
if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_sector, addr, 0, 0, 0)) {
325+
if (0 == swd_flash_syscall_exec(&flash->sys_call_s, flash->erase_sector, addr, 0, 0, 0, FLASHALGO_RETURN_BOOL)) {
312326
return ERROR_ERASE_SECTOR;
313327
}
314328

@@ -325,6 +339,11 @@ static error_t target_flash_erase_chip(void)
325339
region_info_t * flash_region = g_board_info.target_cfg->flash_regions;
326340

327341
for (; flash_region->start != 0 || flash_region->end != 0; ++flash_region) {
342+
program_target_t *new_flash_algo = get_flash_algo(flash_region->start);
343+
if ((new_flash_algo != NULL) && ((new_flash_algo->algo_flags & kAlgoSkipChipErase) != 0)) {
344+
// skip flash region
345+
continue;
346+
}
328347
status = target_flash_set(flash_region->start);
329348
if (status != ERROR_SUCCESS) {
330349
return status;
@@ -333,7 +352,7 @@ static error_t target_flash_erase_chip(void)
333352
if (status != ERROR_SUCCESS) {
334353
return status;
335354
}
336-
if (0 == swd_flash_syscall_exec(&current_flash_algo->sys_call_s, current_flash_algo->erase_chip, 0, 0, 0, 0)) {
355+
if (0 == swd_flash_syscall_exec(&current_flash_algo->sys_call_s, current_flash_algo->erase_chip, 0, 0, 0, 0, FLASHALGO_RETURN_BOOL)) {
337356
return ERROR_ERASE_ALL;
338357
}
339358
}
@@ -352,7 +371,7 @@ static error_t target_flash_erase_chip(void)
352371
static uint32_t target_flash_program_page_min_size(uint32_t addr)
353372
{
354373
if (g_board_info.target_cfg){
355-
uint32_t size = 256;
374+
uint32_t size = DEFAULT_PROGRAM_PAGE_MIN_SIZE;
356375
if (size > target_flash_erase_sector_size(addr)) {
357376
size = target_flash_erase_sector_size(addr);
358377
}

source/hic_hal/flash_blob.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* DAPLink Interface Firmware
66
* Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
7+
* Copyright 2019, Cypress Semiconductor Corporation
8+
* or a subsidiary of Cypress Semiconductor Corporation.
79
* SPDX-License-Identifier: Apache-2.0
810
*
911
* Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -28,6 +30,13 @@
2830
extern "C" {
2931
#endif
3032

33+
// Flags for program_target
34+
enum {
35+
kAlgoVerifyReturnsAddress = (1u << 0u), /*!< Verify function returns address if bit set */
36+
kAlgoSingleInitType = (1u << 1u), /*!< The init function ignores the function code. */
37+
kAlgoSkipChipErase = (1u << 2u), /*!< Skip region when erase.act action triggers. */
38+
};
39+
3140
typedef struct __attribute__((__packed__)) {
3241
uint32_t breakpoint;
3342
uint32_t static_base;
@@ -47,6 +56,7 @@ typedef struct __attribute__((__packed__)) {
4756
const uint32_t algo_size;
4857
const uint32_t *algo_blob;
4958
const uint32_t program_buffer_size;
59+
const uint32_t algo_flags; /*!< Combination of kAlgoVerifyReturnsAddress, kAlgoSingleInitType and kAlgoSkipChipErase*/
5060
} program_target_t;
5161

5262
typedef struct __attribute__((__packed__)) {

0 commit comments

Comments
 (0)