From c5cc990cb32e7b3da7b1874e49a30f95ccf385a8 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Wed, 17 Mar 2021 11:25:37 +0100 Subject: [PATCH] samples/tree-wide: remove flash_write_protection_set() usage This patch removes scenario which was testing deprecated API behaviors. Needed as As flash_write_protection_set() was deprecated and became no-operation. Signed-off-by: Andrzej Puzdrowski --- samples/arch/mpu/mpu_test/src/main.c | 8 ---- samples/drivers/flash_shell/src/main.c | 51 +++--------------------- samples/drivers/soc_flash_nrf/src/main.c | 5 --- samples/drivers/spi_flash/src/main.c | 2 - 4 files changed, 6 insertions(+), 60 deletions(-) diff --git a/samples/arch/mpu/mpu_test/src/main.c b/samples/arch/mpu/mpu_test/src/main.c index 02be7bb6f64..292c297a03f 100644 --- a/samples/arch/mpu/mpu_test/src/main.c +++ b/samples/arch/mpu/mpu_test/src/main.c @@ -60,16 +60,12 @@ static int cmd_write_mcux(const struct shell *shell, size_t argc, char *argv[]) PR_SHELL(shell, "write address: 0x%x\n", offset); - flash_write_protection_set(flash_dev, false); - if (flash_write(flash_dev, offset, value, sizeof(value)) != 0) { PR_ERROR(shell, "Flash write failed!\n"); return 1; } - flash_write_protection_set(flash_dev, true); - return 0; } @@ -90,15 +86,11 @@ static int cmd_write_stm32(const struct shell *shell, size_t argc, char *argv[]) PR_SHELL(shell, "write address: 0x%x\n", offset); - flash_write_protection_set(flash_dev, false); - if (flash_write(flash_dev, offset, &value, sizeof(value)) != 0) { PR_ERROR(shell, "Flash write failed!\n"); return 1; } - flash_write_protection_set(flash_dev, true); - return 0; } #else diff --git a/samples/drivers/flash_shell/src/main.c b/samples/drivers/flash_shell/src/main.c index 07ebe4987c6..8e01958b2e8 100644 --- a/samples/drivers/flash_shell/src/main.c +++ b/samples/drivers/flash_shell/src/main.c @@ -193,53 +193,32 @@ static int do_read(const struct shell *shell, off_t offset, size_t len) return ret; } -/* Erase area, handling write protection and printing on error. */ +/* Erase area and printing on error. */ static int do_erase(const struct shell *shell, off_t offset, size_t size) { int ret; - ret = flash_write_protection_set(flash_device, false); - if (ret) { - PR_ERROR(shell, "Failed to disable flash protection (err: %d)." - "\n", ret); - return ret; - } ret = flash_erase(flash_device, offset, size); if (ret) { PR_ERROR(shell, "flash_erase failed (err:%d).\n", ret); return ret; } - ret = flash_write_protection_set(flash_device, true); - if (ret) { - PR_ERROR(shell, "Failed to enable flash protection (err: %d)." - "\n", ret); - } + return ret; } -/* Write bytes, handling write protection and printing on error. */ +/* Write bytes and printing on error. */ static int do_write(const struct shell *shell, off_t offset, uint8_t *buf, size_t len, bool read_back) { int ret; - ret = flash_write_protection_set(flash_device, false); - if (ret) { - PR_ERROR(shell, "Failed to disable flash protection (err: %d)." - "\n", ret); - return ret; - } ret = flash_write(flash_device, offset, buf, len); if (ret) { PR_ERROR(shell, "flash_write failed (err:%d).\n", ret); return ret; } - ret = flash_write_protection_set(flash_device, true); - if (ret) { - PR_ERROR(shell, "Failed to enable flash protection (err: %d)." - "\n", ret); - return ret; - } + if (read_back) { PR_SHELL(shell, "Reading back written bytes:\n"); ret = do_read(shell, offset, len); @@ -262,23 +241,12 @@ static int do_write_unaligned(const struct shell *shell, off_t offset, uint8_t * char *before_data; char *after_data; - ret = flash_write_protection_set(flash_device, false); - if (ret) { - PR_ERROR(shell, "Failed to disable flash protection (err: %d)." - "\n", ret); - return ret; - } - if (0 == size_before && 0 == size_after) { /* Aligned write */ flash_erase(flash_device, offset, len); flash_write(flash_device, offset, buf, len); - ret = flash_write_protection_set(flash_device, true); - if (ret) { - PR_ERROR(shell, "Failed to enable flash protection (err: %d)." - "\n", ret); - } - return ret; + + return 0; } before_data = k_malloc(page_size); @@ -371,13 +339,6 @@ free_buffers: k_free(before_data); k_free(after_data); - int ret1 = flash_write_protection_set(flash_device, true); - if (ret1) { - PR_ERROR(shell, "Failed to enable flash protection (err: %d)." - "\n", ret1); - return ret1; - } - return ret; } diff --git a/samples/drivers/soc_flash_nrf/src/main.c b/samples/drivers/soc_flash_nrf/src/main.c index 01e6d870656..8668707f616 100644 --- a/samples/drivers/soc_flash_nrf/src/main.c +++ b/samples/drivers/soc_flash_nrf/src/main.c @@ -53,7 +53,6 @@ void main(void) } printf("\nTest 1: Flash erase page at 0x%x\n", FLASH_TEST_OFFSET); - flash_write_protection_set(flash_dev, false); if (flash_erase(flash_dev, FLASH_TEST_OFFSET, FLASH_PAGE_SIZE) != 0) { printf(" Flash erase failed!\n"); } else { @@ -61,7 +60,6 @@ void main(void) } printf("\nTest 2: Flash write (word array 1)\n"); - flash_write_protection_set(flash_dev, false); for (i = 0U; i < ARRAY_SIZE(buf_array_1); i++) { offset = FLASH_TEST_OFFSET + (i << 2); printf(" Attempted to write %x at 0x%x\n", buf_array_1[i], @@ -94,7 +92,6 @@ void main(void) } printf("\nTest 4: Flash write (word array 2)\n"); - flash_write_protection_set(flash_dev, false); for (i = 0U; i < ARRAY_SIZE(buf_array_2); i++) { offset = FLASH_TEST_OFFSET + (i << 2); printf(" Attempted to write %x at 0x%x\n", buf_array_2[i], @@ -126,7 +123,6 @@ void main(void) } printf("\nTest 6: Non-word aligned write (word array 3)\n"); - flash_write_protection_set(flash_dev, false); for (i = 0U; i < ARRAY_SIZE(buf_array_3); i++) { offset = FLASH_TEST_OFFSET + (i << 2) + 1; printf(" Attempted to write %x at 0x%x\n", buf_array_3[i], @@ -149,7 +145,6 @@ void main(void) printf(" Data read does not match data written!\n"); } } - flash_write_protection_set(flash_dev, true); #if defined(CONFIG_FLASH_PAGE_LAYOUT) struct flash_pages_info info; diff --git a/samples/drivers/spi_flash/src/main.c b/samples/drivers/spi_flash/src/main.c index cf6c81dfd57..c6477ec95a6 100644 --- a/samples/drivers/spi_flash/src/main.c +++ b/samples/drivers/spi_flash/src/main.c @@ -63,7 +63,6 @@ void main(void) * operations. */ printf("\nTest 1: Flash erase\n"); - flash_write_protection_set(flash_dev, false); rc = flash_erase(flash_dev, FLASH_TEST_REGION_OFFSET, FLASH_SECTOR_SIZE); @@ -74,7 +73,6 @@ void main(void) } printf("\nTest 2: Flash write\n"); - flash_write_protection_set(flash_dev, false); printf("Attempting to write %u bytes\n", len); rc = flash_write(flash_dev, FLASH_TEST_REGION_OFFSET, expected, len);