diff --git a/tools/cmake/scripts/data_file_embed_asm.cmake b/tools/cmake/scripts/data_file_embed_asm.cmake index 291f9fea2..0422ed185 100644 --- a/tools/cmake/scripts/data_file_embed_asm.cmake +++ b/tools/cmake/scripts/data_file_embed_asm.cmake @@ -38,9 +38,7 @@ string(REGEX REPLACE "[^\n]+$" ".byte \\0\n" data "${data}") string(REGEX REPLACE "[0-9a-f][0-9a-f]" "0x\\0, " data "${data}") # hex formatted C bytes string(REGEX REPLACE ", \n" "\n" data "${data}") # trim the last comma -## Come up with C-friendly symbol name based on source file -get_filename_component(source_filename "${DATA_FILE}" NAME) -string(MAKE_C_IDENTIFIER "${source_filename}" varname) +get_filename_component(varname "${DATA_FILE}" NAME) function(append str) file(APPEND "${SOURCE_FILE}" "${str}") @@ -50,13 +48,14 @@ function(append_line str) append("${str}\n") endfunction() -function(append_identifier symbol) -append_line("\n.global ${symbol}") -append("${symbol}:") -if(${ARGC} GREATER 1) # optional comment - append(" /* ${ARGV1} */") -endif() -append("\n") +function(make_and_append_identifier str) + string(MAKE_C_IDENTIFIER "${str}" symbol) + append_line("\n.global ${symbol}") + append("${symbol}:") + if(${ARGC} GREATER 1) # optional comment + append(" /* ${ARGV1} */") + endif() + append("\n") endfunction() file(WRITE "${SOURCE_FILE}" "/*") @@ -68,16 +67,15 @@ append_line(" */") append_line(".data") append_line(".section .rodata.embedded") -append_identifier("${varname}") -append_identifier("_binary_${varname}_start" "for objcopy compatibility") +make_and_append_identifier("${varname}") +make_and_append_identifier("_binary_${varname}_start" "for objcopy compatibility") append("${data}") - -append_identifier("_binary_${varname}_end" "for objcopy compatibility") +make_and_append_identifier("_binary_${varname}_end" "for objcopy compatibility") append_line("") if(FILE_TYPE STREQUAL "TEXT") - append_identifier("${varname}_length" "not including null byte") + make_and_append_identifier("${varname}_length" "not including null byte") else() - append_identifier("${varname}_length") + make_and_append_identifier("${varname}_length") endif() append_line(".word ${data_len}") diff --git a/tools/test_apps/build_system/embed_test/CMakeLists.txt b/tools/test_apps/build_system/embed_test/CMakeLists.txt new file mode 100644 index 000000000..37f6ccfc1 --- /dev/null +++ b/tools/test_apps/build_system/embed_test/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(file_embed_test) diff --git a/tools/test_apps/build_system/embed_test/README.txt b/tools/test_apps/build_system/embed_test/README.txt new file mode 100644 index 000000000..a847054bc --- /dev/null +++ b/tools/test_apps/build_system/embed_test/README.txt @@ -0,0 +1 @@ +This project tests that proper identifiers are generated during build for embedded files. diff --git a/tools/test_apps/build_system/embed_test/main/2file.txt b/tools/test_apps/build_system/embed_test/main/2file.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tools/test_apps/build_system/embed_test/main/CMakeLists.txt b/tools/test_apps/build_system/embed_test/main/CMakeLists.txt new file mode 100644 index 000000000..cee0c41d0 --- /dev/null +++ b/tools/test_apps/build_system/embed_test/main/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "test_main.c" + INCLUDE_DIRS "." + # Test file names starting with a number, a letter and an underscore. + EMBED_TXTFILES "2file.txt" "file.txt" "_file.txt") diff --git a/tools/test_apps/build_system/embed_test/main/_file.txt b/tools/test_apps/build_system/embed_test/main/_file.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tools/test_apps/build_system/embed_test/main/file.txt b/tools/test_apps/build_system/embed_test/main/file.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tools/test_apps/build_system/embed_test/main/test_main.c b/tools/test_apps/build_system/embed_test/main/test_main.c new file mode 100644 index 000000000..5c2881b80 --- /dev/null +++ b/tools/test_apps/build_system/embed_test/main/test_main.c @@ -0,0 +1,18 @@ +#include +#include + +extern uint8_t _2file_start[] asm("_binary_2file_txt_start"); +extern uint8_t _2file_end[] asm("_binary_2file_txt_end"); +extern uint8_t file_start[] asm("_binary_file_txt_start"); +extern uint8_t file_end[] asm("_binary_file_txt_start"); +extern uint8_t _file_start[] asm("_binary__file_txt_start"); +extern uint8_t _file_end[] asm("_binary__file_txt_start"); + +#define PRINT_ADDR(f) printf("%s -> start: %p end:%p\n", #f, f ## _start, f ## _end); + +void app_main(void) +{ + PRINT_ADDR(_2file); + PRINT_ADDR(file); + PRINT_ADDR(_file); +}