4
4
*
5
5
* DAPLink Interface Firmware
6
6
* Copyright (c) 2009-2019, ARM Limited, All Rights Reserved
7
+ * Copyright 2019, Cypress Semiconductor Corporation
8
+ * or a subsidiary of Cypress Semiconductor Corporation.
7
9
* SPDX-License-Identifier: Apache-2.0
8
10
*
9
11
* Licensed under the Apache License, Version 2.0 (the "License"); you may
32
34
#include "target_family.h"
33
35
#include "target_board.h"
34
36
37
+ #define DEFAULT_PROGRAM_PAGE_MIN_SIZE (256u)
38
+
35
39
typedef enum {
36
40
STATE_CLOSED ,
37
41
STATE_OPEN ,
@@ -107,13 +111,15 @@ static error_t flash_func_start(flash_func_t func)
107
111
{
108
112
// Finish the currently active function.
109
113
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 )) {
111
116
return ERROR_UNINIT ;
112
117
}
113
118
114
119
// Start a new function.
115
120
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 )) {
117
123
return ERROR_INIT ;
118
124
}
119
125
@@ -237,7 +243,8 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
237
243
addr ,
238
244
write_size ,
239
245
flash -> program_buffer ,
240
- 0 )) {
246
+ 0 ,
247
+ FLASHALGO_RETURN_BOOL )) {
241
248
return ERROR_WRITE ;
242
249
}
243
250
@@ -248,12 +255,19 @@ static error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint
248
255
if (status != ERROR_SUCCESS ) {
249
256
return status ;
250
257
}
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
+ }
251
264
if (!swd_flash_syscall_exec (& flash -> sys_call_s ,
252
265
flash -> verify ,
253
266
addr ,
254
267
write_size ,
255
268
flash -> program_buffer ,
256
- 0 )) {
269
+ 0 ,
270
+ return_type )) {
257
271
return ERROR_WRITE_VERIFY ;
258
272
}
259
273
} else {
@@ -308,7 +322,7 @@ static error_t target_flash_erase_sector(uint32_t addr)
308
322
return status ;
309
323
}
310
324
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 )) {
312
326
return ERROR_ERASE_SECTOR ;
313
327
}
314
328
@@ -325,6 +339,11 @@ static error_t target_flash_erase_chip(void)
325
339
region_info_t * flash_region = g_board_info .target_cfg -> flash_regions ;
326
340
327
341
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
+ }
328
347
status = target_flash_set (flash_region -> start );
329
348
if (status != ERROR_SUCCESS ) {
330
349
return status ;
@@ -333,7 +352,7 @@ static error_t target_flash_erase_chip(void)
333
352
if (status != ERROR_SUCCESS ) {
334
353
return status ;
335
354
}
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 )) {
337
356
return ERROR_ERASE_ALL ;
338
357
}
339
358
}
@@ -352,7 +371,7 @@ static error_t target_flash_erase_chip(void)
352
371
static uint32_t target_flash_program_page_min_size (uint32_t addr )
353
372
{
354
373
if (g_board_info .target_cfg ){
355
- uint32_t size = 256 ;
374
+ uint32_t size = DEFAULT_PROGRAM_PAGE_MIN_SIZE ;
356
375
if (size > target_flash_erase_sector_size (addr )) {
357
376
size = target_flash_erase_sector_size (addr );
358
377
}
0 commit comments