From 9542cb7c3d9f4b66d2df3d8412a73d008077ab86 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Thu, 15 Nov 2018 12:19:25 +0100 Subject: [PATCH 1/1] flash/nor: consolidate flash protect/protect_check Make flash_driver methods protect() and protect_check() optional. Remove dummy definitions of these methods from the drivers which do not implement protection handling. Some drivers did not define protect method. It raised segfault before this change and now it is handled properly. Lot of drivers returned ERROR_OK from dummy protect() - now flash_driver_protect() returns an error if not handled by the driver. Change-Id: I2d4a0da316bf03c6379791b1b1c6198fbf22e66c Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/4765 Tested-by: jenkins Reviewed-by: Andreas Bolsch Reviewed-by: Christopher Head --- src/flash/nor/aduc702x.c | 14 -------------- src/flash/nor/aducm360.c | 16 ---------------- src/flash/nor/avrf.c | 16 +--------------- src/flash/nor/cc26xx.c | 13 ------------- src/flash/nor/cc3220sf.c | 13 ------------- src/flash/nor/cfi.c | 5 ----- src/flash/nor/core.c | 5 +++++ src/flash/nor/driver.h | 4 ++++ src/flash/nor/faux.c | 13 ------------- src/flash/nor/fm4.c | 6 ------ src/flash/nor/jtagspi.c | 11 ----------- src/flash/nor/lpc2000.c | 14 -------------- src/flash/nor/lpc288x.c | 1 + src/flash/nor/lpc2900.c | 20 +++++++------------- src/flash/nor/mdr.c | 12 ------------ src/flash/nor/mrvlqspi.c | 8 -------- src/flash/nor/msp432.c | 13 ------------- src/flash/nor/ocl.c | 12 ------------ src/flash/nor/psoc5lp.c | 22 ---------------------- src/flash/nor/stm32lx.c | 10 +--------- src/flash/nor/tcl.c | 16 ++++++++++++---- 21 files changed, 31 insertions(+), 213 deletions(-) diff --git a/src/flash/nor/aduc702x.c b/src/flash/nor/aduc702x.c index 34cc362eba..824112b1bc 100644 --- a/src/flash/nor/aduc702x.c +++ b/src/flash/nor/aduc702x.c @@ -74,12 +74,6 @@ static int aduc702x_build_sector_list(struct flash_bank *bank) return ERROR_OK; } -static int aduc702x_protect_check(struct flash_bank *bank) -{ - printf("aduc702x_protect_check not implemented yet.\n"); - return ERROR_OK; -} - static int aduc702x_erase(struct flash_bank *bank, int first, int last) { /* int res; */ @@ -130,12 +124,6 @@ static int aduc702x_erase(struct flash_bank *bank, int first, int last) return ERROR_OK; } -static int aduc702x_protect(struct flash_bank *bank, int set, int first, int last) -{ - printf("aduc702x_protect not implemented yet.\n"); - return ERROR_FLASH_OPERATION_FAILED; -} - /* If this fn returns ERROR_TARGET_RESOURCE_NOT_AVAILABLE, then the caller can fall * back to another mechanism that does not require onboard RAM * @@ -394,11 +382,9 @@ struct flash_driver aduc702x_flash = { .name = "aduc702x", .flash_bank_command = aduc702x_flash_bank_command, .erase = aduc702x_erase, - .protect = aduc702x_protect, .write = aduc702x_write, .read = default_flash_read, .probe = aduc702x_probe, .auto_probe = aduc702x_probe, .erase_check = default_flash_blank_check, - .protect_check = aduc702x_protect_check, }; diff --git a/src/flash/nor/aducm360.c b/src/flash/nor/aducm360.c index 8681a25af4..7663783478 100644 --- a/src/flash/nor/aducm360.c +++ b/src/flash/nor/aducm360.c @@ -102,13 +102,6 @@ static int aducm360_build_sector_list(struct flash_bank *bank) return ERROR_OK; } -/* ----------------------------------------------------------------------- */ -static int aducm360_protect_check(struct flash_bank *bank) -{ - LOG_WARNING("aducm360_protect_check not implemented."); - return ERROR_OK; -} - /* ----------------------------------------------------------------------- */ static int aducm360_mass_erase(struct target *target) { @@ -194,13 +187,6 @@ static int aducm360_erase(struct flash_bank *bank, int first, int last) return res; } -/* ----------------------------------------------------------------------- */ -static int aducm360_protect(struct flash_bank *bank, int set, int first, int last) -{ - LOG_ERROR("aducm360_protect not implemented."); - return ERROR_FLASH_OPERATION_FAILED; -} - /* ----------------------------------------------------------------------- */ static int aducm360_write_block_sync( struct flash_bank *bank, @@ -572,11 +558,9 @@ struct flash_driver aducm360_flash = { .name = "aducm360", .flash_bank_command = aducm360_flash_bank_command, .erase = aducm360_erase, - .protect = aducm360_protect, .write = aducm360_write, .read = default_flash_read, .probe = aducm360_probe, .auto_probe = aducm360_probe, .erase_check = default_flash_blank_check, - .protect_check = aducm360_protect_check, }; diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 65ac6015f0..b88f6f61c3 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -233,12 +233,6 @@ static int avrf_erase(struct flash_bank *bank, int first, int last) return avr_jtagprg_leaveprogmode(avr); } -static int avrf_protect(struct flash_bank *bank, int set, int first, int last) -{ - LOG_INFO("%s", __func__); - return ERROR_OK; -} - static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct target *target = bank->target; @@ -338,7 +332,7 @@ static int avrf_probe(struct flash_bank *bank) bank->sectors[i].offset = i * avr_info->flash_page_size; bank->sectors[i].size = avr_info->flash_page_size; bank->sectors[i].is_erased = -1; - bank->sectors[i].is_protected = 1; + bank->sectors[i].is_protected = -1; } avrf_info->probed = 1; @@ -360,12 +354,6 @@ static int avrf_auto_probe(struct flash_bank *bank) return avrf_probe(bank); } -static int avrf_protect_check(struct flash_bank *bank) -{ - LOG_INFO("%s", __func__); - return ERROR_OK; -} - static int avrf_info(struct flash_bank *bank, char *buf, int buf_size) { struct target *target = bank->target; @@ -479,13 +467,11 @@ struct flash_driver avr_flash = { .commands = avrf_command_handlers, .flash_bank_command = avrf_flash_bank_command, .erase = avrf_erase, - .protect = avrf_protect, .write = avrf_write, .read = default_flash_read, .probe = avrf_probe, .auto_probe = avrf_auto_probe, .erase_check = default_flash_blank_check, - .protect_check = avrf_protect_check, .info = avrf_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/cc26xx.c b/src/flash/nor/cc26xx.c index e6e9e5999f..7b87441433 100644 --- a/src/flash/nor/cc26xx.c +++ b/src/flash/nor/cc26xx.c @@ -312,12 +312,6 @@ static int cc26xx_erase(struct flash_bank *bank, int first, int last) return retval; } -static int cc26xx_protect(struct flash_bank *bank, int set, int first, - int last) -{ - return ERROR_OK; -} - static int cc26xx_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { @@ -508,11 +502,6 @@ static int cc26xx_auto_probe(struct flash_bank *bank) return retval; } -static int cc26xx_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int cc26xx_info(struct flash_bank *bank, char *buf, int buf_size) { struct cc26xx_bank *cc26xx_bank = bank->driver_priv; @@ -555,13 +544,11 @@ struct flash_driver cc26xx_flash = { .name = "cc26xx", .flash_bank_command = cc26xx_flash_bank_command, .erase = cc26xx_erase, - .protect = cc26xx_protect, .write = cc26xx_write, .read = default_flash_read, .probe = cc26xx_probe, .auto_probe = cc26xx_auto_probe, .erase_check = default_flash_blank_check, - .protect_check = cc26xx_protect_check, .info = cc26xx_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/cc3220sf.c b/src/flash/nor/cc3220sf.c index af45743b92..5ccb428a89 100644 --- a/src/flash/nor/cc3220sf.c +++ b/src/flash/nor/cc3220sf.c @@ -173,12 +173,6 @@ static int cc3220sf_erase(struct flash_bank *bank, int first, int last) return retval; } -static int cc3220sf_protect(struct flash_bank *bank, int set, int first, - int last) -{ - return ERROR_OK; -} - static int cc3220sf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { @@ -496,11 +490,6 @@ static int cc3220sf_auto_probe(struct flash_bank *bank) return retval; } -static int cc3220sf_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int cc3220sf_info(struct flash_bank *bank, char *buf, int buf_size) { int printed; @@ -517,13 +506,11 @@ struct flash_driver cc3220sf_flash = { .name = "cc3220sf", .flash_bank_command = cc3220sf_flash_bank_command, .erase = cc3220sf_erase, - .protect = cc3220sf_protect, .write = cc3220sf_write, .read = default_flash_read, .probe = cc3220sf_probe, .auto_probe = cc3220sf_auto_probe, .erase_check = default_flash_blank_check, - .protect_check = cc3220sf_protect_check, .info = cc3220sf_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index 0ae72d4a28..a2db50f332 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -1098,11 +1098,6 @@ static int cfi_protect(struct flash_bank *bank, int set, int first, int last) return ERROR_TARGET_NOT_HALTED; } - if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { - LOG_ERROR("Invalid sector range"); - return ERROR_FLASH_SECTOR_INVALID; - } - if (cfi_info->qry[0] != 'Q') return ERROR_FLASH_BANK_NOT_PROBED; diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index 49412816c3..0aaa7d26f0 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -68,6 +68,11 @@ int flash_driver_protect(struct flash_bank *bank, int set, int first, int last) /* force "set" to 0/1 */ set = !!set; + if (bank->driver->protect == NULL) { + LOG_ERROR("Flash protection is not supported."); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + /* DANGER! * * We must not use any cached information about protection state!!!! diff --git a/src/flash/nor/driver.h b/src/flash/nor/driver.h index e7b3234439..ef69a0f424 100644 --- a/src/flash/nor/driver.h +++ b/src/flash/nor/driver.h @@ -109,6 +109,8 @@ struct flash_driver { /** * Bank/sector protection routine (target-specific). * + * If protection is not implemented, set method to NULL + * * When called, the driver should enable/disable protection * for MINIMUM the range covered by first..last sectors * inclusive. Some chips have alignment requirements will @@ -178,6 +180,8 @@ struct flash_driver { * flash_sector_s::is_protected field for each of the flash * bank's sectors. * + * If protection is not implemented, set method to NULL + * * @param bank - the bank to check * @returns ERROR_OK if successful; otherwise, an error code. */ diff --git a/src/flash/nor/faux.c b/src/flash/nor/faux.c index 46eda72233..d68940fc6e 100644 --- a/src/flash/nor/faux.c +++ b/src/flash/nor/faux.c @@ -85,12 +85,6 @@ static int faux_erase(struct flash_bank *bank, int first, int last) return ERROR_OK; } -static int faux_protect(struct flash_bank *bank, int set, int first, int last) -{ - LOG_USER("set protection sector %d to %d to %s", first, last, set ? "on" : "off"); - return ERROR_OK; -} - static int faux_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct faux_flash_bank *info = bank->driver_priv; @@ -98,11 +92,6 @@ static int faux_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o return ERROR_OK; } -static int faux_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int faux_info(struct flash_bank *bank, char *buf, int buf_size) { snprintf(buf, buf_size, "faux flash driver"); @@ -129,13 +118,11 @@ struct flash_driver faux_flash = { .commands = faux_command_handlers, .flash_bank_command = faux_flash_bank_command, .erase = faux_erase, - .protect = faux_protect, .write = faux_write, .read = default_flash_read, .probe = faux_probe, .auto_probe = faux_probe, .erase_check = default_flash_blank_check, - .protect_check = faux_protect_check, .info = faux_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/fm4.c b/src/flash/nor/fm4.c index f5eab9c5b3..d4d0f76b46 100644 --- a/src/flash/nor/fm4.c +++ b/src/flash/nor/fm4.c @@ -537,11 +537,6 @@ static int fm4_auto_probe(struct flash_bank *bank) return fm4_probe(bank); } -static int fm4_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int fm4_get_info_command(struct flash_bank *bank, char *buf, int buf_size) { struct fm4_flash_bank *fm4_bank = bank->driver_priv; @@ -714,7 +709,6 @@ struct flash_driver fm4_flash = { .info = fm4_get_info_command, .probe = fm4_probe, .auto_probe = fm4_auto_probe, - .protect_check = fm4_protect_check, .read = default_flash_read, .erase = fm4_flash_erase, .erase_check = default_flash_blank_check, diff --git a/src/flash/nor/jtagspi.c b/src/flash/nor/jtagspi.c index c28ad22f7a..c5c565f2a1 100644 --- a/src/flash/nor/jtagspi.c +++ b/src/flash/nor/jtagspi.c @@ -343,21 +343,11 @@ static int jtagspi_protect(struct flash_bank *bank, int set, int first, int last { int sector; - if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { - LOG_ERROR("Flash sector invalid"); - return ERROR_FLASH_SECTOR_INVALID; - } - for (sector = first; sector <= last; sector++) bank->sectors[sector].is_protected = set; return ERROR_OK; } -static int jtagspi_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int jtagspi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { struct jtagspi_flash_bank *info = bank->driver_priv; @@ -431,7 +421,6 @@ struct flash_driver jtagspi_flash = { .probe = jtagspi_probe, .auto_probe = jtagspi_probe, .erase_check = default_flash_blank_check, - .protect_check = jtagspi_protect_check, .info = jtagspi_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/lpc2000.c b/src/flash/nor/lpc2000.c index 8e15c3122d..77beac1ca1 100644 --- a/src/flash/nor/lpc2000.c +++ b/src/flash/nor/lpc2000.c @@ -1018,12 +1018,6 @@ static int lpc2000_erase(struct flash_bank *bank, int first, int last) return retval; } -static int lpc2000_protect(struct flash_bank *bank, int set, int first, int last) -{ - /* can't protect/unprotect on the lpc2000 */ - return ERROR_OK; -} - static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct target *target = bank->target; @@ -1501,12 +1495,6 @@ static int lpc2000_erase_check(struct flash_bank *bank) return lpc2000_iap_blank_check(bank, 0, bank->num_sectors - 1); } -static int lpc2000_protect_check(struct flash_bank *bank) -{ - /* sectors are always protected */ - return ERROR_OK; -} - static int get_lpc2000_info(struct flash_bank *bank, char *buf, int buf_size) { struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv; @@ -1571,13 +1559,11 @@ struct flash_driver lpc2000_flash = { .commands = lpc2000_command_handlers, .flash_bank_command = lpc2000_flash_bank_command, .erase = lpc2000_erase, - .protect = lpc2000_protect, .write = lpc2000_write, .read = default_flash_read, .probe = lpc2000_probe, .auto_probe = lpc2000_probe, .erase_check = lpc2000_erase_check, - .protect_check = lpc2000_protect_check, .info = get_lpc2000_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/lpc288x.c b/src/flash/nor/lpc288x.c index 24729138a0..474e721eb8 100644 --- a/src/flash/nor/lpc288x.c +++ b/src/flash/nor/lpc288x.c @@ -167,6 +167,7 @@ static int lpc288x_read_part_info(struct flash_bank *bank) return ERROR_OK; } +/* TODO: Revisit! Is it impossible to read protection status? */ static int lpc288x_protect_check(struct flash_bank *bank) { return ERROR_OK; diff --git a/src/flash/nor/lpc2900.c b/src/flash/nor/lpc2900.c index 1c65933e21..022fb82a3e 100644 --- a/src/flash/nor/lpc2900.c +++ b/src/flash/nor/lpc2900.c @@ -1035,18 +1035,13 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last) return ERROR_OK; } -static int lpc2900_protect(struct flash_bank *bank, int set, int first, int last) -{ - /* This command is not supported. - * "Protection" in LPC2900 terms is handled transparently. Sectors will - * automatically be unprotected as needed. - * Instead we use the concept of sector security. A secured sector is shown - * as "protected" in OpenOCD. Sector security is a permanent feature, and - * cannot be disabled once activated. - */ - - return ERROR_OK; -} +/* lpc2900_protect command is not supported. +* "Protection" in LPC2900 terms is handled transparently. Sectors will +* automatically be unprotected as needed. +* Instead we use the concept of sector security. A secured sector is shown +* as "protected" in OpenOCD. Sector security is a permanent feature, and +* cannot be disabled once activated. +*/ /** * Write data to flash. @@ -1591,7 +1586,6 @@ struct flash_driver lpc2900_flash = { .commands = lpc2900_command_handlers, .flash_bank_command = lpc2900_flash_bank_command, .erase = lpc2900_erase, - .protect = lpc2900_protect, .write = lpc2900_write, .read = default_flash_read, .probe = lpc2900_probe, diff --git a/src/flash/nor/mdr.c b/src/flash/nor/mdr.c index f3916ded98..c4a4458f9e 100644 --- a/src/flash/nor/mdr.c +++ b/src/flash/nor/mdr.c @@ -86,11 +86,6 @@ FLASH_BANK_COMMAND_HANDLER(mdr_flash_bank_command) return ERROR_OK; } -static int mdr_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int mdr_mass_erase(struct flash_bank *bank) { struct target *target = bank->target; @@ -217,11 +212,6 @@ reset_pg_and_lock: return retval; } -static int mdr_protect(struct flash_bank *bank, int set, int first, int last) -{ - return ERROR_OK; -} - static int mdr_write_block(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { @@ -625,13 +615,11 @@ struct flash_driver mdr_flash = { ": 0 for main memory, 1 for info memory", .flash_bank_command = mdr_flash_bank_command, .erase = mdr_erase, - .protect = mdr_protect, .write = mdr_write, .read = mdr_read, .probe = mdr_probe, .auto_probe = mdr_auto_probe, .erase_check = default_flash_blank_check, - .protect_check = mdr_protect_check, .info = get_mdr_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/mrvlqspi.c b/src/flash/nor/mrvlqspi.c index eda6cc1ad2..132e5f36b3 100644 --- a/src/flash/nor/mrvlqspi.c +++ b/src/flash/nor/mrvlqspi.c @@ -899,12 +899,6 @@ static int mrvlqspi_flash_erase_check(struct flash_bank *bank) return ERROR_OK; } -static int mrvlqspi_protect_check(struct flash_bank *bank) -{ - /* Not implemented yet */ - return ERROR_OK; -} - int mrvlqspi_get_info(struct flash_bank *bank, char *buf, int buf_size) { struct mrvlqspi_flash_bank *mrvlqspi_info = bank->driver_priv; @@ -947,13 +941,11 @@ struct flash_driver mrvlqspi_flash = { .name = "mrvlqspi", .flash_bank_command = mrvlqspi_flash_bank_command, .erase = mrvlqspi_flash_erase, - .protect = NULL, .write = mrvlqspi_flash_write, .read = mrvlqspi_flash_read, .probe = mrvlqspi_probe, .auto_probe = mrvlqspi_auto_probe, .erase_check = mrvlqspi_flash_erase_check, - .protect_check = mrvlqspi_protect_check, .info = mrvlqspi_get_info, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c index 5caa0520d5..e2e65d4f0b 100644 --- a/src/flash/nor/msp432.c +++ b/src/flash/nor/msp432.c @@ -655,12 +655,6 @@ static int msp432_erase(struct flash_bank *bank, int first, int last) return retval; } -static int msp432_protect(struct flash_bank *bank, int set, int first, - int last) -{ - return ERROR_OK; -} - static int msp432_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { @@ -985,11 +979,6 @@ static int msp432_auto_probe(struct flash_bank *bank) return retval; } -static int msp432_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - static int msp432_info(struct flash_bank *bank, char *buf, int buf_size) { struct msp432_bank *msp432_bank = bank->driver_priv; @@ -1091,13 +1080,11 @@ struct flash_driver msp432_flash = { .commands = msp432_command_handlers, .flash_bank_command = msp432_flash_bank_command, .erase = msp432_erase, - .protect = msp432_protect, .write = msp432_write, .read = default_flash_read, .probe = msp432_probe, .auto_probe = msp432_auto_probe, .erase_check = default_flash_blank_check, - .protect_check = msp432_protect_check, .info = msp432_info, .free_driver_priv = msp432_flash_free_driver_priv, }; diff --git a/src/flash/nor/ocl.c b/src/flash/nor/ocl.c index 895c4af219..f8913c0905 100644 --- a/src/flash/nor/ocl.c +++ b/src/flash/nor/ocl.c @@ -35,11 +35,6 @@ static int ocl_erase_check(struct flash_bank *bank) return ERROR_OK; } -static int ocl_protect_check(struct flash_bank *bank) -{ - return ERROR_OK; -} - /* flash_bank ocl 0 0 0 0 */ FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command) { @@ -111,11 +106,6 @@ static int ocl_erase(struct flash_bank *bank, int first, int last) return ERROR_OK; } -static int ocl_protect(struct flash_bank *bank, int set, int first, int last) -{ - return ERROR_OK; -} - static int ocl_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct ocl_priv *ocl = bank->driver_priv; @@ -333,12 +323,10 @@ struct flash_driver ocl_flash = { .name = "ocl", .flash_bank_command = ocl_flash_bank_command, .erase = ocl_erase, - .protect = ocl_protect, .write = ocl_write, .read = default_flash_read, .probe = ocl_probe, .erase_check = ocl_erase_check, - .protect_check = ocl_protect_check, .auto_probe = ocl_auto_probe, .free_driver_priv = default_flash_free_driver_priv, }; diff --git a/src/flash/nor/psoc5lp.c b/src/flash/nor/psoc5lp.c index b88abbb470..d8e1c15682 100644 --- a/src/flash/nor/psoc5lp.c +++ b/src/flash/nor/psoc5lp.c @@ -753,16 +753,6 @@ static int psoc5lp_nvl_write(struct flash_bank *bank, return ERROR_OK; } -static int psoc5lp_nvl_protect_check(struct flash_bank *bank) -{ - int i; - - for (i = 0; i < bank->num_sectors; i++) - bank->sectors[i].is_protected = -1; - - return ERROR_OK; -} - static int psoc5lp_nvl_get_info_command(struct flash_bank *bank, char *buf, int buf_size) { @@ -855,7 +845,6 @@ struct flash_driver psoc5lp_nvl_flash = { .info = psoc5lp_nvl_get_info_command, .probe = psoc5lp_nvl_probe, .auto_probe = psoc5lp_nvl_auto_probe, - .protect_check = psoc5lp_nvl_protect_check, .read = psoc5lp_nvl_read, .erase = psoc5lp_nvl_erase, .erase_check = psoc5lp_nvl_erase_check, @@ -945,16 +934,6 @@ static int psoc5lp_eeprom_write(struct flash_bank *bank, return ERROR_OK; } -static int psoc5lp_eeprom_protect_check(struct flash_bank *bank) -{ - int i; - - for (i = 0; i < bank->num_sectors; i++) - bank->sectors[i].is_protected = -1; - - return ERROR_OK; -} - static int psoc5lp_eeprom_get_info_command(struct flash_bank *bank, char *buf, int buf_size) { struct psoc5lp_eeprom_flash_bank *psoc_eeprom_bank = bank->driver_priv; @@ -1064,7 +1043,6 @@ struct flash_driver psoc5lp_eeprom_flash = { .info = psoc5lp_eeprom_get_info_command, .probe = psoc5lp_eeprom_probe, .auto_probe = psoc5lp_eeprom_auto_probe, - .protect_check = psoc5lp_eeprom_protect_check, .read = default_flash_read, .erase = psoc5lp_eeprom_erase, .erase_check = default_flash_blank_check, diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index 3251df3fcf..1be950fe0b 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -424,13 +424,6 @@ static int stm32lx_erase(struct flash_bank *bank, int first, int last) return ERROR_OK; } -static int stm32lx_protect(struct flash_bank *bank, int set, int first, - int last) -{ - LOG_WARNING("protection of the STM32L flash is not implemented"); - return ERROR_OK; -} - static int stm32lx_write_half_pages(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { @@ -862,7 +855,7 @@ static int stm32lx_probe(struct flash_bank *bank) bank->sectors[i].offset = i * FLASH_SECTOR_SIZE; bank->sectors[i].size = FLASH_SECTOR_SIZE; bank->sectors[i].is_erased = -1; - bank->sectors[i].is_protected = 1; + bank->sectors[i].is_protected = -1; } stm32lx_info->probed = 1; @@ -955,7 +948,6 @@ struct flash_driver stm32lx_flash = { .commands = stm32lx_command_handlers, .flash_bank_command = stm32lx_flash_bank_command, .erase = stm32lx_erase, - .protect = stm32lx_protect, .write = stm32lx_write, .read = default_flash_read, .probe = stm32lx_probe, diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 95ca8192f7..f056e07538 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -98,10 +98,18 @@ COMMAND_HANDLER(handle_flash_info_command) if (retval != ERROR_OK) return retval; - /* We must query the hardware to avoid printing stale information! */ - retval = p->driver->protect_check(p); - if (retval != ERROR_OK) - return retval; + /* If the driver does not implement protection, we show the default + * state of is_protected array - usually protection state unknown */ + if (p->driver->protect_check == NULL) { + retval = ERROR_FLASH_OPER_UNSUPPORTED; + } else { + /* We must query the hardware to avoid printing stale information! */ + retval = p->driver->protect_check(p); + if (retval != ERROR_OK && retval != ERROR_FLASH_OPER_UNSUPPORTED) + return retval; + } + if (retval == ERROR_FLASH_OPER_UNSUPPORTED) + LOG_WARNING("Flash protection check is not implemented."); command_print(CMD_CTX, "#%d : %s at 0x%8.8" PRIx32 ", size 0x%8.8" PRIx32 -- 2.30.2