diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ebea6f7..8660e3db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,55 +1,48 @@ cmake_minimum_required(VERSION 3.5) - -set(COMPONENT_ADD_INCLUDEDIRS main components/tools) - -if((DEFINED "$ENV{PROJECT_BUILD_NAME}") AND (DEFINED "$ENV{PROJECT_CONFIG_TARGET}")) - set(PROJECT_VER "$ENV{PROJECT_BUILD_NAME}-$ENV{PROJECT_CONFIG_TARGET}" ) -endif() - - - - - -if(DEFINED "$ENV{PROJECT_NAME}") - set(PROJECT_NAME "$ENV{PROJECT_NAME}") - message("Project name is $PROJECT_NAME") -else() - message("Project name is not set! Defaulting") - set(PROJECT_NAME "squeezelite-esp32") -endif() +set(EXTRA_COMPONENT_DIRS components/platform_console/app_recovery components/platform_console/app_squeezelite ) include($ENV{IDF_PATH}/tools/cmake/project.cmake) +message(WARNING "Building RECOVERY") -if(NOT ${PROJECT_NAME} STREQUAL "squeezelite-esp32" ) - add_definitions( -DRECOVERY_APPLICATION=1 ) - message(WARNING "Building Recovery") - project(recovery) -else() - message(WARNING "Building Squeezelite") - add_definitions( -DRECOVERY_APPLICATION=0 ) - project(squeezelite) -endif() +project(recovery) +set_property(TARGET recovery.elf PROPERTY RECOVERY_BUILD 0 ) +set_property(TARGET recovery.elf PROPERTY RECOVERY_PREFIX app_recovery ) + +# +#message(WARNING "Building SQUEEZELITE") +#set(project_name squeezelite) +#__project(${project_name} C CXX ASM) +# +set(squeezelite_project_elf squeezelite.elf) +# +# # Create a dummy file to work around CMake requirement of having a source +# # file while adding an executable +set(squeezelite_project_elf_src ${CMAKE_BINARY_DIR}/squeezelite_project_elf_src.c) +add_custom_command(OUTPUT ${squeezelite_project_elf_src} + COMMAND ${CMAKE_COMMAND} -E touch ${squeezelite_project_elf_src} + VERBATIM) + add_custom_command(OUTPUT "${build_dir}/.squeezelite_bin_timestamp" + COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${esptool_elf2image_args} + -o "${build_dir}/squeezelite.bin" "squeezelite.elf" + COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/squeezelite.bin" + COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/squeezelite.bin" > "${build_dir}/.squeezelite_bin_timestamp" + DEPENDS ${elf} + VERBATIM + WORKING_DIRECTORY ${build_dir} + COMMENT "Generating binary image from built executable" + ) -# Include ESP-IDF components in the build, may be thought as an equivalent of -# add_subdirectory() but with some additional procesing and magic for ESP-IDF build -# specific build processes. -#idf_build_process(esp32) +add_custom_target(_squeezelite_project_elf_src DEPENDS "${squeezelite_project_elf_src}" "${build_dir}/.squeezelite_bin_timestamp") +add_executable(${squeezelite_project_elf} "${squeezelite_project_elf_src}") +add_dependencies(${squeezelite_project_elf} _squeezelite_project_elf_src) +set_property(TARGET ${squeezelite_project_elf} PROPERTY RECOVERY_BUILD 0 ) +set_property(TARGET ${squeezelite_project_elf} PROPERTY RECOVERY_PREFIX app_squeezelite) -# Create the project executable and plainly link the newlib component to it using -# its alias, idf::newlib. -#add_executable(${CMAKE_PROJECT_NAME}.elf main.c) -#target_link_libraries(${CMAKE_PROJECT_NAME}.elf idf::newlib) - -# Let the build system know what the project executable is to attach more targets, dependencies, etc. -#idf_build_executable(${CMAKE_PROJECT_NAME}.elf) - - - - - - -# add_custom_target(size -# DEPENDS ${project_elf} -# COMMAND ${idf_size} ${mapfile} -# ) \ No newline at end of file +idf_build_get_property(bca BUILD_COMPONENT_ALIASES) +target_link_libraries(${squeezelite_project_elf} ${bca}) +set(squeezelite_mapfile "${CMAKE_BINARY_DIR}/squeezelite.map") +target_link_libraries(${squeezelite_project_elf} "-Wl,--cref -Wl,--Map=${squeezelite_mapfile}") +set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY + ADDITIONAL_MAKE_CLEAN_FILES + "${squeezelite_mapfile}" "${squeezelite_project_elf_src}") diff --git a/components/platform_bluetooth/CMakeLists.txt b/components/bluetooth/CMakeLists.txt similarity index 100% rename from components/platform_bluetooth/CMakeLists.txt rename to components/bluetooth/CMakeLists.txt diff --git a/components/platform_bluetooth/component.mk b/components/bluetooth/component.mk similarity index 100% rename from components/platform_bluetooth/component.mk rename to components/bluetooth/component.mk diff --git a/components/platform_bluetooth/platform_bt_core.c b/components/bluetooth/platform_bt_core.c similarity index 100% rename from components/platform_bluetooth/platform_bt_core.c rename to components/bluetooth/platform_bt_core.c diff --git a/components/platform_bluetooth/platform_bt_core.h b/components/bluetooth/platform_bt_core.h similarity index 100% rename from components/platform_bluetooth/platform_bt_core.h rename to components/bluetooth/platform_bt_core.h diff --git a/components/platform_bluetooth/platform_bt_sink.c b/components/bluetooth/platform_bt_sink.c similarity index 100% rename from components/platform_bluetooth/platform_bt_sink.c rename to components/bluetooth/platform_bt_sink.c diff --git a/components/platform_bluetooth/platform_bt_sink.h b/components/bluetooth/platform_bt_sink.h similarity index 100% rename from components/platform_bluetooth/platform_bt_sink.h rename to components/bluetooth/platform_bt_sink.h diff --git a/components/platform_bluetooth/platform_bt_source.c b/components/bluetooth/platform_bt_source.c similarity index 100% rename from components/platform_bluetooth/platform_bt_source.c rename to components/bluetooth/platform_bt_source.c diff --git a/components/codecs/CMakeLists.txt b/components/codecs/CMakeLists.txt index b38ddc16..63654a81 100644 --- a/components/codecs/CMakeLists.txt +++ b/components/codecs/CMakeLists.txt @@ -1,5 +1,6 @@ idf_component_register(SRC_DIRS . INCLUDE_DIRS . ./inc inc/alac inc/faad2 inc/FLAC inc/helix-aac inc/mad inc/ogg inc/opus inc/opusfile inc/resample16 inc/soxr inc/vorbis + PRIV_REQUIRES newlib ) add_prebuilt_library(libmad lib/libmad.a) diff --git a/components/platform_config/CMakeLists.txt b/components/platform_config/CMakeLists.txt index 1e41ace3..876257f4 100644 --- a/components/platform_config/CMakeLists.txt +++ b/components/platform_config/CMakeLists.txt @@ -1,6 +1,6 @@ idf_component_register( SRC_DIRS . INCLUDE_DIRS . - PRIV_REQUIRES json newlib console esp_common freertos + PRIV_REQUIRES json tools newlib console esp_common freertos REQUIRES nvs_flash ) diff --git a/components/platform_config/platform_config.c b/components/platform_config/platform_config.c index 1302f228..9c578a18 100644 --- a/components/platform_config/platform_config.c +++ b/components/platform_config/platform_config.c @@ -21,6 +21,7 @@ //#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE #include "platform_config.h" #include "nvs_utilities.h" +#include "platform_esp32.h" #include #include @@ -69,38 +70,18 @@ void config_set_entry_changed_flag(cJSON * entry, cJSON_bool flag); void * pval = config_alloc_get(nt, key);\ if(pval!=NULL){ *value = *(t * )pval; free(pval); return ESP_OK; }\ return ESP_FAIL;} -#if RECOVERY_APPLICATION==0 static void * malloc_fn(size_t sz){ - void * ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM); + void * ptr = is_recovery_running?malloc(sz):heap_caps_malloc(sz, MALLOC_CAP_SPIRAM); if(ptr==NULL){ ESP_LOGE(TAG,"malloc_fn: unable to allocate memory!"); } return ptr; } -/* -static void * free_fn(void * ptr){ - if(ptr!=NULL){ - heap_caps_free(ptr); - } - else { - ESP_LOGW(TAG,"free_fn: Cannot free null pointer!"); - } - return NULL; -} -*/ -#endif void init_cJSON(){ static cJSON_Hooks hooks; - // initialize cJSON hooks it uses SPIRAM memory - // as opposed to IRAM -#if RECOVERY_APPLICATION==0 - // In squeezelite mode, allocate memory from PSRAM. Otherwise allocate from internal RAM - // as recovery will lock flash access when erasing FLASH or writing to OTA partition. hooks.malloc_fn=&malloc_fn; - //hooks.free_fn=&free_fn; cJSON_InitHooks(&hooks); -#endif } void config_init(){ ESP_LOGD(TAG, "Creating mutex for Config"); diff --git a/components/platform_console/CMakeLists.txt b/components/platform_console/CMakeLists.txt index b92312e6..ba560328 100644 --- a/components/platform_console/CMakeLists.txt +++ b/components/platform_console/CMakeLists.txt @@ -1,5 +1,17 @@ -idf_component_register( SRC_DIRS . +idf_component_register( SRCS + cmd_i2ctools.c + cmd_nvs.c + cmd_ota.c + cmd_system.c + cmd_wifi.c + 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 squeezelite ) - \ No newline at end of file + PRIV_REQUIRES console tools services spi_flash app_update platform_config vfs pthread wifi-manager platform_config codecs newlib ) + + +#target_link_libraries(__idf_platform_console $ ) +message($) + +target_link_libraries(__idf_platform_console ${build_dir}/esp-idf/$/lib$.a ) +#target_link_libraries(__idf_platform_console $:${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 $) diff --git a/components/platform_console/app_recovery/recovery.c b/components/platform_console/app_recovery/recovery.c new file mode 100644 index 00000000..eb367ac4 --- /dev/null +++ b/components/platform_console/app_recovery/recovery.c @@ -0,0 +1,5 @@ +int main(int argc, char **argv){ + return 1; +} +void register_squeezelite(){ +} diff --git a/components/platform_console/app_squeezelite/CMakeLists.txt b/components/platform_console/app_squeezelite/CMakeLists.txt new file mode 100644 index 00000000..3af2ae78 --- /dev/null +++ b/components/platform_console/app_squeezelite/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register( SRC_DIRS . + INCLUDE_DIRS . + PRIV_REQUIRES console squeezelite pthread tools platform_config) + diff --git a/components/platform_console/cmd_squeezelite.c b/components/platform_console/app_squeezelite/cmd_squeezelite.c similarity index 96% rename from components/platform_console/cmd_squeezelite.c rename to components/platform_console/app_squeezelite/cmd_squeezelite.c index f6f83088..35ae9385 100644 --- a/components/platform_console/cmd_squeezelite.c +++ b/components/platform_console/app_squeezelite/cmd_squeezelite.c @@ -1,10 +1,5 @@ - -//size_t esp_console_split_argv(char *line, char **argv, size_t argv_size); -#include "cmd_squeezelite.h" - #include #include -#include "cmd_decl.h" #include "esp_log.h" #include "esp_console.h" diff --git a/components/platform_console/cmd_squeezelite.h b/components/platform_console/cmd_squeezelite.h deleted file mode 100644 index 77df2b19..00000000 --- a/components/platform_console/cmd_squeezelite.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -// Register WiFi functions -void register_squeezelite(); - -#ifdef __cplusplus -} -#endif - diff --git a/components/platform_console/cmd_system.c b/components/platform_console/cmd_system.c index 1921cb4a..cc4dbb8e 100644 --- a/components/platform_console/cmd_system.c +++ b/components/platform_console/cmd_system.c @@ -99,7 +99,7 @@ static void register_version() esp_err_t guided_boot(esp_partition_subtype_t partition_subtype) { -#if RECOVERY_APPLICATION +if(is_recovery_running){ if(partition_subtype ==ESP_PARTITION_SUBTYPE_APP_FACTORY){ ESP_LOGW(TAG,"RECOVERY application is already active"); if(!wait_for_commit()){ @@ -110,7 +110,8 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype) esp_restart(); return ESP_OK; } -#else +} +else { if(partition_subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY){ ESP_LOGW(TAG,"SQUEEZELITE application is already active"); if(!wait_for_commit()){ @@ -121,7 +122,7 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype) esp_restart(); return ESP_OK; } -#endif +} esp_err_t err = ESP_OK; bool bFound=false; ESP_LOGI(TAG, "Looking for partition type %u",partition_subtype); diff --git a/components/platform_console/platform_console.c b/components/platform_console/platform_console.c index 0c84fc55..cdaf3451 100644 --- a/components/platform_console/platform_console.c +++ b/components/platform_console/platform_console.c @@ -27,14 +27,13 @@ #include "cmd_decl.h" #include "wifi_manager.h" -#include "cmd_squeezelite.h" #include "platform_config.h" pthread_t thread_console; static void * console_thread(); void console_start(); static const char * TAG = "console"; extern bool bypass_wifi_manager; - +extern void register_squeezelite(); /* Prompt to be printed before each line. * This can be customized, made dynamic, etc. @@ -60,10 +59,9 @@ void process_autoexec(){ if(!bypass_wifi_manager){ ESP_LOGW(TAG, "Processing autoexec commands while wifi_manager active. Wifi related commands will be ignored."); } -#if RECOVERY_APPLICATION - ESP_LOGD(TAG, "Processing autoexec commands in recovery mode. Squeezelite commands will be ignored."); -#endif - + if(is_recovery_running){ + ESP_LOGD(TAG, "Processing autoexec commands in recovery mode. Squeezelite commands will be ignored."); + } if(str_flag !=NULL ){ autoexec_flag=atoi(str_flag); ESP_LOGI(TAG,"autoexec is set to %s auto-process", autoexec_flag>0?"perform":"skip"); @@ -76,11 +74,9 @@ void process_autoexec(){ if(!bypass_wifi_manager && strstr(autoexec_value, "join ")!=NULL ){ ESP_LOGW(TAG,"Ignoring wifi join command."); } -#if RECOVERY_APPLICATION - else if(!strstr(autoexec_value, "squeezelite " ) ){ + else if(is_recovery_running && !strstr(autoexec_value, "squeezelite " ) ){ ESP_LOGW(TAG,"Ignoring command. "); } -#endif else { ESP_LOGI(TAG,"Running command %s = %s", autoexec_name, autoexec_value); run_command(autoexec_value); @@ -164,32 +160,30 @@ void console_start() { register_system(); register_nvs(); register_wifi(); -#if RECOVERY_APPLICATION!=1 - register_squeezelite(); -#elif RECOVERY_APPLICATION==1 - register_ota_cmd(); -#else -#error "Unknown build configuration" -#endif + if(!is_recovery_running){ + register_squeezelite(); + } + else { + register_ota_cmd(); + } register_i2ctools(); - printf("\n" -#if RECOVERY_APPLICATION - "****************************************************************\n" - "RECOVERY APPLICATION\n" - "This mode is used to flash Squeezelite into the OTA partition\n" - "****\n\n" -#endif - "Type 'help' to get the list of commands.\n" - "Use UP/DOWN arrows to navigate through command history.\n" - "Press TAB when typing command name to auto-complete.\n" - "\n" -#if !RECOVERY_APPLICATION - "To automatically execute lines at startup:\n" - "\tSet NVS variable autoexec (U8) = 1 to enable, 0 to disable automatic execution.\n" - "\tSet NVS variable autoexec[1~9] (string)to a command that should be executed automatically\n" -#endif - "\n" - "\n"); + printf("\n"); + if(is_recovery_running){ + printf("****************************************************************\n" + "RECOVERY APPLICATION\n" + "This mode is used to flash Squeezelite into the OTA partition\n" + "****\n\n"); + } + printf("Type 'help' to get the list of commands.\n" + "Use UP/DOWN arrows to navigate through command history.\n" + "Press TAB when typing command name to auto-complete.\n" + "\n"); + if(!is_recovery_running){ + printf("To automatically execute lines at startup:\n" + "\tSet NVS variable autoexec (U8) = 1 to enable, 0 to disable automatic execution.\n" + "\tSet NVS variable autoexec[1~9] (string)to a command that should be executed automatically\n"); + } + printf("\n\n"); /* Figure out if the terminal supports escape sequences */ int probe_status = linenoiseProbe(); @@ -211,9 +205,9 @@ void console_start() { esp_pthread_cfg_t cfg = esp_pthread_get_default_config(); cfg.thread_name= "console"; cfg.inherit_cfg = true; -#if RECOVERY_APPLICATION - cfg.stack_size = 4096 ; -#endif + if(is_recovery_running){ + cfg.stack_size = 4096 ; + } esp_pthread_set_cfg(&cfg); pthread_attr_t attr; pthread_attr_init(&attr); @@ -238,9 +232,9 @@ void run_command(char * line){ } } static void * console_thread() { -#if !RECOVERY_APPLICATION - process_autoexec(); -#endif + if(!is_recovery_running){ + process_autoexec(); + } /* Main loop */ while (1) { /* Get a line using linenoise. diff --git a/components/squeezelite-ota/CMakeLists.txt b/components/squeezelite-ota/CMakeLists.txt index cf52bba1..a0276051 100644 --- a/components/squeezelite-ota/CMakeLists.txt +++ b/components/squeezelite-ota/CMakeLists.txt @@ -1,7 +1,7 @@ idf_component_register(SRC_DIRS . INCLUDE_DIRS . REQUIRES app_update esp_https_ota - PRIV_REQUIRES console platform_config spi_flash vfs console freertos platform_console + PRIV_REQUIRES console tools platform_config spi_flash vfs console freertos platform_console ) diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c index 0527cdf4..27bda936 100644 --- a/components/squeezelite-ota/squeezelite-ota.c +++ b/components/squeezelite-ota/squeezelite-ota.c @@ -24,12 +24,14 @@ #include "tcpip_adapter.h" #include "squeezelite-ota.h" #include "platform_config.h" +#include "platform_esp32.h" #include #include #include #include "esp_secure_boot.h" #include "esp_flash_encrypt.h" #include "esp_spi_flash.h" +#include "platform_esp32.h" #include "sdkconfig.h" #include "esp_ota_ops.h" @@ -593,22 +595,19 @@ esp_err_t process_recovery_ota(const char * bin_url){ esp_err_t start_ota(const char * bin_url) { -// uint8_t * config_alloc_get_default(NVS_TYPE_BLOB, "certs", server_cert_pem_start , server_cert_pem_end-server_cert_pem_start); -#if RECOVERY_APPLICATION - return process_recovery_ota(bin_url); -#else - ESP_LOGW(TAG, "Called to update the firmware from url: %s",bin_url); - if(config_set_value(NVS_TYPE_STR, "fwurl", bin_url) != ESP_OK){ - ESP_LOGE(TAG,"Failed to save the OTA url into nvs cache"); - return ESP_FAIL; - } + if(is_recovery_running){ + return process_recovery_ota(bin_url); + } + ESP_LOGW(TAG, "Called to update the firmware from url: %s",bin_url); + if(config_set_value(NVS_TYPE_STR, "fwurl", bin_url) != ESP_OK){ + ESP_LOGE(TAG,"Failed to save the OTA url into nvs cache"); + return ESP_FAIL; + } - if(!wait_for_commit()){ - ESP_LOGW(TAG,"Unable to commit configuration. "); - } + if(!wait_for_commit()){ + ESP_LOGW(TAG,"Unable to commit configuration. "); + } - ESP_LOGW(TAG, "Rebooting to recovery to complete the installation"); + ESP_LOGW(TAG, "Rebooting to recovery to complete the installation"); return guided_factory(); - return ESP_OK; -#endif } diff --git a/components/squeezelite-ota/squeezelite-ota.h b/components/squeezelite-ota/squeezelite-ota.h index 8e51ee74..76492565 100644 --- a/components/squeezelite-ota/squeezelite-ota.h +++ b/components/squeezelite-ota/squeezelite-ota.h @@ -9,16 +9,7 @@ #include "esp_attr.h" #include "esp_image_format.h" #include "esp_ota_ops.h" - -#if RECOVERY_APPLICATION -#define CODE_RAM_LOCATION -#define RECOVERY_IRAM_FUNCTION IRAM_ATTR -#else -#define RECOVERY_IRAM_FUNCTION -#define CODE_RAM_LOCATION -#endif - - +// // ERASE BLOCK needs to be a multiple of sector size. If a different multiple is passed // the OTA process will adjust. Here, we need to strike the balance between speed and diff --git a/components/squeezelite/CMakeLists.txt b/components/squeezelite/CMakeLists.txt index 4c6ba362..07e8249e 100644 --- a/components/squeezelite/CMakeLists.txt +++ b/components/squeezelite/CMakeLists.txt @@ -6,7 +6,7 @@ idf_component_register( SRC_DIRS . external a1s tas57xx esp_common esp-dsp platform_config - platform_bluetooth + bluetooth codecs services raop diff --git a/components/squeezelite/component.mk b/components/squeezelite/component.mk index 0b83b1b1..ed38471f 100644 --- a/components/squeezelite/component.mk +++ b/components/squeezelite/component.mk @@ -13,7 +13,7 @@ CFLAGS += -O3 -DLINKALL -DLOOPBACK -DNO_FAAD -DRESAMPLE16 -DEMBEDDED -DTREMOR_ON -I$(COMPONENT_PATH)/../tools \ -I$(COMPONENT_PATH)/../codecs/inc/opus \ -I$(COMPONENT_PATH)/../codecs/inc/opusfile \ - -I$(COMPONENT_PATH)/../platform_bluetooth \ + -I$(COMPONENT_PATH)/../bluetooth \ -I$(COMPONENT_PATH)/../raop \ -I$(COMPONENT_PATH)/../services diff --git a/components/tools/platform_esp32.h b/components/tools/platform_esp32.h index 0291154c..06a8c7bf 100644 --- a/components/tools/platform_esp32.h +++ b/components/tools/platform_esp32.h @@ -25,7 +25,7 @@ #ifndef SQUEEZELITE_ESP32_RELEASE_URL #define SQUEEZELITE_ESP32_RELEASE_URL "https://github.com/sle118/squeezelite-esp32/releases" #endif - +extern bool is_recovery_running; extern void run_command(char * line); extern bool wait_for_wifi(); extern void console_start(); diff --git a/components/wifi-manager/CMakeLists.txt b/components/wifi-manager/CMakeLists.txt index fd468dc7..a1645f27 100644 --- a/components/wifi-manager/CMakeLists.txt +++ b/components/wifi-manager/CMakeLists.txt @@ -3,7 +3,5 @@ idf_component_register( SRC_DIRS . REQUIRES squeezelite-ota json mdns PRIV_REQUIRES tools services platform_config esp_common json newlib freertos spi_flash nvs_flash mdns pthread wpa_supplicant platform_console EMBED_FILES style.css code.js index.html bootstrap.min.css.gz jquery.min.js.gz popper.min.js.gz bootstrap.min.js.gz - - ) diff --git a/components/wifi-manager/dns_server.c b/components/wifi-manager/dns_server.c index d5f0f529..eb61323d 100644 --- a/components/wifi-manager/dns_server.c +++ b/components/wifi-manager/dns_server.c @@ -59,11 +59,11 @@ static const char TAG[] = "dns_server"; static TaskHandle_t task_dns_server = NULL; int socket_fd; -void CODE_RAM_LOCATION dns_server_start() { +void dns_server_start() { xTaskCreate(&dns_server, "dns_server", 3072, NULL, WIFI_MANAGER_TASK_PRIORITY-1, &task_dns_server); } -void CODE_RAM_LOCATION dns_server_stop(){ +void dns_server_stop(){ if(task_dns_server){ vTaskDelete(task_dns_server); close(socket_fd); @@ -74,7 +74,7 @@ void CODE_RAM_LOCATION dns_server_stop(){ -void CODE_RAM_LOCATION dns_server(void *pvParameters) { +void dns_server(void *pvParameters) { diff --git a/components/wifi-manager/dns_server.h b/components/wifi-manager/dns_server.h index 631fea4b..81367169 100644 --- a/components/wifi-manager/dns_server.h +++ b/components/wifi-manager/dns_server.h @@ -127,9 +127,9 @@ typedef struct __attribute__((__packed__)) dns_answer_t{ uint32_t RDATA; /* For the sake of simplicity only ipv4 is supported, and as such it's a unsigned 32 bit */ }dns_answer_t; -void CODE_RAM_LOCATION dns_server(void *pvParameters); -void CODE_RAM_LOCATION dns_server_start(); -void CODE_RAM_LOCATION dns_server_stop(); +void dns_server(void *pvParameters); +void dns_server_start(); +void dns_server_stop(); diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c index 0cce4f10..d6fdc248 100644 --- a/components/wifi-manager/http_server.c +++ b/components/wifi-manager/http_server.c @@ -43,6 +43,7 @@ function to process requests, decode URLs, serve files, etc. etc. #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "platform_config.h" +#include "platform_esp32.h" #define HTTP_STACK_SIZE (5*1024) @@ -51,11 +52,7 @@ static const char TAG[] = "http_server"; /* @brief task handle for the http server */ static TaskHandle_t task_http_server = NULL; static StaticTask_t task_http_buffer; -#if RECOVERY_APPLICATION -static StackType_t task_http_stack[HTTP_STACK_SIZE]; -#else static StackType_t EXT_RAM_ATTR task_http_stack[HTTP_STACK_SIZE]; -#endif SemaphoreHandle_t http_server_config_mutex = NULL; /** @@ -490,11 +487,12 @@ void http_server_netconn_serve(struct netconn *conn) { netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); //200ok if(bOTA) { -#if RECOVERY_APPLICATION - ESP_LOGW(TAG, "Starting process OTA for url %s",otaURL); -#else - ESP_LOGW(TAG, "Restarting system to process OTA for url %s",otaURL); -#endif + if(is_recovery_running){ + ESP_LOGW(TAG, "Starting process OTA for url %s",otaURL); + } + else{ + ESP_LOGW(TAG, "Restarting system to process OTA for url %s",otaURL); + } wifi_manager_reboot_ota(otaURL); free(otaURL); } diff --git a/components/wifi-manager/http_server.h b/components/wifi-manager/http_server.h index 89542f24..5472d96c 100644 --- a/components/wifi-manager/http_server.h +++ b/components/wifi-manager/http_server.h @@ -67,13 +67,13 @@ extern "C" { * @brief RTOS task for the HTTP server. Do not start manually. * @see void http_server_start() */ -void CODE_RAM_LOCATION http_server(void *pvParameters); +void http_server(void *pvParameters); /* @brief helper function that processes one HTTP request at a time */ -void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn); +void http_server_netconn_serve(struct netconn *conn); /* @brief create the task for the http server */ -void CODE_RAM_LOCATION http_server_start(); +void http_server_start(); /** * @brief gets a char* pointer to the first occurence of header_name withing the complete http request request. @@ -86,9 +86,9 @@ void CODE_RAM_LOCATION http_server_start(); * @param len the size of the header value if found. * @return pointer to the beginning of the header value. */ -char* CODE_RAM_LOCATION http_server_get_header(char *request, char *header_name, int *len); +char* http_server_get_header(char *request, char *header_name, int *len); -void CODE_RAM_LOCATION strreplace(char *src, char *str, char *rep); +void strreplace(char *src, char *str, char *rep); /* @brief lock the json config object */ bool http_server_lock_json_object(TickType_t xTicksToWait); /* @brief unlock the json config object */ diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index 5ea12881..4a051459 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -64,10 +64,6 @@ Contains the freeRTOS task and all necessary support #include "monitor.h" #include "globdefs.h" -#ifndef RECOVERY_APPLICATION -#define RECOVERY_APPLICATION 0 -#endif - #ifndef SQUEEZELITE_ESP32_RELEASE_URL #define SQUEEZELITE_ESP32_RELEASE_URL "https://github.com/sle118/squeezelite-esp32/releases" #endif @@ -452,7 +448,7 @@ cJSON * wifi_manager_get_basic_info(cJSON **old){ cJSON_AddItemToObject(root, "project_name", cJSON_CreateString(desc->project_name)); cJSON_AddItemToObject(root, "version", cJSON_CreateString(desc->version)); if(release_url !=NULL) cJSON_AddItemToObject(root, "release_url", cJSON_CreateString(release_url)); - cJSON_AddNumberToObject(root,"recovery", RECOVERY_APPLICATION ); + cJSON_AddNumberToObject(root,"recovery", is_recovery_running?1:0); cJSON_AddItemToObject(root, "ota_dsc", cJSON_CreateString(ota_get_status())); cJSON_AddNumberToObject(root,"ota_pct", ota_get_pct_complete() ); cJSON_AddItemToObject(root, "Jack", cJSON_CreateString(jack_inserted_svc() ? "1" : "0")); diff --git a/components/wifi-manager/wifi_manager.h b/components/wifi-manager/wifi_manager.h index 5b260e1c..932f5ddc 100644 --- a/components/wifi-manager/wifi_manager.h +++ b/components/wifi-manager/wifi_manager.h @@ -42,18 +42,6 @@ extern "C" { #include "squeezelite-ota.h" #include "cJSON.h" -#ifndef RECOVERY_APPLICATION -#error "RECOVERY_APPLICATION not defined. Defaulting to squeezelite" -#endif - -#if RECOVERY_APPLICATION==1 -#elif RECOVERY_APPLICATION==0 -#pragma message "compiling for squeezelite." -#else -#error "unknown configuration" -#endif - - /** * @brief Defines the maximum size of a SSID name. 32 is IEEE standard. diff --git a/main/esp_app_main.c b/main/esp_app_main.c index 7aecce81..44ed94b6 100644 --- a/main/esp_app_main.c +++ b/main/esp_app_main.c @@ -70,6 +70,7 @@ extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end"); // as an exception _init function don't need include extern void services_init(void); extern void display_init(char *welcome); +bool is_recovery_running; /* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */ void cb_connection_got_ip(void *pvParameter){ @@ -357,6 +358,9 @@ void register_default_nvs(){ void app_main() { + const esp_partition_t *running = esp_ota_get_running_partition(); + is_recovery_running = (running->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY); + char * fwurl = NULL; ESP_LOGI(TAG,"Starting app_main"); initialize_nvs(); @@ -381,10 +385,10 @@ void app_main() ESP_LOGD(TAG,"Initializing display"); display_init("SqueezeESP32"); -#if !RECOVERY_APPLICATION - ESP_LOGI(TAG,"Checking if certificates need to be updated"); - update_certificates(); -#endif + if(!is_recovery_running){ + ESP_LOGI(TAG,"Checking if certificates need to be updated"); + update_certificates(); + } ESP_LOGD(TAG,"Getting firmware OTA URL (if any)"); fwurl = process_ota_url(); @@ -428,16 +432,17 @@ void app_main() } console_start(); if(fwurl && strlen(fwurl)>0){ -#if RECOVERY_APPLICATION - while(!bWifiConnected){ - wait_for_wifi(); - taskYIELD(); + if(is_recovery_running){ + while(!bWifiConnected){ + wait_for_wifi(); + taskYIELD(); + } + ESP_LOGI(TAG,"Updating firmware from link: %s",fwurl); + start_ota(fwurl); + } + else { + ESP_LOGE(TAG,"Restarted to application partition. We're not going to perform OTA!"); } - ESP_LOGI(TAG,"Updating firmware from link: %s",fwurl); - start_ota(fwurl); -#else - ESP_LOGE(TAG,"Restarted to application partition. We're not going to perform OTA!"); -#endif free(fwurl); } } diff --git a/mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt b/mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt deleted file mode 100644 index 6a6ed5fd..00000000 --- a/mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt +++ /dev/null @@ -1 +0,0 @@ -cmd='' diff --git a/mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt.in b/mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt.in deleted file mode 100644 index b3f09efc..00000000 --- a/mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt.in +++ /dev/null @@ -1 +0,0 @@ -cmd='@cmd@'