diff --git a/components/bootloader_support/src/flash_partitions.c b/components/bootloader_support/src/flash_partitions.c index 51359ea6..1f4487ef 100644 --- a/components/bootloader_support/src/flash_partitions.c +++ b/components/bootloader_support/src/flash_partitions.c @@ -109,7 +109,7 @@ esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition { int md5_found = 0; int num_parts; - uint32_t chip_size = flashchip.chip_size; + uint32_t chip_size = g_rom_flashchip.chip_size; *num_partitions = 0; for (num_parts = 0; num_parts < ESP_PARTITION_TABLE_MAX_ENTRIES; num_parts++) { diff --git a/components/esp8266/include/esp8266/rom_functions.h b/components/esp8266/include/esp8266/rom_functions.h index 246622a8..cabdb2eb 100644 --- a/components/esp8266/include/esp8266/rom_functions.h +++ b/components/esp8266/include/esp8266/rom_functions.h @@ -6,16 +6,16 @@ #define ROM_FLASH_BUF_DECLARE(__name, __size) uint8_t __name[__size] __attribute__((aligned(4))) -typedef struct esp_spi_flash_chip { - uint32_t deviceId; - uint32_t chip_size; // chip size in byte - uint32_t block_size; - uint32_t sector_size; - uint32_t page_size; - uint32_t status_mask; -} esp_spi_flash_chip_t; +typedef struct { + uint32_t device_id; + uint32_t chip_size; // chip size in bytes + uint32_t block_size; + uint32_t sector_size; + uint32_t page_size; + uint32_t status_mask; +} esp_rom_spiflash_chip_t; -extern esp_spi_flash_chip_t flashchip; +extern esp_rom_spiflash_chip_t g_rom_flashchip; uint32_t Wait_SPI_Idle(); @@ -27,13 +27,13 @@ void system_soft_wdt_feed(); void Cache_Read_Enable_New(); -int SPI_page_program(esp_spi_flash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len); -int SPI_read_data(esp_spi_flash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len); -int SPI_write_enable(esp_spi_flash_chip_t *chip); -int SPI_sector_erase(esp_spi_flash_chip_t *chip, uint32_t sect_addr); -int SPI_write_status(esp_spi_flash_chip_t *chip, uint32_t status); -int SPI_read_status(esp_spi_flash_chip_t *chip, uint32_t *status); -int Enable_QMode(esp_spi_flash_chip_t *chip); +int SPI_page_program(esp_rom_spiflash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len); +int SPI_read_data(esp_rom_spiflash_chip_t *chip, uint32_t dst_addr, void *pbuf, uint32_t len); +int SPI_write_enable(esp_rom_spiflash_chip_t *chip); +int SPI_sector_erase(esp_rom_spiflash_chip_t *chip, uint32_t sect_addr); +int SPI_write_status(esp_rom_spiflash_chip_t *chip, uint32_t status); +int SPI_read_status(esp_rom_spiflash_chip_t *chip, uint32_t *status); +int Enable_QMode(esp_rom_spiflash_chip_t *chip); int SPIWrite(uint32_t addr, const uint8_t *src, uint32_t size); int SPIRead(uint32_t addr, void *dst, uint32_t size); diff --git a/components/esp8266/include/esp_libc.h b/components/esp8266/include/esp_libc.h index e9e01828..d77ea28a 100644 --- a/components/esp8266/include/esp_libc.h +++ b/components/esp8266/include/esp_libc.h @@ -29,6 +29,7 @@ #include #include #include +#include "rom/ets_sys.h" #ifndef BOOTLOADER_BUILD #include "esp_heap_caps.h" #endif @@ -60,18 +61,6 @@ int ets_putc(int c); */ int ets_vprintf(const char *fmt, va_list ap); -/** - * @brief Printf the strings to uart or other devices, similar with printf, simple than printf. - * Can not print float point data format, or longlong data format. - * - * @param const char *fmt : See printf. - * - * @param ... : See printf. - * - * @return int : the length printed to the output device. - */ -int ets_printf(const char *fmt, ...); - #ifndef os_printf #define os_printf printf #endif diff --git a/components/esp8266/include/rom/ets_sys.h b/components/esp8266/include/rom/ets_sys.h index b5e37330..d9057d0a 100644 --- a/components/esp8266/include/rom/ets_sys.h +++ b/components/esp8266/include/rom/ets_sys.h @@ -109,6 +109,18 @@ void os_delay_us(uint16_t us); */ void ets_delay_us(uint32_t us); +/** + * @brief Printf the strings to uart or other devices, similar with printf, simple than printf. + * Can not print float point data format, or longlong data format. + * + * @param const char *fmt : See printf. + * + * @param ... : See printf. + * + * @return int : the length printed to the output device. + */ +int ets_printf(const char *fmt, ...); + /** * @brief Register the print output function. * diff --git a/components/esp8266/include/rom/spi_flash.h b/components/esp8266/include/rom/spi_flash.h new file mode 100644 index 00000000..c3d0d100 --- /dev/null +++ b/components/esp8266/include/rom/spi_flash.h @@ -0,0 +1,25 @@ +// Copyright 2010-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _ROM_SPI_FLASH_H_ +#define _ROM_SPI_FLASH_H_ + +#include +#include + +#include "esp_attr.h" + +#include "esp8266/rom_functions.h" + +#endif /* _ROM_SPI_FLASH_H_ */ diff --git a/components/spi_flash/include/priv/esp_spi_flash_raw.h b/components/spi_flash/include/priv/esp_spi_flash_raw.h index c3c6931b..57b7e39c 100644 --- a/components/spi_flash/include/priv/esp_spi_flash_raw.h +++ b/components/spi_flash/include/priv/esp_spi_flash_raw.h @@ -48,21 +48,21 @@ typedef struct { uint8_t dummy_bits; } spi_cmd_t; -bool spi_user_cmd_raw(esp_spi_flash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd); +bool spi_user_cmd_raw(esp_rom_spiflash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd); -uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip); +uint32_t spi_flash_get_id_raw(esp_rom_spiflash_chip_t *chip); -esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip); +esp_err_t spi_flash_enable_qmode_raw(esp_rom_spiflash_chip_t *chip); -esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status); +esp_err_t spi_flash_read_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t *status); -esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status_value); +esp_err_t spi_flash_write_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t status_value); -esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void *dest, size_t size); +esp_err_t spi_flash_read_raw(esp_rom_spiflash_chip_t *chip, size_t src_addr, void *dest, size_t size); -esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, const void *src, size_t size); +esp_err_t spi_flash_write_raw(esp_rom_spiflash_chip_t *chip, size_t dest_addr, const void *src, size_t size); -esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, size_t sec_size); +esp_err_t spi_flash_erase_sector_raw(esp_rom_spiflash_chip_t *chip, size_t sec, size_t sec_size); void spi_flash_switch_to_qio_raw(void); diff --git a/components/spi_flash/port/port.c b/components/spi_flash/port/port.c index e683e1fd..527e60c6 100644 --- a/components/spi_flash/port/port.c +++ b/components/spi_flash/port/port.c @@ -69,7 +69,7 @@ static uint32_t s_v2_flash_bin_size; static uint32_t s_v2_flash_size; static sys_param_t s_sys_param; static boot_param_t s_boot_param; -static esp_spi_flash_chip_t s_flash_chip = { +static esp_rom_spiflash_chip_t s_flash_chip = { 0x1640ef, CONFIG_SPI_FLASH_SIZE, 64 * 1024, diff --git a/components/spi_flash/src/spi_flash.c b/components/spi_flash/src/spi_flash.c index 468b5376..f4c622df 100644 --- a/components/spi_flash/src/spi_flash.c +++ b/components/spi_flash/src/spi_flash.c @@ -64,7 +64,7 @@ extern void vPortEnterCritical(void); extern void vPortExitCritical(void); -esp_spi_flash_chip_t flashchip = { +esp_rom_spiflash_chip_t g_rom_flashchip = { 0x1640ef, CONFIG_SPI_FLASH_SIZE, 64 * 1024, @@ -89,7 +89,7 @@ bool spi_user_cmd(spi_cmd_dir_t mode, spi_cmd_t *p_cmd) FLASH_INTR_LOCK(c_tmp); FlashIsOnGoing = 1; - ret = spi_user_cmd_raw(&flashchip, mode, p_cmd); + ret = spi_user_cmd_raw(&g_rom_flashchip, mode, p_cmd); FlashIsOnGoing = 0; FLASH_INTR_UNLOCK(c_tmp); @@ -174,7 +174,7 @@ uint32_t spi_flash_get_id(void) FlashIsOnGoing = 1; - rdid = spi_flash_get_id_raw(&flashchip); + rdid = spi_flash_get_id_raw(&g_rom_flashchip); FlashIsOnGoing = 0; @@ -192,7 +192,7 @@ esp_err_t spi_flash_read_status(uint32_t *status) FlashIsOnGoing = 1; - ret = spi_flash_read_status_raw(&flashchip, status); + ret = spi_flash_read_status_raw(&g_rom_flashchip, status); FlashIsOnGoing = 0; @@ -209,7 +209,7 @@ esp_err_t spi_flash_write_status(uint32_t status_value) FlashIsOnGoing = 1; - spi_flash_write_status_raw(&flashchip, status_value); + spi_flash_write_status_raw(&g_rom_flashchip, status_value); FlashIsOnGoing = 0; @@ -436,7 +436,7 @@ void user_spi_flash_dio_to_qio_pre_init(void) } //ENBALE FLASH QIO 0X01H+0X00+0X02 } else { - if (spi_flash_enable_qmode_raw(&flashchip) == ESP_OK) { + if (spi_flash_enable_qmode_raw(&g_rom_flashchip) == ESP_OK) { to_qio = true; } } @@ -452,7 +452,7 @@ esp_err_t spi_flash_erase_sector(size_t sec) esp_err_t ret; - if (sec >= (flashchip.chip_size / flashchip.sector_size)) { + if (sec >= (g_rom_flashchip.chip_size / g_rom_flashchip.sector_size)) { return ESP_ERR_FLASH_OP_FAIL; } @@ -463,7 +463,7 @@ esp_err_t spi_flash_erase_sector(size_t sec) FLASH_INTR_LOCK(c_tmp); FlashIsOnGoing = 1; - ret = spi_flash_erase_sector_raw(&flashchip, sec, flashchip.sector_size); + ret = spi_flash_erase_sector_raw(&g_rom_flashchip, sec, g_rom_flashchip.sector_size); FlashIsOnGoing = 0; FLASH_INTR_UNLOCK(c_tmp); @@ -477,15 +477,15 @@ static esp_err_t spi_flash_program(uint32_t target, uint32_t *src_addr, size_t l uint32_t pgm_len, pgm_num; uint8_t i; - page_size = flashchip.page_size; + page_size = g_rom_flashchip.page_size; pgm_len = page_size - (target % page_size); if (len < pgm_len) { - if (ESP_OK != spi_flash_write_raw(&flashchip, target, src_addr, len)) { + if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target, src_addr, len)) { return ESP_ERR_FLASH_OP_FAIL; } } else { - if (ESP_OK != spi_flash_write_raw(&flashchip, target, src_addr, pgm_len)) { + if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target, src_addr, pgm_len)) { return ESP_ERR_FLASH_OP_FAIL; } @@ -493,7 +493,7 @@ static esp_err_t spi_flash_program(uint32_t target, uint32_t *src_addr, size_t l pgm_num = (len - pgm_len) / page_size; for (i = 0; i < pgm_num; i++) { - if (ESP_OK != spi_flash_write_raw(&flashchip, target + pgm_len, src_addr + (pgm_len >> 2), page_size)) { + if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target + pgm_len, src_addr + (pgm_len >> 2), page_size)) { return ESP_ERR_FLASH_OP_FAIL; } @@ -501,7 +501,7 @@ static esp_err_t spi_flash_program(uint32_t target, uint32_t *src_addr, size_t l } //remain parts to program - if (ESP_OK != spi_flash_write_raw(&flashchip, target + pgm_len, src_addr + (pgm_len >> 2), len - pgm_len)) { + if (ESP_OK != spi_flash_write_raw(&g_rom_flashchip, target + pgm_len, src_addr + (pgm_len >> 2), len - pgm_len)) { return ESP_ERR_FLASH_OP_FAIL; } } @@ -556,7 +556,7 @@ esp_err_t spi_flash_write(size_t dest_addr, const void *src, size_t size) return ESP_ERR_FLASH_OP_FAIL; } - if ((dest_addr + size) > flashchip.chip_size) { + if ((dest_addr + size) > g_rom_flashchip.chip_size) { return ESP_ERR_FLASH_OP_FAIL; } @@ -619,7 +619,7 @@ static esp_err_t __spi_flash_read(size_t src_addr, void *dest, size_t size) FLASH_INTR_LOCK(c_tmp); FlashIsOnGoing = 1; - ret = spi_flash_read_raw(&flashchip, src_addr, dest, size); + ret = spi_flash_read_raw(&g_rom_flashchip, src_addr, dest, size); FlashIsOnGoing = 0; FLASH_INTR_UNLOCK(c_tmp); @@ -779,5 +779,5 @@ uintptr_t spi_flash_cache2phys(const void *cached) size_t spi_flash_get_chip_size() { - return flashchip.chip_size; + return g_rom_flashchip.chip_size; } diff --git a/components/spi_flash/src/spi_flash_raw.c b/components/spi_flash/src/spi_flash_raw.c index 9fc3afca..dee89962 100644 --- a/components/spi_flash/src/spi_flash_raw.c +++ b/components/spi_flash/src/spi_flash_raw.c @@ -35,7 +35,7 @@ void Cache_Read_Enable_2() } void Cache_Read_Enable_New(void) __attribute__((alias("Cache_Read_Enable_2"))); -uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip) +uint32_t spi_flash_get_id_raw(esp_rom_spiflash_chip_t *chip) { uint32_t rdid = 0; @@ -54,7 +54,7 @@ uint32_t spi_flash_get_id_raw(esp_spi_flash_chip_t *chip) return rdid; } -esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status) +esp_err_t spi_flash_read_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t *status) { esp_err_t ret; @@ -67,7 +67,7 @@ esp_err_t spi_flash_read_status_raw(esp_spi_flash_chip_t *chip, uint32_t *status return ret; } -esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status_value) +esp_err_t spi_flash_write_status_raw(esp_rom_spiflash_chip_t *chip, uint32_t status_value) { Cache_Read_Disable_2(); @@ -86,7 +86,7 @@ esp_err_t spi_flash_write_status_raw(esp_spi_flash_chip_t *chip, uint32_t status return ESP_OK; } -esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, size_t sec_size) +esp_err_t spi_flash_erase_sector_raw(esp_rom_spiflash_chip_t *chip, size_t sec, size_t sec_size) { esp_err_t ret = ESP_OK; @@ -105,7 +105,7 @@ esp_err_t spi_flash_erase_sector_raw(esp_spi_flash_chip_t *chip, size_t sec, siz return ret; } -esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip) +esp_err_t spi_flash_enable_qmode_raw(esp_rom_spiflash_chip_t *chip) { esp_err_t ret; @@ -120,7 +120,7 @@ esp_err_t spi_flash_enable_qmode_raw(esp_spi_flash_chip_t *chip) return ret; } -esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, const void *src, size_t size) +esp_err_t spi_flash_write_raw(esp_rom_spiflash_chip_t *chip, size_t dest_addr, const void *src, size_t size) { esp_err_t ret; @@ -133,7 +133,7 @@ esp_err_t spi_flash_write_raw(esp_spi_flash_chip_t *chip, size_t dest_addr, cons return ret; } -esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void *dest, size_t size) +esp_err_t spi_flash_read_raw(esp_rom_spiflash_chip_t *chip, size_t src_addr, void *dest, size_t size) { esp_err_t ret; @@ -146,7 +146,7 @@ esp_err_t spi_flash_read_raw(esp_spi_flash_chip_t *chip, size_t src_addr, void * return ret; } -bool spi_user_cmd_raw(esp_spi_flash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd) +bool spi_user_cmd_raw(esp_rom_spiflash_chip_t *chip, spi_cmd_dir_t mode, spi_cmd_t *p_cmd) { int idx = 0; diff --git a/components/spiffs/CMakeLists.txt b/components/spiffs/CMakeLists.txt index 17e5a558..cb18c92c 100644 --- a/components/spiffs/CMakeLists.txt +++ b/components/spiffs/CMakeLists.txt @@ -1,3 +1,4 @@ +if(CONFIG_USING_SPIFFS) set(COMPONENT_ADD_INCLUDEDIRS "include") set(COMPONENT_PRIV_INCLUDEDIRS "." "spiffs/src") set(COMPONENT_SRCS "esp_spiffs.c" @@ -7,6 +8,7 @@ set(COMPONENT_SRCS "esp_spiffs.c" "spiffs/src/spiffs_gc.c" "spiffs/src/spiffs_hydrogen.c" "spiffs/src/spiffs_nucleus.c") +endif() set(COMPONENT_REQUIRES spi_flash) set(COMPONENT_PRIV_REQUIRES bootloader_support) diff --git a/components/spiffs/Kconfig b/components/spiffs/Kconfig index 697f2b68..4bbcb0fc 100644 --- a/components/spiffs/Kconfig +++ b/components/spiffs/Kconfig @@ -1,4 +1,10 @@ -menu "SPIFFS Configuration" +menuconfig USING_SPIFFS + bool "SPIFFS" + select USING_ESP_VFS + help + Select this option to enable support for the SPIFFS. + +if USING_SPIFFS config SPIFFS_MAX_PARTITIONS int "Maximum Number of Partitions" @@ -158,4 +164,4 @@ config SPIFFS_TEST_VISUALISATION endmenu -endmenu +endif diff --git a/components/spiffs/component.mk b/components/spiffs/component.mk index f245a57e..916c7eb8 100644 --- a/components/spiffs/component.mk +++ b/components/spiffs/component.mk @@ -1,5 +1,9 @@ +ifdef CONFIG_USING_SPIFFS COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := . spiffs/src COMPONENT_SRCDIRS := . spiffs/src - -COMPONENT_SUBMODULES := spiffs +else +COMPONENT_ADD_INCLUDEDIRS := +COMPONENT_PRIV_INCLUDEDIRS := +COMPONENT_SRCDIRS := +endif \ No newline at end of file diff --git a/components/spiffs/include/spiffs_config.h b/components/spiffs/include/spiffs_config.h index a382ba6f..1a36a7c6 100644 --- a/components/spiffs/include/spiffs_config.h +++ b/components/spiffs/include/spiffs_config.h @@ -205,7 +205,7 @@ _Static_assert(SPIFFS_OBJ_META_LEN + SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZ #define SPIFFS_SINGLETON 0 // Enable this if your target needs aligned data for index tables -#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0 +#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 4 // Enable this if you want the HAL callbacks to be called with the spiffs struct #define SPIFFS_HAL_CALLBACK_EXTRA 1 diff --git a/tools/unit-test-app/components/unity/test_utils.c b/tools/unit-test-app/components/unity/test_utils.c index 36aae4c2..7834e697 100644 --- a/tools/unit-test-app/components/unity/test_utils.c +++ b/tools/unit-test-app/components/unity/test_utils.c @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include "unity.h" #include "test_utils.h" #include "rom/ets_sys.h" diff --git a/tools/unit-test-app/sdkconfig.defaults b/tools/unit-test-app/sdkconfig.defaults index ab100149..8f274aa1 100644 --- a/tools/unit-test-app/sdkconfig.defaults +++ b/tools/unit-test-app/sdkconfig.defaults @@ -5,3 +5,4 @@ CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_TASK_WDT= CONFIG_ENABLE_PTHREAD=y +CONFIG_USING_SPIFFS=y