esp_partition: partition_linux.c and its test do not use hard-coded file anymore

This commit is contained in:
Jakob Hasse
2023-03-14 16:58:35 +08:00
parent 3c184338f2
commit f67bcc669a
4 changed files with 10 additions and 3 deletions

View File

@@ -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)

View File

@@ -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}\"")

View File

@@ -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;

View File

@@ -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));
}