Skip to content

Commit f197483

Browse files
Steven Stallionthinkfat
authored andcommitted
flash/esirisc: refactor register write protection
This patch removes use of register write protection in protect() and protect_check() now that Change 4765 has merged. Change-Id: I42c429dc283c5b53989a6b98ebfc58214274ff16 Signed-off-by: Steven Stallion <[email protected]> Reviewed-on: http://openocd.zylin.com/4791 Tested-by: jenkins Reviewed-by: Tomas Vanek <[email protected]>
1 parent c5eb990 commit f197483

File tree

1 file changed

+12
-53
lines changed

1 file changed

+12
-53
lines changed

src/flash/nor/esirisc_flash.c

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int esirisc_flash_disable_protect(struct flash_bank *bank)
156156
if (!(control & CONTROL_WP))
157157
return ERROR_OK;
158158

159-
esirisc_flash_unlock(bank);
159+
(void)esirisc_flash_unlock(bank);
160160

161161
control &= ~CONTROL_WP;
162162

@@ -175,7 +175,7 @@ static int esirisc_flash_enable_protect(struct flash_bank *bank)
175175
if (control & CONTROL_WP)
176176
return ERROR_OK;
177177

178-
esirisc_flash_unlock(bank);
178+
(void)esirisc_flash_unlock(bank);
179179

180180
control |= CONTROL_WP;
181181

@@ -261,7 +261,7 @@ static int esirisc_flash_erase(struct flash_bank *bank, int first, int last)
261261
if (target->state != TARGET_HALTED)
262262
return ERROR_TARGET_NOT_HALTED;
263263

264-
esirisc_flash_disable_protect(bank);
264+
(void)esirisc_flash_disable_protect(bank);
265265

266266
for (int page = first; page < last; ++page) {
267267
uint32_t address = page * PAGE_SIZE;
@@ -275,7 +275,7 @@ static int esirisc_flash_erase(struct flash_bank *bank, int first, int last)
275275
}
276276
}
277277

278-
esirisc_flash_enable_protect(bank);
278+
(void)esirisc_flash_enable_protect(bank);
279279

280280
return retval;
281281
}
@@ -289,15 +289,15 @@ static int esirisc_flash_mass_erase(struct flash_bank *bank)
289289
if (target->state != TARGET_HALTED)
290290
return ERROR_TARGET_NOT_HALTED;
291291

292-
esirisc_flash_disable_protect(bank);
292+
(void)esirisc_flash_disable_protect(bank);
293293

294294
target_write_u32(target, esirisc_info->cfg + ADDRESS, 0);
295295

296296
retval = esirisc_flash_control(bank, CONTROL_E);
297297
if (retval != ERROR_OK)
298298
LOG_ERROR("%s: failed to mass erase", bank->name);
299299

300-
esirisc_flash_enable_protect(bank);
300+
(void)esirisc_flash_enable_protect(bank);
301301

302302
return retval;
303303
}
@@ -315,32 +315,17 @@ static int esirisc_flash_ref_erase(struct flash_bank *bank)
315315
if (target->state != TARGET_HALTED)
316316
return ERROR_TARGET_NOT_HALTED;
317317

318-
esirisc_flash_disable_protect(bank);
318+
(void)esirisc_flash_disable_protect(bank);
319319

320320
retval = esirisc_flash_control(bank, CONTROL_ERC);
321321
if (retval != ERROR_OK)
322322
LOG_ERROR("%s: failed to erase reference cell", bank->name);
323323

324-
esirisc_flash_enable_protect(bank);
324+
(void)esirisc_flash_enable_protect(bank);
325325

326326
return retval;
327327
}
328328

329-
static int esirisc_flash_protect(struct flash_bank *bank, int set, int first, int last)
330-
{
331-
struct target *target = bank->target;
332-
333-
if (target->state != TARGET_HALTED)
334-
return ERROR_TARGET_NOT_HALTED;
335-
336-
if (set)
337-
esirisc_flash_enable_protect(bank);
338-
else
339-
esirisc_flash_disable_protect(bank);
340-
341-
return ERROR_OK;
342-
}
343-
344329
static int esirisc_flash_fill_pb(struct flash_bank *bank,
345330
const uint8_t *buffer, uint32_t count)
346331
{
@@ -382,7 +367,7 @@ static int esirisc_flash_write(struct flash_bank *bank,
382367
if (target->state != TARGET_HALTED)
383368
return ERROR_TARGET_NOT_HALTED;
384369

385-
esirisc_flash_disable_protect(bank);
370+
(void)esirisc_flash_disable_protect(bank);
386371

387372
/*
388373
* The address register is auto-incremented based on the contents of
@@ -413,7 +398,7 @@ static int esirisc_flash_write(struct flash_bank *bank,
413398
count -= num_bytes;
414399
}
415400

416-
esirisc_flash_enable_protect(bank);
401+
(void)esirisc_flash_enable_protect(bank);
417402

418403
return retval;
419404
}
@@ -439,7 +424,7 @@ static int esirisc_flash_init(struct flash_bank *bank)
439424
uint32_t value;
440425
int retval;
441426

442-
esirisc_flash_disable_protect(bank);
427+
(void)esirisc_flash_disable_protect(bank);
443428

444429
/* initialize timing registers */
445430
value = TIMING0_F(esirisc_flash_num_cycles(bank, TNVH))
@@ -465,7 +450,7 @@ static int esirisc_flash_init(struct flash_bank *bank)
465450
if (retval != ERROR_OK)
466451
LOG_ERROR("%s: failed to recall trim code", bank->name);
467452

468-
esirisc_flash_enable_protect(bank);
453+
(void)esirisc_flash_enable_protect(bank);
469454

470455
return retval;
471456
}
@@ -482,13 +467,6 @@ static int esirisc_flash_probe(struct flash_bank *bank)
482467
bank->num_sectors = bank->size / PAGE_SIZE;
483468
bank->sectors = alloc_block_array(0, PAGE_SIZE, bank->num_sectors);
484469

485-
/*
486-
* Register write protection is enforced using a single protection
487-
* block for the entire bank. This is as good as it gets.
488-
*/
489-
bank->num_prot_blocks = 1;
490-
bank->prot_blocks = alloc_block_array(0, bank->size, bank->num_prot_blocks);
491-
492470
retval = esirisc_flash_init(bank);
493471
if (retval != ERROR_OK) {
494472
LOG_ERROR("%s: failed to initialize bank", bank->name);
@@ -510,23 +488,6 @@ static int esirisc_flash_auto_probe(struct flash_bank *bank)
510488
return esirisc_flash_probe(bank);
511489
}
512490

513-
static int esirisc_flash_protect_check(struct flash_bank *bank)
514-
{
515-
struct esirisc_flash_bank *esirisc_info = bank->driver_priv;
516-
struct target *target = bank->target;
517-
uint32_t control;
518-
519-
if (target->state != TARGET_HALTED)
520-
return ERROR_TARGET_NOT_HALTED;
521-
522-
target_read_u32(target, esirisc_info->cfg + CONTROL, &control);
523-
524-
/* single protection block (also see: esirisc_flash_probe()) */
525-
bank->prot_blocks[0].is_protected = !!(control & CONTROL_WP);
526-
527-
return ERROR_OK;
528-
}
529-
530491
static int esirisc_flash_info(struct flash_bank *bank, char *buf, int buf_size)
531492
{
532493
struct esirisc_flash_bank *esirisc_info = bank->driver_priv;
@@ -616,13 +577,11 @@ struct flash_driver esirisc_flash = {
616577
"cfg_address clock_hz wait_states",
617578
.flash_bank_command = esirisc_flash_bank_command,
618579
.erase = esirisc_flash_erase,
619-
.protect = esirisc_flash_protect,
620580
.write = esirisc_flash_write,
621581
.read = default_flash_read,
622582
.probe = esirisc_flash_probe,
623583
.auto_probe = esirisc_flash_auto_probe,
624584
.erase_check = default_flash_blank_check,
625-
.protect_check = esirisc_flash_protect_check,
626585
.info = esirisc_flash_info,
627586
.free_driver_priv = default_flash_free_driver_priv,
628587
};

0 commit comments

Comments
 (0)