From b4b57a25b80fd0b2e8aed7832d4a2f4025644004 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Sun, 30 May 2021 16:32:06 +0800 Subject: [PATCH] esp_wifi: backport some wifi fix 1.support multi phy init data bin embedded 2.fix not tx 9M rate issue --- components/esp_wifi/CMakeLists.txt | 48 ++++++++++--- components/esp_wifi/Kconfig | 8 +++ components/esp_wifi/Makefile.projbuild | 2 +- .../{ => esp32}/phy_multiple_init_data.bin | Bin .../esp32c3/phy_multiple_init_data.bin | Bin 0 -> 1072 bytes .../esp32s2/phy_multiple_init_data.bin | Bin 0 -> 1072 bytes .../esp32s3/phy_multiple_init_data.bin | Bin 0 -> 1072 bytes components/esp_wifi/lib | 2 +- components/esp_wifi/src/phy_init.c | 63 +++++++++++++++--- 9 files changed, 101 insertions(+), 22 deletions(-) rename components/esp_wifi/{ => esp32}/phy_multiple_init_data.bin (100%) create mode 100644 components/esp_wifi/esp32c3/phy_multiple_init_data.bin create mode 100644 components/esp_wifi/esp32s2/phy_multiple_init_data.bin create mode 100644 components/esp_wifi/esp32s3/phy_multiple_init_data.bin diff --git a/components/esp_wifi/CMakeLists.txt b/components/esp_wifi/CMakeLists.txt index e8730e0ee8..5ae2b0b999 100644 --- a/components/esp_wifi/CMakeLists.txt +++ b/components/esp_wifi/CMakeLists.txt @@ -15,7 +15,16 @@ else() set(extra_priv_requires) endif() -idf_component_register(SRCS "src/coexist.c" +idf_build_get_property(build_dir BUILD_DIR) + +if(CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN) + if(NOT EXISTS "${build_dir}/phy_multiple_init_data.bin") + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin DESTINATION "${build_dir}") + endif() +endif() + +if(CONFIG_ESP32_MULTIPLE_PHY_DATA_BIN_EMBEDDED) + idf_component_register(SRCS "src/coexist.c" "src/lib_printf.c" "src/mesh_event.c" "src/phy_init.c" @@ -25,13 +34,31 @@ idf_component_register(SRCS "src/coexist.c" "src/wifi_default.c" "src/wifi_netif.c" "${idf_target}/esp_adapter.c" - INCLUDE_DIRS "include" "${idf_target}/include" - PRIV_REQUIRES wpa_supplicant nvs_flash esp_netif driver ${extra_priv_requires} - REQUIRES esp_event - PRIV_REQUIRES esp_timer esp_pm wpa_supplicant nvs_flash esp_netif ${extra_priv_requires} - LDFRAGMENTS "${ldfragments}") - -idf_build_get_property(build_dir BUILD_DIR) + INCLUDE_DIRS "include" "${idf_target}/include" + PRIV_REQUIRES wpa_supplicant nvs_flash esp_netif driver ${extra_priv_requires} + REQUIRES esp_event + PRIV_REQUIRES esp_timer esp_pm wpa_supplicant nvs_flash esp_netif ${extra_priv_requires} + LDFRAGMENTS "${ldfragments}" + EMBED_FILES "${build_dir}/phy_multiple_init_data.bin" + ) +else() + idf_component_register(SRCS "src/coexist.c" + "src/lib_printf.c" + "src/mesh_event.c" + "src/phy_init.c" + "src/smartconfig.c" + "src/smartconfig_ack.c" + "src/wifi_init.c" + "src/wifi_default.c" + "src/wifi_netif.c" + "${idf_target}/esp_adapter.c" + INCLUDE_DIRS "include" "${idf_target}/include" + PRIV_REQUIRES wpa_supplicant nvs_flash esp_netif driver ${extra_priv_requires} + REQUIRES esp_event + PRIV_REQUIRES esp_timer esp_pm wpa_supplicant nvs_flash esp_netif ${extra_priv_requires} + LDFRAGMENTS "${ldfragments}" + ) +endif() set(target_name "${idf_target}") target_link_libraries(${COMPONENT_LIB} PUBLIC "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") @@ -58,7 +85,10 @@ if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION) partition_table_get_partition_info(phy_partition_offset "--partition-type data --partition-subtype phy" "offset") if(CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN) - set(phy_init_data_bin "${CMAKE_CURRENT_SOURCE_DIR}/phy_multiple_init_data.bin") + set(phy_init_data_bin "${build_dir}/phy_multiple_init_data.bin") + if(CONFIG_ESP32_MULTIPLE_PHY_DATA_BIN_EMBEDDED) + set(COMPONENT_EMBED_FILES "${build_dir}/phy_multiple_init_data.bin") + endif() else() set(phy_init_data_bin "${build_dir}/phy_init_data.bin") diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 1a5284dd15..07c25a5b96 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -373,6 +373,14 @@ menu "PHY" 3. Country configured by API esp_wifi_set_country() and the parameter policy is WIFI_COUNTRY_POLICY_AUTO. + config ESP32_MULTIPLE_PHY_DATA_BIN_EMBEDDED + bool "Support embedded multiple phy init data bin to app bin" + depends on ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN + default n + help + If enabled, multiple phy init data bin will embedded into app bin + If not enabled, multiple phy init data bin will still leave alone, and need to be flashed by users. + config ESP32_PHY_INIT_DATA_ERROR bool "Terminate operation when PHY init data error" depends on ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN diff --git a/components/esp_wifi/Makefile.projbuild b/components/esp_wifi/Makefile.projbuild index a6c4a35591..869b72d5cb 100644 --- a/components/esp_wifi/Makefile.projbuild +++ b/components/esp_wifi/Makefile.projbuild @@ -3,7 +3,7 @@ ifdef CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION ESP_WIFI_COMPONENT_PATH := $(COMPONENT_PATH) ifdef CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN -PHY_INIT_DATA_BIN = $(ESP_WIFI_COMPONENT_PATH)/phy_multiple_init_data.bin +PHY_INIT_DATA_BIN = $(ESP_WIFI_COMPONENT_PATH)/$(IDF_TARGET)/phy_multiple_init_data.bin else PHY_INIT_DATA_OBJ = $(BUILD_DIR_BASE)/phy_init_data.o PHY_INIT_DATA_BIN = $(BUILD_DIR_BASE)/phy_init_data.bin diff --git a/components/esp_wifi/phy_multiple_init_data.bin b/components/esp_wifi/esp32/phy_multiple_init_data.bin similarity index 100% rename from components/esp_wifi/phy_multiple_init_data.bin rename to components/esp_wifi/esp32/phy_multiple_init_data.bin diff --git a/components/esp_wifi/esp32c3/phy_multiple_init_data.bin b/components/esp_wifi/esp32c3/phy_multiple_init_data.bin new file mode 100644 index 0000000000000000000000000000000000000000..0f754a2c496b5cf7b712c49b15e83a02082692f4 GIT binary patch literal 1072 zcmWIWi1hUH3}Ikk2nY!9@$vBS@Nn^Rb8}+&PdZ>A7cep`gSlh6%ptaIvLd;R4D1XI zSj|IsC!-rO`0s!WaPhDjOjwYSF%~nN7;SuDz{bYrzljG7n3$NL^ISl{#KeTKRajLp zGJVBnzYP-jj~p0oxOiAiCoIUwY>3T%nD>2X?tc~yEcPQuxC1U9gMtN-8VGw8s|rTe k1z79{#VH))wOA7cep`gSlh6%ptaIvLd;R4D1XI zSj|IsC!-rO`0s!WaPhDjOjwYSF%~nN7;SuDz{bYrzljG7n3$NL^ISl{#KeTKRajLp zGJVBnzYP-jj~p0oxOiAiCoIUwY>3T%nD>2X?tc~yEcPQuxC1U9gMtN-8VGw8s|rTe k1z79{#VH))wOcheck_algorithm) == PHY_CRC_ALGORITHM) { err = phy_crc_check_init_data(init_data_control_info->multiple_bin_checksum, init_data_control_info->control_info_checksum, sizeof(phy_control_info_data_t) - sizeof(init_data_control_info->control_info_checksum)); @@ -726,6 +749,9 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, return ESP_FAIL; } +#if CONFIG_ESP32_MULTIPLE_PHY_DATA_BIN_EMBEDDED + memcpy(init_data_multiple, multi_phy_init_data_bin_start + init_data_store_length + sizeof(phy_control_info_data_t), sizeof(esp_phy_init_data_t) * init_data_control_info->number); +#else err = esp_partition_read(partition, init_data_store_length + sizeof(phy_control_info_data_t), init_data_multiple, sizeof(esp_phy_init_data_t) * init_data_control_info->number); if (err != ESP_OK) { @@ -734,7 +760,7 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, ESP_LOGE(TAG, "failed to read PHY init data multiple bin partition (0x%x)", err); return ESP_FAIL; } - +#endif if ((init_data_control_info->check_algorithm) == PHY_CRC_ALGORITHM) { err = phy_crc_check_init_data(init_data_multiple, init_data_control_info->multiple_bin_checksum, sizeof(esp_phy_init_data_t) * init_data_control_info->number); @@ -766,6 +792,19 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type) { +#if CONFIG_ESP32_MULTIPLE_PHY_DATA_BIN_EMBEDDED + esp_err_t err = ESP_OK; + const esp_partition_t* partition = NULL; + size_t init_data_store_length = sizeof(phy_init_magic_pre) + + sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post); + uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length); + if (init_data_store == NULL) { + ESP_LOGE(TAG, "failed to allocate memory for updated country code PHY init data"); + return ESP_ERR_NO_MEM; + } + memcpy(init_data_store, multi_phy_init_data_bin_start, init_data_store_length); + ESP_LOGI(TAG, "load embedded multi phy init data"); +#else const esp_partition_t* partition = esp_partition_find_first( ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL); if (partition == NULL) { @@ -786,6 +825,7 @@ esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type) ESP_LOGE(TAG, "failed to read updated country code PHY data partition (0x%x)", err); return ESP_FAIL; } +#endif if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 || memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post), PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) { @@ -831,6 +871,12 @@ esp_err_t esp_phy_update_country_info(const char *country) { #if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN uint8_t phy_init_data_type_map = 0; + + if (!s_multiple_phy_init_data_bin) { + ESP_LOGD(TAG, "Does not support multiple PHY init data bins"); + return ESP_FAIL; + } + //if country equal s_phy_current_country, return; if (!memcmp(country, s_phy_current_country, sizeof(s_phy_current_country))) { return ESP_OK; @@ -838,11 +884,6 @@ esp_err_t esp_phy_update_country_info(const char *country) memcpy(s_phy_current_country, country, sizeof(s_phy_current_country)); - if (!s_multiple_phy_init_data_bin) { - ESP_LOGD(TAG, "Does not support multiple PHY init data bins"); - return ESP_FAIL; - } - phy_init_data_type_map = phy_find_bin_type_according_country(country); if (phy_init_data_type_map == s_phy_init_data_type) { return ESP_OK;