mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 16:41:55 +00:00
chip/stm32/flash-f: Clear option byte write enable/erase operation when done
Before
72afc55bd9 "stm32: cleanup flash-f by using constant from register.h"
lock() function would simply do:
STM32_FLASH_CR = FLASH_CR_LOCK;
which would clear all other bits in STM32_FLASH_CR, including
FLASH_CR_OPTER and FLASH_CR_OPTWRE.
This allow preserve_optb to work, as it does:
1. erase_optb
a. unlock()
b. Set FLASH_CR_OPTER
c. lock() (clears FLASH_CR_OPTER!)
2. write_optb
a. unlock()
b. Set FLASH_CR_OPTPG
c. Write option byte
d. Clear FLASH_CR_OPTPG
e. lock()
After the patch, we now have:
STM32_FLASH_CR |= FLASH_CR_LOCK;
which seems more correct. However, 1.c. does not clear FLASH_CR_OPTER,
and 2.b. ends up with both FLASH_CR_OPTPG and FLASH_CR_OPTER set,
and the programming operation does not do anything.
This patches does 3 things:
- Rename FLASH_CR_OPTSTRT to FLASH_CR_OPTER, as that's the correct
register name for STM32F0 and STM32F3.
- Fix the above by clearing FLASH_CR_OPTER in erase_optb
- Also clear FLASH_CR_OPTWRE in lock(). Not strictly necessary,
but this seems to be the right thing to do.
BRANCH=none
BUG=chromium:739608
TEST=On hammer, type flashwp true; reboot; flashwp all; reboot
flashinfo => All flash is protected
Change-Id: Ic276545ae3c0bdb685c7b117a7f896ec341731bb
Reviewed-on: https://chromium-review.googlesource.com/562839
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Wei-Ning Huang <wnhuang@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
bdd39d51a3
commit
241e7e3a01
@@ -82,6 +82,10 @@ static int unlock(int locks)
|
||||
|
||||
static void lock(void)
|
||||
{
|
||||
#if defined(CHIP_FAMILY_STM32F0) || defined(CHIP_FAMILY_STM32F3)
|
||||
/* FLASH_CR_OPTWRE was set by writing the keys in unlock(). */
|
||||
STM32_FLASH_CR &= ~FLASH_CR_OPTWRE;
|
||||
#endif
|
||||
STM32_FLASH_CR |= FLASH_CR_LOCK;
|
||||
}
|
||||
|
||||
@@ -147,10 +151,13 @@ static int erase_optb(void)
|
||||
return rv;
|
||||
|
||||
/* Must be set in 2 separate lines. */
|
||||
STM32_FLASH_CR |= FLASH_CR_OPTSTRT;
|
||||
STM32_FLASH_CR |= FLASH_CR_OPTER;
|
||||
STM32_FLASH_CR |= FLASH_CR_STRT;
|
||||
|
||||
rv = wait_busy();
|
||||
|
||||
STM32_FLASH_CR &= ~FLASH_CR_OPTER;
|
||||
|
||||
if (rv)
|
||||
return rv;
|
||||
lock();
|
||||
|
||||
@@ -1342,7 +1342,7 @@ typedef volatile struct stm32_spi_regs stm32_spi_regs_t;
|
||||
#define FLASH_CR_PG (1 << 0)
|
||||
#define FLASH_CR_PER (1 << 1)
|
||||
#define FLASH_CR_OPTPG (1 << 4)
|
||||
#define FLASH_CR_OPTSTRT (1 << 5)
|
||||
#define FLASH_CR_OPTER (1 << 5)
|
||||
#define FLASH_CR_STRT (1 << 6)
|
||||
#define FLASH_CR_LOCK (1 << 7)
|
||||
#define FLASH_CR_OPTWRE (1 << 9)
|
||||
|
||||
Reference in New Issue
Block a user