From c898810991c8b032516d2fd84c68120e2c0bf47e Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 10 Jun 2021 13:33:54 +0800 Subject: [PATCH] esp_phy: support copy multi phy init data bin to build dir --- components/esp_phy/CMakeLists.txt | 32 ++++++++++++++++++++++--------- components/esp_phy/src/phy_init.c | 4 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index b59948788e..174a6b4e58 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -14,15 +14,29 @@ else() set(srcs "src/phy_init.c") endif() -idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS "include" "${idf_target}/include" - PRIV_REQUIRES nvs_flash - LDFRAGMENTS "${ldfragments}" - EMBED_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin" - ) - 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 "${srcs}" + INCLUDE_DIRS "include" "${idf_target}/include" + PRIV_REQUIRES nvs_flash + LDFRAGMENTS "${ldfragments}" + EMBED_FILES "${build_dir}/phy_multiple_init_data.bin" + ) +else() + idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS "include" "${idf_target}/include" + PRIV_REQUIRES nvs_flash + LDFRAGMENTS "${ldfragments}" + ) +endif() + set(target_name "${idf_target}") target_link_libraries(${COMPONENT_LIB} PUBLIC "-L \"${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}\"") @@ -54,9 +68,9 @@ 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}/${idf_target}/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 "${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin") + 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_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index b5dcff7b8c..bcd5e3f809 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -332,6 +332,10 @@ const esp_phy_init_data_t* esp_phy_get_init_data(void) 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, "loading embedded multiple PHY init data"); #else