Each bank had to store its options only, there is no need for bank1
to sneak into bank2 options.
Furthermore, some variants do not have a second bank.
Change-Id: I9229eb8ab4b5860ba2b0c5dbe626a54a84bca4d6
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5290
Tested-by: jenkins
Reviewed-by: Christopher Head <chead@zaber.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
struct stm32x_options {
uint8_t RDP;
struct stm32x_options {
uint8_t RDP;
- uint32_t protection; /* bank1 WRP */
- uint32_t protection2; /* bank2 WRP */
+ uint32_t protection; /* bank sectors's write protection (WPSN register) */
uint8_t user_options;
uint8_t user2_options;
uint8_t user3_options;
uint8_t user_options;
uint8_t user2_options;
uint8_t user3_options;
static int stm32x_read_options(struct flash_bank *bank)
{
uint32_t optiondata;
static int stm32x_read_options(struct flash_bank *bank)
{
uint32_t optiondata;
- struct stm32h7x_flash_bank *stm32x_info = NULL;
+ struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv;
struct target *target = bank->target;
struct target *target = bank->target;
- stm32x_info = bank->driver_priv;
-
/* read current option bytes */
int retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTSR_CUR, &optiondata);
if (retval != ERROR_OK)
/* read current option bytes */
int retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTSR_CUR, &optiondata);
if (retval != ERROR_OK)
LOG_INFO("Device Security Bit Set");
/* read current WPSN option bytes */
LOG_INFO("Device Security Bit Set");
/* read current WPSN option bytes */
- retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSN_CUR, &optiondata);
+ retval = target_read_u32(target, stm32x_get_flash_reg(bank, FLASH_WPSN_CUR), &optiondata);
if (retval != ERROR_OK)
return retval;
stm32x_info->option_bytes.protection = optiondata & 0xff;
if (retval != ERROR_OK)
return retval;
stm32x_info->option_bytes.protection = optiondata & 0xff;
- /* read current WPSN2 option bytes */
- retval = target_read_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSN_CUR, &optiondata);
- if (retval != ERROR_OK)
- return retval;
- stm32x_info->option_bytes.protection2 = optiondata & 0xff;
-
return ERROR_OK;
}
static int stm32x_write_options(struct flash_bank *bank)
{
return ERROR_OK;
}
static int stm32x_write_options(struct flash_bank *bank)
{
- struct stm32h7x_flash_bank *stm32x_info = NULL;
+ struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv;
struct target *target = bank->target;
uint32_t optiondata;
struct target *target = bank->target;
uint32_t optiondata;
- stm32x_info = bank->driver_priv;
-
int retval = stm32x_unlock_option_reg(bank);
if (retval != ERROR_OK)
return retval;
int retval = stm32x_unlock_option_reg(bank);
if (retval != ERROR_OK)
return retval;
optiondata = stm32x_info->option_bytes.protection & 0xff;
/* Program protection WPSNPRG */
optiondata = stm32x_info->option_bytes.protection & 0xff;
/* Program protection WPSNPRG */
- retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSN_PRG, optiondata);
- if (retval != ERROR_OK)
- return retval;
-
- optiondata = stm32x_info->option_bytes.protection2 & 0xff;
- /* Program protection WPSNPRG2 */
- retval = target_write_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSN_PRG, optiondata);
+ retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_WPSN_PRG), optiondata);
if (retval != ERROR_OK)
return retval;
if (retval != ERROR_OK)
return retval;
}
for (int i = 0; i < bank->num_sectors; i++) {
}
for (int i = 0; i < bank->num_sectors; i++) {
- if (stm32x_info->flash_base == FLASH_REG_BASE_B0) {
- if (stm32x_info->option_bytes.protection & (1 << i))
- bank->sectors[i].is_protected = 0;
- else
- bank->sectors[i].is_protected = 1;
- } else {
- if (stm32x_info->option_bytes.protection2 & (1 << i))
- bank->sectors[i].is_protected = 0;
- else
- bank->sectors[i].is_protected = 1;
- }
+ bank->sectors[i].is_protected = stm32x_info->option_bytes.protection & (1 << i) ? 0 : 1;
}
for (int i = first; i <= last; i++) {
}
for (int i = first; i <= last; i++) {
- if (stm32x_info->flash_base == FLASH_REG_BASE_B0) {
- if (set)
- stm32x_info->option_bytes.protection &= ~(1 << i);
- else
- stm32x_info->option_bytes.protection |= (1 << i);
- } else {
- if (set)
- stm32x_info->option_bytes.protection2 &= ~(1 << i);
- else
- stm32x_info->option_bytes.protection2 |= (1 << i);
- }
+ if (set)
+ stm32x_info->option_bytes.protection &= ~(1 << i);
+ else
+ stm32x_info->option_bytes.protection |= (1 << i);
- LOG_INFO("stm32x_protect, option_bytes written WRP1 0x%x , WRP2 0x%x",
- (stm32x_info->option_bytes.protection & 0xff), (stm32x_info->option_bytes.protection2 & 0xff));
+ LOG_DEBUG("stm32x_protect, option_bytes written WPSN 0x%x",
+ (stm32x_info->option_bytes.protection & 0xff));
retval = stm32x_write_options(bank);
if (retval != ERROR_OK)
retval = stm32x_write_options(bank);
if (retval != ERROR_OK)
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)