From f67bcc669a3eec57626a4eeadc86ca42a1fbcb31 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Tue, 14 Mar 2023 16:58:35 +0800 Subject: [PATCH] esp_partition: partition_linux.c and its test do not use hard-coded file anymore --- components/esp_partition/CMakeLists.txt | 4 ++++ .../host_test/partition_api_test/main/CMakeLists.txt | 3 +++ .../host_test/partition_api_test/main/partition_api_test.c | 4 ++-- components/esp_partition/partition_linux.c | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/components/esp_partition/CMakeLists.txt b/components/esp_partition/CMakeLists.txt index 5220e47671..371dae2c24 100644 --- a/components/esp_partition/CMakeLists.txt +++ b/components/esp_partition/CMakeLists.txt @@ -3,6 +3,7 @@ set(priv_reqs esp_system bootloader_support spi_flash app_update partition_table set(reqs) set(include_dirs "include") +idf_build_get_property(build_dir BUILD_DIR) idf_build_get_property(target IDF_TARGET) if(${target} STREQUAL "linux") list(APPEND srcs "partition_linux.c") @@ -22,6 +23,9 @@ idf_component_register(SRCS "${srcs}" PRIV_REQUIRES ${priv_reqs}) if(${target} STREQUAL "linux") + # set BUILD_DIR because partition_linux.c uses a file created in the build directory + target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"") + # link bsd library for strlcpy find_library(LIB_BSD bsd) if(LIB_BSD) diff --git a/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt b/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt index 5dee25b740..d0d6d1e909 100644 --- a/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt +++ b/components/esp_partition/host_test/partition_api_test/main/CMakeLists.txt @@ -1,2 +1,5 @@ idf_component_register(SRCS "partition_api_test.c" REQUIRES esp_partition 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/esp_partition/host_test/partition_api_test/main/partition_api_test.c b/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c index f6ab19c432..a82952c26b 100644 --- a/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c +++ b/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c @@ -171,7 +171,7 @@ TEST(partition_api, test_partition_mmap_diff_size) memset(p_file_mmap_ctrl, 0, sizeof(*p_file_mmap_ctrl)); p_file_mmap_ctrl->flash_file_size = 0x800000; // 8MB - strlcpy(p_file_mmap_ctrl->partition_file_name, "./build/partition_table/partition-table_8M.bin", sizeof(p_file_mmap_ctrl->partition_file_name)); + strlcpy(p_file_mmap_ctrl->partition_file_name, BUILD_DIR "/partition_table/partition-table_8M.bin", sizeof(p_file_mmap_ctrl->partition_file_name)); // esp_partition_find_first calls the esp_partition_file_mmap in the background const esp_partition_t *partition_data = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage"); @@ -483,7 +483,7 @@ TEST(partition_api, test_partition_mmap_size_too_small) memset(p_file_mmap_ctrl_input, 0, sizeof(*p_file_mmap_ctrl_input)); // set valid partition table name and very small flash size - strlcpy(p_file_mmap_ctrl_input->partition_file_name, "./build/partition_table/partition-table.bin", sizeof(p_file_mmap_ctrl_input->partition_file_name)); + strlcpy(p_file_mmap_ctrl_input->partition_file_name, BUILD_DIR "/partition_table/partition-table.bin", sizeof(p_file_mmap_ctrl_input->partition_file_name)); p_file_mmap_ctrl_input->flash_file_size = 1; const uint8_t *p_mem_block = NULL; diff --git a/components/esp_partition/partition_linux.c b/components/esp_partition/partition_linux.c index 50ebe0103c..4c55e5e579 100644 --- a/components/esp_partition/partition_linux.c +++ b/components/esp_partition/partition_linux.c @@ -140,7 +140,7 @@ esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start) // check if partition file is present, if not, use default if (!has_partfile) { - strlcpy(s_esp_partition_file_mmap_ctrl_act.partition_file_name, "build/partition_table/partition-table.bin", sizeof(s_esp_partition_file_mmap_ctrl_act.partition_file_name)); + strlcpy(s_esp_partition_file_mmap_ctrl_act.partition_file_name, BUILD_DIR "/partition_table/partition-table.bin", sizeof(s_esp_partition_file_mmap_ctrl_act.partition_file_name)); } else { strlcpy(s_esp_partition_file_mmap_ctrl_act.partition_file_name, s_esp_partition_file_mmap_ctrl_input.partition_file_name, sizeof(s_esp_partition_file_mmap_ctrl_act.partition_file_name)); }