diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 88deb00f9b46..000000000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: docker - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - -on: - push: - branches: - - 'master' - - 'release/*' - tags: - - 'v*.*' - -env: - # Platforms to build the image for - BUILD_PLATFORMS: linux/amd64,linux/arm64 - DOCKERHUB_REPO: ${{ github.repository_owner }}/idf - -jobs: - docker: - # Disable the job in forks - if: ${{ github.repository_owner == 'espressif' }} - - runs-on: ubuntu-latest - steps: - # Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile - # as a build arg) and TAG_NAME (used when tagging the image). - # - # The following 3 steps cover the alternatives (tag, release branch, master branch): - - name: Set variables (tags) - if: ${{ github.ref_type == 'tag' }} - run: | - echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV - echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV - - name: Set variables (release branches) - if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }} - run: | - echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV - echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV - - name: Set variables (main branch) - if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} - run: | - echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV - echo "TAG_NAME=latest" >> $GITHUB_ENV - - # Display the variables set above, just in case. - - name: Check variables - run: | - echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG" - echo "CHECKOUT_REF: $CHECKOUT_REF" - echo "TAG_NAME: $TAG_NAME" - - # The following steps are the standard boilerplate from - # https://github.com/marketplace/actions/build-and-push-docker-images - - name: Checkout - uses: actions/checkout@v3 - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Set up QEMU for multiarch builds - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: tools/docker - push: true - tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} - platforms: ${{ env.BUILD_PLATFORMS }} - build-args: | - IDF_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git - IDF_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }} - - - name: Update Docker Hub repository description (master branch) - if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} - uses: peter-evans/dockerhub-description@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - # Token based authentication is not supported here: - # https://github.com/peter-evans/dockerhub-description/issues/10 - # https://github.com/docker/roadmap/issues/115#issuecomment-891694974 - password: ${{ secrets.DOCKERHUB_PASSWORD }} - repository: ${{ env.DOCKERHUB_REPO }} - readme-filepath: ./tools/docker/README.md diff --git a/.github/workflows/issue_comment.yml b/.github/workflows/issue_comment.yml deleted file mode 100644 index b542f792f906..000000000000 --- a/.github/workflows/issue_comment.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Sync issue comments to JIRA - -# This workflow will be triggered when new issue comment is created (including PR comments) -on: issue_comment - -# Limit to single concurrent run for workflows which can create Jira issues. -# Same concurrency group is used in new_issues.yml -concurrency: jira_issues - -jobs: - sync_issue_comments_to_jira: - name: Sync Issue Comments to Jira - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Sync issue comments to JIRA - uses: espressif/github-actions/sync_issues_to_jira@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JIRA_PASS: ${{ secrets.JIRA_PASS }} - JIRA_PROJECT: IDFGH - JIRA_URL: ${{ secrets.JIRA_URL }} - JIRA_USER: ${{ secrets.JIRA_USER }} diff --git a/.github/workflows/release_zips.yml b/.github/workflows/release_zips.yml index a88dd90128e8..ccce907041e8 100644 --- a/.github/workflows/release_zips.yml +++ b/.github/workflows/release_zips.yml @@ -10,8 +10,8 @@ jobs: name: Create release zip file runs-on: ubuntu-20.04 steps: - - name: Create a recursive clone source zip - uses: espressif/github-actions/release_zips@master + - name: Create a recursive clone source and stripped zip + uses: Jason2866/github-actions/release_zips@release_idf env: RELEASE_PROJECT_NAME: ESP-IDF GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitmodules b/.gitmodules index e944b5da3735..6558be99ae89 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,15 +37,6 @@ sbom-description = A small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors sbom-hash = 24c60e243580c7868f4334a1ba3123481fe1aa48 -[submodule "components/spiffs/spiffs"] - path = components/spiffs/spiffs - url = ../../pellepl/spiffs.git - sbom-version = 0.2-255-g0dbb3f71c5f6 - sbom-supplier = Person: Peter Andersson - sbom-url = https://github.com/pellepl/spiffs - sbom-description = Wear-leveled SPI flash file system for embedded devices - sbom-hash = 0dbb3f71c5f6fae3747a9d935372773762baf852 - [submodule "components/json/cJSON"] path = components/json/cJSON url = ../../DaveGamble/cJSON.git @@ -64,10 +55,6 @@ path = components/lwip/lwip url = ../../espressif/esp-lwip.git -[submodule "components/mqtt/esp-mqtt"] - path = components/mqtt/esp-mqtt - url = ../../espressif/esp-mqtt.git - [submodule "components/protobuf-c/protobuf-c"] path = components/protobuf-c/protobuf-c url = ../../protobuf-c/protobuf-c.git diff --git a/components/driver/dac/dac_continuous.c b/components/driver/dac/dac_continuous.c index fc5b75673e39..f73c867ea1e3 100644 --- a/components/driver/dac/dac_continuous.c +++ b/components/driver/dac/dac_continuous.c @@ -570,16 +570,17 @@ static esp_err_t s_dac_wait_to_load_dma_data(dac_continuous_handle_t handle, uin DAC_STAILQ_REMOVE(&handle->head, desc, lldesc_s, qe); } - static bool split_flag = false; + // TASMOTA: remove split because it does some harm and I'm not sure why it was there in the first place. No such code in 4.x + // static bool split_flag = false; uint8_t *dma_buf = (uint8_t *)desc->buf; - if (buf_size * DAC_16BIT_ALIGN_COEFF < 2 * handle->cfg.buf_size) { - if (!split_flag) { - buf_size >>= 1; - split_flag = true; - } else { - split_flag = false; - } - } + // if (buf_size * DAC_16BIT_ALIGN_COEFF < 2 * handle->cfg.buf_size) { + // if (!split_flag) { + // buf_size >>= 1; + // split_flag = true; + // } else { + // split_flag = false; + // } + // } size_t load_bytes = s_dac_load_data_into_buf(handle, dma_buf, handle->cfg.buf_size, buf, buf_size); lldesc_config(desc, LLDESC_HW_OWNED, 1, 0, load_bytes); desc->size = load_bytes; diff --git a/components/esp_eth/CMakeLists.txt b/components/esp_eth/CMakeLists.txt index af18088efbb0..3860e9c6044c 100644 --- a/components/esp_eth/CMakeLists.txt +++ b/components/esp_eth/CMakeLists.txt @@ -26,7 +26,8 @@ if(CONFIG_ETH_ENABLED) "src/esp_eth_phy_ip101.c" "src/esp_eth_phy_ksz80xx.c" "src/esp_eth_phy_lan87xx.c" - "src/esp_eth_phy_rtl8201.c") + "src/esp_eth_phy_rtl8201.c" + "src/esp_eth_phy_jl1101.c") endif() if(CONFIG_ETH_SPI_ETHERNET_DM9051) diff --git a/components/esp_eth/include/esp_eth_phy.h b/components/esp_eth/include/esp_eth_phy.h index ebba324f6bde..6fde66248ae2 100644 --- a/components/esp_eth/include/esp_eth_phy.h +++ b/components/esp_eth/include/esp_eth_phy.h @@ -339,6 +339,17 @@ esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config); */ esp_eth_phy_t *esp_eth_phy_new_ksz80xx(const eth_phy_config_t *config); +/** +* @brief Create a PHY instance of JL1101 +* +* @param[in] config: configuration of PHY +* +* @return +* - instance: create PHY instance successfully +* - NULL: create PHY instance failed because some error occurred +*/ +esp_eth_phy_t *esp_eth_phy_new_jl1101(const eth_phy_config_t *config); + #if CONFIG_ETH_SPI_ETHERNET_DM9051 /** * @brief Create a PHY instance of DM9051 diff --git a/components/esp_eth/src/esp_eth_phy_jl1101.c b/components/esp_eth/src/esp_eth_phy_jl1101.c new file mode 100644 index 000000000000..cb792d665e45 --- /dev/null +++ b/components/esp_eth/src/esp_eth_phy_jl1101.c @@ -0,0 +1,145 @@ +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include "esp_log.h" +#include "esp_check.h" +#include "esp_eth_phy_802_3.h" + +static const char *TAG = "jl1101"; + +/***************Vendor Specific Register***************/ + +/** + * @brief PSR(Page Select Register) + * + */ +typedef union { + struct { + uint16_t page_select : 8; /* Select register page, default is 0 */ + uint16_t reserved : 8; /* Reserved */ + }; + uint16_t val; +} psr_reg_t; +#define ETH_PHY_PSR_REG_ADDR (0x1F) + +typedef struct { + phy_802_3_t phy_802_3; +} phy_jl1101_t; + +static esp_err_t jl1101_page_select(phy_jl1101_t *jl1101, uint32_t page) +{ + esp_err_t ret = ESP_OK; + esp_eth_mediator_t *eth = jl1101->phy_802_3.eth; + psr_reg_t psr = { + .page_select = page + }; + ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, jl1101->phy_802_3.addr, ETH_PHY_PSR_REG_ADDR, psr.val), err, TAG, "write PSR failed"); + return ESP_OK; +err: + return ret; +} + +static esp_err_t jl1101_update_link_duplex_speed(phy_jl1101_t *jl1101) +{ + esp_err_t ret = ESP_OK; + esp_eth_mediator_t *eth = jl1101->phy_802_3.eth; + uint32_t addr = jl1101->phy_802_3.addr; + eth_speed_t speed = ETH_SPEED_10M; + eth_duplex_t duplex = ETH_DUPLEX_HALF; + bmcr_reg_t bmcr; + bmsr_reg_t bmsr; + uint32_t peer_pause_ability = false; + anlpar_reg_t anlpar; + ESP_GOTO_ON_ERROR(jl1101_page_select(jl1101, 0), err, TAG, "select page 0 failed"); + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)), err, TAG, "read BMSR failed"); + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, addr, ETH_PHY_ANLPAR_REG_ADDR, &(anlpar.val)), err, TAG, "read ANLPAR failed"); + eth_link_t link = bmsr.link_status ? ETH_LINK_UP : ETH_LINK_DOWN; + /* check if link status changed */ + if (jl1101->phy_802_3.link_status != link) { + /* when link up, read negotiation result */ + if (link == ETH_LINK_UP) { + ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed"); + if (bmcr.speed_select) { + speed = ETH_SPEED_100M; + } else { + speed = ETH_SPEED_10M; + } + if (bmcr.duplex_mode) { + duplex = ETH_DUPLEX_FULL; + } else { + duplex = ETH_DUPLEX_HALF; + } + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_SPEED, (void *)speed), err, TAG, "change speed failed"); + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_DUPLEX, (void *)duplex), err, TAG, "change duplex failed"); + /* if we're in duplex mode, and peer has the flow control ability */ + if (duplex == ETH_DUPLEX_FULL && anlpar.symmetric_pause) { + peer_pause_ability = 1; + } else { + peer_pause_ability = 0; + } + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_PAUSE, (void *)peer_pause_ability), err, TAG, "change pause ability failed"); + } + ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LINK, (void *)link), err, TAG, "change link failed"); + jl1101->phy_802_3.link_status = link; + } + return ESP_OK; +err: + return ret; +} + +static esp_err_t jl1101_get_link(esp_eth_phy_t *phy) +{ + esp_err_t ret = ESP_OK; + phy_jl1101_t *jl1101 = __containerof(esp_eth_phy_into_phy_802_3(phy), phy_jl1101_t, phy_802_3); + /* Updata information about link, speed, duplex */ + ESP_GOTO_ON_ERROR(jl1101_update_link_duplex_speed(jl1101), err, TAG, "update link duplex speed failed"); + return ESP_OK; +err: + return ret; +} + +static esp_err_t jl1101_init(esp_eth_phy_t *phy) +{ + esp_err_t ret = ESP_OK; + phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy); + + /* Basic PHY init */ + ESP_GOTO_ON_ERROR(esp_eth_phy_802_3_basic_phy_init(phy_802_3), err, TAG, "failed to init PHY"); + + /* Check PHY ID */ + uint32_t oui; + uint8_t model; + ESP_GOTO_ON_ERROR(esp_eth_phy_802_3_read_oui(phy_802_3, &oui), err, TAG, "read OUI failed"); + ESP_GOTO_ON_ERROR(esp_eth_phy_802_3_read_manufac_info(phy_802_3, &model, NULL), err, TAG, "read manufacturer's info failed"); + ESP_GOTO_ON_FALSE(oui == 0x24DF10 && model == 0x2, ESP_FAIL, err, TAG, "wrong chip ID"); + + return ESP_OK; +err: + return ret; +} + +esp_eth_phy_t *esp_eth_phy_new_jl1101(const eth_phy_config_t *config) +{ + esp_eth_phy_t *ret = NULL; + phy_jl1101_t *jl1101 = calloc(1, sizeof(phy_jl1101_t)); + ESP_GOTO_ON_FALSE(jl1101, NULL, err, TAG, "calloc jl1101 failed"); + ESP_GOTO_ON_FALSE(esp_eth_phy_802_3_obj_config_init(&jl1101->phy_802_3, config) == ESP_OK, + NULL, err, TAG, "configuration initialization of PHY 802.3 failed"); + + // redefine functions which need to be customized for sake of jl1101 + jl1101->phy_802_3.parent.init = jl1101_init; + jl1101->phy_802_3.parent.get_link = jl1101_get_link; + + return &jl1101->phy_802_3.parent; +err: + if (jl1101 != NULL) { + free(jl1101); + } + return ret; +} diff --git a/components/esp_hw_support/mac_addr.c b/components/esp_hw_support/mac_addr.c index c917b57c1091..2f7003c8f309 100644 --- a/components/esp_hw_support/mac_addr.c +++ b/components/esp_hw_support/mac_addr.c @@ -278,6 +278,8 @@ static esp_err_t get_efuse_mac_get_default(uint8_t *mac) uint32_t mac_low = ((uint32_t)mac[2] << 24) | ((uint32_t)mac[3] << 16) | ((uint32_t)mac[4] << 8) | mac[5]; if (((mac_high & 0xFFFF) == 0x18fe) && (mac_low >= 0x346a85c7) && (mac_low <= 0x346a85f8)) { return ESP_OK; + } else if (esp_efuse_get_pkg_ver() == 3) { + return ESP_OK; // override for Xiaomi SOC's and maybe others too } else { ESP_LOGE(TAG, "Base MAC address from BLK0 of EFUSE CRC error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc); #ifdef CONFIG_ESP_MAC_IGNORE_MAC_CRC_ERROR diff --git a/components/esp_psram/esp32/esp_psram_impl_quad.c b/components/esp_psram/esp32/esp_psram_impl_quad.c index 3d6ac5d9f6e1..2beb6dd83ad4 100644 --- a/components/esp_psram/esp32/esp_psram_impl_quad.c +++ b/components/esp_psram/esp32/esp_psram_impl_quad.c @@ -845,7 +845,7 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra psram_io.psram_cs_io = D2WD_PSRAM_CS_IO; } else if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 && ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 300)) { ESP_EARLY_LOGE(TAG, "This chip is ESP32-PICO-V3. It does not support PSRAM (disable it in Kconfig)"); - abort(); + return ESP_FAIL; } else if ((pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) || (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32U4WDH)) { ESP_EARLY_LOGI(TAG, "This chip is %s", (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4)? "ESP32-PICO": "ESP32-U4WDH"); @@ -882,7 +882,7 @@ esp_err_t IRAM_ATTR esp_psram_impl_enable(psram_vaddr_mode_t vaddrmode) //psra psram_io.psram_cs_io = D0WDR2_V3_PSRAM_CS_IO; } else { ESP_EARLY_LOGE(TAG, "Not a valid or known package id: %d", pkg_ver); - abort(); + return ESP_FAIL; } s_psram_cs_io = psram_io.psram_cs_io; diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index b33fd436a26d..0d52f1ec4d82 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -281,7 +281,7 @@ menu "Wi-Fi" config ESP_WIFI_ENABLE_WPA3_SAE bool "Enable WPA3-Personal" default y - select ESP_WIFI_MBEDTLS_CRYPTO + depends on ESP_WIFI_MBEDTLS_CRYPTO help Select this option to allow the device to establish a WPA3-Personal connection with eligible AP's. PMF (Protected Management Frames) is a prerequisite feature for a WPA3 connection, it needs to be @@ -465,16 +465,9 @@ menu "Wi-Fi" select MBEDTLS_ECP_C select MBEDTLS_ECDH_C select MBEDTLS_ECDSA_C - select MBEDTLS_CMAC_C - select MBEDTLS_ECP_DP_SECP256R1_ENABLED + select MBEDTLS_TLS_ENABLED help - Select this option to enable the use of MbedTLS crypto APIs. - The internal crypto support within the supplicant is limited - and may not suffice for all new security features, including WPA3. - - It is recommended to always keep this option enabled. Additionally, - note that MbedTLS can leverage hardware acceleration if available, - resulting in significantly faster cryptographic operations. + Select this option to use MbedTLS crypto APIs which utilize hardware acceleration. if ESP_WIFI_MBEDTLS_CRYPTO config ESP_WIFI_MBEDTLS_TLS_CLIENT @@ -500,7 +493,6 @@ menu "Wi-Fi" config ESP_WIFI_SUITE_B_192 bool "Enable NSA suite B support with 192 bit key" default n - depends on SOC_WIFI_GCMP_SUPPORT select ESP_WIFI_GCMP_SUPPORT select ESP_WIFI_GMAC_SUPPORT help diff --git a/components/mqtt/.build-test-rules.yml b/components/mqtt/.build-test-rules.yml deleted file mode 100644 index 5a5f690987e7..000000000000 --- a/components/mqtt/.build-test-rules.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps - -components/mqtt/test_apps: - disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c2"] - temporary: false - reason: Not needed to test on all targets (chosen two, one for each architecture) diff --git a/components/mqtt/CMakeLists.txt b/components/mqtt/CMakeLists.txt deleted file mode 100644 index d2bb24a78ed0..000000000000 --- a/components/mqtt/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/esp-mqtt/CMakeLists.txt) - set(COMMAND "git submodule update --init --recursive") - message(FATAL_ERROR "Missing esp-mqtt submodule. Please run '${COMMAND}' in ESP-IDF directory to fix this.") -else() - include(${CMAKE_CURRENT_LIST_DIR}/esp-mqtt/CMakeLists.txt) -endif() diff --git a/components/mqtt/esp-mqtt b/components/mqtt/esp-mqtt deleted file mode 160000 index e6afdb4025fe..000000000000 --- a/components/mqtt/esp-mqtt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e6afdb4025fe018ae0add44e3c45249ea1974774 diff --git a/components/mqtt/host_test/mocks/heap/CMakeLists.txt b/components/mqtt/host_test/mocks/heap/CMakeLists.txt deleted file mode 100644 index 0a0c8a6341c2..000000000000 --- a/components/mqtt/host_test/mocks/heap/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_get_property(original_heap_dir heap COMPONENT_OVERRIDEN_DIR) - -idf_component_register(SRCS heap_mock.c - INCLUDE_DIRS "${original_heap_dir}/include") diff --git a/components/mqtt/host_test/mocks/heap/heap_mock.c b/components/mqtt/host_test/mocks/heap/heap_mock.c deleted file mode 100644 index e0fc666ba0a2..000000000000 --- a/components/mqtt/host_test/mocks/heap/heap_mock.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "esp_heap_caps.h" -#include -#include - - - -void *heap_caps_calloc(size_t n, size_t size, uint32_t caps) { - (void)caps; - return calloc(n, size); - -} diff --git a/components/mqtt/test_apps/common/CMakeLists.txt b/components/mqtt/test_apps/common/CMakeLists.txt deleted file mode 100644 index 97ab3b53bcad..000000000000 --- a/components/mqtt/test_apps/common/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ - -idf_component_register(SRCS test_mqtt_connection.c - INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include - PRIV_REQUIRES unity esp_event esp_netif esp_eth) diff --git a/components/mqtt/test_apps/common/include/test_mqtt_connection.h b/components/mqtt/test_apps/common/include/test_mqtt_connection.h deleted file mode 100644 index 460beccfe64d..000000000000 --- a/components/mqtt/test_apps/common/include/test_mqtt_connection.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once -#include "soc/soc_caps.h" - -/** - * Connection test fixture setup, so we expect the broker is available - * on network - */ -void connect_test_fixture_setup(void); - -/** - * Cleans up the connection - */ -void connect_test_fixture_teardown(void); diff --git a/components/mqtt/test_apps/common/test_mqtt_connection.c b/components/mqtt/test_apps/common/test_mqtt_connection.c deleted file mode 100644 index 0e8200391875..000000000000 --- a/components/mqtt/test_apps/common/test_mqtt_connection.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include "freertos/FreeRTOS.h" -#include "freertos/event_groups.h" -#include "unity.h" -#include "esp_event.h" -#include "esp_netif.h" -#include "esp_eth.h" -#include "esp_log.h" - - -#if SOC_EMAC_SUPPORTED -#define ETH_START_BIT BIT(0) -#define ETH_STOP_BIT BIT(1) -#define ETH_CONNECT_BIT BIT(2) -#define ETH_GOT_IP_BIT BIT(3) -#define ETH_STOP_TIMEOUT_MS (10000) -#define ETH_GET_IP_TIMEOUT_MS (60000) - - -static const char *TAG = "esp32_eth_test_fixture"; -static EventGroupHandle_t s_eth_event_group = NULL; -static esp_netif_t *s_eth_netif = NULL; -static esp_eth_mac_t *s_mac = NULL; -static esp_eth_phy_t *s_phy = NULL; -static esp_eth_handle_t s_eth_handle = NULL; -static esp_eth_netif_glue_handle_t s_eth_glue = NULL; - - -/** Event handler for Ethernet events */ -static void eth_event_handler(void *arg, esp_event_base_t event_base, - int32_t event_id, void *event_data) -{ - EventGroupHandle_t eth_event_group = (EventGroupHandle_t)arg; - switch (event_id) { - case ETHERNET_EVENT_CONNECTED: - xEventGroupSetBits(eth_event_group, ETH_CONNECT_BIT); - ESP_LOGI(TAG, "Ethernet Link Up"); - break; - case ETHERNET_EVENT_DISCONNECTED: - ESP_LOGI(TAG, "Ethernet Link Down"); - break; - case ETHERNET_EVENT_START: - xEventGroupSetBits(eth_event_group, ETH_START_BIT); - ESP_LOGI(TAG, "Ethernet Started"); - break; - case ETHERNET_EVENT_STOP: - xEventGroupSetBits(eth_event_group, ETH_STOP_BIT); - ESP_LOGI(TAG, "Ethernet Stopped"); - break; - default: - break; - } -} - -/** Event handler for IP_EVENT_ETH_GOT_IP */ -static void got_ip_event_handler(void *arg, esp_event_base_t event_base, - int32_t event_id, void *event_data) -{ - EventGroupHandle_t eth_event_group = (EventGroupHandle_t)arg; - ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; - const esp_netif_ip_info_t *ip_info = &event->ip_info; - ESP_LOGI(TAG, "Ethernet Got IP Address"); - ESP_LOGI(TAG, "~~~~~~~~~~~"); - ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip)); - ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask)); - ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw)); - ESP_LOGI(TAG, "~~~~~~~~~~~"); - xEventGroupSetBits(eth_event_group, ETH_GOT_IP_BIT); -} - -static esp_err_t test_uninstall_driver(esp_eth_handle_t eth_hdl, uint32_t ms_to_wait) -{ - int i = 0; - ms_to_wait += 100; - for (i = 0; i < ms_to_wait / 100; i++) { - vTaskDelay(pdMS_TO_TICKS(100)); - if (esp_eth_driver_uninstall(eth_hdl) == ESP_OK) { - break; - } - } - if (i < ms_to_wait / 10) { - return ESP_OK; - } else { - return ESP_FAIL; - } -} - - -void connect_test_fixture_setup(void) -{ - EventBits_t bits; - s_eth_event_group = xEventGroupCreate(); - TEST_ASSERT(s_eth_event_group != NULL); - TEST_ESP_OK(esp_event_loop_create_default()); - // create TCP/IP netif - esp_netif_config_t netif_cfg = ESP_NETIF_DEFAULT_ETH(); - s_eth_netif = esp_netif_new(&netif_cfg); - - eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); - s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); - eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); - s_phy = esp_eth_phy_new_ip101(&phy_config); - esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(s_mac, s_phy); - - // install Ethernet driver - TEST_ESP_OK(esp_eth_driver_install(ð_config, &s_eth_handle)); - // combine driver with netif - s_eth_glue = esp_eth_new_netif_glue(s_eth_handle); - TEST_ESP_OK(esp_netif_attach(s_eth_netif, s_eth_glue)); - // register user defined event handers - TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, s_eth_event_group)); - TEST_ESP_OK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, s_eth_event_group)); - // start Ethernet driver - TEST_ESP_OK(esp_eth_start(s_eth_handle)); - /* wait for IP lease */ - bits = xEventGroupWaitBits(s_eth_event_group, ETH_GOT_IP_BIT, true, true, pdMS_TO_TICKS(ETH_GET_IP_TIMEOUT_MS)); - TEST_ASSERT((bits & ETH_GOT_IP_BIT) == ETH_GOT_IP_BIT); -} - -void connect_test_fixture_teardown(void) -{ - EventBits_t bits; - // stop Ethernet driver - TEST_ESP_OK(esp_eth_stop(s_eth_handle)); - /* wait for connection stop */ - bits = xEventGroupWaitBits(s_eth_event_group, ETH_STOP_BIT, true, true, pdMS_TO_TICKS(ETH_STOP_TIMEOUT_MS)); - TEST_ASSERT((bits & ETH_STOP_BIT) == ETH_STOP_BIT); - TEST_ESP_OK(esp_eth_del_netif_glue(s_eth_glue)); - /* driver should be uninstalled within 2 seconds */ - TEST_ESP_OK(test_uninstall_driver(s_eth_handle, 2000)); - TEST_ESP_OK(s_phy->del(s_phy)); - TEST_ESP_OK(s_mac->del(s_mac)); - TEST_ESP_OK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_ETH_GOT_IP, got_ip_event_handler)); - TEST_ESP_OK(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler)); - esp_netif_destroy(s_eth_netif); - TEST_ESP_OK(esp_event_loop_delete_default()); - vEventGroupDelete(s_eth_event_group); -} -#endif // SOC_EMAC_SUPPORTED diff --git a/components/mqtt/test_apps/test_mqtt/CMakeLists.txt b/components/mqtt/test_apps/test_mqtt/CMakeLists.txt deleted file mode 100644 index bc86bdba3eb5..000000000000 --- a/components/mqtt/test_apps/test_mqtt/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -#This is the project CMakeLists.txt file for the test subproject -cmake_minimum_required(VERSION 3.16) - -set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components" - "../common") - -set(COMPONENTS main) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp_mqtt_client_test) diff --git a/components/mqtt/test_apps/test_mqtt/README.md b/components/mqtt/test_apps/test_mqtt/README.md deleted file mode 100644 index a8b7833fa30d..000000000000 --- a/components/mqtt/test_apps/test_mqtt/README.md +++ /dev/null @@ -1,2 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/mqtt/test_apps/test_mqtt/main/CMakeLists.txt b/components/mqtt/test_apps/test_mqtt/main/CMakeLists.txt deleted file mode 100644 index e7499a2e4634..000000000000 --- a/components/mqtt/test_apps/test_mqtt/main/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(srcs test_mqtt_client_broker.c test_mqtt.c) - -if(CONFIG_MQTT_PROTOCOL_5) - list(APPEND srcs test_mqtt5_client_broker.c test_mqtt5.c) -endif() - -idf_component_register(SRCS "${srcs}" - PRIV_REQUIRES cmock test_utils mqtt nvs_flash app_update esp_eth esp_netif spi_flash common) - target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/mqtt/test_apps/test_mqtt/main/Kconfig.projbuild b/components/mqtt/test_apps/test_mqtt/main/Kconfig.projbuild deleted file mode 100644 index 30b2c1087a60..000000000000 --- a/components/mqtt/test_apps/test_mqtt/main/Kconfig.projbuild +++ /dev/null @@ -1,14 +0,0 @@ -menu "ESP-MQTT Unit Test Config" - - config MQTT_TEST_BROKER_URI - string "URI of the test broker" - default "mqtt://mqtt.eclipseprojects.io" - help - URL of an mqtt broker which this test connects to. - - config MQTT5_TEST_BROKER_URI - string "URI of the test broker" - default "mqtt://mqtt.eclipseprojects.io" - help - URL of an mqtt broker which this test connects to. -endmenu diff --git a/components/mqtt/test_apps/test_mqtt/main/test_mqtt.c b/components/mqtt/test_apps/test_mqtt/main/test_mqtt.c deleted file mode 100644 index cb56a5e0636a..000000000000 --- a/components/mqtt/test_apps/test_mqtt/main/test_mqtt.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - * - * This test code is in the Public Domain (or CC0 licensed, at your option.) - * - * Unless required by applicable law or agreed to in writing, this - * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. - */ - -#include -#include "unity_fixture.h" -#include "unity_fixture_extras.h" -#include "test_utils.h" -#include "memory_checks.h" -#include "mqtt_client.h" -#include "esp_ota_ops.h" -#include "test_mqtt_client_broker.h" -#include "test_mqtt_connection.h" -#include "esp_partition.h" - -TEST_GROUP(mqtt); - -TEST_SETUP(mqtt){ - test_utils_record_free_mem(); - TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); -} - -TEST_TEAR_DOWN(mqtt){ - test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL), - test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL)); -} - -TEST(mqtt, init_with_invalid_url) -{ - const esp_mqtt_client_config_t mqtt_cfg = { - .broker.address.uri = "INVALID", - }; - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); - TEST_ASSERT_EQUAL(NULL, client ); -} - -TEST(mqtt, init_and_deinit) -{ - const esp_mqtt_client_config_t mqtt_cfg = { - // no connection takes place, but the uri has to be valid for init() to succeed - .broker.address.uri = "mqtts://localhost:8883", - }; - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); - TEST_ASSERT_NOT_EQUAL(NULL, client ); - esp_mqtt_client_destroy(client); -} - -static const char* this_bin_addr(void) -{ - esp_partition_mmap_handle_t out_handle; - const void *binary_address; - const esp_partition_t* partition = esp_ota_get_running_partition(); - esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle); - return binary_address; -} - -TEST(mqtt, enqueue_and_destroy_outbox) -{ - const char * bin_addr = this_bin_addr(); - - // Reseting leak detection since this_bin_addr adds to allocated memory. - test_utils_record_free_mem(); - TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); - const int messages = 20; - const int size = 2000; - const esp_mqtt_client_config_t mqtt_cfg = { - // no connection takes place, but the uri has to be valid for init() to succeed - .broker.address.uri = "mqtts://localhost:8883", - }; - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); - TEST_ASSERT_NOT_EQUAL(NULL, client ); - int bytes_before = esp_get_free_heap_size(); - for (int i=0; iqos; - xEventGroupSetBits(s_event_group, DATA_BIT); - } -} - -static void mqtt_data_handler_lwt(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - if (event_id == MQTT_EVENT_DATA) { - esp_mqtt_event_handle_t event = event_data; - ESP_LOGI("mqtt-lwt", "MQTT_EVENT_DATA"); - ESP_LOGI("mqtt-lwt", "TOPIC=%.*s", event->topic_len, event->topic); - ESP_LOGI("mqtt-lwt", "DATA=%.*s", event->data_len, event->data); - if (strncmp(event->data, "no-lwt", event->data_len) == 0) { - // no lwt, just to indicate the test has finished - xEventGroupSetBits(s_event_group, DATA_BIT); - } else { - // count up any potential lwt message - int * count = handler_args; - *count = *count + 1; - ESP_LOGE("mqtt-lwt", "count=%d", *count); - } - } -} - -static void mqtt_data_handler_subscribe(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - if (event_id == MQTT_EVENT_SUBSCRIBED) { - esp_mqtt_event_handle_t event = event_data; - ESP_LOGI("mqtt-subscribe", "MQTT_EVENT_SUBSCRIBED, data size=%d", event->data_len); - int * sub_payload = handler_args; - if (event->data_len == 1) { - ESP_LOGI("mqtt-subscribe", "DATA=%d", *(uint8_t*)event->data); - *sub_payload = *(uint8_t*)event->data; - } - xEventGroupSetBits(s_event_group, DATA_BIT); - } -} - - -static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - switch ((esp_mqtt_event_id_t)event_id) { - case MQTT_EVENT_CONNECTED: - xEventGroupSetBits(s_event_group, CONNECT_BIT); - break; - - case MQTT_EVENT_DISCONNECTED: - xEventGroupSetBits(s_event_group, DISCONNECT_BIT); - break; - default: - break; - } -} - -bool mqtt_connect_disconnect(void) -{ - const esp_mqtt_client_config_t mqtt_cfg = { - .broker.address.uri = CONFIG_MQTT_TEST_BROKER_URI, - .network.disable_auto_reconnect = true, - }; - s_event_group = xEventGroupCreate(); - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); - TEST_ASSERT_TRUE(NULL != client ); - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt_client_start(client)); - WAIT_FOR_EVENT(CONNECT_BIT); - esp_mqtt_client_disconnect(client); - WAIT_FOR_EVENT(DISCONNECT_BIT); - esp_mqtt_client_reconnect(client); - WAIT_FOR_EVENT(CONNECT_BIT); - esp_mqtt_client_destroy(client); - vEventGroupDelete(s_event_group); - return true; -} - -bool mqtt_subscribe_publish(void) -{ - const esp_mqtt_client_config_t mqtt_cfg = { - .broker.address.uri = CONFIG_MQTT_TEST_BROKER_URI, - }; - char* topic = append_mac("topic"); - TEST_ASSERT_TRUE(NULL != topic); - s_event_group = xEventGroupCreate(); - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); - TEST_ASSERT_TRUE(NULL != client ); - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt_client_start(client)); - WAIT_FOR_EVENT(CONNECT_BIT); - int qos = -1; - esp_mqtt_client_register_event(client, MQTT_EVENT_DATA, mqtt_data_handler_qos, &qos); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client, topic, 2) != -1); - TEST_ASSERT_TRUE(esp_mqtt_client_publish(client, topic, "message", 0, 2, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos == 2); - TEST_ASSERT_TRUE(esp_mqtt_client_publish(client, topic, "message", 0, 1, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos == 1); - esp_mqtt_client_destroy(client); - vEventGroupDelete(s_event_group); - free(topic); - return true; -} - -bool mqtt_lwt_clean_disconnect(void) -{ - char* lwt = append_mac("lwt"); - TEST_ASSERT_TRUE(lwt); - const esp_mqtt_client_config_t mqtt_cfg1 = { - .broker.address.uri = CONFIG_MQTT_TEST_BROKER_URI, - .credentials.set_null_client_id = true, - .session.last_will.topic = lwt, - .session.last_will.msg = "lwt_msg" - }; - const esp_mqtt_client_config_t mqtt_cfg2 = { - .broker.address.uri = CONFIG_MQTT_TEST_BROKER_URI, - .credentials.set_null_client_id = true, - .session.last_will.topic = lwt, - .session.last_will.msg = "lwt_msg" - }; - s_event_group = xEventGroupCreate(); - - esp_mqtt_client_handle_t client1 = esp_mqtt_client_init(&mqtt_cfg1); - esp_mqtt_client_handle_t client2 = esp_mqtt_client_init(&mqtt_cfg2); - TEST_ASSERT_TRUE(NULL != client1 && NULL != client2 ); - esp_mqtt_client_register_event(client1, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); - esp_mqtt_client_register_event(client2, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); - TEST_ASSERT_TRUE(esp_mqtt_client_start(client1) == ESP_OK); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(esp_mqtt_client_start(client2) == ESP_OK); - WAIT_FOR_EVENT(CONNECT_BIT); - int counter = 0; - esp_mqtt_client_register_event(client1, MQTT_EVENT_DATA, mqtt_data_handler_lwt, &counter); - esp_mqtt_client_register_event(client2, MQTT_EVENT_DATA, mqtt_data_handler_lwt, &counter); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client1, lwt, 0) != -1); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client2, lwt, 0) != -1); - esp_mqtt_client_disconnect(client1); - WAIT_FOR_EVENT(DISCONNECT_BIT); - esp_mqtt_client_reconnect(client1); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client1, lwt, 0) != -1); - esp_mqtt_client_stop(client2); - esp_mqtt_client_start(client2); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client2, lwt, 0) != -1); - TEST_ASSERT_TRUE(esp_mqtt_client_publish(client1, lwt, "no-lwt", 0, 0, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(counter == 0); - esp_mqtt_client_destroy(client1); - esp_mqtt_client_destroy(client2); - vEventGroupDelete(s_event_group); - free(lwt); - return true; -} - -bool mqtt_subscribe_payload(void) -{ - const esp_mqtt_client_config_t mqtt_cfg = { - .broker.address.uri = CONFIG_MQTT_TEST_BROKER_URI, - .network.disable_auto_reconnect = true, - }; - char* topic = append_mac("topic"); - TEST_ASSERT_TRUE(NULL != topic); - s_event_group = xEventGroupCreate(); - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); - TEST_ASSERT_TRUE(NULL != client ); - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt_client_start(client)); - WAIT_FOR_EVENT(CONNECT_BIT); - int qos_payload = -1; - esp_mqtt_client_register_event(client, MQTT_EVENT_SUBSCRIBED, mqtt_data_handler_subscribe, &qos_payload); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client, topic, 2) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos_payload == 2); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client, topic, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos_payload == 0); - esp_mqtt_client_destroy(client); - vEventGroupDelete(s_event_group); - free(topic); - return true; -} diff --git a/components/mqtt/test_apps/test_mqtt/main/test_mqtt_client_broker.h b/components/mqtt/test_apps/test_mqtt/main/test_mqtt_client_broker.h deleted file mode 100644 index 63e7856f70d8..000000000000 --- a/components/mqtt/test_apps/test_mqtt/main/test_mqtt_client_broker.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once -#include "esp_log.h" - -/** - * @brief MQTT client-broker tests are not implemented as separate test cases - * due to time consuming connection setup/teardown. - * This utility macro is used to run functional cases as MQTT tests - * and evaluate as separate assertions in one "mqtt broker tests" test case. - */ -#define RUN_MQTT_BROKER_TEST(test_name) \ - do { \ - ESP_LOGI("mqtt_test", "Running test:" #test_name "()"); \ - TEST_ASSERT_TRUE_MESSAGE(test_name(), "Mqtt test failed: " #test_name "() "); \ - ESP_LOGI("mqtt_test", "Test:" #test_name "() passed "); \ - } while(0) - - -/** - * @brief This module contains mqtt test cases interacting the client with a (real) broker - */ - -/** - * @brief The client subscribes and publishes on the same topic - * and verifies the received published qos in the event - */ -bool mqtt_subscribe_publish(void); - -/** - * @brief The client connects, disconnects and reconnects. - * Tests basic client state transitions - */ -bool mqtt_connect_disconnect(void); - -/** - * @brief Two clients with defined lwt connect and subscribe to lwt topic. - * This test verifies that no lwt is send when each of the client disconnects. - * (we expect a clean disconnection, so no last-will being sent) - */ -bool mqtt_lwt_clean_disconnect(void); - -/** - * @brief The client subscribes to a topic with certain qos - * and verifies the qos in SUBACK message from the broker. - */ -bool mqtt_subscribe_payload(void); diff --git a/components/mqtt/test_apps/test_mqtt/pytest_mqtt_ut.py b/components/mqtt/test_apps/test_mqtt/pytest_mqtt_ut.py deleted file mode 100644 index f3333fae45fb..000000000000 --- a/components/mqtt/test_apps/test_mqtt/pytest_mqtt_ut.py +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Unlicense OR CC0-1.0 -import pytest -from pytest_embedded import Dut - - -@pytest.mark.esp32 -@pytest.mark.esp32c2 -@pytest.mark.ethernet -def test_mqtt_client(dut: Dut) -> None: - dut.expect_unity_test_output() diff --git a/components/mqtt/test_apps/test_mqtt/sdkconfig.defaults b/components/mqtt/test_apps/test_mqtt/sdkconfig.defaults deleted file mode 100644 index 2bcae3f3bc30..000000000000 --- a/components/mqtt/test_apps/test_mqtt/sdkconfig.defaults +++ /dev/null @@ -1,3 +0,0 @@ -# General options for additional checks -CONFIG_ESP_TASK_WDT_EN=n -CONFIG_UNITY_ENABLE_FIXTURE=y diff --git a/components/mqtt/test_apps/test_mqtt5/CMakeLists.txt b/components/mqtt/test_apps/test_mqtt5/CMakeLists.txt deleted file mode 100644 index 1c7881c5adf8..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -#This is the project CMakeLists.txt file for the test subproject -cmake_minimum_required(VERSION 3.16) - -set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components" - "../common") - -set(COMPONENTS main) -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp_mqtt5_client_test) diff --git a/components/mqtt/test_apps/test_mqtt5/README.md b/components/mqtt/test_apps/test_mqtt5/README.md deleted file mode 100644 index a8b7833fa30d..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/README.md +++ /dev/null @@ -1,2 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | diff --git a/components/mqtt/test_apps/test_mqtt5/main/CMakeLists.txt b/components/mqtt/test_apps/test_mqtt5/main/CMakeLists.txt deleted file mode 100644 index 326b8fa3000b..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/main/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(srcs test_mqtt5_client_broker.c test_mqtt5.c) - -idf_component_register(SRCS "${srcs}" - PRIV_REQUIRES cmock test_utils mqtt nvs_flash app_update esp_eth esp_netif spi_flash common) - target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") diff --git a/components/mqtt/test_apps/test_mqtt5/main/Kconfig.projbuild b/components/mqtt/test_apps/test_mqtt5/main/Kconfig.projbuild deleted file mode 100644 index 30b2c1087a60..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/main/Kconfig.projbuild +++ /dev/null @@ -1,14 +0,0 @@ -menu "ESP-MQTT Unit Test Config" - - config MQTT_TEST_BROKER_URI - string "URI of the test broker" - default "mqtt://mqtt.eclipseprojects.io" - help - URL of an mqtt broker which this test connects to. - - config MQTT5_TEST_BROKER_URI - string "URI of the test broker" - default "mqtt://mqtt.eclipseprojects.io" - help - URL of an mqtt broker which this test connects to. -endmenu diff --git a/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5.c b/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5.c deleted file mode 100644 index 9d8705d83f75..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include "unity_fixture.h" -#include "unity_fixture_extras.h" -#include "test_utils.h" -#include "memory_checks.h" -#include "mqtt_client.h" -#include "esp_ota_ops.h" -#include "test_mqtt5_client_broker.h" -#include "test_mqtt_connection.h" -#include "esp_partition.h" - - -TEST_GROUP(mqtt5); - -TEST_SETUP(mqtt5) -{ - test_utils_record_free_mem(); - TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); -} - -TEST_TEAR_DOWN(mqtt5) -{ - test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL), - test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL)); -} - -static esp_mqtt5_user_property_item_t user_property_arr[3] = { - {"board", "esp32"}, - {"u", "user"}, - {"p", "password"} -}; - -TEST(mqtt5, init_with_invalid_url) -{ - const esp_mqtt_client_config_t mqtt5_cfg = { - .broker.address.uri = "INVALID", - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt5_cfg); - TEST_ASSERT_EQUAL(NULL, client ); -} - -TEST(mqtt5, init_and_deinit) -{ - const esp_mqtt_client_config_t mqtt5_cfg = { - // no connection takes place, but the uri has to be valid for init() to succeed - .broker.address.uri = "mqtts://localhost:8883", - .session.protocol_ver = MQTT_PROTOCOL_V_5, - .credentials.username = "123", - .credentials.authentication.password = "456", - .session.last_will.topic = "/topic/will", - .session.last_will.msg = "i will leave", - .session.last_will.msg_len = 12, - .session.last_will.qos = 1, - .session.last_will.retain = true, - }; - esp_mqtt5_connection_property_config_t connect_property = { - .session_expiry_interval = 10, - .maximum_packet_size = 1024, - .receive_maximum = 65535, - .topic_alias_maximum = 2, - .request_resp_info = true, - .request_problem_info = true, - .will_delay_interval = 10, - .payload_format_indicator = true, - .message_expiry_interval = 10, - .content_type = "json", - .response_topic = "/test/response", - .correlation_data = "123456", - .correlation_data_len = 6, - }; - - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt5_cfg); - esp_mqtt5_client_set_user_property(&connect_property.user_property, user_property_arr, 3); - esp_mqtt5_client_set_user_property(&connect_property.will_user_property, user_property_arr, 3); - esp_mqtt5_client_set_connect_property(client, &connect_property); - esp_mqtt5_client_delete_user_property(connect_property.user_property); - esp_mqtt5_client_delete_user_property(connect_property.will_user_property); - TEST_ASSERT_NOT_EQUAL(NULL, client ); - esp_mqtt_client_destroy(client); -} - -static const char *this_bin_addr(void) -{ - esp_partition_mmap_handle_t out_handle; - const void *binary_address; - const esp_partition_t *partition = esp_ota_get_running_partition(); - esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle); - return binary_address; -} - -TEST(mqtt5, enqueue_and_destroy_outbox) -{ - const char *bin_addr = this_bin_addr(); - // Reseting leak detection since this_bin_addr adds to allocated memory. - test_utils_record_free_mem(); - TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL)); - const int messages = 20; - const int size = 2000; - const esp_mqtt_client_config_t mqtt5_cfg = { - // no connection takes place, but the uri has to be valid for init() to succeed - .broker.address.uri = "mqtts://localhost:8883", - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - esp_mqtt5_publish_property_config_t publish_property = { - .payload_format_indicator = 1, - .message_expiry_interval = 1000, - .topic_alias = 0, - .response_topic = "/topic/test/response", - .correlation_data = "123456", - .correlation_data_len = 6, - .content_type = "json", - }; - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt5_cfg); - TEST_ASSERT_NOT_EQUAL(NULL, client ); - int bytes_before = esp_get_free_heap_size(); - for (int i = 0; i < messages; i ++) { - esp_mqtt5_client_set_user_property(&publish_property.user_property, user_property_arr, 3); - esp_mqtt5_client_set_publish_property(client, &publish_property); - esp_mqtt_client_publish(client, "test", bin_addr, size, 1, 0); - esp_mqtt5_client_delete_user_property(publish_property.user_property); - publish_property.user_property = NULL; - } - int bytes_after = esp_get_free_heap_size(); - // check that outbox allocated all messages on heap - TEST_ASSERT_GREATER_OR_EQUAL(messages * size, bytes_before - bytes_after); - - esp_mqtt_client_destroy(client); -} - -#if SOC_EMAC_SUPPORTED -/** - * This test cases uses ethernet kit, so build and use it only if EMAC supported - */ -TEST(mqtt5, broker_tests) -{ - test_case_uses_tcpip(); - connect_test_fixture_setup(); - - RUN_MQTT5_BROKER_TEST(mqtt5_connect_disconnect); - RUN_MQTT5_BROKER_TEST(mqtt5_subscribe_publish); - RUN_MQTT5_BROKER_TEST(mqtt5_lwt_clean_disconnect); - RUN_MQTT5_BROKER_TEST(mqtt5_subscribe_payload); - - connect_test_fixture_teardown(); -} -#endif // SOC_EMAC_SUPPORTED - -TEST_GROUP_RUNNER(mqtt5) -{ -#if !DISABLED_FOR_TARGETS(ESP32H2) - RUN_TEST_CASE(mqtt5, init_with_invalid_url); - RUN_TEST_CASE(mqtt5, init_and_deinit); - RUN_TEST_CASE(mqtt5, enqueue_and_destroy_outbox); - -#if SOC_EMAC_SUPPORTED - RUN_TEST_CASE(mqtt5, broker_tests); -#endif // SOC_EMAC_SUPPORTED -#endif //!DISABLED_FOR_TARGETS(ESP32H2) -} - - -void app_main(void) -{ - UNITY_MAIN(mqtt5); -} diff --git a/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5_client_broker.c b/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5_client_broker.c deleted file mode 100644 index 0ac4c3dd0195..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5_client_broker.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "freertos/FreeRTOS.h" -#include "freertos/event_groups.h" -#include "mqtt_client.h" -#include "esp_log.h" -#include "esp_mac.h" - -#define WAIT_FOR_EVENT(event) \ - TEST_ASSERT_TRUE(xEventGroupWaitBits(s_event_group, event, pdTRUE, pdTRUE, pdMS_TO_TICKS(COMMON_OPERATION_TIMEOUT)) & event); - -#define TEST_ASSERT_TRUE(condition) TEST_ASSERT_TRUE_LINE(condition, __LINE__) -#define TEST_ASSERT_TRUE_LINE(condition, line) \ - do { \ - if (!(condition)) { \ - ESP_LOGE("test_mqtt5_client_broker.c", \ - "Assertion failed in line %d", line); \ - return false; \ - } \ - } while(0) - - -static const int COMMON_OPERATION_TIMEOUT = 10000; -static const int CONNECT_BIT = BIT0; -static const int DISCONNECT_BIT = BIT1; -static const int DATA_BIT = BIT2; - -static EventGroupHandle_t s_event_group; - -static esp_mqtt5_user_property_item_t user_property_arr[3] = { - {"board", "esp32"}, - {"u", "user"}, - {"p", "password"} -}; - -static char* append_mac(const char* string) -{ - uint8_t mac[6]; - char *id_string = NULL; - esp_read_mac(mac, ESP_MAC_WIFI_STA); - asprintf(&id_string, "%s_%02x%02X%02X", string, mac[3], mac[4], mac[5]); - return id_string; -} - -static void mqtt5_data_handler_qos(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - if (event_id == MQTT_EVENT_DATA) { - esp_mqtt_event_handle_t event = event_data; - int * qos = handler_args; - *qos = event->qos; - xEventGroupSetBits(s_event_group, DATA_BIT); - } -} - -static void mqtt5_data_handler_lwt(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - if (event_id == MQTT_EVENT_DATA) { - esp_mqtt_event_handle_t event = event_data; - ESP_LOGI("mqtt-lwt", "MQTT_EVENT_DATA"); - ESP_LOGI("mqtt-lwt", "TOPIC=%.*s", event->topic_len, event->topic); - ESP_LOGI("mqtt-lwt", "DATA=%.*s", event->data_len, event->data); - if (strncmp(event->data, "no-lwt", event->data_len) == 0) { - // no lwt, just to indicate the test has finished - xEventGroupSetBits(s_event_group, DATA_BIT); - } else { - // count up any potential lwt message - int * count = handler_args; - *count = *count + 1; - ESP_LOGE("mqtt5-lwt", "count=%d", *count); - } - } -} - -static void mqtt5_data_handler_subscribe(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - if (event_id == MQTT_EVENT_SUBSCRIBED) { - esp_mqtt_event_handle_t event = event_data; - ESP_LOGI("mqtt5-subscribe", "MQTT_EVENT_SUBSCRIBED, data size=%d", event->data_len); - int * sub_payload = handler_args; - if (event->data_len == 1) { - ESP_LOGI("mqtt5-subscribe", "DATA=%d", *(uint8_t*)event->data); - *sub_payload = *(uint8_t*)event->data; - } - xEventGroupSetBits(s_event_group, DATA_BIT); - } -} - - -static void mqtt5_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) -{ - switch ((esp_mqtt_event_id_t)event_id) { - case MQTT_EVENT_CONNECTED: - xEventGroupSetBits(s_event_group, CONNECT_BIT); - break; - - case MQTT_EVENT_DISCONNECTED: - xEventGroupSetBits(s_event_group, DISCONNECT_BIT); - break; - default: - break; - } -} - -bool mqtt5_connect_disconnect(void) -{ - const esp_mqtt_client_config_t mqtt5_cfg = { - .broker.address.uri = CONFIG_MQTT5_TEST_BROKER_URI, - .network.disable_auto_reconnect = true, - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - esp_mqtt5_connection_property_config_t connect_property = { - .session_expiry_interval = 10, - .maximum_packet_size = 1024, - .receive_maximum = 65535, - .topic_alias_maximum = 2, - .request_resp_info = true, - .request_problem_info = true, - }; - esp_mqtt5_disconnect_property_config_t disconnect_property = { - .session_expiry_interval = 10, - .disconnect_reason = 0, - }; - s_event_group = xEventGroupCreate(); - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt5_cfg); - TEST_ASSERT_TRUE(NULL != client ); - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt5_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_user_property(&connect_property.user_property, user_property_arr, 3)); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_connect_property(client, &connect_property)); - esp_mqtt5_client_delete_user_property(connect_property.user_property); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt_client_start(client)); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_user_property(&disconnect_property.user_property, user_property_arr, 3)); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_disconnect_property(client, &disconnect_property)); - esp_mqtt5_client_delete_user_property(disconnect_property.user_property); - esp_mqtt_client_disconnect(client); - WAIT_FOR_EVENT(DISCONNECT_BIT); - esp_mqtt_client_reconnect(client); - WAIT_FOR_EVENT(CONNECT_BIT); - esp_mqtt_client_destroy(client); - vEventGroupDelete(s_event_group); - return true; -} - -bool mqtt5_subscribe_publish(void) -{ - const esp_mqtt_client_config_t mqtt5_cfg = { - .broker.address.uri = CONFIG_MQTT5_TEST_BROKER_URI, - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - esp_mqtt5_publish_property_config_t publish_property = { - .payload_format_indicator = 1, - .message_expiry_interval = 1000, - .topic_alias = 1, - .response_topic = "/topic/test/response", - .correlation_data = "123456", - .correlation_data_len = 6, - .content_type = "json", - }; - esp_mqtt5_subscribe_property_config_t subscribe_property = { - .subscribe_id = 25555, - .no_local_flag = false, - .retain_as_published_flag = true, - .retain_handle = 0, - }; - char* topic = append_mac("topic"); - TEST_ASSERT_TRUE(NULL != topic); - s_event_group = xEventGroupCreate(); - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt5_cfg); - TEST_ASSERT_TRUE(NULL != client ); - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt5_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt_client_start(client)); - WAIT_FOR_EVENT(CONNECT_BIT); - int qos = -1; - esp_mqtt_client_register_event(client, MQTT_EVENT_DATA, mqtt5_data_handler_qos, &qos); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_subscribe_property(client, &subscribe_property)); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client, topic, 2) != -1); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_publish_property(client, &publish_property)); - TEST_ASSERT_TRUE(esp_mqtt_client_publish(client, topic, "message", 0, 2, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos == 2); - TEST_ASSERT_TRUE(esp_mqtt_client_publish(client, topic, "message", 0, 1, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos == 1); - esp_mqtt_client_destroy(client); - vEventGroupDelete(s_event_group); - free(topic); - return true; -} - -bool mqtt5_lwt_clean_disconnect(void) -{ - char* lwt = append_mac("lwt"); - TEST_ASSERT_TRUE(lwt); - const esp_mqtt_client_config_t mqtt5_cfg1 = { - .broker.address.uri = CONFIG_MQTT5_TEST_BROKER_URI, - .credentials.set_null_client_id = true, - .session.last_will.topic = lwt, - .session.last_will.msg = "lwt_msg", - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - const esp_mqtt_client_config_t mqtt5_cfg2 = { - .broker.address.uri = CONFIG_MQTT5_TEST_BROKER_URI, - .credentials.set_null_client_id = true, - .session.last_will.topic = lwt, - .session.last_will.msg = "lwt_msg", - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - esp_mqtt5_connection_property_config_t connect_property = { - .will_delay_interval = 10, - .payload_format_indicator = true, - .message_expiry_interval = 10, - .content_type = "json", - .response_topic = "/test/response", - .correlation_data = "123456", - .correlation_data_len = 6, - }; - s_event_group = xEventGroupCreate(); - - esp_mqtt_client_handle_t client1 = esp_mqtt_client_init(&mqtt5_cfg1); - esp_mqtt_client_handle_t client2 = esp_mqtt_client_init(&mqtt5_cfg2); - TEST_ASSERT_TRUE(NULL != client1 && NULL != client2 ); - esp_mqtt_client_register_event(client1, ESP_EVENT_ANY_ID, mqtt5_event_handler, NULL); - esp_mqtt_client_register_event(client2, ESP_EVENT_ANY_ID, mqtt5_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_connect_property(client1, &connect_property)); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt5_client_set_connect_property(client2, &connect_property)); - TEST_ASSERT_TRUE(esp_mqtt_client_start(client1) == ESP_OK); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(esp_mqtt_client_start(client2) == ESP_OK); - WAIT_FOR_EVENT(CONNECT_BIT); - int counter = 0; - esp_mqtt_client_register_event(client1, MQTT_EVENT_DATA, mqtt5_data_handler_lwt, &counter); - esp_mqtt_client_register_event(client2, MQTT_EVENT_DATA, mqtt5_data_handler_lwt, &counter); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client1, lwt, 0) != -1); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client2, lwt, 0) != -1); - esp_mqtt_client_disconnect(client1); - WAIT_FOR_EVENT(DISCONNECT_BIT); - esp_mqtt_client_reconnect(client1); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client1, lwt, 0) != -1); - esp_mqtt_client_stop(client2); - esp_mqtt_client_start(client2); - WAIT_FOR_EVENT(CONNECT_BIT); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client2, lwt, 0) != -1); - TEST_ASSERT_TRUE(esp_mqtt_client_publish(client1, lwt, "no-lwt", 0, 0, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(counter == 0); - esp_mqtt_client_destroy(client1); - esp_mqtt_client_destroy(client2); - vEventGroupDelete(s_event_group); - free(lwt); - return true; -} - -bool mqtt5_subscribe_payload(void) -{ - const esp_mqtt_client_config_t mqtt5_cfg = { - .broker.address.uri = CONFIG_MQTT5_TEST_BROKER_URI, - .network.disable_auto_reconnect = true, - .session.protocol_ver = MQTT_PROTOCOL_V_5, - }; - char* topic = append_mac("topic"); - TEST_ASSERT_TRUE(NULL != topic); - s_event_group = xEventGroupCreate(); - esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt5_cfg); - TEST_ASSERT_TRUE(NULL != client ); - esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt5_event_handler, NULL); - TEST_ASSERT_TRUE(ESP_OK == esp_mqtt_client_start(client)); - WAIT_FOR_EVENT(CONNECT_BIT); - int qos_payload = -1; - esp_mqtt_client_register_event(client, MQTT_EVENT_SUBSCRIBED, mqtt5_data_handler_subscribe, &qos_payload); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client, topic, 2) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos_payload == 2); - TEST_ASSERT_TRUE(esp_mqtt_client_subscribe(client, topic, 0) != -1); - WAIT_FOR_EVENT(DATA_BIT); - TEST_ASSERT_TRUE(qos_payload == 0); - esp_mqtt_client_destroy(client); - vEventGroupDelete(s_event_group); - free(topic); - return true; -} diff --git a/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5_client_broker.h b/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5_client_broker.h deleted file mode 100644 index a181dd8e068d..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/main/test_mqtt5_client_broker.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once -#include "esp_log.h" - -/** - * @brief MQTT5 client-broker tests are not implemented as separate test cases - * due to time consuming connection setup/teardown. - * This utility macro is used to run functional cases as MQTT tests - * and evaluate as separate assertions in one "mqtt5 broker tests" test case. - */ -#define RUN_MQTT5_BROKER_TEST(test_name) \ - do { \ - ESP_LOGI("mqtt5_test", "Running test:" #test_name "()"); \ - TEST_ASSERT_TRUE_MESSAGE(test_name(), "Mqtt5 test failed: " #test_name "() "); \ - ESP_LOGI("mqtt5_test", "Test:" #test_name "() passed "); \ - } while(0) - - -/** - * @brief This module contains mqtt5 test cases interacting the client with a (real) broker - */ - -/** - * @brief The client subscribes and publishes on the same topic - * and verifies the received published qos in the event - */ -bool mqtt5_subscribe_publish(void); - -/** - * @brief The client connects, disconnects and reconnects. - * Tests basic client state transitions - */ -bool mqtt5_connect_disconnect(void); - -/** - * @brief Two clients with defined lwt connect and subscribe to lwt topic. - * This test verifies that no lwt is send when each of the client disconnects. - * (we expect a clean disconnection, so no last-will being sent) - */ -bool mqtt5_lwt_clean_disconnect(void); - -/** - * @brief The client subscribes to a topic with certain qos - * and verifies the qos in SUBACK message from the broker. - */ -bool mqtt5_subscribe_payload(void); diff --git a/components/mqtt/test_apps/test_mqtt5/pytest_mqtt5_ut.py b/components/mqtt/test_apps/test_mqtt5/pytest_mqtt5_ut.py deleted file mode 100644 index 35766cbc7f90..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/pytest_mqtt5_ut.py +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Unlicense OR CC0-1.0 -import pytest -from pytest_embedded import Dut - - -@pytest.mark.esp32 -@pytest.mark.esp32c2 -@pytest.mark.ethernet -def test_mqtt5_client(dut: Dut) -> None: - dut.expect_unity_test_output() diff --git a/components/mqtt/test_apps/test_mqtt5/sdkconfig.defaults b/components/mqtt/test_apps/test_mqtt5/sdkconfig.defaults deleted file mode 100644 index 06c58d7b6a56..000000000000 --- a/components/mqtt/test_apps/test_mqtt5/sdkconfig.defaults +++ /dev/null @@ -1,4 +0,0 @@ -# General options for additional checks -CONFIG_ESP_TASK_WDT_EN=n -CONFIG_MQTT_PROTOCOL_5=y -CONFIG_UNITY_ENABLE_FIXTURE=y diff --git a/components/soc/esp32c2/include/soc/soc.h b/components/soc/esp32c2/include/soc/soc.h index 038ecf381635..373500290053 100644 --- a/components/soc/esp32c2/include/soc/soc.h +++ b/components/soc/esp32c2/include/soc/soc.h @@ -30,6 +30,7 @@ #define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // only one GPSPI #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Registers Operation {{ diff --git a/components/soc/esp32c2/include/soc/soc_caps.h b/components/soc/esp32c2/include/soc/soc_caps.h index 94e4a0a77963..16343b8177ec 100644 --- a/components/soc/esp32c2/include/soc/soc_caps.h +++ b/components/soc/esp32c2/include/soc/soc_caps.h @@ -67,6 +67,8 @@ #define SOC_ADC_PATT_LEN_MAX (8) /*!< One pattern table, each contains 8 items. Each item takes 1 byte */ #define SOC_ADC_DIGI_MIN_BITWIDTH (12) #define SOC_ADC_DIGI_MAX_BITWIDTH (12) +#define SOC_ADC_DIGI_RESULT_BYTES (4) +#define SOC_ADC_DIGI_DATA_BYTES_PER_CONV (4) #define SOC_ADC_DIGI_IIR_FILTER_NUM (2) #define SOC_ADC_DIGI_MONITOR_NUM (2) /*!< F_sample = F_digi_con / 2 / interval. F_digi_con = 5M for now. 30 <= interval<= 4095 */ diff --git a/components/soc/esp32c2/include/soc/spi_reg.h b/components/soc/esp32c2/include/soc/spi_reg.h index 24fa77c80ebc..eaa92535e1ec 100644 --- a/components/soc/esp32c2/include/soc/spi_reg.h +++ b/components/soc/esp32c2/include/soc/spi_reg.h @@ -6,12 +6,11 @@ #ifndef _SOC_SPI_REG_H_ #define _SOC_SPI_REG_H_ +#include "soc/soc.h" #ifdef __cplusplus extern "C" { #endif -#include "soc/soc.h" -#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (i - 2) * 0x1000) #define SPI_CMD_REG(i) (REG_SPI_BASE(i) + 0x0) /* SPI_USR : R/W/SC ;bitpos:[24] ;default: 1'b0 ; */ diff --git a/components/soc/esp32c2/ld/esp32c2.peripherals.ld b/components/soc/esp32c2/ld/esp32c2.peripherals.ld index 6ae565bbb986..3484877eeac1 100644 --- a/components/soc/esp32c2/ld/esp32c2.peripherals.ld +++ b/components/soc/esp32c2/ld/esp32c2.peripherals.ld @@ -16,7 +16,6 @@ PROVIDE ( LEDC = 0x60019000 ); PROVIDE ( TIMERG0 = 0x6001F000 ); PROVIDE ( SYSTIMER = 0x60023000 ); PROVIDE ( GPSPI2 = 0x60024000 ); -PROVIDE ( GPSPI3 = 0x60025000 ); PROVIDE ( SYSCON = 0x60026000 ); PROVIDE ( APB_SARADC = 0x60040000 ); PROVIDE ( GDMA = 0x6003F000 ); diff --git a/components/soc/esp32c3/include/soc/soc.h b/components/soc/esp32c3/include/soc/soc.h index 1fb082c844ce..8d9c68ef545f 100644 --- a/components/soc/esp32c3/include/soc/soc.h +++ b/components/soc/esp32c3/include/soc/soc.h @@ -23,6 +23,7 @@ #define REG_I2S_BASE(i) (DR_REG_I2S_BASE + (i) * 0x1E000) #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // only one GPSPI #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Registers Operation {{ diff --git a/components/soc/esp32c3/include/soc/spi_reg.h b/components/soc/esp32c3/include/soc/spi_reg.h index a08cb24f3cda..9bfeb798e14f 100644 --- a/components/soc/esp32c3/include/soc/spi_reg.h +++ b/components/soc/esp32c3/include/soc/spi_reg.h @@ -14,11 +14,11 @@ #ifndef _SOC_SPI_REG_H_ #define _SOC_SPI_REG_H_ +#include "soc.h" #ifdef __cplusplus extern "C" { #endif -#include "soc.h" #define SPI_CMD_REG(i) (REG_SPI_BASE(i) + 0x0) /* SPI_USR : R/W/SC ;bitpos:[24] ;default: 1'b0 ; */ diff --git a/components/soc/esp32c3/ld/esp32c3.peripherals.ld b/components/soc/esp32c3/ld/esp32c3.peripherals.ld index 804869683d72..12b81a44a82a 100644 --- a/components/soc/esp32c3/ld/esp32c3.peripherals.ld +++ b/components/soc/esp32c3/ld/esp32c3.peripherals.ld @@ -26,10 +26,8 @@ PROVIDE ( TIMERG0 = 0x6001F000 ); PROVIDE ( TIMERG1 = 0x60020000 ); PROVIDE ( SYSTIMER = 0x60023000 ); PROVIDE ( GPSPI2 = 0x60024000 ); -PROVIDE ( GPSPI3 = 0x60025000 ); PROVIDE ( SYSCON = 0x60026000 ); PROVIDE ( TWAI = 0x6002B000 ); -PROVIDE ( GPSPI4 = 0x60037000 ); PROVIDE ( APB_SARADC = 0x60040000 ); PROVIDE ( USB_SERIAL_JTAG = 0x60043000 ); PROVIDE ( GDMA = 0x6003F000 ); diff --git a/components/soc/esp32c6/include/soc/soc.h b/components/soc/esp32c6/include/soc/soc.h index 70e3a947f4a4..8ec5a1a08925 100644 --- a/components/soc/esp32c6/include/soc/soc.h +++ b/components/soc/esp32c6/include/soc/soc.h @@ -23,10 +23,10 @@ #define REG_I2S_BASE(i) (DR_REG_I2S_BASE) // only one I2S on C6 #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i) * 0x1000) // TIMERG0 and TIMERG1 #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE + (i) * 0x1000) // SPIMEM0 and SPIMEM1 -#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE) // only one GPSPI on C6 +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // only one GPSPI on C6 #define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE) // only one I2C on C6 #define REG_MCPWM_BASE(i) (DR_REG_MCPWM_BASE) // only one MCPWM on C6 -#define REG_TWAI_BASE(i) (DR_REG_TWAI0_BASE + (i) * 0x2000) // TWAI0 and TWAI1 +#define REG_TWAI_BASE(i) (DR_REG_TWAI0_BASE + (i) * 0x2000) // TWAI0 and TWAI1 //Registers Operation {{ #define ETS_UNCACHED_ADDR(addr) (addr) diff --git a/components/soc/esp32h2/include/soc/soc.h b/components/soc/esp32h2/include/soc/soc.h index df23f1f34d90..667b0b9076ef 100644 --- a/components/soc/esp32h2/include/soc/soc.h +++ b/components/soc/esp32h2/include/soc/soc.h @@ -23,8 +23,8 @@ #define REG_I2S_BASE(i) (DR_REG_I2S_BASE + (i) * 0x1E000) #define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE + (i) * 0x1000) +#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (i - 2) * 0x1000) // only one GPSPI #define REG_I2C_BASE(i) (DR_REG_I2C_EXT0_BASE + (i) * 0x1000) -#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (i - 2) * 0x1000) //Registers Operation {{ #define ETS_UNCACHED_ADDR(addr) (addr) diff --git a/components/soc/esp32s2/include/soc/reg_base.h b/components/soc/esp32s2/include/soc/reg_base.h index dbc2d2a5ccfe..0a809c6ebf70 100644 --- a/components/soc/esp32s2/include/soc/reg_base.h +++ b/components/soc/esp32s2/include/soc/reg_base.h @@ -56,7 +56,6 @@ #define DR_REG_SYSCON_BASE 0x3f426000 #define DR_REG_APB_CTRL_BASE 0x3f426000 /* Old name for SYSCON, to be removed */ #define DR_REG_I2C1_EXT_BASE 0x3f427000 -#define DR_REG_SPI4_BASE 0x3f437000 #define DR_REG_USB_WRAP_BASE 0x3f439000 #define DR_REG_APB_SARADC_BASE 0x3f440000 #define DR_REG_USB_BASE 0x60080000 diff --git a/components/soc/esp32s2/include/soc/soc.h b/components/soc/esp32s2/include/soc/soc.h index 5b96f7d4f723..10afcc296f9f 100644 --- a/components/soc/esp32s2/include/soc/soc.h +++ b/components/soc/esp32s2/include/soc/soc.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -18,14 +18,15 @@ #define SOC_MAX_CONTIGUOUS_RAM_SIZE (SOC_EXTRAM_DATA_HIGH - SOC_EXTRAM_DATA_LOW) ///< Largest span of contiguous memory (DRAM or IRAM) in the address space -#define REG_UHCI_BASE(i) (DR_REG_UHCI0_BASE) -#define REG_UART_BASE( i ) (DR_REG_UART_BASE + (i) * 0x10000 ) -#define REG_UART_AHB_BASE(i) (0x60000000 + (i) * 0x10000 ) -#define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) -#define REG_I2S_BASE( i ) (DR_REG_I2S_BASE) -#define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) +#define REG_UHCI_BASE(i) (DR_REG_UHCI0_BASE) +#define REG_UART_BASE( i ) (DR_REG_UART_BASE + (i) * 0x10000 ) +#define REG_UART_AHB_BASE(i) (0x60000000 + (i) * 0x10000 ) +#define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) +#define REG_I2S_BASE( i ) (DR_REG_I2S_BASE) +#define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) -#define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) +#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (((i)>3) ? (((i-2)* 0x1000) + 0x10000) : ((i - 2)* 0x1000 ))) +#define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Convenient way to replace the register ops when ulp riscv projects //consume this file @@ -145,6 +146,7 @@ #define CPU_CLK_FREQ_MHZ_BTLD (80) // The cpu clock frequency (in MHz) to set at 2nd stage bootloader system clock configuration #define CPU_CLK_FREQ APB_CLK_FREQ #define APB_CLK_FREQ ( 80*1000000 ) //unit: Hz +#define MODEM_REQUIRED_MIN_APB_CLK_FREQ ( 80*1000000 ) #define REF_CLK_FREQ ( 1000000 ) #define UART_CLK_FREQ APB_CLK_FREQ #define WDT_CLK_FREQ APB_CLK_FREQ diff --git a/components/soc/esp32s2/include/soc/spi_mem_reg.h b/components/soc/esp32s2/include/soc/spi_mem_reg.h index fd3bf04a4197..b08abdc1fbb8 100644 --- a/components/soc/esp32s2/include/soc/spi_mem_reg.h +++ b/components/soc/esp32s2/include/soc/spi_mem_reg.h @@ -1,25 +1,16 @@ -// Copyright 2017-2018 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. +/* + * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef _SOC_SPI_MEM_REG_H_ #define _SOC_SPI_MEM_REG_H_ +#include "soc.h" #ifdef __cplusplus extern "C" { #endif -#include "soc.h" -#define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) #define SPI_MEM_CMD_REG(i) (REG_SPI_MEM_BASE(i) + 0x000) /* SPI_MEM_FLASH_READ : R/W ;bitpos:[31] ;default: 1'b0 ; */ diff --git a/components/soc/esp32s2/include/soc/spi_reg.h b/components/soc/esp32s2/include/soc/spi_reg.h index 0f0f732baa51..9dabcac5b787 100644 --- a/components/soc/esp32s2/include/soc/spi_reg.h +++ b/components/soc/esp32s2/include/soc/spi_reg.h @@ -14,12 +14,11 @@ #ifndef _SOC_SPI_REG_H_ #define _SOC_SPI_REG_H_ +#include "soc.h" #ifdef __cplusplus extern "C" { #endif -#include "soc.h" -#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE + (((i)>3) ? (((i-2)* 0x1000) + 0x10000) : ((i - 2)* 0x1000 ))) #define SPI_CMD_REG(i) (REG_SPI_BASE(i) + 0x000) /* SPI_USR : R/W ;bitpos:[24] ;default: 1'b0 ; */ diff --git a/components/soc/esp32s3/include/soc/soc.h b/components/soc/esp32s3/include/soc/soc.h index 38c0ae248086..efbd8a27aa86 100644 --- a/components/soc/esp32s3/include/soc/soc.h +++ b/components/soc/esp32s3/include/soc/soc.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -27,14 +27,15 @@ #define DR_REG_EXT_MEM_ENC 0x600CC000 -#define REG_UHCI_BASE(i) (DR_REG_UHCI0_BASE - (i) * 0x8000) -#define REG_UART_BASE( i ) (DR_REG_UART_BASE + (i) * 0x10000 + ( (i) > 1 ? 0xe000 : 0 ) ) -#define REG_UART_AHB_BASE(i) (0x60000000 + (i) * 0x10000 + ( (i) > 1 ? 0xe000 : 0 ) ) -#define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) -#define REG_I2S_BASE( i ) (DR_REG_I2S_BASE + (i) * 0x1E000) -#define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) +#define REG_UHCI_BASE(i) (DR_REG_UHCI0_BASE - (i) * 0x8000) +#define REG_UART_BASE( i ) (DR_REG_UART_BASE + (i) * 0x10000 + ( (i) > 1 ? 0xe000 : 0 ) ) +#define REG_UART_AHB_BASE(i) (0x60000000 + (i) * 0x10000 + ( (i) > 1 ? 0xe000 : 0 ) ) +#define UART_FIFO_AHB_REG(i) (REG_UART_AHB_BASE(i) + 0x0) +#define REG_I2S_BASE( i ) (DR_REG_I2S_BASE + (i) * 0x1E000) +#define REG_TIMG_BASE(i) (DR_REG_TIMERGROUP0_BASE + (i)*0x1000) #define REG_SPI_MEM_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000) -#define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) +#define REG_SPI_BASE(i) (((i)==2) ? (DR_REG_SPI2_BASE) : (DR_REG_SPI0_BASE - ((i) * 0x1000))) // GPSPI2 and GPSPI3 +#define REG_I2C_BASE(i) (DR_REG_I2C_EXT_BASE + (i) * 0x14000 ) //Convenient way to replace the register ops when ulp riscv projects //consume this file @@ -155,6 +156,7 @@ #define CPU_CLK_FREQ_MHZ_BTLD (80) // The cpu clock frequency (in MHz) to set at 2nd stage bootloader system clock configuration #define CPU_CLK_FREQ APB_CLK_FREQ #define APB_CLK_FREQ (80*1000000) +#define MODEM_REQUIRED_MIN_APB_CLK_FREQ (80*1000000) #define REF_CLK_FREQ (1000000) #define XTAL_CLK_FREQ (40*1000000) #define UART_CLK_FREQ APB_CLK_FREQ @@ -186,7 +188,7 @@ #define SOC_EXTRAM_DATA_LOW 0x3C000000 #define SOC_EXTRAM_DATA_HIGH 0x3E000000 #define SOC_IROM_MASK_LOW 0x40000000 -#define SOC_IROM_MASK_HIGH 0x4001A100 +#define SOC_IROM_MASK_HIGH 0x40060000 #define SOC_EXTRAM_DATA_SIZE (SOC_EXTRAM_DATA_HIGH - SOC_EXTRAM_DATA_LOW) #define SOC_MAX_CONTIGUOUS_RAM_SIZE (SOC_EXTRAM_DATA_HIGH - SOC_EXTRAM_DATA_LOW) ///< Largest span of contiguous memory (DRAM or IRAM) in the address space diff --git a/components/soc/esp32s3/ld/esp32s3.peripherals.ld b/components/soc/esp32s3/ld/esp32s3.peripherals.ld index f75bc70beda1..0b6d8881a23a 100644 --- a/components/soc/esp32s3/ld/esp32s3.peripherals.ld +++ b/components/soc/esp32s3/ld/esp32s3.peripherals.ld @@ -38,7 +38,6 @@ PROVIDE ( SYSCON = 0x60026000 ); PROVIDE ( I2C1 = 0x60027000 ); PROVIDE ( SDMMC = 0x60028000 ); PROVIDE ( TWAI = 0x6002B000 ); -PROVIDE ( GPSPI4 = 0x60037000 ); PROVIDE ( GDMA = 0x6003F000 ); PROVIDE ( UART2 = 0x6002E000 ); PROVIDE ( DMA = 0x6003F000 ); diff --git a/components/spiffs/.build-test-rules.yml b/components/spiffs/.build-test-rules.yml deleted file mode 100644 index c6d7af716023..000000000000 --- a/components/spiffs/.build-test-rules.yml +++ /dev/null @@ -1,9 +0,0 @@ -components/spiffs/host_test: - enable: - - if: IDF_TARGET == "linux" - reason: only test on linux - -components/spiffs/test_apps: - disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3", "esp32s3"] - reason: These chips should be sufficient for test coverage (Xtensa and RISC-V, single and dual core) diff --git a/components/spiffs/CMakeLists.txt b/components/spiffs/CMakeLists.txt deleted file mode 100644 index 142ad9ec29ef..000000000000 --- a/components/spiffs/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -idf_build_get_property(target IDF_TARGET) - -set(original_srcs "spiffs/src/spiffs_cache.c" - "spiffs/src/spiffs_check.c" - "spiffs/src/spiffs_gc.c" - "spiffs/src/spiffs_hydrogen.c" - "spiffs/src/spiffs_nucleus.c") - -list(APPEND srcs "spiffs_api.c" ${original_srcs}) - -if(NOT ${target} STREQUAL "linux") - list(APPEND pr bootloader_support esptool_py vfs) - list(APPEND srcs "esp_spiffs.c") -endif() - -idf_component_register(SRCS ${srcs} - INCLUDE_DIRS "include" - PRIV_INCLUDE_DIRS "." "spiffs/src" - REQUIRES esp_partition - PRIV_REQUIRES ${pr} spi_flash) - -if(CMAKE_C_COMPILER_ID MATCHES "GNU") - set_source_files_properties(spiffs/src/spiffs_nucleus.c PROPERTIES COMPILE_FLAGS -Wno-stringop-truncation) -endif() - -# Upstream SPIFFS code uses format specifiers in debug logging macros inconsistently -set_source_files_properties(${original_srcs} PROPERTIES COMPILE_FLAGS -Wno-format) diff --git a/components/spiffs/Kconfig b/components/spiffs/Kconfig deleted file mode 100644 index 785f3acb3e64..000000000000 --- a/components/spiffs/Kconfig +++ /dev/null @@ -1,181 +0,0 @@ -menu "SPIFFS Configuration" - - config SPIFFS_MAX_PARTITIONS - int "Maximum Number of Partitions" - default 3 - range 1 10 - help - Define maximum number of partitions that can be mounted. - - menu "SPIFFS Cache Configuration" - config SPIFFS_CACHE - bool "Enable SPIFFS Cache" - default "y" - help - Enables/disable memory read caching of nucleus file system - operations. - - config SPIFFS_CACHE_WR - bool "Enable SPIFFS Write Caching" - default "y" - depends on SPIFFS_CACHE - help - Enables memory write caching for file descriptors in hydrogen. - - config SPIFFS_CACHE_STATS - bool "Enable SPIFFS Cache Statistics" - default "n" - depends on SPIFFS_CACHE - help - Enable/disable statistics on caching. Debug/test purpose only. - - endmenu - - config SPIFFS_PAGE_CHECK - bool "Enable SPIFFS Page Check" - default "y" - help - Always check header of each accessed page to ensure consistent state. - If enabled it will increase number of reads from flash, especially - if cache is disabled. - - config SPIFFS_GC_MAX_RUNS - int "Set Maximum GC Runs" - default 10 - range 1 10000 - help - Define maximum number of GC runs to perform to reach desired free pages. - - config SPIFFS_GC_STATS - bool "Enable SPIFFS GC Statistics" - default "n" - help - 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 - range 1 256 - help - Object name maximum length. Note that this length include the - zero-termination character, meaning maximum string of characters - can at most be SPIFFS_OBJ_NAME_LEN - 1. - - SPIFFS_OBJ_NAME_LEN + SPIFFS_META_LENGTH should not exceed - SPIFFS_PAGE_SIZE - 64. - - config SPIFFS_FOLLOW_SYMLINKS - bool "Enable symbolic links for image creation" - default "n" - help - If this option is enabled, symbolic links are taken into account - during partition image creation. - - config SPIFFS_USE_MAGIC - bool "Enable SPIFFS Filesystem Magic" - default "y" - help - Enable this to have an identifiable spiffs filesystem. - This will look for a magic in all sectors to determine if this - is a valid spiffs system or not at mount time. - - config SPIFFS_USE_MAGIC_LENGTH - bool "Enable SPIFFS Filesystem Length Magic" - default "y" - depends on SPIFFS_USE_MAGIC - help - If this option is enabled, the magic will also be dependent - on the length of the filesystem. For example, a filesystem - configured and formatted for 4 megabytes will not be accepted - for mounting with a configuration defining the filesystem as 2 megabytes. - - config SPIFFS_META_LENGTH - int "Size of per-file metadata field" - default 4 - help - This option sets the number of extra bytes stored in the file header. - These bytes can be used in an application-specific manner. - Set this to at least 4 bytes to enable support for saving file - modification time. - - SPIFFS_OBJ_NAME_LEN + SPIFFS_META_LENGTH should not exceed - SPIFFS_PAGE_SIZE - 64. - - config SPIFFS_USE_MTIME - bool "Save file modification time" - default "y" - depends on SPIFFS_META_LENGTH >= 4 - help - If enabled, then the first 4 bytes of per-file metadata will be used - to store file modification time (mtime), accessible through - stat/fstat functions. - Modification time is updated when the file is opened. - - config SPIFFS_MTIME_WIDE_64_BITS - bool "The time field occupies 64 bits in the image instead of 32 bits" - default n - depends on SPIFFS_META_LENGTH >= 8 - help - If this option is not set, the time field is 32 bits (up to 2106 year), - otherwise it is 64 bits and make sure it matches SPIFFS_META_LENGTH. - If the chip already has the spiffs image with the time field = 32 bits - then this option cannot be applied in this case. - Erase it first before using this option. - To resolve the Y2K38 problem for the spiffs, use a toolchain with - 64-bit time_t support. - - menu "Debug Configuration" - - config SPIFFS_DBG - bool "Enable general SPIFFS debug" - default "n" - help - Enabling this option will print general debug mesages to the console. - - config SPIFFS_API_DBG - bool "Enable SPIFFS API debug" - default "n" - help - Enabling this option will print API debug mesages to the console. - - config SPIFFS_GC_DBG - bool "Enable SPIFFS Garbage Cleaner debug" - default "n" - help - Enabling this option will print GC debug mesages to the console. - - config SPIFFS_CACHE_DBG - bool "Enable SPIFFS Cache debug" - default "n" - depends on SPIFFS_CACHE - help - Enabling this option will print cache debug mesages to the console. - - config SPIFFS_CHECK_DBG - bool "Enable SPIFFS Filesystem Check debug" - default "n" - help - Enabling this option will print Filesystem Check debug mesages - to the console. - - config SPIFFS_TEST_VISUALISATION - bool "Enable SPIFFS Filesystem Visualization" - default "n" - help - Enable this option to enable SPIFFS_vis function in the API. - - endmenu - -endmenu diff --git a/components/spiffs/esp_spiffs.c b/components/spiffs/esp_spiffs.c deleted file mode 100644 index c6d4a5b1edf7..000000000000 --- a/components/spiffs/esp_spiffs.c +++ /dev/null @@ -1,921 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "esp_spiffs.h" -#include "spiffs.h" -#include "spiffs_nucleus.h" -#include "esp_log.h" -#include "esp_partition.h" -#include "spi_flash_mmap.h" -#include "esp_image_format.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include -#include -#include -#include -#include -#include "esp_vfs.h" -#include "esp_err.h" -#include "esp_rom_spiflash.h" - -#include "spiffs_api.h" - -static const char* TAG = "SPIFFS"; - -#ifdef CONFIG_SPIFFS_USE_MTIME -#ifdef CONFIG_SPIFFS_MTIME_WIDE_64_BITS -typedef time_t spiffs_time_t; -#else -typedef unsigned long spiffs_time_t; -#endif -_Static_assert(CONFIG_SPIFFS_META_LENGTH >= sizeof(spiffs_time_t), - "SPIFFS_META_LENGTH size should be >= sizeof(spiffs_time_t)"); -#endif //CONFIG_SPIFFS_USE_MTIME - -_Static_assert(ESP_SPIFFS_PATH_MAX == ESP_VFS_PATH_MAX, - "SPIFFS max path length has to be aligned with the VFS max path length"); - -/** - * @brief SPIFFS DIR structure - */ -typedef struct { - DIR dir; /*!< VFS DIR struct */ - spiffs_DIR d; /*!< SPIFFS DIR struct */ - struct dirent e; /*!< Last open dirent */ - long offset; /*!< Offset of the current dirent */ - char path[SPIFFS_OBJ_NAME_LEN]; /*!< Requested directory name */ -} vfs_spiffs_dir_t; - -static int spiffs_res_to_errno(s32_t fr); -static int vfs_spiffs_open(void* ctx, const char * path, int flags, int mode); -static ssize_t vfs_spiffs_write(void* ctx, int fd, const void * data, size_t size); -static ssize_t vfs_spiffs_read(void* ctx, int fd, void * dst, size_t size); -static int vfs_spiffs_close(void* ctx, int fd); -static off_t vfs_spiffs_lseek(void* ctx, int fd, off_t offset, int mode); -static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st); -#ifdef CONFIG_VFS_SUPPORT_DIR -static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st); -static int vfs_spiffs_unlink(void* ctx, const char *path); -static int vfs_spiffs_link(void* ctx, const char* n1, const char* n2); -static int vfs_spiffs_rename(void* ctx, const char *src, const char *dst); -static DIR* vfs_spiffs_opendir(void* ctx, const char* name); -static int vfs_spiffs_closedir(void* ctx, DIR* pdir); -static struct dirent* vfs_spiffs_readdir(void* ctx, DIR* pdir); -static int vfs_spiffs_readdir_r(void* ctx, DIR* pdir, - struct dirent* entry, struct dirent** out_dirent); -static long vfs_spiffs_telldir(void* ctx, DIR* pdir); -static void vfs_spiffs_seekdir(void* ctx, DIR* pdir, long offset); -static int vfs_spiffs_mkdir(void* ctx, const char* name, mode_t mode); -static int vfs_spiffs_rmdir(void* ctx, const char* name); -static int vfs_spiffs_truncate(void* ctx, const char *path, off_t length); -static int vfs_spiffs_ftruncate(void* ctx, int fd, off_t length); -#ifdef CONFIG_SPIFFS_USE_MTIME -static int vfs_spiffs_utime(void *ctx, const char *path, const struct utimbuf *times); -#endif // CONFIG_SPIFFS_USE_MTIME -#endif // CONFIG_VFS_SUPPORT_DIR -static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file f); -static time_t vfs_spiffs_get_mtime(const spiffs_stat* s); - -static esp_spiffs_t * _efs[CONFIG_SPIFFS_MAX_PARTITIONS]; - -static void esp_spiffs_free(esp_spiffs_t ** efs) -{ - esp_spiffs_t * e = *efs; - if (*efs == NULL) { - return; - } - *efs = NULL; - - if (e->fs) { - SPIFFS_unmount(e->fs); - free(e->fs); - } - vSemaphoreDelete(e->lock); - free(e->fds); - free(e->cache); - free(e->work); - free(e); -} - -static esp_err_t esp_spiffs_by_label(const char* label, int * index){ - int i; - esp_spiffs_t * p; - for (i = 0; i < CONFIG_SPIFFS_MAX_PARTITIONS; i++) { - p = _efs[i]; - if (p) { - if (!label && !p->by_label) { - *index = i; - return ESP_OK; - } - if (label && p->by_label && strncmp(label, p->partition->label, 17) == 0) { - *index = i; - return ESP_OK; - } - } - } - return ESP_ERR_NOT_FOUND; -} - -static esp_err_t esp_spiffs_get_empty(int * index){ - int i; - for (i = 0; i < CONFIG_SPIFFS_MAX_PARTITIONS; i++) { - if (_efs[i] == NULL) { - *index = i; - return ESP_OK; - } - } - return ESP_ERR_NOT_FOUND; -} - -static esp_err_t esp_spiffs_init(const esp_vfs_spiffs_conf_t* conf) -{ - int index; - //find if such partition is already mounted - if (esp_spiffs_by_label(conf->partition_label, &index) == ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - - if (esp_spiffs_get_empty(&index) != ESP_OK) { - ESP_LOGE(TAG, "max mounted partitions reached"); - 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 (%" PRIu32 ")", - 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, - subtype, conf->partition_label); - if (!partition) { - ESP_LOGE(TAG, "spiffs partition could not be found"); - return ESP_ERR_NOT_FOUND; - } - - if (partition->encrypted) { - ESP_LOGE(TAG, "spiffs can not run on encrypted partition"); - return ESP_ERR_INVALID_STATE; - } - - const size_t flash_erase_sector_size = g_rom_flashchip.sector_size; - - /* Older versions of IDF allowed creating misaligned data partitions. - * This would result in hard-to-diagnose SPIFFS failures due to failing erase operations. - */ - if (partition->address % flash_erase_sector_size != 0) { - ESP_LOGE(TAG, "spiffs partition is not aligned to flash sector size, please check the partition table"); - /* No return intentional to avoid accidentally breaking applications - * which used misaligned read-only SPIFFS partitions. - */ - } - - /* Check if the SPIFFS internal data types are wide enough. - * Casting -1 to the unsigned type produces the maximum value the type can hold. - * All the checks here are based on comments for the said data types in spiffs_config.h. - */ - if (partition->size / flash_erase_sector_size > (spiffs_block_ix) -1) { - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_block_ix type"); - return ESP_ERR_INVALID_ARG; - } - if (partition->size / log_page_size > (spiffs_page_ix) -1) { - /* For 256 byte pages the largest partition is 16MB, but larger partitions can be supported - * by increasing the page size (reducing the number of pages). - */ - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_page_ix type. Please increase CONFIG_SPIFFS_PAGE_SIZE."); - return ESP_ERR_INVALID_ARG; - } - if (2 + 2 * (partition->size / (2 * log_page_size)) > (spiffs_obj_id) -1) { - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_obj_id type. Please increase CONFIG_SPIFFS_PAGE_SIZE."); - return ESP_ERR_INVALID_ARG; - } - if (partition->size / log_page_size - 1 > (spiffs_span_ix) -1) { - ESP_LOGE(TAG, "spiffs partition is too large for spiffs_span_ix type. Please increase CONFIG_SPIFFS_PAGE_SIZE."); - return ESP_ERR_INVALID_ARG; - } - - esp_spiffs_t * efs = calloc(sizeof(esp_spiffs_t), 1); - if (efs == NULL) { - ESP_LOGE(TAG, "esp_spiffs could not be malloced"); - return ESP_ERR_NO_MEM; - } - - efs->cfg.hal_erase_f = spiffs_api_erase; - efs->cfg.hal_read_f = spiffs_api_read; - efs->cfg.hal_write_f = spiffs_api_write; - efs->cfg.log_block_size = flash_erase_sector_size; - efs->cfg.log_page_size = log_page_size; - efs->cfg.phys_addr = 0; - efs->cfg.phys_erase_block = flash_erase_sector_size; - efs->cfg.phys_size = partition->size; - - efs->by_label = conf->partition_label != NULL; - - efs->lock = xSemaphoreCreateMutex(); - if (efs->lock == NULL) { - ESP_LOGE(TAG, "mutex lock could not be created"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - - efs->fds_sz = conf->max_files * sizeof(spiffs_fd); - efs->fds = calloc(efs->fds_sz, 1); - if (efs->fds == NULL) { - ESP_LOGE(TAG, "fd buffer could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - -#if SPIFFS_CACHE - efs->cache_sz = sizeof(spiffs_cache) + conf->max_files * (sizeof(spiffs_cache_page) - + efs->cfg.log_page_size); - efs->cache = calloc(efs->cache_sz, 1); - if (efs->cache == NULL) { - ESP_LOGE(TAG, "cache buffer could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } -#endif - - const uint32_t work_sz = efs->cfg.log_page_size * 2; - efs->work = calloc(work_sz, 1); - if (efs->work == NULL) { - ESP_LOGE(TAG, "work buffer could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - - efs->fs = calloc(sizeof(spiffs), 1); - if (efs->fs == NULL) { - ESP_LOGE(TAG, "spiffs could not be allocated"); - esp_spiffs_free(&efs); - return ESP_ERR_NO_MEM; - } - - efs->fs->user_data = (void *)efs; - efs->partition = partition; - - s32_t res = SPIFFS_mount(efs->fs, &efs->cfg, efs->work, efs->fds, efs->fds_sz, - efs->cache, efs->cache_sz, spiffs_api_check); - - if (conf->format_if_mount_failed && res != SPIFFS_OK) { - ESP_LOGW(TAG, "mount failed, %" PRId32 ". formatting...", SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - res = SPIFFS_format(efs->fs); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "format failed, %" PRId32, SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - esp_spiffs_free(&efs); - return ESP_FAIL; - } - res = SPIFFS_mount(efs->fs, &efs->cfg, efs->work, efs->fds, efs->fds_sz, - efs->cache, efs->cache_sz, spiffs_api_check); - } - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "mount failed, %" PRId32, SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - esp_spiffs_free(&efs); - return ESP_FAIL; - } - _efs[index] = efs; - return ESP_OK; -} - -bool esp_spiffs_mounted(const char* partition_label) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return false; - } - return (SPIFFS_mounted(_efs[index]->fs)); -} - -esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - SPIFFS_info(_efs[index]->fs, (uint32_t *)total_bytes, (uint32_t *)used_bytes); - return ESP_OK; -} - -esp_err_t esp_spiffs_check(const char* partition_label) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - if (SPIFFS_check(_efs[index]->fs) != SPIFFS_OK) { - int spiffs_res = SPIFFS_errno(_efs[index]->fs); - ESP_LOGE(TAG, "SPIFFS_check failed (%d)", spiffs_res); - errno = spiffs_res_to_errno(SPIFFS_errno(_efs[index]->fs)); - SPIFFS_clearerr(_efs[index]->fs); - return ESP_FAIL; - } - return ESP_OK; -} - -esp_err_t esp_spiffs_format(const char* partition_label) -{ - bool partition_was_mounted = false; - int index; - /* If the partition is not mounted, need to create SPIFFS structures - * and mount the partition, unmount, format, delete SPIFFS structures. - * See SPIFFS wiki for the reason why. - */ - esp_err_t err = esp_spiffs_by_label(partition_label, &index); - if (err != ESP_OK) { - esp_vfs_spiffs_conf_t conf = { - .format_if_mount_failed = true, - .partition_label = partition_label, - .max_files = 1 - }; - err = esp_spiffs_init(&conf); - if (err != ESP_OK) { - return err; - } - err = esp_spiffs_by_label(partition_label, &index); - assert(err == ESP_OK && "failed to get index of the partition just mounted"); - } else if (SPIFFS_mounted(_efs[index]->fs)) { - partition_was_mounted = true; - } - - SPIFFS_unmount(_efs[index]->fs); - - s32_t res = SPIFFS_format(_efs[index]->fs); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "format failed, %" PRId32, SPIFFS_errno(_efs[index]->fs)); - SPIFFS_clearerr(_efs[index]->fs); - /* If the partition was previously mounted, but format failed, don't - * try to mount the partition back (it will probably fail). On the - * other hand, if it was not mounted, need to clean up. - */ - if (!partition_was_mounted) { - esp_spiffs_free(&_efs[index]); - } - return ESP_FAIL; - } - - if (partition_was_mounted) { - res = SPIFFS_mount(_efs[index]->fs, &_efs[index]->cfg, _efs[index]->work, - _efs[index]->fds, _efs[index]->fds_sz, _efs[index]->cache, - _efs[index]->cache_sz, spiffs_api_check); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "mount failed, %" PRId32, SPIFFS_errno(_efs[index]->fs)); - SPIFFS_clearerr(_efs[index]->fs); - return ESP_FAIL; - } - } else { - esp_spiffs_free(&_efs[index]); - } - return ESP_OK; -} - -esp_err_t esp_spiffs_gc(const char* partition_label, size_t size_to_gc) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - int res = SPIFFS_gc(_efs[index]->fs, size_to_gc); - if (res != SPIFFS_OK) { - ESP_LOGE(TAG, "SPIFFS_gc failed, %d", res); - SPIFFS_clearerr(_efs[index]->fs); - if (res == SPIFFS_ERR_FULL) { - return ESP_ERR_NOT_FINISHED; - } - return ESP_FAIL; - } - return ESP_OK; -} - -esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf) -{ - assert(conf->base_path); - const esp_vfs_t vfs = { - .flags = ESP_VFS_FLAG_CONTEXT_PTR, - .write_p = &vfs_spiffs_write, - .lseek_p = &vfs_spiffs_lseek, - .read_p = &vfs_spiffs_read, - .open_p = &vfs_spiffs_open, - .close_p = &vfs_spiffs_close, - .fstat_p = &vfs_spiffs_fstat, -#ifdef CONFIG_VFS_SUPPORT_DIR - .stat_p = &vfs_spiffs_stat, - .link_p = &vfs_spiffs_link, - .unlink_p = &vfs_spiffs_unlink, - .rename_p = &vfs_spiffs_rename, - .opendir_p = &vfs_spiffs_opendir, - .closedir_p = &vfs_spiffs_closedir, - .readdir_p = &vfs_spiffs_readdir, - .readdir_r_p = &vfs_spiffs_readdir_r, - .seekdir_p = &vfs_spiffs_seekdir, - .telldir_p = &vfs_spiffs_telldir, - .mkdir_p = &vfs_spiffs_mkdir, - .rmdir_p = &vfs_spiffs_rmdir, - .truncate_p = &vfs_spiffs_truncate, - .ftruncate_p = &vfs_spiffs_ftruncate, -#ifdef CONFIG_SPIFFS_USE_MTIME - .utime_p = &vfs_spiffs_utime, -#else - .utime_p = NULL, -#endif // CONFIG_SPIFFS_USE_MTIME -#endif // CONFIG_VFS_SUPPORT_DIR - }; - - esp_err_t err = esp_spiffs_init(conf); - if (err != ESP_OK) { - return err; - } - - int index; - if (esp_spiffs_by_label(conf->partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - - strlcat(_efs[index]->base_path, conf->base_path, ESP_VFS_PATH_MAX + 1); - err = esp_vfs_register(conf->base_path, &vfs, _efs[index]); - if (err != ESP_OK) { - esp_spiffs_free(&_efs[index]); - return err; - } - - return ESP_OK; -} - -esp_err_t esp_vfs_spiffs_unregister(const char* partition_label) -{ - int index; - if (esp_spiffs_by_label(partition_label, &index) != ESP_OK) { - return ESP_ERR_INVALID_STATE; - } - esp_err_t err = esp_vfs_unregister(_efs[index]->base_path); - if (err != ESP_OK) { - return err; - } - esp_spiffs_free(&_efs[index]); - return ESP_OK; -} - -static int spiffs_res_to_errno(s32_t fr) -{ - switch(fr) { - case SPIFFS_OK : - return 0; - case SPIFFS_ERR_NOT_MOUNTED : - return ENODEV; - case SPIFFS_ERR_NOT_A_FS : - return ENODEV; - case SPIFFS_ERR_FULL : - return ENOSPC; - case SPIFFS_ERR_BAD_DESCRIPTOR : - return EBADF; - case SPIFFS_ERR_MOUNTED : - return EEXIST; - case SPIFFS_ERR_FILE_EXISTS : - return EEXIST; - case SPIFFS_ERR_NOT_FOUND : - return ENOENT; - case SPIFFS_ERR_NOT_A_FILE : - return ENOENT; - case SPIFFS_ERR_DELETED : - return ENOENT; - case SPIFFS_ERR_FILE_DELETED : - return ENOENT; - case SPIFFS_ERR_NAME_TOO_LONG : - return ENAMETOOLONG; - case SPIFFS_ERR_RO_NOT_IMPL : - return EROFS; - case SPIFFS_ERR_RO_ABORTED_OPERATION : - return EROFS; - default : - return EIO; - } - return ENOTSUP; -} - -static int spiffs_mode_conv(int m) -{ - int res = 0; - int acc_mode = m & O_ACCMODE; - if (acc_mode == O_RDONLY) { - res |= SPIFFS_O_RDONLY; - } else if (acc_mode == O_WRONLY) { - res |= SPIFFS_O_WRONLY; - } else if (acc_mode == O_RDWR) { - res |= SPIFFS_O_RDWR; - } - if ((m & O_CREAT) && (m & O_EXCL)) { - res |= SPIFFS_O_CREAT | SPIFFS_O_EXCL; - } else if ((m & O_CREAT) && (m & O_TRUNC)) { - res |= SPIFFS_O_CREAT | SPIFFS_O_TRUNC; - } - if (m & O_APPEND) { - res |= SPIFFS_O_CREAT | SPIFFS_O_APPEND; - } - return res; -} - -static int vfs_spiffs_open(void* ctx, const char * path, int flags, int mode) -{ - assert(path); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int spiffs_flags = spiffs_mode_conv(flags); - int fd = SPIFFS_open(efs->fs, path, spiffs_flags, mode); - if (fd < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - if (!(spiffs_flags & SPIFFS_RDONLY)) { - vfs_spiffs_update_mtime(efs->fs, fd); - } - return fd; -} - -static ssize_t vfs_spiffs_write(void* ctx, int fd, const void * data, size_t size) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - ssize_t res = SPIFFS_write(efs->fs, fd, (void *)data, size); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static ssize_t vfs_spiffs_read(void* ctx, int fd, void * dst, size_t size) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - ssize_t res = SPIFFS_read(efs->fs, fd, dst, size); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_close(void* ctx, int fd) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_close(efs->fs, fd); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static off_t vfs_spiffs_lseek(void* ctx, int fd, off_t offset, int mode) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - off_t res = SPIFFS_lseek(efs->fs, fd, offset, mode); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_fstat(void* ctx, int fd, struct stat * st) -{ - assert(st); - spiffs_stat s; - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - off_t res = SPIFFS_fstat(efs->fs, fd, &s); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - memset(st, 0, sizeof(*st)); - st->st_size = s.size; - st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFREG; - st->st_mtime = vfs_spiffs_get_mtime(&s); - st->st_atime = 0; - st->st_ctime = 0; - return res; -} - -#ifdef CONFIG_VFS_SUPPORT_DIR - -static int vfs_spiffs_stat(void* ctx, const char * path, struct stat * st) -{ - assert(path); - assert(st); - spiffs_stat s; - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - off_t res = SPIFFS_stat(efs->fs, path, &s); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - memset(st, 0, sizeof(*st)); - st->st_size = s.size; - st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO; - st->st_mode |= (s.type == SPIFFS_TYPE_DIR)?S_IFDIR:S_IFREG; - st->st_mtime = vfs_spiffs_get_mtime(&s); - st->st_atime = 0; - st->st_ctime = 0; - return res; -} - -static int vfs_spiffs_rename(void* ctx, const char *src, const char *dst) -{ - assert(src); - assert(dst); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_rename(efs->fs, src, dst); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_unlink(void* ctx, const char *path) -{ - assert(path); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_remove(efs->fs, path); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static DIR* vfs_spiffs_opendir(void* ctx, const char* name) -{ - assert(name); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = calloc(1, sizeof(vfs_spiffs_dir_t)); - if (!dir) { - errno = ENOMEM; - return NULL; - } - if (!SPIFFS_opendir(efs->fs, name, &dir->d)) { - free(dir); - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return NULL; - } - dir->offset = 0; - strlcpy(dir->path, name, SPIFFS_OBJ_NAME_LEN); - return (DIR*) dir; -} - -static int vfs_spiffs_closedir(void* ctx, DIR* pdir) -{ - assert(pdir); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - int res = SPIFFS_closedir(&dir->d); - free(dir); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static struct dirent* vfs_spiffs_readdir(void* ctx, DIR* pdir) -{ - assert(pdir); - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - struct dirent* out_dirent; - int err = vfs_spiffs_readdir_r(ctx, pdir, &dir->e, &out_dirent); - if (err != 0) { - errno = err; - return NULL; - } - return out_dirent; -} - -static int vfs_spiffs_readdir_r(void* ctx, DIR* pdir, struct dirent* entry, - struct dirent** out_dirent) -{ - assert(pdir); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - struct spiffs_dirent out; - size_t plen; - char * item_name; - do { - if (SPIFFS_readdir(&dir->d, &out) == 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - if (!errno) { - *out_dirent = NULL; - } - return errno; - } - item_name = (char *)out.name; - plen = strlen(dir->path); - - } while ((plen > 1) && (strncasecmp(dir->path, (const char*)out.name, plen) || out.name[plen] != '/' || !out.name[plen + 1])); - - if (plen > 1) { - item_name += plen + 1; - } else if (item_name[0] == '/') { - item_name++; - } - entry->d_ino = 0; - entry->d_type = out.type; - strncpy(entry->d_name, item_name, SPIFFS_OBJ_NAME_LEN); - entry->d_name[SPIFFS_OBJ_NAME_LEN - 1] = '\0'; - dir->offset++; - *out_dirent = entry; - return 0; -} - -static long vfs_spiffs_telldir(void* ctx, DIR* pdir) -{ - assert(pdir); - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - return dir->offset; -} - -static void vfs_spiffs_seekdir(void* ctx, DIR* pdir, long offset) -{ - assert(pdir); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - vfs_spiffs_dir_t * dir = (vfs_spiffs_dir_t *)pdir; - struct spiffs_dirent tmp; - if (offset < dir->offset) { - //rewind dir - SPIFFS_closedir(&dir->d); - if (!SPIFFS_opendir(efs->fs, NULL, &dir->d)) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return; - } - dir->offset = 0; - } - while (dir->offset < offset) { - if (SPIFFS_readdir(&dir->d, &tmp) == 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return; - } - size_t plen = strlen(dir->path); - if (plen > 1) { - if (strncasecmp(dir->path, (const char *)tmp.name, plen) || tmp.name[plen] != '/' || !tmp.name[plen+1]) { - continue; - } - } - dir->offset++; - } -} - -static int vfs_spiffs_mkdir(void* ctx, const char* name, mode_t mode) -{ - errno = ENOTSUP; - return -1; -} - -static int vfs_spiffs_rmdir(void* ctx, const char* name) -{ - errno = ENOTSUP; - return -1; -} - -static int vfs_spiffs_truncate(void* ctx, const char *path, off_t length) -{ - assert(path); - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int fd = SPIFFS_open(efs->fs, path, SPIFFS_WRONLY, 0); - if (fd < 0) { - goto err; - } - - int res = SPIFFS_ftruncate(efs->fs, fd, length); - if (res < 0) { - (void)SPIFFS_close(efs->fs, fd); - goto err; - } - - res = SPIFFS_close(efs->fs, fd); - if (res < 0) { - goto err; - } - return res; -err: - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; -} - -static int vfs_spiffs_ftruncate(void* ctx, int fd, off_t length) -{ - esp_spiffs_t * efs = (esp_spiffs_t *)ctx; - int res = SPIFFS_ftruncate(efs->fs, fd, length); - if (res < 0) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - return res; -} - -static int vfs_spiffs_link(void* ctx, const char* n1, const char* n2) -{ - errno = ENOTSUP; - return -1; -} - -#ifdef CONFIG_SPIFFS_USE_MTIME -static int vfs_spiffs_update_mtime_value(spiffs *fs, const char *path, spiffs_time_t t) -{ - int ret = SPIFFS_OK; - spiffs_stat s; - if (CONFIG_SPIFFS_META_LENGTH > sizeof(t)) { - ret = SPIFFS_stat(fs, path, &s); - } - if (ret == SPIFFS_OK) { - memcpy(s.meta, &t, sizeof(t)); - ret = SPIFFS_update_meta(fs, path, s.meta); - } - if (ret != SPIFFS_OK) { - ESP_LOGW(TAG, "Failed to update mtime (%d)", ret); - } - return ret; -} -#endif //CONFIG_SPIFFS_USE_MTIME - -#ifdef CONFIG_SPIFFS_USE_MTIME -static int vfs_spiffs_utime(void *ctx, const char *path, const struct utimbuf *times) -{ - assert(path); - - esp_spiffs_t *efs = (esp_spiffs_t *) ctx; - spiffs_time_t t; - - if (times) { - t = (spiffs_time_t)times->modtime; - } else { - // use current time - t = (spiffs_time_t)time(NULL); - } - - int ret = vfs_spiffs_update_mtime_value(efs->fs, path, t); - - if (ret != SPIFFS_OK) { - errno = spiffs_res_to_errno(SPIFFS_errno(efs->fs)); - SPIFFS_clearerr(efs->fs); - return -1; - } - - return 0; -} -#endif //CONFIG_SPIFFS_USE_MTIME - -#endif // CONFIG_VFS_SUPPORT_DIR - -static void vfs_spiffs_update_mtime(spiffs *fs, spiffs_file fd) -{ -#ifdef CONFIG_SPIFFS_USE_MTIME - spiffs_time_t t = (spiffs_time_t)time(NULL); - spiffs_stat s; - int ret = SPIFFS_OK; - if (CONFIG_SPIFFS_META_LENGTH > sizeof(t)) { - ret = SPIFFS_fstat(fs, fd, &s); - } - if (ret == SPIFFS_OK) { - memcpy(s.meta, &t, sizeof(t)); - ret = SPIFFS_fupdate_meta(fs, fd, s.meta); - } - if (ret != SPIFFS_OK) { - ESP_LOGW(TAG, "Failed to update mtime (%d)", ret); - } -#endif //CONFIG_SPIFFS_USE_MTIME -} - -static time_t vfs_spiffs_get_mtime(const spiffs_stat* s) -{ -#ifdef CONFIG_SPIFFS_USE_MTIME - spiffs_time_t t = 0; - memcpy(&t, s->meta, sizeof(t)); -#else - time_t t = 0; -#endif - return (time_t)t; -} diff --git a/components/spiffs/host_test/CMakeLists.txt b/components/spiffs/host_test/CMakeLists.txt deleted file mode 100644 index 521c80b60d3c..000000000000 --- a/components/spiffs/host_test/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(COMPONENTS main) -# Freertos is included via common components, however, currently only the mock component is compatible with linux -# target. -list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/") - -project(host_test_spiffs) - -# Custom procedure to build/clean image.bin -add_custom_target(image.bin) - -# Expand image.bin to the same size as "spiffs" partition in partition_table.csv - 2*1024*1024 = 2097152 = 2M -add_custom_command( - TARGET image.bin - POST_BUILD - COMMAND python ../../spiffsgen.py 2097152 ../../spiffs ${build_dir}/image.bin -) - -set_property( - DIRECTORY - APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${build_dir}/image.bin") - - -add_dependencies(host_test_spiffs.elf image.bin) diff --git a/components/spiffs/host_test/README.md b/components/spiffs/host_test/README.md deleted file mode 100644 index a545955fa399..000000000000 --- a/components/spiffs/host_test/README.md +++ /dev/null @@ -1,17 +0,0 @@ -| Supported Targets | Linux | -| ----------------- | ----- | - -This is a test project for spiffs-related APIs on Linux target (CONFIG_IDF_TARGET_LINUX). - -# Build -Source the IDF environment as usual. - -Once this is done, build the application: -```bash -idf.py build -``` - -# Run -```bash -idf.py monitor -``` diff --git a/components/spiffs/host_test/main/CMakeLists.txt b/components/spiffs/host_test/main/CMakeLists.txt deleted file mode 100644 index 9e7cfedc7595..000000000000 --- a/components/spiffs/host_test/main/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -idf_component_register(SRCS "host_test_spiffs.c" - PRIV_INCLUDE_DIRS "../.." "../../spiffs/src" - REQUIRES spiffs unity) - -# set BUILD_DIR because test uses a file created in the build directory -target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"") diff --git a/components/spiffs/host_test/main/host_test_spiffs.c b/components/spiffs/host_test/main/host_test_spiffs.c deleted file mode 100644 index 5dbf0ab0d258..000000000000 --- a/components/spiffs/host_test/main/host_test_spiffs.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Mockqueue.h" - -#include "esp_partition.h" -#include "spiffs.h" -#include "spiffs_nucleus.h" -#include "spiffs_api.h" - -#include "unity.h" -#include "unity_fixture.h" - -TEST_GROUP(spiffs); - -TEST_SETUP(spiffs) -{ - // CMock init for spiffs xSemaphore* use - xQueueSemaphoreTake_IgnoreAndReturn(0); - xQueueGenericSend_IgnoreAndReturn(0); -} - -TEST_TEAR_DOWN(spiffs) -{ -} - -static void init_spiffs(spiffs *fs, uint32_t max_files) -{ - spiffs_config cfg = {}; - s32_t spiffs_res; - u32_t flash_sector_size; - - const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "storage"); - TEST_ASSERT_NOT_NULL(partition); - - // Configure objects needed by SPIFFS - esp_spiffs_t *user_data = (esp_spiffs_t *) calloc(1, sizeof(*user_data)); - user_data->partition = partition; - fs->user_data = (void *)user_data; - - flash_sector_size = 4096; - - cfg.hal_erase_f = spiffs_api_erase; - cfg.hal_read_f = spiffs_api_read; - cfg.hal_write_f = spiffs_api_write; - cfg.log_block_size = flash_sector_size; - cfg.log_page_size = CONFIG_SPIFFS_PAGE_SIZE; - cfg.phys_addr = 0; - cfg.phys_erase_block = flash_sector_size; - cfg.phys_size = partition->size; - - uint32_t work_sz = cfg.log_page_size * 2; - uint8_t *work = (uint8_t *) malloc(work_sz); - - uint32_t fds_sz = max_files * sizeof(spiffs_fd); - uint8_t *fds = (uint8_t *) malloc(fds_sz); - -#if CONFIG_SPIFFS_CACHE - uint32_t cache_sz = sizeof(spiffs_cache) + max_files * (sizeof(spiffs_cache_page) - + cfg.log_page_size); - uint8_t *cache = (uint8_t *) malloc(cache_sz); -#else - uint32_t cache_sz = 0; - uint8_t cache = NULL; -#endif - - // Special mounting procedure: mount, format, mount as per - // https://github.com/pellepl/spiffs/wiki/Using-spiffs - spiffs_res = SPIFFS_mount(fs, &cfg, work, fds, fds_sz, - cache, cache_sz, spiffs_api_check); - - if (spiffs_res == SPIFFS_ERR_NOT_A_FS) { - spiffs_res = SPIFFS_format(fs); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - spiffs_res = SPIFFS_mount(fs, &cfg, work, fds, fds_sz, - cache, cache_sz, spiffs_api_check); - } - - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); -} - -static void deinit_spiffs(spiffs *fs) -{ - SPIFFS_unmount(fs); - - free(fs->work); - free(fs->user_data); - free(fs->fd_space); - -#if CONFIG_SPIFFS_CACHE - free(fs->cache); -#endif -} - -static void check_spiffs_files(spiffs *fs, const char *base_path, char *cur_path) -{ - DIR *dir; - struct dirent *entry; - size_t len = strlen(cur_path); - - if (len == 0) { - strcpy(cur_path, base_path); - len = strlen(base_path); - } - - dir = opendir(cur_path); - TEST_ASSERT_TRUE(dir != 0); - - while ((entry = readdir(dir)) != NULL) { - char *name = entry->d_name; - - char path[PATH_MAX] = { 0 }; - - // Read the file from host FS - strcpy(path, cur_path); - strcat(path, "/"); - strcat(path, name); - - struct stat sb; - stat(path, &sb); - if (S_ISDIR(sb.st_mode)) { - if (!strcmp(name, ".") || !strcmp(name, "..")) { - continue; - } - cur_path[len] = '/'; - strcpy(cur_path + len + 1, name); - check_spiffs_files(fs, base_path, cur_path); - cur_path[len] = '\0'; - } else { - FILE *f = fopen(path, "r"); - TEST_ASSERT_NOT_NULL(f); - fseek(f, 0, SEEK_END); - long sz = ftell(f); - fseek(f, 0, SEEK_SET); - - char *f_contents = (char *) malloc(sz); - TEST_ASSERT(fread(f_contents, 1, sz, f) == sz); - fclose(f); - - s32_t spiffs_res; - - // Read the file from SPIFFS - char *spiffs_path = path + strlen(base_path); - spiffs_res = SPIFFS_open(fs, spiffs_path, SPIFFS_RDONLY, 0); - - TEST_ASSERT_TRUE(spiffs_res > SPIFFS_OK); - - spiffs_file fd = spiffs_res; - - spiffs_stat stat; - spiffs_res = SPIFFS_stat(fs, spiffs_path, &stat); - - char *spiffs_f_contents = (char *) malloc(stat.size); - spiffs_res = SPIFFS_read(fs, fd, spiffs_f_contents, stat.size); - TEST_ASSERT_TRUE(spiffs_res == stat.size); - - // Compare the contents - TEST_ASSERT_TRUE(sz == stat.size); - - bool same = memcmp(f_contents, spiffs_f_contents, sz) == 0; - TEST_ASSERT_TRUE(same); - - free(f_contents); - free(spiffs_f_contents); - } - } - closedir(dir); -} - -TEST(spiffs, format_disk_open_file_write_and_read_file) -{ - spiffs fs; - s32_t spiffs_res; - - init_spiffs(&fs, 5); - - // Open test file - spiffs_res = SPIFFS_open(&fs, "test.txt", SPIFFS_O_CREAT | SPIFFS_O_RDWR, 0); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - // Generate data - spiffs_file file = spiffs_res; - - uint32_t data_size = 100000; - - char *data = (char *) malloc(data_size); - char *read = (char *) malloc(data_size); - - for (uint32_t i = 0; i < data_size; i += sizeof(i)) { - *((uint32_t *)(data + i)) = i; - } - - // Write data to file - spiffs_res = SPIFFS_write(&fs, file, (void *)data, data_size); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - TEST_ASSERT_TRUE(spiffs_res == data_size); - - // Set the file object pointer to the beginning - spiffs_res = SPIFFS_lseek(&fs, file, 0, SPIFFS_SEEK_SET); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - // Read the file - spiffs_res = SPIFFS_read(&fs, file, (void *)read, data_size); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - TEST_ASSERT_TRUE(spiffs_res == data_size); - - // Close the test file - spiffs_res = SPIFFS_close(&fs, file); - TEST_ASSERT_TRUE(spiffs_res >= SPIFFS_OK); - - TEST_ASSERT_TRUE(memcmp(data, read, data_size) == 0); - - deinit_spiffs(&fs); - - free(read); - free(data); -} - -TEST(spiffs, can_read_spiffs_image) -{ - spiffs fs; - s32_t spiffs_res; - - const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, "storage"); - TEST_ASSERT_NOT_NULL(partition); - - // Write the contents of the image file to partition - FILE *img_file = fopen(BUILD_DIR "/image.bin", "r"); - TEST_ASSERT_NOT_NULL(img_file); - - fseek(img_file, 0, SEEK_END); - long img_size = ftell(img_file); - fseek(img_file, 0, SEEK_SET); - - char *img = (char *) malloc(img_size); - TEST_ASSERT(fread(img, 1, img_size, img_file) == img_size); - fclose(img_file); - TEST_ASSERT_EQUAL(partition->size, img_size); - - esp_partition_erase_range(partition, 0, partition->size); - esp_partition_write(partition, 0, img, img_size); - - free(img); - - // Mount the spiffs partition and init filesystem, using the contents of - // the image file - init_spiffs(&fs, 1024); - - // Check spiffs consistency - spiffs_res = SPIFFS_check(&fs); - TEST_ASSERT_TRUE(spiffs_res == SPIFFS_OK); - - char path_buf[PATH_MAX] = {0}; - - // The image is created from the spiffs source directory. Compare the files in that - // directory to the files read from the SPIFFS image. - check_spiffs_files(&fs, BUILD_DIR "/../../spiffs", path_buf); - - deinit_spiffs(&fs); -} - -TEST_GROUP_RUNNER(spiffs) -{ - RUN_TEST_CASE(spiffs, format_disk_open_file_write_and_read_file); - RUN_TEST_CASE(spiffs, can_read_spiffs_image); -} - -static void run_all_tests(void) -{ - RUN_TEST_GROUP(spiffs); -} - -int main(int argc, char **argv) -{ - UNITY_MAIN_FUNC(run_all_tests); - return 0; -} diff --git a/components/spiffs/host_test/partition_table.csv b/components/spiffs/host_test/partition_table.csv deleted file mode 100644 index 81487dc1eaf7..000000000000 --- a/components/spiffs/host_test/partition_table.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1M, -storage, data, spiffs, , 2M, diff --git a/components/spiffs/host_test/pytest_spiffs_linux.py b/components/spiffs/host_test/pytest_spiffs_linux.py deleted file mode 100644 index b4719cc5f1bd..000000000000 --- a/components/spiffs/host_test/pytest_spiffs_linux.py +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Unlicense OR CC0-1.0 -import pytest -from pytest_embedded import Dut - - -@pytest.mark.linux -@pytest.mark.host_test -def test_spiffs_linux(dut: Dut) -> None: - dut.expect_unity_test_output(timeout=5) diff --git a/components/spiffs/host_test/sdkconfig.defaults b/components/spiffs/host_test/sdkconfig.defaults deleted file mode 100644 index 275e768c6c6a..000000000000 --- a/components/spiffs/host_test/sdkconfig.defaults +++ /dev/null @@ -1,8 +0,0 @@ -CONFIG_IDF_TARGET="linux" -CONFIG_COMPILER_CXX_EXCEPTIONS=y -CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n -CONFIG_UNITY_ENABLE_FIXTURE=y -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table.csv" -CONFIG_ESPTOOLPY_FLASHSIZE="4MB" -CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y diff --git a/components/spiffs/include/esp_spiffs.h b/components/spiffs/include/esp_spiffs.h deleted file mode 100644 index 1b59b9cfde07..000000000000 --- a/components/spiffs/include/esp_spiffs.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _ESP_SPIFFS_H_ -#define _ESP_SPIFFS_H_ - -#include -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Configuration structure for esp_vfs_spiffs_register - */ -typedef struct { - const char* base_path; /*!< File path prefix associated with the filesystem. */ - const char* partition_label; /*!< Optional, label of SPIFFS partition to use. If set to NULL, first partition with subtype=spiffs will be used. */ - size_t max_files; /*!< Maximum files that could be open at the same time. */ - bool format_if_mount_failed; /*!< If true, it will format the file system if it fails to mount. */ -} esp_vfs_spiffs_conf_t; - -/** - * Register and mount SPIFFS to VFS with given path prefix. - * - * @param conf Pointer to esp_vfs_spiffs_conf_t configuration structure - * - * @return - * - ESP_OK if success - * - ESP_ERR_NO_MEM if objects could not be allocated - * - ESP_ERR_INVALID_STATE if already mounted or partition is encrypted - * - ESP_ERR_NOT_FOUND if partition for SPIFFS was not found - * - ESP_FAIL if mount or format fails - */ -esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf); - -/** - * Unregister and unmount SPIFFS from VFS - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register. - * - * @return - * - ESP_OK if successful - * - ESP_ERR_INVALID_STATE already unregistered - */ -esp_err_t esp_vfs_spiffs_unregister(const char* partition_label); - -/** - * Check if SPIFFS is mounted - * - * @param partition_label Optional, label of the partition to check. - * If not specified, first partition with subtype=spiffs is used. - * - * @return - * - true if mounted - * - false if not mounted - */ -bool esp_spiffs_mounted(const char* partition_label); - -/** - * Format the SPIFFS partition - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register. - * @return - * - ESP_OK if successful - * - ESP_FAIL on error - */ -esp_err_t esp_spiffs_format(const char* partition_label); - -/** - * Get information for SPIFFS - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register - * @param[out] total_bytes Size of the file system - * @param[out] used_bytes Current used bytes in the file system - * - * @return - * - ESP_OK if success - * - ESP_ERR_INVALID_STATE if not mounted - */ -esp_err_t esp_spiffs_info(const char* partition_label, size_t *total_bytes, size_t *used_bytes); - -/** - * Check integrity of SPIFFS - * - * @param partition_label Same label as passed to esp_vfs_spiffs_register - * @return - * - ESP_OK if successful - * - ESP_ERR_INVALID_STATE if not mounted - * - ESP_FAIL on error - */ -esp_err_t esp_spiffs_check(const char* partition_label); - - -/** - * @brief Perform garbage collection in SPIFFS partition - * - * Call this function to run GC and ensure that at least the given amount of - * space is available in the partition. This function will fail with ESP_ERR_NOT_FINISHED - * if it is not possible to reclaim the requested space (that is, not enough free - * or deleted pages in the filesystem). This function will also fail if it fails to - * reclaim the requested space after CONFIG_SPIFFS_GC_MAX_RUNS number of GC iterations. - * On one GC iteration, SPIFFS will erase one logical block (4kB). Therefore the value - * of CONFIG_SPIFFS_GC_MAX_RUNS should be set at least to the maximum expected size_to_gc, - * divided by 4096. For example, if the application expects to make room for a 1MB file and - * calls esp_spiffs_gc(label, 1024 * 1024), CONFIG_SPIFFS_GC_MAX_RUNS should be set to - * at least 256. - * On the other hand, increasing CONFIG_SPIFFS_GC_MAX_RUNS value increases the maximum - * amount of time for which any SPIFFS GC or write operation may potentially block. - * - * @param partition_label Label of the partition to be garbage-collected. - * The partition must be already mounted. - * @param size_to_gc The number of bytes that the GC process should attempt - * to make available. - * @return - * - ESP_OK on success - * - ESP_ERR_NOT_FINISHED if GC fails to reclaim the size given by size_to_gc - * - ESP_ERR_INVALID_STATE if the partition is not mounted - * - ESP_FAIL on all other errors - */ -esp_err_t esp_spiffs_gc(const char* partition_label, size_t size_to_gc); - -#ifdef __cplusplus -} -#endif - -#endif /* _ESP_SPIFFS_H_ */ diff --git a/components/spiffs/include/spiffs_config.h b/components/spiffs/include/spiffs_config.h deleted file mode 100644 index b245a5d1b54e..000000000000 --- a/components/spiffs/include/spiffs_config.h +++ /dev/null @@ -1,323 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2013-2017 Peter Andersson (pelleplutt1976gmail.com) - * - * SPDX-License-Identifier: MIT - */ -/* - * spiffs_config.h - * - * Created on: Jul 3, 2013 - * Author: petera - */ - -#ifndef SPIFFS_CONFIG_H_ -#define SPIFFS_CONFIG_H_ - -// ----------- 8< ------------ -// Following includes are for the linux test build of spiffs -// These may/should/must be removed/altered/replaced in your target -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "esp_assert.h" - -// compile time switches -#define SPIFFS_TAG "SPIFFS" - -// Set generic spiffs debug output call. -#if CONFIG_SPIFFS_DBG -#define SPIFFS_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_DBG(...) -#endif -#if CONFIG_SPIFFS_API_DBG -#define SPIFFS_API_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_API_DBG(...) -#endif -#if CONFIG_SPIFFS_DBG -#define SPIFFS_GC_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_GC_DBG(...) -#endif -#if CONFIG_SPIFFS_CACHE_DBG -#define SPIFFS_CACHE_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_CACHE_DBG(...) -#endif -#if CONFIG_SPIFFS_CHECK_DBG -#define SPIFFS_CHECK_DBG(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#else -#define SPIFFS_CHECK_DBG(...) -#endif - -// needed types -typedef int32_t s32_t; -typedef uint32_t u32_t; -typedef int16_t s16_t; -typedef uint16_t u16_t; -typedef int8_t s8_t; -typedef uint8_t u8_t; - -struct spiffs_t; -extern void spiffs_api_lock(struct spiffs_t *fs); -extern void spiffs_api_unlock(struct spiffs_t *fs); - -// Defines spiffs debug print formatters -// some general signed number -#define _SPIPRIi "%"PRIdMAX -// address -#define _SPIPRIad "%08x" -// block -#define _SPIPRIbl "%04x" -// page -#define _SPIPRIpg "%04x" -// span index -#define _SPIPRIsp "%04x" -// file descriptor -#define _SPIPRIfd "%d" -// file object id -#define _SPIPRIid "%04x" -// file flags -#define _SPIPRIfl "%02x" - - -// Enable/disable API functions to determine exact number of bytes -// for filedescriptor and cache buffers. Once decided for a configuration, -// this can be disabled to reduce flash. -#define SPIFFS_BUFFER_HELP 0 - -// Enables/disable memory read caching of nucleus file system operations. -// If enabled, memory area must be provided for cache in SPIFFS_mount. -#ifdef CONFIG_SPIFFS_CACHE -#define SPIFFS_CACHE (1) -#else -#define SPIFFS_CACHE (0) -#endif -#if SPIFFS_CACHE -// Enables memory write caching for file descriptors in hydrogen -#ifdef CONFIG_SPIFFS_CACHE_WR -#define SPIFFS_CACHE_WR (1) -#else -#define SPIFFS_CACHE_WR (0) -#endif - -// Enable/disable statistics on caching. Debug/test purpose only. -#ifdef CONFIG_SPIFFS_CACHE_STATS -#define SPIFFS_CACHE_STATS (1) -#else -#define SPIFFS_CACHE_STATS (0) -#endif -#endif - -// Always check header of each accessed page to ensure consistent state. -// If enabled it will increase number of reads, will increase flash. -#ifdef CONFIG_SPIFFS_PAGE_CHECK -#define SPIFFS_PAGE_CHECK (1) -#else -#define SPIFFS_PAGE_CHECK (0) -#endif - -// Define maximum number of gc runs to perform to reach desired free pages. -#define SPIFFS_GC_MAX_RUNS CONFIG_SPIFFS_GC_MAX_RUNS - -// Enable/disable statistics on gc. Debug/test purpose only. -#ifdef CONFIG_SPIFFS_GC_STATS -#define SPIFFS_GC_STATS (1) -#else -#define SPIFFS_GC_STATS (0) -#endif - -// Garbage collecting examines all pages in a block which and sums up -// to a block score. Deleted pages normally gives positive score and -// used pages normally gives a negative score (as these must be moved). -// To have a fair wear-leveling, the erase age is also included in score, -// whose factor normally is the most positive. -// The larger the score, the more likely it is that the block will -// picked for garbage collection. - -// Garbage collecting heuristics - weight used for deleted pages. -#define SPIFFS_GC_HEUR_W_DELET (5) -// Garbage collecting heuristics - weight used for used pages. -#define SPIFFS_GC_HEUR_W_USED (-1) -// Garbage collecting heuristics - weight used for time between -// last erased and erase of this block. -#define SPIFFS_GC_HEUR_W_ERASE_AGE (50) - -// Object name maximum length. Note that this length include the -// zero-termination character, meaning maximum string of characters -// can at most be SPIFFS_OBJ_NAME_LEN - 1. -#define SPIFFS_OBJ_NAME_LEN (CONFIG_SPIFFS_OBJ_NAME_LEN) - -// Maximum length of the metadata associated with an object. -// Setting to non-zero value enables metadata-related API but also -// changes the on-disk format, so the change is not backward-compatible. -// -// Do note: the meta length must never exceed -// logical_page_size - (SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZE) -// -// This is derived from following: -// logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) + -// spiffs_object_ix_header fields + at least some LUT entries) -#define SPIFFS_OBJ_META_LEN (CONFIG_SPIFFS_META_LENGTH) -#define SPIFFS_PAGE_EXTRA_SIZE (64) -ESP_STATIC_ASSERT(SPIFFS_OBJ_META_LEN + SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZE - <= CONFIG_SPIFFS_PAGE_SIZE, "SPIFFS_OBJ_META_LEN or SPIFFS_OBJ_NAME_LEN too long"); - -// Size of buffer allocated on stack used when copying data. -// Lower value generates more read/writes. No meaning having it bigger -// than logical page size. -#define SPIFFS_COPY_BUFFER_STACK (256) - -// Enable this to have an identifiable spiffs filesystem. This will look for -// a magic in all sectors to determine if this is a valid spiffs system or -// not on mount point. If not, SPIFFS_format must be called prior to mounting -// again. -#ifdef CONFIG_SPIFFS_USE_MAGIC -#define SPIFFS_USE_MAGIC (1) -#else -#define SPIFFS_USE_MAGIC (0) -#endif - -#if SPIFFS_USE_MAGIC -// Only valid when SPIFFS_USE_MAGIC is enabled. If SPIFFS_USE_MAGIC_LENGTH is -// enabled, the magic will also be dependent on the length of the filesystem. -// For example, a filesystem configured and formatted for 4 megabytes will not -// be accepted for mounting with a configuration defining the filesystem as 2 -// megabytes. -#ifdef CONFIG_SPIFFS_USE_MAGIC_LENGTH -#define SPIFFS_USE_MAGIC_LENGTH (1) -#else -#define SPIFFS_USE_MAGIC_LENGTH (0) -#endif -#endif - -// SPIFFS_LOCK and SPIFFS_UNLOCK protects spiffs from reentrancy on api level -// These should be defined on a multithreaded system - -// define this to enter a mutex if you're running on a multithreaded system -#define SPIFFS_LOCK(fs) spiffs_api_lock(fs) -// define this to exit a mutex if you're running on a multithreaded system -#define SPIFFS_UNLOCK(fs) spiffs_api_unlock(fs) - -// Enable if only one spiffs instance with constant configuration will exist -// on the target. This will reduce calculations, flash and memory accesses. -// Parts of configuration must be defined below instead of at time of mount. -#define SPIFFS_SINGLETON 0 - -// Enable this if your target needs aligned data for index tables -#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 0 - -// Enable this if you want the HAL callbacks to be called with the spiffs struct -#define SPIFFS_HAL_CALLBACK_EXTRA 1 - -// Enable this if you want to add an integer offset to all file handles -// (spiffs_file). This is useful if running multiple instances of spiffs on -// same target, in order to recognise to what spiffs instance a file handle -// belongs. -// NB: This adds config field fh_ix_offset in the configuration struct when -// mounting, which must be defined. -#define SPIFFS_FILEHDL_OFFSET 0 - -// Enable this to compile a read only version of spiffs. -// This will reduce binary size of spiffs. All code comprising modification -// of the file system will not be compiled. Some config will be ignored. -// HAL functions for erasing and writing to spi-flash may be null. Cache -// can be disabled for even further binary size reduction (and ram savings). -// Functions modifying the fs will return SPIFFS_ERR_RO_NOT_IMPL. -// If the file system cannot be mounted due to aborted erase operation and -// SPIFFS_USE_MAGIC is enabled, SPIFFS_ERR_RO_ABORTED_OPERATION will be -// returned. -// Might be useful for e.g. bootloaders and such. -#define SPIFFS_READ_ONLY 0 - -// Enable this to add a temporal file cache using the fd buffer. -// The effects of the cache is that SPIFFS_open will find the file faster in -// certain cases. It will make it a lot easier for spiffs to find files -// opened frequently, reducing number of readings from the spi flash for -// finding those files. -// This will grow each fd by 6 bytes. If your files are opened in patterns -// with a degree of temporal locality, the system is optimized. -// Examples can be letting spiffs serve web content, where one file is the css. -// The css is accessed for each html file that is opened, meaning it is -// accessed almost every second time a file is opened. Another example could be -// a log file that is often opened, written, and closed. -// The size of the cache is number of given file descriptors, as it piggybacks -// on the fd update mechanism. The cache lives in the closed file descriptors. -// When closed, the fd know the whereabouts of the file. Instead of forgetting -// this, the temporal cache will keep handling updates to that file even if the -// fd is closed. If the file is opened again, the location of the file is found -// directly. If all available descriptors become opened, all cache memory is -// lost. -#define SPIFFS_TEMPORAL_FD_CACHE 1 - -// Temporal file cache hit score. Each time a file is opened, all cached files -// will lose one point. If the opened file is found in cache, that entry will -// gain SPIFFS_TEMPORAL_CACHE_HIT_SCORE points. One can experiment with this -// value for the specific access patterns of the application. However, it must -// be between 1 (no gain for hitting a cached entry often) and 255. -#define SPIFFS_TEMPORAL_CACHE_HIT_SCORE 4 - -// Enable to be able to map object indices to memory. -// This allows for faster and more deterministic reading if cases of reading -// large files and when changing file offset by seeking around a lot. -// When mapping a file's index, the file system will be scanned for index pages -// and the info will be put in memory provided by user. When reading, the -// memory map can be looked up instead of searching for index pages on the -// medium. This way, user can trade memory against performance. -// Whole, parts of, or future parts not being written yet can be mapped. The -// memory array will be owned by spiffs and updated accordingly during garbage -// collecting or when modifying the indices. The latter is invoked by when the -// file is modified in some way. The index buffer is tied to the file -// descriptor. -#define SPIFFS_IX_MAP 1 - -// Set SPIFFS_TEST_VISUALISATION to non-zero to enable SPIFFS_vis function -// in the api. This function will visualize all filesystem using given printf -// function. -#ifdef CONFIG_SPIFFS_TEST_VISUALISATION -#define SPIFFS_TEST_VISUALISATION 1 -#else -#define SPIFFS_TEST_VISUALISATION 0 -#endif -#if SPIFFS_TEST_VISUALISATION -#ifndef spiffs_printf -#define spiffs_printf(...) ESP_LOGD(SPIFFS_TAG, __VA_ARGS__) -#endif -// spiffs_printf argument for a free page -#define SPIFFS_TEST_VIS_FREE_STR "_" -// spiffs_printf argument for a deleted page -#define SPIFFS_TEST_VIS_DELE_STR "/" -// spiffs_printf argument for an index page for given object id -#define SPIFFS_TEST_VIS_INDX_STR(id) "i" -// spiffs_printf argument for a data page for given object id -#define SPIFFS_TEST_VIS_DATA_STR(id) "d" -#endif - -// Types depending on configuration such as the amount of flash bytes -// given to spiffs file system in total (spiffs_file_system_size), -// the logical block size (log_block_size), and the logical page size -// (log_page_size) - -// Block index type. Make sure the size of this type can hold -// the highest number of all blocks - i.e. spiffs_file_system_size / log_block_size -typedef u16_t spiffs_block_ix; -// Page index type. Make sure the size of this type can hold -// the highest page number of all pages - i.e. spiffs_file_system_size / log_page_size -typedef u16_t spiffs_page_ix; -// Object id type - most significant bit is reserved for index flag. Make sure the -// size of this type can hold the highest object id on a full system, -// i.e. 2 + (spiffs_file_system_size / (2*log_page_size))*2 -typedef u16_t spiffs_obj_id; -// Object span index type. Make sure the size of this type can -// hold the largest possible span index on the system - -// i.e. (spiffs_file_system_size / log_page_size) - 1 -typedef u16_t spiffs_span_ix; - -#endif /* SPIFFS_CONFIG_H_ */ diff --git a/components/spiffs/project_include.cmake b/components/spiffs/project_include.cmake deleted file mode 100644 index c322a64b06d6..000000000000 --- a/components/spiffs/project_include.cmake +++ /dev/null @@ -1,68 +0,0 @@ -# spiffs_create_partition_image -# -# Create a spiffs image of the specified directory on the host during build and optionally -# have the created image flashed using `idf.py flash` -function(spiffs_create_partition_image partition base_dir) - set(options FLASH_IN_PROJECT) - set(multi DEPENDS) - cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}") - - idf_build_get_property(idf_path IDF_PATH) - set(spiffsgen_py ${PYTHON} ${idf_path}/components/spiffs/spiffsgen.py) - - get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE) - - partition_table_get_partition_info(size "--partition-name ${partition}" "size") - partition_table_get_partition_info(offset "--partition-name ${partition}" "offset") - - if("${size}" AND "${offset}") - set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin) - - if(CONFIG_SPIFFS_USE_MAGIC) - set(use_magic "--use-magic") - endif() - - if(CONFIG_SPIFFS_USE_MAGIC_LENGTH) - set(use_magic_len "--use-magic-len") - endif() - - if(CONFIG_SPIFFS_FOLLOW_SYMLINKS) - set(follow_symlinks "--follow-symlinks") - endif() - - # Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for - # contents of the base dir changing. - add_custom_target(spiffs_${partition}_bin ALL - COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file} - --page-size=${CONFIG_SPIFFS_PAGE_SIZE} - --obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN} - --meta-len=${CONFIG_SPIFFS_META_LENGTH} - ${follow_symlinks} - ${use_magic} - ${use_magic_len} - DEPENDS ${arg_DEPENDS} - ) - - set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY - ADDITIONAL_CLEAN_FILES - ${image_file}) - - idf_component_get_property(main_args esptool_py FLASH_ARGS) - idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS) - # Last (optional) parameter is the encryption for the target. In our - # case, spiffs is not encrypt so pass FALSE to the function. - esptool_py_flash_target(${partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT) - esptool_py_flash_to_partition(${partition}-flash "${partition}" "${image_file}") - - add_dependencies(${partition}-flash spiffs_${partition}_bin) - - if(arg_FLASH_IN_PROJECT) - esptool_py_flash_to_partition(flash "${partition}" "${image_file}") - add_dependencies(flash spiffs_${partition}_bin) - endif() - else() - set(message "Failed to create SPIFFS image for partition '${partition}'. " - "Check project configuration if using the correct partition table file.") - fail_at_build_time(spiffs_${partition}_bin "${message}") - endif() -endfunction() diff --git a/components/spiffs/spiffs b/components/spiffs/spiffs deleted file mode 160000 index 0dbb3f71c5f6..000000000000 --- a/components/spiffs/spiffs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0dbb3f71c5f6fae3747a9d935372773762baf852 diff --git a/components/spiffs/spiffs_api.c b/components/spiffs/spiffs_api.c deleted file mode 100644 index 207b7a67d614..000000000000 --- a/components/spiffs/spiffs_api.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "freertos/FreeRTOS.h" -#include "esp_log.h" -#include "esp_partition.h" -#include "esp_spiffs.h" -#include "spiffs_api.h" - -static const char* TAG = "SPIFFS"; - -void spiffs_api_lock(spiffs *fs) -{ - (void) xSemaphoreTake(((esp_spiffs_t *)(fs->user_data))->lock, portMAX_DELAY); -} - -void spiffs_api_unlock(spiffs *fs) -{ - xSemaphoreGive(((esp_spiffs_t *)(fs->user_data))->lock); -} - -s32_t spiffs_api_read(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *dst) -{ - esp_err_t err = esp_partition_read(((esp_spiffs_t *)(fs->user_data))->partition, - addr, dst, size); - if (unlikely(err)) { - ESP_LOGE(TAG, "failed to read addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err); - return -1; - } - return 0; -} - -s32_t spiffs_api_write(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *src) -{ - esp_err_t err = esp_partition_write(((esp_spiffs_t *)(fs->user_data))->partition, - addr, src, size); - if (unlikely(err)) { - ESP_LOGE(TAG, "failed to write addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err); - return -1; - } - return 0; -} - -s32_t spiffs_api_erase(spiffs *fs, uint32_t addr, uint32_t size) -{ - esp_err_t err = esp_partition_erase_range(((esp_spiffs_t *)(fs->user_data))->partition, - addr, size); - if (err) { - ESP_LOGE(TAG, "failed to erase addr 0x%08" PRIx32 ", size 0x%08" PRIx32 ", err %d", addr, size, err); - return -1; - } - return 0; -} - -void spiffs_api_check(spiffs *fs, spiffs_check_type type, - spiffs_check_report report, uint32_t arg1, uint32_t arg2) -{ - static const char * spiffs_check_type_str[3] = { - "LOOKUP", - "INDEX", - "PAGE" - }; - - static const char * spiffs_check_report_str[7] = { - "PROGRESS", - "ERROR", - "FIX INDEX", - "FIX LOOKUP", - "DELETE ORPHANED INDEX", - "DELETE PAGE", - "DELETE BAD FILE" - }; - - if (report != SPIFFS_CHECK_PROGRESS) { - ESP_LOGE(TAG, "CHECK: type:%s, report:%s, %" PRIx32 ":%" PRIx32, spiffs_check_type_str[type], - spiffs_check_report_str[report], arg1, arg2); - } else { - ESP_LOGV(TAG, "CHECK PROGRESS: report:%s, %" PRIx32 ":%" PRIx32, - spiffs_check_report_str[report], arg1, arg2); - } -} diff --git a/components/spiffs/spiffs_api.h b/components/spiffs/spiffs_api.h deleted file mode 100644 index 512598a7d20a..000000000000 --- a/components/spiffs/spiffs_api.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "spiffs.h" -#include "esp_compiler.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ESP_SPIFFS_PATH_MAX 15 - -/** - * @brief SPIFFS definition structure - */ -typedef struct { - spiffs *fs; /*!< Handle to the underlying SPIFFS */ - SemaphoreHandle_t lock; /*!< FS lock */ - const esp_partition_t* partition; /*!< The partition on which SPIFFS is located */ - char base_path[ESP_SPIFFS_PATH_MAX+1]; /*!< Mount point */ - bool by_label; /*!< Partition was mounted by label */ - spiffs_config cfg; /*!< SPIFFS Mount configuration */ - uint8_t *work; /*!< Work Buffer */ - uint8_t *fds; /*!< File Descriptor Buffer */ - uint32_t fds_sz; /*!< File Descriptor Buffer Length */ - uint8_t *cache; /*!< Cache Buffer */ - uint32_t cache_sz; /*!< Cache Buffer Length */ -} esp_spiffs_t; - -s32_t spiffs_api_read(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *dst); - -s32_t spiffs_api_write(spiffs *fs, uint32_t addr, uint32_t size, uint8_t *src); - -s32_t spiffs_api_erase(spiffs *fs, uint32_t addr, uint32_t size); - -void spiffs_api_check(spiffs *fs, spiffs_check_type type, - spiffs_check_report report, uint32_t arg1, uint32_t arg2); - -#ifdef __cplusplus -} -#endif diff --git a/components/spiffs/spiffsgen.py b/components/spiffs/spiffsgen.py deleted file mode 100755 index 45f84492f821..000000000000 --- a/components/spiffs/spiffsgen.py +++ /dev/null @@ -1,593 +0,0 @@ -#!/usr/bin/env python -# -# spiffsgen is a tool used to generate a spiffs image from a directory -# -# SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Apache-2.0 - -from __future__ import division, print_function - -import argparse -import io -import math -import os -import struct - -try: - import typing - - TSP = typing.TypeVar('TSP', bound='SpiffsObjPageWithIdx') - ObjIdsItem = typing.Tuple[int, typing.Type[TSP]] -except ImportError: - pass - - -SPIFFS_PH_FLAG_USED_FINAL_INDEX = 0xF8 -SPIFFS_PH_FLAG_USED_FINAL = 0xFC - -SPIFFS_PH_FLAG_LEN = 1 -SPIFFS_PH_IX_SIZE_LEN = 4 -SPIFFS_PH_IX_OBJ_TYPE_LEN = 1 -SPIFFS_TYPE_FILE = 1 - -# Based on typedefs under spiffs_config.h -SPIFFS_OBJ_ID_LEN = 2 # spiffs_obj_id -SPIFFS_SPAN_IX_LEN = 2 # spiffs_span_ix -SPIFFS_PAGE_IX_LEN = 2 # spiffs_page_ix -SPIFFS_BLOCK_IX_LEN = 2 # spiffs_block_ix - - -class SpiffsBuildConfig(object): - def __init__(self, - page_size, # type: int - page_ix_len, # type: int - block_size, # type: int - block_ix_len, # type: int - meta_len, # type: int - obj_name_len, # type: int - obj_id_len, # type: int - span_ix_len, # type: int - packed, # type: bool - aligned, # type: bool - endianness, # type: str - use_magic, # type: bool - use_magic_len, # type: bool - aligned_obj_ix_tables # type: bool - ): - if block_size % page_size != 0: - raise RuntimeError('block size should be a multiple of page size') - - self.page_size = page_size - self.block_size = block_size - self.obj_id_len = obj_id_len - self.span_ix_len = span_ix_len - self.packed = packed - self.aligned = aligned - self.obj_name_len = obj_name_len - self.meta_len = meta_len - self.page_ix_len = page_ix_len - self.block_ix_len = block_ix_len - self.endianness = endianness - self.use_magic = use_magic - self.use_magic_len = use_magic_len - self.aligned_obj_ix_tables = aligned_obj_ix_tables - - self.PAGES_PER_BLOCK = self.block_size // self.page_size - self.OBJ_LU_PAGES_PER_BLOCK = int(math.ceil(self.block_size / self.page_size * self.obj_id_len / self.page_size)) - self.OBJ_USABLE_PAGES_PER_BLOCK = self.PAGES_PER_BLOCK - self.OBJ_LU_PAGES_PER_BLOCK - - self.OBJ_LU_PAGES_OBJ_IDS_LIM = self.page_size // self.obj_id_len - - self.OBJ_DATA_PAGE_HEADER_LEN = self.obj_id_len + self.span_ix_len + SPIFFS_PH_FLAG_LEN - - pad = 4 - (4 if self.OBJ_DATA_PAGE_HEADER_LEN % 4 == 0 else self.OBJ_DATA_PAGE_HEADER_LEN % 4) - - self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED = self.OBJ_DATA_PAGE_HEADER_LEN + pad - self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED_PAD = pad - self.OBJ_DATA_PAGE_CONTENT_LEN = self.page_size - self.OBJ_DATA_PAGE_HEADER_LEN - - self.OBJ_INDEX_PAGES_HEADER_LEN = (self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED + SPIFFS_PH_IX_SIZE_LEN + - SPIFFS_PH_IX_OBJ_TYPE_LEN + self.obj_name_len + self.meta_len) - if aligned_obj_ix_tables: - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED = (self.OBJ_INDEX_PAGES_HEADER_LEN + SPIFFS_PAGE_IX_LEN - 1) & ~(SPIFFS_PAGE_IX_LEN - 1) - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED_PAD = self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED - self.OBJ_INDEX_PAGES_HEADER_LEN - else: - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED = self.OBJ_INDEX_PAGES_HEADER_LEN - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED_PAD = 0 - - self.OBJ_INDEX_PAGES_OBJ_IDS_HEAD_LIM = (self.page_size - self.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED) // self.block_ix_len - self.OBJ_INDEX_PAGES_OBJ_IDS_LIM = (self.page_size - self.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED) // self.block_ix_len - - -class SpiffsFullError(RuntimeError): - pass - - -class SpiffsPage(object): - _endianness_dict = { - 'little': '<', - 'big': '>' - } - - _len_dict = { - 1: 'B', - 2: 'H', - 4: 'I', - 8: 'Q' - } - - def __init__(self, bix, build_config): # type: (int, SpiffsBuildConfig) -> None - self.build_config = build_config - self.bix = bix - - def to_binary(self): # type: () -> bytes - raise NotImplementedError() - - -class SpiffsObjPageWithIdx(SpiffsPage): - def __init__(self, obj_id, build_config): # type: (int, SpiffsBuildConfig) -> None - super(SpiffsObjPageWithIdx, self).__init__(0, build_config) - self.obj_id = obj_id - - def to_binary(self): # type: () -> bytes - raise NotImplementedError() - - -class SpiffsObjLuPage(SpiffsPage): - def __init__(self, bix, build_config): # type: (int, SpiffsBuildConfig) -> None - SpiffsPage.__init__(self, bix, build_config) - - self.obj_ids_limit = self.build_config.OBJ_LU_PAGES_OBJ_IDS_LIM - self.obj_ids = list() # type: typing.List[ObjIdsItem] - - def _calc_magic(self, blocks_lim): # type: (int) -> int - # Calculate the magic value mirroring computation done by the macro SPIFFS_MAGIC defined in - # spiffs_nucleus.h - magic = 0x20140529 ^ self.build_config.page_size - if self.build_config.use_magic_len: - magic = magic ^ (blocks_lim - self.bix) - # narrow the result to build_config.obj_id_len bytes - mask = (2 << (8 * self.build_config.obj_id_len)) - 1 - return magic & mask - - def register_page(self, page): # type: (TSP) -> None - if not self.obj_ids_limit > 0: - raise SpiffsFullError() - - obj_id = (page.obj_id, page.__class__) - self.obj_ids.append(obj_id) - self.obj_ids_limit -= 1 - - def to_binary(self): # type: () -> bytes - img = b'' - - for (obj_id, page_type) in self.obj_ids: - if page_type == SpiffsObjIndexPage: - obj_id ^= (1 << ((self.build_config.obj_id_len * 8) - 1)) - img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.obj_id_len], obj_id) - - assert len(img) <= self.build_config.page_size - - img += b'\xFF' * (self.build_config.page_size - len(img)) - - return img - - def magicfy(self, blocks_lim): # type: (int) -> None - # Only use magic value if no valid obj id has been written to the spot, which is the - # spot taken up by the last obj id on last lookup page. The parent is responsible - # for determining which is the last lookup page and calling this function. - remaining = self.obj_ids_limit - empty_obj_id_dict = { - 1: 0xFF, - 2: 0xFFFF, - 4: 0xFFFFFFFF, - 8: 0xFFFFFFFFFFFFFFFF - } - if remaining >= 2: - for i in range(remaining): - if i == remaining - 2: - self.obj_ids.append((self._calc_magic(blocks_lim), SpiffsObjDataPage)) - break - else: - self.obj_ids.append((empty_obj_id_dict[self.build_config.obj_id_len], SpiffsObjDataPage)) - self.obj_ids_limit -= 1 - - -class SpiffsObjIndexPage(SpiffsObjPageWithIdx): - def __init__(self, obj_id, span_ix, size, name, build_config - ): # type: (int, int, int, str, SpiffsBuildConfig) -> None - super(SpiffsObjIndexPage, self).__init__(obj_id, build_config) - self.span_ix = span_ix - self.name = name - self.size = size - - if self.span_ix == 0: - self.pages_lim = self.build_config.OBJ_INDEX_PAGES_OBJ_IDS_HEAD_LIM - else: - self.pages_lim = self.build_config.OBJ_INDEX_PAGES_OBJ_IDS_LIM - - self.pages = list() # type: typing.List[int] - - def register_page(self, page): # type: (SpiffsObjDataPage) -> None - if not self.pages_lim > 0: - raise SpiffsFullError - - self.pages.append(page.offset) - self.pages_lim -= 1 - - def to_binary(self): # type: () -> bytes - obj_id = self.obj_id ^ (1 << ((self.build_config.obj_id_len * 8) - 1)) - img = struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.obj_id_len] + - SpiffsPage._len_dict[self.build_config.span_ix_len] + - SpiffsPage._len_dict[SPIFFS_PH_FLAG_LEN], - obj_id, - self.span_ix, - SPIFFS_PH_FLAG_USED_FINAL_INDEX) - - # Add padding before the object index page specific information - img += b'\xFF' * self.build_config.OBJ_DATA_PAGE_HEADER_LEN_ALIGNED_PAD - - # If this is the first object index page for the object, add filname, type - # and size information - if self.span_ix == 0: - img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[SPIFFS_PH_IX_SIZE_LEN] + - SpiffsPage._len_dict[SPIFFS_PH_FLAG_LEN], - self.size, - SPIFFS_TYPE_FILE) - - img += self.name.encode() + (b'\x00' * ( - (self.build_config.obj_name_len - len(self.name)) - + self.build_config.meta_len - + self.build_config.OBJ_INDEX_PAGES_HEADER_LEN_ALIGNED_PAD)) - - # Finally, add the page index of daa pages - for page in self.pages: - page = page >> int(math.log(self.build_config.page_size, 2)) - img += struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.page_ix_len], page) - - assert len(img) <= self.build_config.page_size - - img += b'\xFF' * (self.build_config.page_size - len(img)) - - return img - - -class SpiffsObjDataPage(SpiffsObjPageWithIdx): - def __init__(self, offset, obj_id, span_ix, contents, build_config - ): # type: (int, int, int, bytes, SpiffsBuildConfig) -> None - super(SpiffsObjDataPage, self).__init__(obj_id, build_config) - self.span_ix = span_ix - self.contents = contents - self.offset = offset - - def to_binary(self): # type: () -> bytes - img = struct.pack(SpiffsPage._endianness_dict[self.build_config.endianness] + - SpiffsPage._len_dict[self.build_config.obj_id_len] + - SpiffsPage._len_dict[self.build_config.span_ix_len] + - SpiffsPage._len_dict[SPIFFS_PH_FLAG_LEN], - self.obj_id, - self.span_ix, - SPIFFS_PH_FLAG_USED_FINAL) - - img += self.contents - - assert len(img) <= self.build_config.page_size - - img += b'\xFF' * (self.build_config.page_size - len(img)) - - return img - - -class SpiffsBlock(object): - def _reset(self): # type: () -> None - self.cur_obj_index_span_ix = 0 - self.cur_obj_data_span_ix = 0 - self.cur_obj_id = 0 - self.cur_obj_idx_page = None # type: typing.Optional[SpiffsObjIndexPage] - - def __init__(self, bix, build_config): # type: (int, SpiffsBuildConfig) -> None - self.build_config = build_config - self.offset = bix * self.build_config.block_size - self.remaining_pages = self.build_config.OBJ_USABLE_PAGES_PER_BLOCK - self.pages = list() # type: typing.List[SpiffsPage] - self.bix = bix - - lu_pages = list() - for i in range(self.build_config.OBJ_LU_PAGES_PER_BLOCK): - page = SpiffsObjLuPage(self.bix, self.build_config) - lu_pages.append(page) - - self.pages.extend(lu_pages) - - self.lu_page_iter = iter(lu_pages) - self.lu_page = next(self.lu_page_iter) - - self._reset() - - def _register_page(self, page): # type: (TSP) -> None - if isinstance(page, SpiffsObjDataPage): - assert self.cur_obj_idx_page is not None - self.cur_obj_idx_page.register_page(page) # can raise SpiffsFullError - - try: - self.lu_page.register_page(page) - except SpiffsFullError: - self.lu_page = next(self.lu_page_iter) - try: - self.lu_page.register_page(page) - except AttributeError: # no next lookup page - # Since the amount of lookup pages is pre-computed at every block instance, - # this should never occur - raise RuntimeError('invalid attempt to add page to a block when there is no more space in lookup') - - self.pages.append(page) - - def begin_obj(self, obj_id, size, name, obj_index_span_ix=0, obj_data_span_ix=0 - ): # type: (int, int, str, int, int) -> None - if not self.remaining_pages > 0: - raise SpiffsFullError() - self._reset() - - self.cur_obj_id = obj_id - self.cur_obj_index_span_ix = obj_index_span_ix - self.cur_obj_data_span_ix = obj_data_span_ix - - page = SpiffsObjIndexPage(obj_id, self.cur_obj_index_span_ix, size, name, self.build_config) - self._register_page(page) - - self.cur_obj_idx_page = page - - self.remaining_pages -= 1 - self.cur_obj_index_span_ix += 1 - - def update_obj(self, contents): # type: (bytes) -> None - if not self.remaining_pages > 0: - raise SpiffsFullError() - page = SpiffsObjDataPage(self.offset + (len(self.pages) * self.build_config.page_size), - self.cur_obj_id, self.cur_obj_data_span_ix, contents, self.build_config) - - self._register_page(page) - - self.cur_obj_data_span_ix += 1 - self.remaining_pages -= 1 - - def end_obj(self): # type: () -> None - self._reset() - - def is_full(self): # type: () -> bool - return self.remaining_pages <= 0 - - def to_binary(self, blocks_lim): # type: (int) -> bytes - img = b'' - - if self.build_config.use_magic: - for (idx, page) in enumerate(self.pages): - if idx == self.build_config.OBJ_LU_PAGES_PER_BLOCK - 1: - assert isinstance(page, SpiffsObjLuPage) - page.magicfy(blocks_lim) - img += page.to_binary() - else: - for page in self.pages: - img += page.to_binary() - - assert len(img) <= self.build_config.block_size - - img += b'\xFF' * (self.build_config.block_size - len(img)) - return img - - -class SpiffsFS(object): - def __init__(self, img_size, build_config): # type: (int, SpiffsBuildConfig) -> None - if img_size % build_config.block_size != 0: - raise RuntimeError('image size should be a multiple of block size') - - self.img_size = img_size - self.build_config = build_config - - self.blocks = list() # type: typing.List[SpiffsBlock] - self.blocks_lim = self.img_size // self.build_config.block_size - self.remaining_blocks = self.blocks_lim - self.cur_obj_id = 1 # starting object id - - def _create_block(self): # type: () -> SpiffsBlock - if self.is_full(): - raise SpiffsFullError('the image size has been exceeded') - - block = SpiffsBlock(len(self.blocks), self.build_config) - self.blocks.append(block) - self.remaining_blocks -= 1 - return block - - def is_full(self): # type: () -> bool - return self.remaining_blocks <= 0 - - def create_file(self, img_path, file_path): # type: (str, str) -> None - if len(img_path) > self.build_config.obj_name_len: - raise RuntimeError("object name '%s' too long" % img_path) - - name = img_path - - with open(file_path, 'rb') as obj: - contents = obj.read() - - stream = io.BytesIO(contents) - - try: - block = self.blocks[-1] - block.begin_obj(self.cur_obj_id, len(contents), name) - except (IndexError, SpiffsFullError): - block = self._create_block() - block.begin_obj(self.cur_obj_id, len(contents), name) - - contents_chunk = stream.read(self.build_config.OBJ_DATA_PAGE_CONTENT_LEN) - - while contents_chunk: - try: - block = self.blocks[-1] - try: - # This can fail because either (1) all the pages in block have been - # used or (2) object index has been exhausted. - block.update_obj(contents_chunk) - except SpiffsFullError: - # If its (1), use the outer exception handler - if block.is_full(): - raise SpiffsFullError - # If its (2), write another object index page - block.begin_obj(self.cur_obj_id, len(contents), name, - obj_index_span_ix=block.cur_obj_index_span_ix, - obj_data_span_ix=block.cur_obj_data_span_ix) - continue - except (IndexError, SpiffsFullError): - # All pages in the block have been exhausted. Create a new block, copying - # the previous state of the block to a new one for the continuation of the - # current object - prev_block = block - block = self._create_block() - block.cur_obj_id = prev_block.cur_obj_id - block.cur_obj_idx_page = prev_block.cur_obj_idx_page - block.cur_obj_data_span_ix = prev_block.cur_obj_data_span_ix - block.cur_obj_index_span_ix = prev_block.cur_obj_index_span_ix - continue - - contents_chunk = stream.read(self.build_config.OBJ_DATA_PAGE_CONTENT_LEN) - - block.end_obj() - - self.cur_obj_id += 1 - - def to_binary(self): # type: () -> bytes - img = b'' - all_blocks = [] - for block in self.blocks: - all_blocks.append(block.to_binary(self.blocks_lim)) - bix = len(self.blocks) - if self.build_config.use_magic: - # Create empty blocks with magic numbers - while self.remaining_blocks > 0: - block = SpiffsBlock(bix, self.build_config) - all_blocks.append(block.to_binary(self.blocks_lim)) - self.remaining_blocks -= 1 - bix += 1 - else: - # Just fill remaining spaces FF's - all_blocks.append(b'\xFF' * (self.img_size - len(all_blocks) * self.build_config.block_size)) - img += b''.join([blk for blk in all_blocks]) - return img - - -class CustomHelpFormatter(argparse.HelpFormatter): - """ - Similar to argparse.ArgumentDefaultsHelpFormatter, except it - doesn't add the default value if "(default:" is already present. - This helps in the case of options with action="store_false", like - --no-magic or --no-magic-len. - """ - def _get_help_string(self, action): # type: (argparse.Action) -> str - if action.help is None: - return '' - if '%(default)' not in action.help and '(default:' not in action.help: - if action.default is not argparse.SUPPRESS: - defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE] - if action.option_strings or action.nargs in defaulting_nargs: - return action.help + ' (default: %(default)s)' - return action.help - - -def main(): # type: () -> None - parser = argparse.ArgumentParser(description='SPIFFS Image Generator', - formatter_class=CustomHelpFormatter) - - parser.add_argument('image_size', - help='Size of the created image') - - parser.add_argument('base_dir', - help='Path to directory from which the image will be created') - - parser.add_argument('output_file', - help='Created image output file path') - - parser.add_argument('--page-size', - help='Logical page size. Set to value same as CONFIG_SPIFFS_PAGE_SIZE.', - type=int, - default=256) - - parser.add_argument('--block-size', - help="Logical block size. Set to the same value as the flash chip's sector size (g_rom_flashchip.sector_size).", - type=int, - default=4096) - - parser.add_argument('--obj-name-len', - help='File full path maximum length. Set to value same as CONFIG_SPIFFS_OBJ_NAME_LEN.', - type=int, - default=32) - - parser.add_argument('--meta-len', - help='File metadata length. Set to value same as CONFIG_SPIFFS_META_LENGTH.', - type=int, - default=4) - - parser.add_argument('--use-magic', - dest='use_magic', - help='Use magic number to create an identifiable SPIFFS image. Specify if CONFIG_SPIFFS_USE_MAGIC.', - action='store_true') - - parser.add_argument('--no-magic', - dest='use_magic', - help='Inverse of --use-magic (default: --use-magic is enabled)', - action='store_false') - - parser.add_argument('--use-magic-len', - dest='use_magic_len', - help='Use position in memory to create different magic numbers for each block. Specify if CONFIG_SPIFFS_USE_MAGIC_LENGTH.', - action='store_true') - - parser.add_argument('--no-magic-len', - dest='use_magic_len', - help='Inverse of --use-magic-len (default: --use-magic-len is enabled)', - action='store_false') - - parser.add_argument('--follow-symlinks', - help='Take into account symbolic links during partition image creation.', - action='store_true') - - parser.add_argument('--big-endian', - help='Specify if the target architecture is big-endian. If not specified, little-endian is assumed.', - action='store_true') - - parser.add_argument('--aligned-obj-ix-tables', - action='store_true', - help='Use aligned object index tables. Specify if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES is set.') - - parser.set_defaults(use_magic=True, use_magic_len=True) - - args = parser.parse_args() - - if not os.path.exists(args.base_dir): - raise RuntimeError('given base directory %s does not exist' % args.base_dir) - - with open(args.output_file, 'wb') as image_file: - image_size = int(args.image_size, 0) - spiffs_build_default = SpiffsBuildConfig(args.page_size, SPIFFS_PAGE_IX_LEN, - args.block_size, SPIFFS_BLOCK_IX_LEN, args.meta_len, - args.obj_name_len, SPIFFS_OBJ_ID_LEN, SPIFFS_SPAN_IX_LEN, - True, True, 'big' if args.big_endian else 'little', - args.use_magic, args.use_magic_len, args.aligned_obj_ix_tables) - - spiffs = SpiffsFS(image_size, spiffs_build_default) - - for root, dirs, files in os.walk(args.base_dir, followlinks=args.follow_symlinks): - for f in files: - full_path = os.path.join(root, f) - spiffs.create_file('/' + os.path.relpath(full_path, args.base_dir).replace('\\', '/'), full_path) - - image = spiffs.to_binary() - - image_file.write(image) - - -if __name__ == '__main__': - main() diff --git a/components/spiffs/test_apps/CMakeLists.txt b/components/spiffs/test_apps/CMakeLists.txt deleted file mode 100644 index b11f543b68ba..000000000000 --- a/components/spiffs/test_apps/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# This is the project CMakeLists.txt file for the test subproject -cmake_minimum_required(VERSION 3.16) - -# "Trim" the build. Include the minimal set of components, main, and anything it depends on. -set(COMPONENTS main) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(test_spiffs) diff --git a/components/spiffs/test_apps/README.md b/components/spiffs/test_apps/README.md deleted file mode 100644 index 7f0be53ea207..000000000000 --- a/components/spiffs/test_apps/README.md +++ /dev/null @@ -1,32 +0,0 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | - -This is a test app for spiffs component. - -# Building -Several configurations are provided as `sdkconfig.ci.XXX` and serve as a template. - -## Example with configuration "release" for target ESP32 - -```bash -rm -rf sdkconfig build -idf.py -DIDF_TARGET=esp32 -DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.ci.release" build -``` - -# Running - -To run locally: - -```bash -idf.py flash monitor -``` - -The tests will be executed and the summary will be printed: - -``` ------------------------ -21 Tests 0 Failures 0 Ignored -OK -``` - -Note, when the Python test script is executed in internal CI, it will test each configuration one by one. When executing this script locally, it will use whichever binary is already built and available in `build` directory. diff --git a/components/spiffs/test_apps/main/CMakeLists.txt b/components/spiffs/test_apps/main/CMakeLists.txt deleted file mode 100644 index e01b34ebe7f2..000000000000 --- a/components/spiffs/test_apps/main/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -idf_component_register(SRCS test_spiffs.c - PRIV_INCLUDE_DIRS . - PRIV_REQUIRES spiffs unity vfs - WHOLE_ARCHIVE - ) diff --git a/components/spiffs/test_apps/main/test_spiffs.c b/components/spiffs/test_apps/main/test_spiffs.c deleted file mode 100644 index efe1b9d4b275..000000000000 --- a/components/spiffs/test_apps/main/test_spiffs.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include -#include -#include -#include "unity.h" -#include "esp_log.h" -#include "esp_system.h" -#include "esp_vfs.h" -#include "esp_spiffs.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" -#include "esp_partition.h" -#include "esp_random.h" -#include "esp_rom_sys.h" - -const char* spiffs_test_hello_str = "Hello, World!\n"; -const char* spiffs_test_partition_label = "storage"; - -void app_main(void) -{ - unity_run_menu(); -} - -static const esp_partition_t *get_partition(void) -{ - const esp_partition_t *result = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, - ESP_PARTITION_SUBTYPE_DATA_SPIFFS, spiffs_test_partition_label); - TEST_ASSERT_NOT_NULL_MESSAGE(result, "partition table not set correctly"); - return result; -} - -static void test_spiffs_create_file_with_text(const char* name, const char* text) -{ - FILE* f = fopen(name, "wb"); - TEST_ASSERT_NOT_NULL(f); - TEST_ASSERT_TRUE(fputs(text, f) != EOF); - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_overwrite_append(const char* filename) -{ - /* Create new file with 'aaaa' */ - test_spiffs_create_file_with_text(filename, "aaaa"); - - /* Append 'bbbb' to file */ - FILE *f_a = fopen(filename, "a"); - TEST_ASSERT_NOT_NULL(f_a); - TEST_ASSERT_NOT_EQUAL(EOF, fputs("bbbb", f_a)); - TEST_ASSERT_EQUAL(0, fclose(f_a)); - - /* Read back 8 bytes from file, verify it's 'aaaabbbb' */ - char buf[10] = { 0 }; - FILE *f_r = fopen(filename, "r"); - TEST_ASSERT_NOT_NULL(f_r); - TEST_ASSERT_EQUAL(8, fread(buf, 1, 8, f_r)); - TEST_ASSERT_EQUAL_STRING_LEN("aaaabbbb", buf, 8); - - /* Be sure we're at end of file */ - TEST_ASSERT_EQUAL(0, fread(buf, 1, 8, f_r)); - - TEST_ASSERT_EQUAL(0, fclose(f_r)); - - /* Overwrite file with 'cccc' */ - test_spiffs_create_file_with_text(filename, "cccc"); - - /* Verify file now only contains 'cccc' */ - f_r = fopen(filename, "r"); - TEST_ASSERT_NOT_NULL(f_r); - bzero(buf, sizeof(buf)); - TEST_ASSERT_EQUAL(4, fread(buf, 1, 8, f_r)); // trying to read 8 bytes, only expecting 4 - TEST_ASSERT_EQUAL_STRING_LEN("cccc", buf, 4); - TEST_ASSERT_EQUAL(0, fclose(f_r)); -} - -static void test_spiffs_read_file(const char* filename) -{ - FILE* f = fopen(filename, "r"); - TEST_ASSERT_NOT_NULL(f); - char buf[32] = { 0 }; - int cb = fread(buf, 1, sizeof(buf), f); - TEST_ASSERT_EQUAL(strlen(spiffs_test_hello_str), cb); - TEST_ASSERT_EQUAL(0, strcmp(spiffs_test_hello_str, buf)); - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_open_max_files(const char* filename_prefix, size_t files_count) -{ - FILE** files = calloc(files_count, sizeof(FILE*)); - for (size_t i = 0; i < files_count; ++i) { - char name[32]; - snprintf(name, sizeof(name), "%s_%d.txt", filename_prefix, i); - files[i] = fopen(name, "w"); - TEST_ASSERT_NOT_NULL(files[i]); - } - /* close everything and clean up */ - for (size_t i = 0; i < files_count; ++i) { - fclose(files[i]); - } - free(files); -} - -static void test_spiffs_lseek(const char* filename) -{ - FILE* f = fopen(filename, "wb+"); - TEST_ASSERT_NOT_NULL(f); - TEST_ASSERT_EQUAL(11, fprintf(f, "0123456789\n")); - TEST_ASSERT_EQUAL(0, fseek(f, -2, SEEK_CUR)); - TEST_ASSERT_EQUAL('9', fgetc(f)); - TEST_ASSERT_EQUAL(0, fseek(f, 3, SEEK_SET)); - TEST_ASSERT_EQUAL('3', fgetc(f)); - TEST_ASSERT_EQUAL(0, fseek(f, -3, SEEK_END)); - TEST_ASSERT_EQUAL('8', fgetc(f)); - TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_END)); - TEST_ASSERT_EQUAL(11, ftell(f)); - TEST_ASSERT_EQUAL(4, fprintf(f, "abc\n")); - TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_END)); - TEST_ASSERT_EQUAL(15, ftell(f)); - TEST_ASSERT_EQUAL(0, fseek(f, 0, SEEK_SET)); - char buf[20]; - TEST_ASSERT_EQUAL(15, fread(buf, 1, sizeof(buf), f)); - const char ref_buf[] = "0123456789\nabc\n"; - TEST_ASSERT_EQUAL_INT8_ARRAY(ref_buf, buf, sizeof(ref_buf) - 1); - - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_stat(const char* filename) -{ - test_spiffs_create_file_with_text(filename, "foo\n"); - struct stat st; - TEST_ASSERT_EQUAL(0, stat(filename, &st)); - TEST_ASSERT(st.st_mode & S_IFREG); - TEST_ASSERT_FALSE(st.st_mode & S_IFDIR); -} - -static void test_spiffs_unlink(const char* filename) -{ - test_spiffs_create_file_with_text(filename, "unlink\n"); - - TEST_ASSERT_EQUAL(0, unlink(filename)); - - TEST_ASSERT_NULL(fopen(filename, "r")); -} - -static void test_spiffs_rename(const char* filename_prefix) -{ - char name_dst[64]; - char name_src[64]; - snprintf(name_dst, sizeof(name_dst), "%s_dst.txt", filename_prefix); - snprintf(name_src, sizeof(name_src), "%s_src.txt", filename_prefix); - - unlink(name_dst); - unlink(name_src); - - FILE* f = fopen(name_src, "w+"); - TEST_ASSERT_NOT_NULL(f); - const char* str = "0123456789"; - for (int i = 0; i < 400; ++i) { - TEST_ASSERT_NOT_EQUAL(EOF, fputs(str, f)); - } - TEST_ASSERT_EQUAL(0, fclose(f)); - TEST_ASSERT_EQUAL(0, rename(name_src, name_dst)); - TEST_ASSERT_NULL(fopen(name_src, "r")); - FILE* fdst = fopen(name_dst, "r"); - TEST_ASSERT_NOT_NULL(fdst); - TEST_ASSERT_EQUAL(0, fseek(fdst, 0, SEEK_END)); - TEST_ASSERT_EQUAL(4000, ftell(fdst)); - TEST_ASSERT_EQUAL(0, fclose(fdst)); -} - -static void test_spiffs_truncate(const char *filename) -{ - int read = 0; - int truncated_len = 0; - - const char input[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char output[sizeof(input)]; - - test_spiffs_create_file_with_text(filename, input); - - // Extending file beyond size is not supported - TEST_ASSERT_EQUAL(-1, truncate(filename, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, truncate(filename, -1)); - - // Truncating should succeed - const char truncated_1[] = "ABCDEFGHIJ"; - truncated_len = strlen(truncated_1); - TEST_ASSERT_EQUAL(0, truncate(filename, truncated_len)); - - - FILE* f = fopen(filename, "rb"); - TEST_ASSERT_NOT_NULL(f); - memset(output, 0, sizeof(output)); - read = fread(output, 1, sizeof(output), f); - TEST_ASSERT_EQUAL(truncated_len, read); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_1, output, truncated_len); - TEST_ASSERT_EQUAL(0, fclose(f)); - - // Once truncated, the new file size should be the basis - // whether truncation should succeed or not - TEST_ASSERT_EQUAL(-1, truncate(filename, truncated_len + 1)); - TEST_ASSERT_EQUAL(-1, truncate(filename, strlen(input))); - TEST_ASSERT_EQUAL(-1, truncate(filename, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, truncate(filename, -1)); - - - // Truncating a truncated file should succeed - const char truncated_2[] = "ABCDE"; - truncated_len = strlen(truncated_2); - TEST_ASSERT_EQUAL(0, truncate(filename, truncated_len)); - - f = fopen(filename, "rb"); - TEST_ASSERT_NOT_NULL(f); - memset(output, 0, sizeof(output)); - read = fread(output, 1, sizeof(output), f); - TEST_ASSERT_EQUAL(truncated_len, read); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_2, output, truncated_len); - TEST_ASSERT_EQUAL(0, fclose(f)); -} - -static void test_spiffs_ftruncate(const char *filename) -{ - int truncated_len = 0; - - const char input[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char output[sizeof(input)]; - - int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC); - TEST_ASSERT_NOT_EQUAL(-1, fd); - - TEST_ASSERT_EQUAL(strlen(input), write(fd, input, strlen(input))); - - // Extending file beyond size is not supported - TEST_ASSERT_EQUAL(-1, ftruncate(fd, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, -1)); - - // Truncating should succeed - const char truncated_1[] = "ABCDEFGHIJ"; - truncated_len = strlen(truncated_1); - TEST_ASSERT_EQUAL(0, ftruncate(fd, truncated_len)); - TEST_ASSERT_EQUAL(0, close(fd)); - - fd = open(filename, O_RDONLY); - TEST_ASSERT_NOT_EQUAL(-1, fd); - memset(output, 0, sizeof(output)); - TEST_ASSERT_EQUAL(truncated_len, read(fd, output, sizeof(output))); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_1, output, truncated_len); - TEST_ASSERT_EQUAL(0, close(fd)); - - // further truncate the file - fd = open(filename, O_WRONLY); - TEST_ASSERT_NOT_EQUAL(-1, fd); - // Once truncated, the new file size should be the basis - // whether truncation should succeed or not - TEST_ASSERT_EQUAL(-1, ftruncate(fd, truncated_len + 1)); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, strlen(input))); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, strlen(input) + 1)); - TEST_ASSERT_EQUAL(-1, ftruncate(fd, -1)); - - // Truncating a truncated file should succeed - const char truncated_2[] = "ABCDE"; - truncated_len = strlen(truncated_2); - - TEST_ASSERT_EQUAL(0, ftruncate(fd, truncated_len)); - TEST_ASSERT_EQUAL(0, close(fd)); - - // open file for reading and validate the content - fd = open(filename, O_RDONLY); - TEST_ASSERT_NOT_EQUAL(-1, fd); - memset(output, 0, sizeof(output)); - TEST_ASSERT_EQUAL(truncated_len, read(fd, output, sizeof(output))); - TEST_ASSERT_EQUAL_STRING_LEN(truncated_2, output, truncated_len); - TEST_ASSERT_EQUAL(0, close(fd)); -} - -static void test_spiffs_can_opendir(const char* path) -{ - char name_dir_file[64]; - const char * file_name = "test_opd.txt"; - snprintf(name_dir_file, sizeof(name_dir_file), "%s/%s", path, file_name); - unlink(name_dir_file); - test_spiffs_create_file_with_text(name_dir_file, "test_opendir\n"); - DIR* dir = opendir(path); - TEST_ASSERT_NOT_NULL(dir); - bool found = false; - while (true) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - if (strcasecmp(de->d_name, file_name) == 0) { - found = true; - break; - } - } - TEST_ASSERT_TRUE(found); - TEST_ASSERT_EQUAL(0, closedir(dir)); - unlink(name_dir_file); -} - -static void test_spiffs_opendir_readdir_rewinddir(const char* dir_prefix) -{ - char name_dir_inner_file[64]; - char name_dir_inner[64]; - char name_dir_file3[64]; - char name_dir_file2[64]; - char name_dir_file1[64]; - - snprintf(name_dir_inner_file, sizeof(name_dir_inner_file), "%s/inner/3.txt", dir_prefix); - snprintf(name_dir_inner, sizeof(name_dir_inner), "%s/inner", dir_prefix); - snprintf(name_dir_file3, sizeof(name_dir_file2), "%s/boo.bin", dir_prefix); - snprintf(name_dir_file2, sizeof(name_dir_file2), "%s/2.txt", dir_prefix); - snprintf(name_dir_file1, sizeof(name_dir_file1), "%s/1.txt", dir_prefix); - - unlink(name_dir_inner_file); - rmdir(name_dir_inner); - unlink(name_dir_file1); - unlink(name_dir_file2); - unlink(name_dir_file3); - rmdir(dir_prefix); - - test_spiffs_create_file_with_text(name_dir_file1, "1\n"); - test_spiffs_create_file_with_text(name_dir_file2, "2\n"); - test_spiffs_create_file_with_text(name_dir_file3, "\01\02\03"); - test_spiffs_create_file_with_text(name_dir_inner_file, "3\n"); - - DIR* dir = opendir(dir_prefix); - TEST_ASSERT_NOT_NULL(dir); - int count = 0; - const char* names[4]; - while(count < 4) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - printf("found '%s'\n", de->d_name); - if (strcasecmp(de->d_name, "1.txt") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "1.txt"; - ++count; - } else if (strcasecmp(de->d_name, "2.txt") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "2.txt"; - ++count; - } else if (strcasecmp(de->d_name, "inner/3.txt") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "inner/3.txt"; - ++count; - } else if (strcasecmp(de->d_name, "boo.bin") == 0) { - TEST_ASSERT_TRUE(de->d_type == DT_REG); - names[count] = "boo.bin"; - ++count; - } else { - TEST_FAIL_MESSAGE("unexpected directory entry"); - } - } - TEST_ASSERT_EQUAL(count, 4); - - rewinddir(dir); - struct dirent* de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[0])); - seekdir(dir, 3); - de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[3])); - seekdir(dir, 1); - de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[1])); - seekdir(dir, 2); - de = readdir(dir); - TEST_ASSERT_NOT_NULL(de); - TEST_ASSERT_EQUAL(0, strcasecmp(de->d_name, names[2])); - - TEST_ASSERT_EQUAL(0, closedir(dir)); -} - -static void test_spiffs_readdir_many_files(const char* dir_prefix) -{ - const int n_files = 40; - const int n_folders = 4; - unsigned char file_count[n_files * n_folders]; - memset(file_count, 0, sizeof(file_count)/sizeof(file_count[0])); - char file_name[ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN]; - - /* clean stale files before the test */ - DIR* dir = opendir(dir_prefix); - if (dir) { - while (true) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - int len = snprintf(file_name, sizeof(file_name), "%s/%s", dir_prefix, de->d_name); - assert(len < sizeof(file_name)); - unlink(file_name); - } - } - - /* create files */ - for (int d = 0; d < n_folders; ++d) { - printf("filling directory %d\n", d); - for (int f = 0; f < n_files; ++f) { - snprintf(file_name, sizeof(file_name), "%s/%d/%d.txt", dir_prefix, d, f); - test_spiffs_create_file_with_text(file_name, file_name); - } - } - - /* list files */ - for (int d = 0; d < n_folders; ++d) { - printf("listing files in directory %d\n", d); - snprintf(file_name, sizeof(file_name), "%s/%d", dir_prefix, d); - dir = opendir(file_name); - TEST_ASSERT_NOT_NULL(dir); - while (true) { - struct dirent* de = readdir(dir); - if (!de) { - break; - } - int file_id; - TEST_ASSERT_EQUAL(1, sscanf(de->d_name, "%d.txt", &file_id)); - file_count[file_id + d * n_files]++; - } - closedir(dir); - } - - /* check that all created files have been seen */ - for (int d = 0; d < n_folders; ++d) { - printf("checking that all files have been found in directory %d\n", d); - for (int f = 0; f < n_files; ++f) { - TEST_ASSERT_EQUAL(1, file_count[f + d * n_files]); - } - } -} - - -typedef struct { - const char* filename; - bool write; - size_t word_count; - int seed; - SemaphoreHandle_t done; - int result; -} read_write_test_arg_t; - -#define READ_WRITE_TEST_ARG_INIT(name, seed_) \ - { \ - .filename = name, \ - .seed = seed_, \ - .word_count = 4096, \ - .write = true, \ - .done = xSemaphoreCreateBinary() \ - } - -static void read_write_task(void* param) -{ - read_write_test_arg_t* args = (read_write_test_arg_t*) param; - FILE* f = fopen(args->filename, args->write ? "wb" : "rb"); - if (f == NULL) { - args->result = ESP_ERR_NOT_FOUND; - goto done; - } - - srand(args->seed); - for (size_t i = 0; i < args->word_count; ++i) { - uint32_t val = rand(); - if (args->write) { - int cnt = fwrite(&val, sizeof(val), 1, f); - if (cnt != 1) { - printf("E(w): i=%d, cnt=%d val=0x%" PRIx32 "\n\n", i, cnt, val); - args->result = ESP_FAIL; - goto close; - } - } else { - uint32_t rval; - int cnt = fread(&rval, sizeof(rval), 1, f); - if (cnt != 1 || rval != val) { - esp_rom_printf("E(r): i=%d, cnt=%d val=0x%" PRIx32 " rval=0x%" PRIx32 "\n\n", i, cnt, rval); - args->result = ESP_FAIL; - goto close; - } - } - } - args->result = ESP_OK; - -close: - fclose(f); - -done: - xSemaphoreGive(args->done); - vTaskDelay(1); - vTaskDelete(NULL); -} - -static void test_spiffs_concurrent(const char* filename_prefix) -{ - char names[4][64]; - for (size_t i = 0; i < 4; ++i) { - snprintf(names[i], sizeof(names[i]), "%s%d", filename_prefix, i + 1); - unlink(names[i]); - } - - read_write_test_arg_t args1 = READ_WRITE_TEST_ARG_INIT(names[0], 1); - read_write_test_arg_t args2 = READ_WRITE_TEST_ARG_INIT(names[1], 2); - - const uint32_t stack_size = 3072; - - printf("writing f1 and f2\n"); - const int cpuid_0 = 0; - const int cpuid_1 = portNUM_PROCESSORS - 1; - xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, cpuid_0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, cpuid_1); - - xSemaphoreTake(args1.done, portMAX_DELAY); - printf("f1 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args1.result); - xSemaphoreTake(args2.done, portMAX_DELAY); - printf("f2 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args2.result); - - args1.write = false; - args2.write = false; - read_write_test_arg_t args3 = READ_WRITE_TEST_ARG_INIT(names[2], 3); - read_write_test_arg_t args4 = READ_WRITE_TEST_ARG_INIT(names[3], 4); - - printf("reading f1 and f2, writing f3 and f4\n"); - - xTaskCreatePinnedToCore(&read_write_task, "rw3", stack_size, &args3, 3, NULL, cpuid_1); - xTaskCreatePinnedToCore(&read_write_task, "rw4", stack_size, &args4, 3, NULL, cpuid_0); - xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, cpuid_0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, cpuid_1); - - xSemaphoreTake(args1.done, portMAX_DELAY); - printf("f1 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args1.result); - xSemaphoreTake(args2.done, portMAX_DELAY); - printf("f2 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args2.result); - xSemaphoreTake(args3.done, portMAX_DELAY); - printf("f3 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args3.result); - xSemaphoreTake(args4.done, portMAX_DELAY); - printf("f4 done\n"); - TEST_ASSERT_EQUAL(ESP_OK, args4.result); - - vSemaphoreDelete(args1.done); - vSemaphoreDelete(args2.done); - vSemaphoreDelete(args3.done); - vSemaphoreDelete(args4.done); -} - - -static void test_setup(void) -{ - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = spiffs_test_partition_label, - .max_files = 5, - .format_if_mount_failed = true - }; - - TEST_ESP_OK(esp_vfs_spiffs_register(&conf)); -} - -static void test_teardown(void) -{ - TEST_ESP_OK(esp_vfs_spiffs_unregister(spiffs_test_partition_label)); -} - -TEST_CASE("can initialize SPIFFS in erased partition", "[spiffs]") -{ - const esp_partition_t* part = get_partition(); - TEST_ASSERT_NOT_NULL(part); - TEST_ESP_OK(esp_partition_erase_range(part, 0, part->size)); - test_setup(); - size_t total = 0, used = 0; - TEST_ESP_OK(esp_spiffs_info(spiffs_test_partition_label, &total, &used)); - printf("total: %d, used: %d\n", total, used); - TEST_ASSERT_EQUAL(0, used); - test_teardown(); -} - -TEST_CASE("can format mounted partition", "[spiffs]") -{ - // Mount SPIFFS, create file, format, check that the file does not exist. - const esp_partition_t* part = get_partition(); - TEST_ASSERT_NOT_NULL(part); - test_setup(); - const char* filename = "/spiffs/hello.txt"; - test_spiffs_create_file_with_text(filename, spiffs_test_hello_str); - esp_spiffs_format(part->label); - FILE* f = fopen(filename, "r"); - TEST_ASSERT_NULL(f); - test_teardown(); -} - -TEST_CASE("can format unmounted partition", "[spiffs]") -{ - // Mount SPIFFS, create file, unmount. Format. Mount again, check that - // the file does not exist. - const esp_partition_t* part = get_partition(); - TEST_ASSERT_NOT_NULL(part); - test_setup(); - const char* filename = "/spiffs/hello.txt"; - test_spiffs_create_file_with_text(filename, spiffs_test_hello_str); - test_teardown(); - esp_spiffs_format(part->label); - // Don't use test_setup here, need to mount without formatting - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = spiffs_test_partition_label, - .max_files = 5, - .format_if_mount_failed = false - }; - TEST_ESP_OK(esp_vfs_spiffs_register(&conf)); - FILE* f = fopen(filename, "r"); - TEST_ASSERT_NULL(f); - test_teardown(); -} - -TEST_CASE("can create and write file", "[spiffs]") -{ - test_setup(); - test_spiffs_create_file_with_text("/spiffs/hello.txt", spiffs_test_hello_str); - test_teardown(); -} - -TEST_CASE("can read file", "[spiffs]") -{ - test_setup(); - test_spiffs_create_file_with_text("/spiffs/hello.txt", spiffs_test_hello_str); - test_spiffs_read_file("/spiffs/hello.txt"); - test_teardown(); -} - -TEST_CASE("can open maximum number of files", "[spiffs]") -{ - size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr */ - esp_vfs_spiffs_conf_t conf = { - .base_path = "/spiffs", - .partition_label = spiffs_test_partition_label, - .format_if_mount_failed = true, - .max_files = max_files - }; - TEST_ESP_OK(esp_vfs_spiffs_register(&conf)); - test_spiffs_open_max_files("/spiffs/f", max_files); - TEST_ESP_OK(esp_vfs_spiffs_unregister(spiffs_test_partition_label)); -} - -TEST_CASE("overwrite and append file", "[spiffs]") -{ - test_setup(); - test_spiffs_overwrite_append("/spiffs/hello.txt"); - test_teardown(); -} - -TEST_CASE("can lseek", "[spiffs]") -{ - test_setup(); - test_spiffs_lseek("/spiffs/seek.txt"); - test_teardown(); -} - - -TEST_CASE("stat returns correct values", "[spiffs]") -{ - test_setup(); - test_spiffs_stat("/spiffs/stat.txt"); - test_teardown(); -} - -TEST_CASE("unlink removes a file", "[spiffs]") -{ - test_setup(); - test_spiffs_unlink("/spiffs/unlink.txt"); - test_teardown(); -} - -TEST_CASE("rename moves a file", "[spiffs]") -{ - test_setup(); - test_spiffs_rename("/spiffs/move"); - test_teardown(); -} - -TEST_CASE("truncate a file", "[spiffs]") -{ - test_setup(); - test_spiffs_truncate("/spiffs/truncate.txt"); - test_teardown(); -} - -TEST_CASE("ftruncate a file", "[spiffs]") -{ - test_setup(); - test_spiffs_ftruncate("/spiffs/ftrunc.txt"); - test_teardown(); -} - -TEST_CASE("can opendir root directory of FS", "[spiffs]") -{ - test_setup(); - test_spiffs_can_opendir("/spiffs"); - test_teardown(); -} - -TEST_CASE("opendir, readdir, rewinddir, seekdir work as expected", "[spiffs]") -{ - test_setup(); - test_spiffs_opendir_readdir_rewinddir("/spiffs/dir"); - test_teardown(); -} - -TEST_CASE("readdir with large number of files", "[spiffs][timeout=30]") -{ - test_setup(); - test_spiffs_readdir_many_files("/spiffs/dir2"); - test_teardown(); -} - -TEST_CASE("multiple tasks can use same volume", "[spiffs]") -{ - test_setup(); - test_spiffs_concurrent("/spiffs/f"); - test_teardown(); -} - -#ifdef CONFIG_SPIFFS_USE_MTIME -TEST_CASE("mtime is updated when file is opened", "[spiffs]") -{ - /* Open a file, check that mtime is set correctly */ - const char* filename = "/spiffs/time"; - test_setup(); - time_t t_before_create = time(NULL); - test_spiffs_create_file_with_text(filename, "\n"); - time_t t_after_create = time(NULL); - - struct stat st; - TEST_ASSERT_EQUAL(0, stat(filename, &st)); - printf("mtime=%d\n", (int) st.st_mtime); - TEST_ASSERT(st.st_mtime >= t_before_create - && st.st_mtime <= t_after_create); - - /* Wait a bit, open again, check that mtime is updated */ - vTaskDelay(2000 / portTICK_PERIOD_MS); - time_t t_before_open = time(NULL); - FILE *f = fopen(filename, "a"); - time_t t_after_open = time(NULL); - TEST_ASSERT_EQUAL(0, fstat(fileno(f), &st)); - printf("mtime=%d\n", (int) st.st_mtime); - TEST_ASSERT(st.st_mtime >= t_before_open - && st.st_mtime <= t_after_open); - fclose(f); - - /* Wait a bit, open for reading, check that mtime is not updated */ - vTaskDelay(2000 / portTICK_PERIOD_MS); - time_t t_before_open_ro = time(NULL); - f = fopen(filename, "r"); - TEST_ASSERT_EQUAL(0, fstat(fileno(f), &st)); - printf("mtime=%d\n", (int) st.st_mtime); - TEST_ASSERT(t_before_open_ro > t_after_open - && st.st_mtime >= t_before_open - && st.st_mtime <= t_after_open); - fclose(f); - - test_teardown(); -} - -TEST_CASE("utime() works well", "[spiffs]") -{ - const char filename[] = "/spiffs/utime.txt"; - struct stat achieved_stat; - struct tm desired_tm; - struct utimbuf desired_time = { - .actime = 0, // access time is not supported - .modtime = 0, - }; - time_t false_now = 0; - memset(&desired_tm, 0, sizeof(struct tm)); - - test_setup(); - { - // Setting up a false actual time - used when the file is created and for modification with the current time - desired_tm.tm_mon = 10 - 1; - desired_tm.tm_mday = 31; - desired_tm.tm_year = 2018 - 1900; - desired_tm.tm_hour = 10; - desired_tm.tm_min = 35; - desired_tm.tm_sec = 23; - - false_now = mktime(&desired_tm); - - struct timeval now = { .tv_sec = false_now }; - settimeofday(&now, NULL); - } - test_spiffs_create_file_with_text(filename, ""); - - // 00:00:00. January 1st, 1900 - desired_tm.tm_mon = 1 - 1; - desired_tm.tm_mday = 1; - desired_tm.tm_year = 0; - desired_tm.tm_hour = 0; - desired_tm.tm_min = 0; - desired_tm.tm_sec = 0; - printf("Testing mod. time: %s", asctime(&desired_tm)); - desired_time.modtime = mktime(&desired_tm); - TEST_ASSERT_EQUAL(0, utime(filename, &desired_time)); - TEST_ASSERT_EQUAL(0, stat(filename, &achieved_stat)); - TEST_ASSERT_EQUAL_UINT32(desired_time.modtime, achieved_stat.st_mtime); - - // 23:59:08. December 31st, 2145 - desired_tm.tm_mon = 12 - 1; - desired_tm.tm_mday = 31; - desired_tm.tm_year = 2145 - 1900; - desired_tm.tm_hour = 23; - desired_tm.tm_min = 59; - desired_tm.tm_sec = 8; - printf("Testing mod. time: %s", asctime(&desired_tm)); - desired_time.modtime = mktime(&desired_tm); - TEST_ASSERT_EQUAL(0, utime(filename, &desired_time)); - TEST_ASSERT_EQUAL(0, stat(filename, &achieved_stat)); - TEST_ASSERT_EQUAL_UINT32(desired_time.modtime, achieved_stat.st_mtime); - - // Current time - TEST_ASSERT_EQUAL(0, utime(filename, NULL)); - TEST_ASSERT_EQUAL(0, stat(filename, &achieved_stat)); - printf("Mod. time changed to (false actual time): %s", ctime(&achieved_stat.st_mtime)); - TEST_ASSERT_NOT_EQUAL(desired_time.modtime, achieved_stat.st_mtime); - TEST_ASSERT(false_now - achieved_stat.st_mtime <= 2); // two seconds of tolerance are given - - test_teardown(); -} -#endif // CONFIG_SPIFFS_USE_MTIME - -static void test_spiffs_rw_speed(const char* filename, void* buf, size_t buf_size, size_t file_size, bool is_write) -{ - const size_t buf_count = file_size / buf_size; - - FILE* f = fopen(filename, (is_write) ? "wb" : "rb"); - TEST_ASSERT_NOT_NULL(f); - - struct timeval tv_start; - gettimeofday(&tv_start, NULL); - for (size_t n = 0; n < buf_count; ++n) { - if (is_write) { - TEST_ASSERT_EQUAL(buf_size, write(fileno(f), buf, buf_size)); - } else { - if (read(fileno(f), buf, buf_size) != buf_size) { - printf("reading at n=%d, eof=%d", n, feof(f)); - TEST_FAIL(); - } - } - } - - struct timeval tv_end; - gettimeofday(&tv_end, NULL); - - TEST_ASSERT_EQUAL(0, fclose(f)); - - float t_s = tv_end.tv_sec - tv_start.tv_sec + 1e-6f * (tv_end.tv_usec - tv_start.tv_usec); - printf("%s %d bytes (block size %d) in %.3fms (%.3f MB/s)\n", - (is_write)?"Wrote":"Read", file_size, buf_size, t_s * 1e3, - file_size / (1024.0f * 1024.0f * t_s)); -} - -TEST_CASE("write/read speed test", "[spiffs][timeout=60]") -{ - /* Erase partition before running the test to get consistent results */ - const esp_partition_t* part = get_partition(); - esp_partition_erase_range(part, 0, part->size); - - test_setup(); - - const size_t buf_size = 16 * 1024; - uint32_t* buf = (uint32_t*) calloc(1, buf_size); - esp_fill_random(buf, buf_size); - const size_t file_size = part->size / 2; - const char* file = "/spiffs/speedtest.bin"; - - test_spiffs_rw_speed(file, buf, 4 * 1024, file_size, true); - TEST_ASSERT_EQUAL(0, unlink(file)); - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, file_size)); - - test_spiffs_rw_speed(file, buf, 8 * 1024, file_size, true); - TEST_ASSERT_EQUAL(0, unlink(file)); - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, file_size)); - - test_spiffs_rw_speed(file, buf, 16 * 1024, file_size, true); - - test_spiffs_rw_speed(file, buf, 4 * 1024, file_size, false); - test_spiffs_rw_speed(file, buf, 8 * 1024, file_size, false); - test_spiffs_rw_speed(file, buf, 16 * 1024, file_size, false); - TEST_ASSERT_EQUAL(0, unlink(file)); - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, file_size)); - - free(buf); - test_teardown(); -} - -TEST_CASE("SPIFFS garbage-collect", "[spiffs][timeout=60]") -{ - // should fail until the partition is initialized - TEST_ESP_ERR(ESP_ERR_INVALID_STATE, esp_spiffs_gc(spiffs_test_partition_label, 4096)); - - test_setup(); - - // reclaiming one block should be possible - TEST_ESP_OK(esp_spiffs_gc(spiffs_test_partition_label, 4096)); - - // shouldn't be possible to reclaim more than the partition size - const esp_partition_t* part = get_partition(); - TEST_ESP_ERR(ESP_ERR_NOT_FINISHED, esp_spiffs_gc(spiffs_test_partition_label, part->size * 2)); - - test_teardown(); -} diff --git a/components/spiffs/test_apps/partitions.csv b/components/spiffs/test_apps/partitions.csv deleted file mode 100644 index 8cbcb7ebc3bb..000000000000 --- a/components/spiffs/test_apps/partitions.csv +++ /dev/null @@ -1,3 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -factory, 0, 0, 0x10000, 1M -storage, data, spiffs, , 256k diff --git a/components/spiffs/test_apps/pytest_spiffs.py b/components/spiffs/test_apps/pytest_spiffs.py deleted file mode 100644 index 33e5253937a8..000000000000 --- a/components/spiffs/test_apps/pytest_spiffs.py +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: CC0-1.0 - -import pytest -from pytest_embedded import Dut - - -@pytest.mark.esp32 -@pytest.mark.esp32c3 -@pytest.mark.generic -@pytest.mark.parametrize('config', [ - 'default', - 'release', -], indirect=True) -def test_spiffs_generic(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output(timeout=120) - - -@pytest.mark.esp32s3 -@pytest.mark.quad_psram -@pytest.mark.parametrize('config', [ - 'psram', -], indirect=True) -def test_spiffs_psram(dut: Dut) -> None: - dut.expect_exact('Press ENTER to see the list of tests') - dut.write('') - dut.expect_exact('Enter test for running.') - dut.write('*') - dut.expect_unity_test_output(timeout=120) diff --git a/components/spiffs/test_apps/sdkconfig.ci.default b/components/spiffs/test_apps/sdkconfig.ci.default deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/components/spiffs/test_apps/sdkconfig.ci.psram b/components/spiffs/test_apps/sdkconfig.ci.psram deleted file mode 100644 index db575808cf98..000000000000 --- a/components/spiffs/test_apps/sdkconfig.ci.psram +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_SPIRAM=y -CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0 diff --git a/components/spiffs/test_apps/sdkconfig.ci.release b/components/spiffs/test_apps/sdkconfig.ci.release deleted file mode 100644 index 4983b4dfe379..000000000000 --- a/components/spiffs/test_apps/sdkconfig.ci.release +++ /dev/null @@ -1 +0,0 @@ -CONFIG_COMPILER_OPTIMIZATION_SIZE=y diff --git a/components/spiffs/test_apps/sdkconfig.defaults b/components/spiffs/test_apps/sdkconfig.defaults deleted file mode 100644 index b3a25e0021c7..000000000000 --- a/components/spiffs/test_apps/sdkconfig.defaults +++ /dev/null @@ -1,21 +0,0 @@ -# General options for additional checks -CONFIG_HEAP_POISONING_COMPREHENSIVE=y -CONFIG_COMPILER_WARN_WRITE_STRINGS=y -CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK=y -CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y -CONFIG_COMPILER_STACK_CHECK=y - -# Disable the task watchdog since this app uses an interactive menu -CONFIG_ESP_TASK_WDT_INIT=n - -# Custom partition table for this test app -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" - -# SPIFFS-specific settings -CONFIG_SPIFFS_USE_MTIME=y - -# Set sufficient number of GC runs for SPIFFS: -# size of the storage partition divided by flash sector size. -# See esp_spiffs_gc description for more info. -CONFIG_SPIFFS_GC_MAX_RUNS=64 diff --git a/components/spiffs/test_spiffsgen/__init__.py b/components/spiffs/test_spiffsgen/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/components/spiffs/test_spiffsgen/test_spiffsgen.py b/components/spiffs/test_spiffsgen/test_spiffsgen.py deleted file mode 100755 index 44f9d2851c35..000000000000 --- a/components/spiffs/test_spiffsgen/test_spiffsgen.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD -# SPDX-License-Identifier: Apache-2.0 -import os -import sys -import unittest - -try: - import typing -except ImportError: - pass - -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) -try: - import spiffsgen -except ImportError: - raise - - -class SpiffsgenTest(unittest.TestCase): - def test_configs(self): # type: () -> None - """Run spiffsgen with different configs, and check that - an image is generated (there is no exception), and the image size - is as expected. - """ - default_config = dict( - page_size=256, - page_ix_len=spiffsgen.SPIFFS_PAGE_IX_LEN, - block_size=4096, - block_ix_len=spiffsgen.SPIFFS_BLOCK_IX_LEN, - meta_len=4, - obj_name_len=32, - obj_id_len=spiffsgen.SPIFFS_BLOCK_IX_LEN, - span_ix_len=spiffsgen.SPIFFS_SPAN_IX_LEN, - packed=True, - aligned=True, - endianness='little', - use_magic=True, - use_magic_len=True, - aligned_obj_ix_tables=False - ) - - def make_config(**kwargs): # type: (typing.Any) -> spiffsgen.SpiffsBuildConfig - """Return SpiffsBuildConfig object with configuration set - by default_config plus any options overridden in kwargs. - """ - new_config = dict(default_config) - new_config.update(**kwargs) - return spiffsgen.SpiffsBuildConfig(**new_config) - - configs = [ - make_config(), - make_config(use_magic_len=False, use_magic=False, aligned_obj_ix_tables=True), - make_config(meta_len=4, obj_name_len=16), - make_config(block_size=8192), - make_config(page_size=512) - ] - - image_size = 64 * 1024 - for config in configs: - spiffs = spiffsgen.SpiffsFS(image_size, config) - spiffs.create_file('/test', __file__) - image = spiffs.to_binary() - self.assertEqual(len(image), image_size) - # Note: it would be nice to compile spiffs for host with the given - # config, and verify that the image is parsed correctly. - - -if __name__ == '__main__': - unittest.main() diff --git a/install.sh b/install.sh index ad8547af21a2..a38ba768a1e5 100755 --- a/install.sh +++ b/install.sh @@ -16,12 +16,12 @@ echo "Checking Python compatibility" TARGETS=`"${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract targets "$@"` echo "Installing ESP-IDF tools" -"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install --targets=${TARGETS} +"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" --non-interactive install --targets=${TARGETS} FEATURES=`"${ESP_PYTHON}" "${IDF_PATH}/tools/install_util.py" extract features "$@"` echo "Installing Python environment and packages" -"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" install-python-env --features=${FEATURES} +"${ESP_PYTHON}" "${IDF_PATH}/tools/idf_tools.py" --non-interactive install-python-env --features=${FEATURES} echo "All done! You can now run:" echo "" diff --git a/package.json b/package.json new file mode 100644 index 000000000000..2cfffc29979b --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "framework-espidf", + "version": "3.50102", + "description": "Espressif IoT Development Framework. Tasmota development framework for ESP32 chip", + "keywords": [ + "framework", + "esp32", + "esp32s2", + "esp32s3", + "esp32c2", + "esp32c3", + "esp32c6", + "esp32h2", + "espressif" + ], + "homepage": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32/", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/tasmota/esp-idf" + } +} diff --git a/version.txt b/version.txt new file mode 100644 index 000000000000..61038a60b023 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +5.1.2.231122