From f398b7923aeb5d4791022fde08e808b4a00698b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rohl=C3=ADnek?= Date: Wed, 10 Apr 2024 10:51:12 +0200 Subject: [PATCH 1/3] fix(storage/fatfs): fix double mouting of spiflash --- components/fatfs/vfs/vfs_fat_spiflash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/fatfs/vfs/vfs_fat_spiflash.c b/components/fatfs/vfs/vfs_fat_spiflash.c index 1ca18938bb..2057f194cf 100644 --- a/components/fatfs/vfs/vfs_fat_spiflash.c +++ b/components/fatfs/vfs/vfs_fat_spiflash.c @@ -242,7 +242,8 @@ esp_err_t esp_vfs_fat_spiflash_format_cfg_rw_wl(const char* base_path, const cha assert(found); if (s_ctx[id]->flags & FORMATTED_DURING_LAST_MOUNT) { ESP_LOGD(TAG, "partition was formatted during mounting, skipping another format"); - return ESP_OK; + ret = ESP_OK; + goto mount_back; } } else { partition_was_mounted = true; From 7c3b9bde0e4cda8710f96775b29a988937159716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rohl=C3=ADnek?= Date: Wed, 10 Apr 2024 11:21:11 +0200 Subject: [PATCH 2/3] feat(storage/fatfs): add testcase with erased spi partition --- .../fatfs/test_apps/flash_wl/main/Kconfig.projbuild | 12 ++++++++++++ .../test_apps/flash_wl/main/test_fatfs_flash_wl.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild diff --git a/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild b/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild new file mode 100644 index 0000000000..6c524b877b --- /dev/null +++ b/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild @@ -0,0 +1,12 @@ +menu "Test configuration" + config SPI_WL_TEST_ERASE_PARTITION + bool "Erase partition" + if IDF_TARGET_LINUX + default y + default n + help + Erase the partition before each format operation. + This will destroy the flash fairly quickly in CI, but is necessary to + ensure that the test is not affected by previous test runs. + Run with caution. +endmenu diff --git a/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c b/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c index 66c9f6930d..2cd2c88ba8 100644 --- a/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c +++ b/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c @@ -46,8 +46,18 @@ static void test_teardown(void) TEST_ESP_OK(esp_vfs_fat_spiflash_unmount_rw_wl("/spiflash", s_test_wl_handle)); } +static void corrupt_wl_data(void) +{ + esp_partition_t* part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + TEST_ASSERT_NOT_NULL(part); + TEST_ESP_OK(esp_partition_erase_range(part, 0, part->size)); +} + TEST_CASE("(WL) can format partition", "[fatfs][wear_levelling][timeout=120]") { +#ifdef CONFIG_SPI_WL_TEST_ERASE_PARTITION + corrupt_wl_data(); +#endif TEST_ESP_OK(esp_vfs_fat_spiflash_format_rw_wl("/spiflash", NULL)); test_setup(); vfs_fat_spiflash_ctx_t* ctx = get_vfs_fat_spiflash_ctx(s_test_wl_handle); @@ -58,6 +68,9 @@ TEST_CASE("(WL) can format partition", "[fatfs][wear_levelling][timeout=120]") TEST_CASE("(WL) can format partition with config", "[fatfs][wear_levelling][timeout=120]") { +#ifdef CONFIG_SPI_WL_TEST_ERASE_PARTITION + corrupt_wl_data(); +#endif esp_vfs_fat_mount_config_t format_config = { .format_if_mount_failed = true, .max_files = 5, From 615a9c674273b2a854a55431b7618859b674b06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rohl=C3=ADnek?= Date: Wed, 10 Apr 2024 12:57:07 +0200 Subject: [PATCH 3/3] feat(storage/example): enable host test for flash wl fatfs --- components/fatfs/test_apps/.build-test-rules.yml | 2 +- components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild | 4 +--- .../fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/fatfs/test_apps/.build-test-rules.yml b/components/fatfs/test_apps/.build-test-rules.yml index 88e45eb621..25c58d1f47 100644 --- a/components/fatfs/test_apps/.build-test-rules.yml +++ b/components/fatfs/test_apps/.build-test-rules.yml @@ -13,7 +13,7 @@ components/fatfs/test_apps/flash_ro: components/fatfs/test_apps/flash_wl: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3"] + - if: IDF_TARGET not in ["esp32", "esp32c3", "linux"] reason: only one target per arch needed depends_components: - esp_partition diff --git a/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild b/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild index 6c524b877b..c729251312 100644 --- a/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild +++ b/components/fatfs/test_apps/flash_wl/main/Kconfig.projbuild @@ -1,9 +1,7 @@ menu "Test configuration" config SPI_WL_TEST_ERASE_PARTITION bool "Erase partition" - if IDF_TARGET_LINUX - default y - default n + default y if IDF_TARGET_LINUX help Erase the partition before each format operation. This will destroy the flash fairly quickly in CI, but is necessary to diff --git a/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c b/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c index 2cd2c88ba8..f193839e14 100644 --- a/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c +++ b/components/fatfs/test_apps/flash_wl/main/test_fatfs_flash_wl.c @@ -46,12 +46,14 @@ static void test_teardown(void) TEST_ESP_OK(esp_vfs_fat_spiflash_unmount_rw_wl("/spiflash", s_test_wl_handle)); } +#ifdef CONFIG_SPI_WL_TEST_ERASE_PARTITION static void corrupt_wl_data(void) { - esp_partition_t* part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + const esp_partition_t* part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); TEST_ASSERT_NOT_NULL(part); TEST_ESP_OK(esp_partition_erase_range(part, 0, part->size)); } +#endif TEST_CASE("(WL) can format partition", "[fatfs][wear_levelling][timeout=120]") {