From 8a81fe821f9bd27a452639bef3cb739439056c85 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sat, 21 Mar 2020 12:38:10 -0400 Subject: [PATCH] fixing the binary app_name for squeezelite --- CMakeLists.txt | 11 ++- components/platform_console/CMakeLists.txt | 5 +- .../app_recovery/CMakeLists.txt | 16 ++-- .../app_recovery/application_name.h | 2 + .../platform_console/app_recovery/recovery.c | 27 ++++++ .../app_squeezelite/CMakeLists.txt | 15 +++- .../app_squeezelite/application_name.h | 2 + .../app_squeezelite/cmd_squeezelite.c | 27 +++++- generate_debug_scripts.cmake | 15 ++-- squeezelite.cmake | 84 ++++++++++++++----- 10 files changed, 157 insertions(+), 47 deletions(-) create mode 100644 components/platform_console/app_recovery/application_name.h create mode 100644 components/platform_console/app_squeezelite/application_name.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6ba2bb..d14afa89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,15 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) message(STATUS "Building RECOVERY") project(recovery) -set_property(TARGET recovery.elf PROPERTY RECOVERY_BUILD 0 ) -set_property(TARGET recovery.elf PROPERTY RECOVERY_PREFIX app_recovery ) + +set_property(TARGET recovery.elf PROPERTY RECOVERY_PREFIX app_recovery ) + + + include(squeezelite.cmake) + + + + \ No newline at end of file diff --git a/components/platform_console/CMakeLists.txt b/components/platform_console/CMakeLists.txt index 4eedf5b3..8f0f0e9f 100644 --- a/components/platform_console/CMakeLists.txt +++ b/components/platform_console/CMakeLists.txt @@ -7,6 +7,9 @@ idf_component_register( SRCS platform_console.c INCLUDE_DIRS . REQUIRES nvs_flash - PRIV_REQUIRES console tools services spi_flash app_update platform_config vfs pthread wifi-manager platform_config newlib telnet ) + PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet ) target_link_libraries(${COMPONENT_LIB} ${build_dir}/esp-idf/$/lib$.a ) + + + diff --git a/components/platform_console/app_recovery/CMakeLists.txt b/components/platform_console/app_recovery/CMakeLists.txt index df17e2bd..fb431851 100644 --- a/components/platform_console/app_recovery/CMakeLists.txt +++ b/components/platform_console/app_recovery/CMakeLists.txt @@ -1,13 +1,9 @@ idf_component_register( SRC_DIRS . INCLUDE_DIRS . + PRIV_REQUIRES bootloader_support ) -#idf_build_get_property(IS_RECOVERY 0 ) -#target_link_options(__idf_platform_console PUBLIC $<$:${COMPONENT_LIB}>) -#add_library(libcmd_squeezelite STATIC cmd_squeezelite.c ) -#__component_add_include_dirs(libcmd_squeezelite "${__INCLUDE_DIRS}" INTERFACE) -#set_property(TARGET libcmd_squeezelite APPEND PROPERTY LINK_LIBRARIES console) -#set_property(TARGET libcmd_squeezelite APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) -# -# -#add_library(librecovery STATIC recovery.c ) -#target_link_options(${COMPONENT_LIB} PUBLIC $) + +target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=esp_app_desc") +idf_build_get_property(project_ver PROJECT_VER) +string(SUBSTRING "${project_ver}" 0 31 PROJECT_VER_CUT) +set_source_files_properties(recovery.c PROPERTIES COMPILE_DEFINITIONS "PROJECT_VER=\"${PROJECT_VER_CUT}\"; PROJECT_NAME=\"recovery\"") diff --git a/components/platform_console/app_recovery/application_name.h b/components/platform_console/app_recovery/application_name.h new file mode 100644 index 00000000..192a48a7 --- /dev/null +++ b/components/platform_console/app_recovery/application_name.h @@ -0,0 +1,2 @@ +#pragma once +#define PROJECT_NAME "recovery" diff --git a/components/platform_console/app_recovery/recovery.c b/components/platform_console/app_recovery/recovery.c index eb367ac4..e48dd5a5 100644 --- a/components/platform_console/app_recovery/recovery.c +++ b/components/platform_console/app_recovery/recovery.c @@ -1,3 +1,30 @@ +#include +#include + +#include "esp_app_format.h" + + +const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { + .magic_word = ESP_APP_DESC_MAGIC_WORD, + .version = PROJECT_VER, + .project_name = PROJECT_NAME, + .idf_ver = IDF_VER, + +#ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION + .secure_version = CONFIG_BOOTLOADER_APP_SECURE_VERSION, +#else + .secure_version = 0, +#endif + +#ifdef CONFIG_APP_COMPILE_TIME_DATE + .time = __TIME__, + .date = __DATE__, +#else + .time = "", + .date = "", +#endif +}; + int main(int argc, char **argv){ return 1; } diff --git a/components/platform_console/app_squeezelite/CMakeLists.txt b/components/platform_console/app_squeezelite/CMakeLists.txt index 738fd047..b9a8d8e7 100644 --- a/components/platform_console/app_squeezelite/CMakeLists.txt +++ b/components/platform_console/app_squeezelite/CMakeLists.txt @@ -1,6 +1,15 @@ -idf_component_register( SRC_DIRS . - INCLUDE_DIRS . - PRIV_REQUIRES console codecs squeezelite newlib pthread tools platform_config) + idf_build_get_property(idf_path IDF_PATH) +idf_component_register( SRCS cmd_squeezelite.c + INCLUDE_DIRS . + PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config ) + + target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof") target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=fdopen") +target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=esp_app_desc") + +idf_build_get_property(project_ver PROJECT_VER) +string(SUBSTRING "${project_ver}" 0 31 PROJECT_VER_CUT) +set_source_files_properties(cmd_squeezelite.c PROPERTIES COMPILE_DEFINITIONS "PROJECT_VER=\"${PROJECT_VER_CUT}\"; PROJECT_NAME=\"squeezelite\"") + diff --git a/components/platform_console/app_squeezelite/application_name.h b/components/platform_console/app_squeezelite/application_name.h new file mode 100644 index 00000000..d6d6a9ef --- /dev/null +++ b/components/platform_console/app_squeezelite/application_name.h @@ -0,0 +1,2 @@ +#pragma once +#define PROJECT_NAME "squeezelite" diff --git a/components/platform_console/app_squeezelite/cmd_squeezelite.c b/components/platform_console/app_squeezelite/cmd_squeezelite.c index 35ae9385..f6ecf11e 100644 --- a/components/platform_console/app_squeezelite/cmd_squeezelite.c +++ b/components/platform_console/app_squeezelite/cmd_squeezelite.c @@ -10,9 +10,34 @@ #include "pthread.h" #include "platform_esp32.h" #include "platform_config.h" - +#include "esp_app_format.h" static const char * TAG = "squeezelite_cmd"; #define SQUEEZELITE_THREAD_STACK_SIZE (6*1024) + + + +const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = { + + .magic_word = ESP_APP_DESC_MAGIC_WORD, + .version = PROJECT_VER, + .project_name = PROJECT_NAME, + .idf_ver = IDF_VER, + +#ifdef CONFIG_BOOTLOADER_APP_SECURE_VERSION + .secure_version = CONFIG_BOOTLOADER_APP_SECURE_VERSION, +#else + .secure_version = 0, +#endif + +#ifdef CONFIG_APP_COMPILE_TIME_DATE + .time = __TIME__, + .date = __DATE__, +#else + .time = "", + .date = "", +#endif +}; + extern int main(int argc, char **argv); static int launchsqueezelite(int argc, char **argv); pthread_t thread_squeezelite; diff --git a/generate_debug_scripts.cmake b/generate_debug_scripts.cmake index 786dd0b9..3d4f72e9 100644 --- a/generate_debug_scripts.cmake +++ b/generate_debug_scripts.cmake @@ -3,7 +3,7 @@ function(___output_debug_target bin_name ) file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" cm_build_dir) if( "${bin_name}" STREQUAL "_" ) - set(debug_file "dbg_project_args" ) + set(debug_file "dbg_project" ) else() set(debug_file "dbg_${bin_name}" ) endif() @@ -15,7 +15,7 @@ function(___output_debug_target bin_name ) file(READ ${flash_args_file} flash_args) - + list(APPEND dbg_cmds "target remote :3333") list(APPEND dbg_cmds "mon reset halt") list(APPEND dbg_cmds "flushregs") list(APPEND dbg_cmds "set remote hardware-watchpoint-limit 2") @@ -38,15 +38,12 @@ function(___output_debug_target bin_name ) list(APPEND flash_dbg_cmds "${line_prefix}${found_bin} ${found_offset}") endif() - if( ( "${found_bin}" MATCHES "${bin_name}" ) ) - list(APPEND dbg_cmds "mon esp32 appoffset ${found_offset}") + if( ( "${found_bin}" MATCHES "${bin_name}" ) AND NOT ( "${bin_name}" STREQUAL "_" ) ) + list(APPEND dbg_cmds "mon esp32 appimage_offset ${found_offset}") endif() endif() endforeach() - list(APPEND dbg_cmds_end "mon reset halt") - list(APPEND dbg_cmds_end "flushregs") - list(APPEND full_dbg_cmds "${dbg_cmds}") list(APPEND full_dbg_cmds "${dbg_cmds_end}") @@ -57,9 +54,9 @@ function(___output_debug_target bin_name ) STRING(REGEX REPLACE ";" "\n" full_dbg_cmds "${full_dbg_cmds}") STRING(REGEX REPLACE ";" "\n" full_flash_dbg_cmds "${full_flash_dbg_cmds}") - message("Writing: ${debug_file} with ${full_dbg_cmds}") +# message("Writing: ${debug_file} with ${full_dbg_cmds}") file(WRITE "${debug_file}" "${full_dbg_cmds}") - message("Writing: ${flash_debug_file} with : ${full_flash_dbg_cmds}") +# message("Writing: ${flash_debug_file} with : ${full_flash_dbg_cmds}") file(WRITE "${flash_debug_file}" "${full_flash_dbg_cmds}") diff --git a/squeezelite.cmake b/squeezelite.cmake index 18b542dd..4b7ae15f 100644 --- a/squeezelite.cmake +++ b/squeezelite.cmake @@ -1,26 +1,45 @@ - -#include($ENV{IDF_PATH}/components/esptool_py/project_include.cmake) - -if(NOT SDKCONFIG OR NOT IDF_PATH OR NOT IDF_TARGET ) - message(FATAL_ERROR "squeezelite should not be made outside of the main project !") -endif() - - function(___register_flash target_name sub_type) partition_table_get_partition_info(otaapp_offset "--partition-type app --partition-subtype ${sub_type}" "offset") esptool_py_flash_project_args(${target_name} ${otaapp_offset} ${build_dir}/${target_name}.bin FLASH_IN_PROJECT) esptool_py_custom_target(${target_name}-flash ${target_name} "${target_name}") endfunction() +# +# Removes the specified compile flag from the specified target. +# _target - The target to remove the compile flag from +# _flag - The compile flag to remove +# +# Pre: apply_global_cxx_flags_to_all_targets() must be invoked. +# +macro(remove_flag_from_target _target _flag) + get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS) + if(_target_cxx_flags) + list(REMOVE_ITEM _target_cxx_flags ${_flag}) + set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}") + endif() +endmacro() +function(___print_list pref listcontent) + message("") + message("${pref}") + foreach(e ${listcontent}) + message("${pref} ${e}") + endforeach() + message("") +endfunction() function(___create_new_target target_name) idf_build_get_property(build_dir BUILD_DIR) + file(TO_CMAKE_PATH "${IDF_PATH}" idf_path) + set(target_elf ${target_name}.elf) + # Create a dummy file to work around CMake requirement of having a source # file while adding an executable + set(target_elf_src ${CMAKE_BINARY_DIR}/${target_name}_src.c) add_custom_command(OUTPUT ${target_elf_src} + BUILD COMMAND ${CMAKE_COMMAND} -E touch ${target_elf_src} VERBATIM) @@ -28,20 +47,30 @@ function(___create_new_target target_name) add_executable(${target_elf} "${target_elf_src}") add_dependencies(${target_elf} _${target_name}_elf) add_dependencies(${target_elf} "recovery.elf") - set_property(TARGET ${target_elf} PROPERTY RECOVERY_BUILD 0 ) + set_property(TARGET ${target_elf} PROPERTY RECOVERY_PREFIX app_${target_name}) - idf_build_get_property(bca BUILD_COMPONENT_ALIASES) + + + + # Remove app_recovery so that app_squeezelite and dependencies are properly resolved + idf_build_get_property(bca BUILD_COMPONENT_ALIASES) + list(REMOVE_ITEM bca "idf::app_recovery") + list(REMOVE_ITEM bca "idf::app_squeezelite") target_link_libraries(${target_elf} ${bca}) + target_link_libraries(${target_elf} idf::app_squeezelite) set(target_name_mapfile "${target_name}.map") target_link_libraries(${target_elf} "-Wl,--cref -Wl,--Map=${CMAKE_BINARY_DIR}/${target_name_mapfile}") + +# idf_build_get_property(link_depends __LINK_DEPENDS) +# idf_build_get_property(link_options LINK_OPTIONS) +# idf_build_get_property(ldgen_libraries __LDGEN_LIBRARIES GENERATOR_EXPRESSION) + add_custom_command( TARGET ${target_elf} + POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/${target_name}.bin" - #COMMAND echo ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${esptool_elf2image_args} - #COMMAND echo ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} - COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} - -o "${build_dir}/${target_name}.bin" "${target_name}.elf" + COMMAND ${CMAKE_COMMAND} -E echo "Generating ${build_dir}/${target_name}.bin" + COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS} -o "${build_dir}/${target_name}.bin" "${target_name}.elf" DEPENDS "${target_name}.elf" WORKING_DIRECTORY ${build_dir} COMMENT "Generating binary image from built executable" @@ -54,17 +83,30 @@ function(___create_new_target target_name) endfunction() - ___create_new_target(squeezelite ) ___register_flash(squeezelite ota_0) -#add_custom_target(_jtag_scripts ALL -# BYPRODUCTS flash_dbg_project_args -# COMMAND ${CMAKE_COMMAND} -# DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/build/partition_table/partition-table.bin" ) + add_custom_target(_jtag_scripts ALL BYPRODUCTS "flash_dbg_project_args" POST_BUILD - COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake") + COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_debug_scripts.cmake" +# COMMAND ${CMAKE_COMMAND} --graphviz=graph.dot . +# $ sed -n 's/.*label="\(.*\)"\s.*/\1/p' graph.dot.foo > foo_dependencies.txt + ) + add_dependencies(partition_table _jtag_scripts) +idf_build_get_property(build_dir BUILD_DIR) +add_custom_command( + TARGET recovery.elf + PRE_LINK + COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a + VERBATIM +) +add_custom_command( + TARGET squeezelite.elf + PRE_LINK + COMMAND xtensa-esp32-elf-objcopy --weaken-symbol esp_app_desc ${build_dir}/esp-idf/app_update/libapp_update.a + VERBATIM +) \ No newline at end of file