Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/flash: deprecation of flash_write_protection_set() API #33216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd1ded8
drivers/flash/nrf_qspi_nor: integrate protection service into write/e…
nvlsianpu Mar 10, 2021
9fa7d21
drivers/flash/spi_nor: integrate protection service into write/erase
nvlsianpu Mar 11, 2021
18f07cf
drivers/flash/soc_flash_mcux: integrate protection service into write…
nvlsianpu Mar 12, 2021
b92b956
drivers/flash/soc_flash_lpc: integrate protection service into write/…
nvlsianpu Mar 12, 2021
3ec4eff
drivers/flash/soc_flash_rv32m1: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
63abfc7
drivers/flash/soc_flash_sam: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
db42843
drivers/flash/soc_flash_sam0: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
41486b4
drivers/flash/flash_gecko: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
ec04395
drivers/flash/flash_stm32: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
d98dfe1
drivers/flash/flash_stm32h7x: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
3769736
drivers/flash/flash_stm32_qspi: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
fdcd317
drivers/flash/soc_flash_nios2_qspi: integrate WP service into write/e…
nvlsianpu Mar 12, 2021
56d7ee2
drivers/flash/flash_simulator: integrate WP service into write/erase
nvlsianpu Mar 12, 2021
f421d07
include/drivers/flash: make write_protection handler optional
nvlsianpu Mar 18, 2021
800671e
drivers/flash: removed write protection API implementations
nvlsianpu Mar 12, 2021
f993cb9
tests/drivers/flash_simulator: remove flash_write_protection_set() usage
nvlsianpu Mar 16, 2021
76b85b6
tests/boards/altera_max10/qspi: remove flash_write_protection_set() u…
nvlsianpu Mar 16, 2021
6188464
tests/tree-wide: remove flash_write_protection_set() usage
nvlsianpu Mar 16, 2021
aa92147
fs/nvs: remove flash_write_protect_set() usage
nvlsianpu Mar 17, 2021
8c5c64b
fs/nvs: removed unneeded `if` statements
nvlsianpu Mar 17, 2021
e32fcec
storage: remove flash_write_protection_set() usage
nvlsianpu Mar 17, 2021
d965b31
disk/disk_acces_flash: remove flash_write_protection_set() usage
nvlsianpu Mar 17, 2021
77ac0fa
drivers/flash/flash_shell: remove flash_write_protection_set() usage
nvlsianpu Mar 17, 2021
ebb697e
drivers/eeprom/eeprom_emulator: remove flash_write_protection_set() u…
nvlsianpu Mar 17, 2021
bd490f5
samples/tree-wide: remove flash_write_protection_set() usage
nvlsianpu Mar 17, 2021
fa9ffa6
include/drivers/flash: deprecation of flash_write_protection_set()
nvlsianpu Mar 12, 2021
fa5b2b8
release-note: flash_api_write_protection() deprecation record
nvlsianpu Mar 16, 2021
b9af114
tests/drivers/flash: allow CI using nrf52840dk_nrf52840
nvlsianpu Mar 26, 2021
d7a8334
drivers/flash/flash_stm32g4x: fixed build issue
nvlsianpu Mar 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/releases/release-notes-2.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Deprecated in this release
Disk API header ``<include/disk/disk_access.h>`` is deprecated in favor of
``<include/storage/disk_access.h>``.

* :c:func:`flash_write_protection_set()`.

==========================

Removed APIs in this release
Expand Down Expand Up @@ -184,6 +186,18 @@ Drivers and Sensors

* Flash

* flash_write_protection_set() has been deprecated and will be removed in
Zephyr 2.8. Responsibility for write/erase protection management has been
moved to the driver-specific implementation of the flash_write() and
flash_erase() API calls. All in-tree flash drivers have been updated,
and the protect implementation removed from their API tables.
During the deprecation period user code invoking
flash_write_protection_set() will have no effect, but the flash_write() and
flash_erase() driver shims will wrap their calls with calls to the protect
implementation if it is present in the API table.
Out-of-tree drivers must be updated before the wrapping in the shims is
removed when the deprecation period ends.

* GPIO

* Hardware Info
Expand Down
5 changes: 0 additions & 5 deletions drivers/disk/flashdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ static int update_flash_block(off_t start_addr, uint32_t size, const void *buff)
/* always align starting address for flash write operation */
fl_addr = ROUND_DOWN(start_addr, CONFIG_DISK_FLASH_ERASE_ALIGNMENT);

/* disable write-protection first before erase */
flash_write_protection_set(flash_dev, false);
if (flash_erase(flash_dev, fl_addr, CONFIG_DISK_ERASE_BLOCK_SIZE)
!= 0) {
return -EIO;
Expand All @@ -171,9 +169,6 @@ static int update_flash_block(off_t start_addr, uint32_t size, const void *buff)
CONFIG_DISK_FLASH_MAX_RW_SIZE);

for (uint32_t i = 0; i < num_write; i++) {
/* flash_write reenabled write-protection so disable it again */
flash_write_protection_set(flash_dev, false);

if (flash_write(flash_dev, fl_addr, src,
CONFIG_DISK_FLASH_MAX_RW_SIZE) != 0) {
return -EIO;
Expand Down
10 changes: 0 additions & 10 deletions drivers/eeprom/eeprom_emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,8 @@ static inline int eeprom_emu_flash_write(const struct device *dev, off_t offset,
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
int rc;

if (flash_write_protection_set(dev_config->flash_dev, false)) {
return -EIO;
}

rc = flash_write(dev_config->flash_dev, dev_config->flash_offset +
offset, blk, len);
(void)flash_write_protection_set(dev_config->flash_dev, true);
return rc;
}

Expand All @@ -147,13 +142,8 @@ static inline int eeprom_emu_flash_erase(const struct device *dev, off_t offset,
const struct eeprom_emu_config *dev_config = DEV_CONFIG(dev);
int rc;

if (flash_write_protection_set(dev_config->flash_dev, false)) {
return -EIO;
}

rc = flash_erase(dev_config->flash_dev, dev_config->flash_offset +
offset, len);
(void)flash_write_protection_set(dev_config->flash_dev, true);
return rc;
}

Expand Down
6 changes: 0 additions & 6 deletions drivers/flash/Kconfig.simulator
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ config FLASH_SIMULATOR_DOUBLE_WRITES
If selected, writing to a non-erased program unit will succeed, otherwise, it will return an error.
Keep in mind that write operations can only pull bits to zero, regardless.

config FLASH_SIMULATOR_ERASE_PROTECT
bool "Enable erase protection on write protection"
default y
help
If selected, turning on write protection will also prevent erasing.

config FLASH_SIMULATOR_SIMULATE_TIMING
bool "Enable hardware timing simulation"

Expand Down
6 changes: 0 additions & 6 deletions drivers/flash/flash_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,6 @@ static int flash_esp32_erase(const struct device *dev, off_t start, size_t len)
return rc;
}

static int flash_esp32_write_protection(const struct device *dev, bool enable)
{
return 0;
}

#if CONFIG_FLASH_PAGE_LAYOUT
static const struct flash_pages_layout flash_esp32_pages_layout = {
.pages_count = DT_REG_SIZE(SOC_NV_FLASH_NODE) / FLASH_ERASE_BLK_SZ,
Expand Down Expand Up @@ -601,7 +596,6 @@ static const struct flash_driver_api flash_esp32_driver_api = {
.read = flash_esp32_read,
.write = flash_esp32_write,
.erase = flash_esp32_erase,
.write_protection = flash_esp32_write_protection,
.get_parameters = flash_esp32_get_parameters,
#ifdef CONFIG_FLASH_PAGE_LAYOUT
.page_layout = flash_esp32_page_layout,
Expand Down
16 changes: 6 additions & 10 deletions drivers/flash/flash_gecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static const struct flash_parameters flash_gecko_parameters = {
static bool write_range_is_valid(off_t offset, uint32_t size);
static bool read_range_is_valid(off_t offset, uint32_t size);
static int erase_flash_block(off_t offset, size_t size);
static void flash_gecko_write_protection(bool enable);

static int flash_gecko_read(const struct device *dev, off_t offset,
void *data,
Expand Down Expand Up @@ -72,13 +73,15 @@ static int flash_gecko_write(const struct device *dev, off_t offset,
}

k_sem_take(&dev_data->mutex, K_FOREVER);
flash_gecko_write_protection(false);

address = (uint8_t *)CONFIG_FLASH_BASE_ADDRESS + offset;
msc_ret = MSC_WriteWord(address, data, size);
if (msc_ret < 0) {
ret = -EIO;
}

flash_gecko_write_protection(true);
k_sem_give(&dev_data->mutex);

return ret;
Expand Down Expand Up @@ -109,20 +112,18 @@ static int flash_gecko_erase(const struct device *dev, off_t offset,
}

k_sem_take(&dev_data->mutex, K_FOREVER);
flash_gecko_write_protection(false);

ret = erase_flash_block(offset, size);

flash_gecko_write_protection(true);
k_sem_give(&dev_data->mutex);

return ret;
}

static int flash_gecko_write_protection(const struct device *dev, bool enable)
static void flash_gecko_write_protection(bool enable)
{
struct flash_gecko_data *const dev_data = DEV_DATA(dev);

k_sem_take(&dev_data->mutex, K_FOREVER);

if (enable) {
/* Lock the MSC module. */
MSC->LOCK = 0;
Expand All @@ -134,10 +135,6 @@ static int flash_gecko_write_protection(const struct device *dev, bool enable)
MSC->LOCK = MSC_UNLOCK_CODE;
#endif
}

k_sem_give(&dev_data->mutex);

return 0;
}

/* Note:
Expand Down Expand Up @@ -218,7 +215,6 @@ static const struct flash_driver_api flash_gecko_driver_api = {
.read = flash_gecko_read,
.write = flash_gecko_write,
.erase = flash_gecko_erase,
.write_protection = flash_gecko_write_protection,
.get_parameters = flash_gecko_get_parameters,
#ifdef CONFIG_FLASH_PAGE_LAYOUT
.page_layout = flash_gecko_page_layout,
Expand Down
7 changes: 0 additions & 7 deletions drivers/flash/flash_mcux_flexspi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,6 @@ static int flash_flexspi_nor_erase(const struct device *dev, off_t offset,
return 0;
}

static int flash_flexspi_nor_write_protection(const struct device *dev,
bool enable)
{
return 0;
}

static const struct flash_parameters *flash_flexspi_nor_get_parameters(
const struct device *dev)
{
Expand Down Expand Up @@ -433,7 +427,6 @@ static int flash_flexspi_nor_init(const struct device *dev)
}

static const struct flash_driver_api flash_flexspi_nor_api = {
.write_protection = flash_flexspi_nor_write_protection,
.erase = flash_flexspi_nor_erase,
.write = flash_flexspi_nor_write,
.read = flash_flexspi_nor_read,
Expand Down
62 changes: 37 additions & 25 deletions drivers/flash/flash_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static const struct flash_parameters flash_sam_parameters = {
#define DEV_DATA(dev) \
((struct flash_sam_dev_data *const)(dev)->data)

static int flash_sam_write_protection(const struct device *dev, bool enable);

static inline void flash_sam_sem_take(const struct device *dev)
{
Expand Down Expand Up @@ -187,29 +188,36 @@ static int flash_sam_write(const struct device *dev, off_t offset,

flash_sam_sem_take(dev);

rc = flash_sam_wait_ready(dev);
if (rc < 0) {
return rc;
rc = flash_sam_write_protection(dev, false);
if (rc >= 0) {
rc = flash_sam_wait_ready(dev);
}

while (len > 0) {
size_t eop_len, write_len;
if (rc >= 0) {
while (len > 0) {
size_t eop_len, write_len;

/* Maximum size without crossing a page */
eop_len = -(offset | ~(IFLASH_PAGE_SIZE - 1));
write_len = MIN(len, eop_len);
/* Maximum size without crossing a page */
eop_len = -(offset | ~(IFLASH_PAGE_SIZE - 1));
write_len = MIN(len, eop_len);

rc = flash_sam_write_page(dev, offset, data8, write_len);
if (rc < 0) {
goto done;
rc = flash_sam_write_page(dev, offset, data8, write_len);
if (rc < 0) {
break;
}

offset += write_len;
data8 += write_len;
len -= write_len;
}
}

int rc2 = flash_sam_write_protection(dev, true);

offset += write_len;
data8 += write_len;
len -= write_len;
if (!rc) {
rc = rc2;
}

done:
flash_sam_sem_give(dev);

return rc;
Expand Down Expand Up @@ -274,15 +282,23 @@ static int flash_sam_erase(const struct device *dev, off_t offset, size_t len)

flash_sam_sem_take(dev);

/* Loop through the pages to erase */
for (i = offset; i < offset + len; i += FLASH_ERASE_BLK_SZ) {
rc = flash_sam_erase_block(dev, i);
if (rc < 0) {
goto done;
rc = flash_sam_write_protection(dev, false);
if (rc >= 0) {
/* Loop through the pages to erase */
for (i = offset; i < offset + len; i += FLASH_ERASE_BLK_SZ) {
rc = flash_sam_erase_block(dev, i);
if (rc < 0) {
break;
}
}
}

done:
int rc2 = flash_sam_write_protection(dev, true);

if (!rc) {
rc = rc2;
}

flash_sam_sem_give(dev);

/*
Expand All @@ -300,8 +316,6 @@ static int flash_sam_write_protection(const struct device *dev, bool enable)
Efc *const efc = DEV_CFG(dev)->regs;
int rc = 0;

flash_sam_sem_take(dev);

if (enable) {
rc = flash_sam_wait_ready(dev);
if (rc < 0) {
Expand All @@ -313,7 +327,6 @@ static int flash_sam_write_protection(const struct device *dev, bool enable)
}

done:
flash_sam_sem_give(dev);
return rc;
}

Expand Down Expand Up @@ -354,7 +367,6 @@ static int flash_sam_init(const struct device *dev)
}

static const struct flash_driver_api flash_sam_api = {
.write_protection = flash_sam_write_protection,
.erase = flash_sam_erase,
.write = flash_sam_write,
.read = flash_sam_read,
Expand Down
Loading