]> granicus.if.org Git - esp-idf/commitdiff
spiffs: add Kconfig option for logical page size
authorIvan Grokhotkov <ivan@espressif.com>
Sun, 28 Jan 2018 15:17:54 +0000 (23:17 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 31 Jan 2018 03:14:56 +0000 (11:14 +0800)
components/spiffs/Kconfig
components/spiffs/esp_spiffs.c

index 1f7a196d729bbe11a55e1dfcf80ee1e6e15417bf..4eeb18762b789a75cfdae590cf8959e655184f0a 100644 (file)
@@ -59,6 +59,18 @@ config SPIFFS_GC_STATS
         Enable/disable statistics on gc. 
         Debug/test purpose only.
 
+config SPIFFS_PAGE_SIZE
+       int "SPIFFS logical page size"
+       default 256
+       range 256 1024
+       help
+               Logical page size of SPIFFS partition, in bytes. Must be multiple
+               of flash page size (which is usually 256 bytes).
+               Larger page sizes reduce overhead when storing large files, and
+               improve filesystem performance when reading large files.
+               Smaller page sizes reduce overhead when storing small (< page size)
+               files.
+
 config SPIFFS_OBJ_NAME_LEN
     int "Set SPIFFS Maximum Name Length"
     default 32
index 2c454e9dd35833b6ba335f2536619c721e89f833..83eba96ee42804e0c7964e102a1806dfe334d07f 100644 (file)
@@ -222,6 +222,14 @@ static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf)
         return ESP_ERR_INVALID_STATE;
     }
 
+    uint32_t flash_page_size = g_rom_flashchip.page_size;
+    uint32_t log_page_size = CONFIG_SPIFFS_PAGE_SIZE;
+    if (log_page_size % flash_page_size != 0) {
+        ESP_LOGE(TAG, "SPIFFS_PAGE_SIZE is not multiple of flash chip page size (%d)",
+                flash_page_size);
+        return ESP_ERR_INVALID_ARG;
+    }
+
     esp_partition_subtype_t subtype = conf->partition_label ?
             ESP_PARTITION_SUBTYPE_ANY : ESP_PARTITION_SUBTYPE_DATA_SPIFFS;
     const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, 
@@ -247,7 +255,7 @@ static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf)
     efs->cfg.hal_read_f        = spiffs_api_read;
     efs->cfg.hal_write_f       = spiffs_api_write;
     efs->cfg.log_block_size    = g_rom_flashchip.sector_size;
-    efs->cfg.log_page_size     = g_rom_flashchip.page_size;
+    efs->cfg.log_page_size     = log_page_size;
     efs->cfg.phys_addr         = 0;
     efs->cfg.phys_erase_block  = g_rom_flashchip.sector_size;
     efs->cfg.phys_size         = partition->size;