Browse Source

idf.py app now builds both squeezelite and recovery in a single pass

Sebastien 5 năm trước cách đây
mục cha
commit
879272dfe4
35 tập tin đã thay đổi với 181 bổ sung222 xóa
  1. 46 53
      CMakeLists.txt
  2. 0 0
      components/bluetooth/CMakeLists.txt
  3. 0 0
      components/bluetooth/component.mk
  4. 0 0
      components/bluetooth/platform_bt_core.c
  5. 0 0
      components/bluetooth/platform_bt_core.h
  6. 0 0
      components/bluetooth/platform_bt_sink.c
  7. 0 0
      components/bluetooth/platform_bt_sink.h
  8. 0 0
      components/bluetooth/platform_bt_source.c
  9. 1 0
      components/codecs/CMakeLists.txt
  10. 1 1
      components/platform_config/CMakeLists.txt
  11. 2 21
      components/platform_config/platform_config.c
  12. 15 3
      components/platform_console/CMakeLists.txt
  13. 13 0
      components/platform_console/app_recovery/CMakeLists.txt
  14. 5 0
      components/platform_console/app_recovery/recovery.c
  15. 4 0
      components/platform_console/app_squeezelite/CMakeLists.txt
  16. 0 5
      components/platform_console/app_squeezelite/cmd_squeezelite.c
  17. 0 13
      components/platform_console/cmd_squeezelite.h
  18. 4 3
      components/platform_console/cmd_system.c
  19. 34 40
      components/platform_console/platform_console.c
  20. 1 1
      components/squeezelite-ota/CMakeLists.txt
  21. 14 15
      components/squeezelite-ota/squeezelite-ota.c
  22. 1 10
      components/squeezelite-ota/squeezelite-ota.h
  23. 1 1
      components/squeezelite/CMakeLists.txt
  24. 1 1
      components/squeezelite/component.mk
  25. 1 1
      components/tools/platform_esp32.h
  26. 0 2
      components/wifi-manager/CMakeLists.txt
  27. 3 3
      components/wifi-manager/dns_server.c
  28. 3 3
      components/wifi-manager/dns_server.h
  29. 7 9
      components/wifi-manager/http_server.c
  30. 5 5
      components/wifi-manager/http_server.h
  31. 1 5
      components/wifi-manager/wifi_manager.c
  32. 0 12
      components/wifi-manager/wifi_manager.h
  33. 18 13
      main/esp_app_main.c
  34. 0 1
      mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt
  35. 0 1
      mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt.in

+ 46 - 53
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)
-
-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()
-
-
-
-# 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)
-
-# 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}
-#        )
+message(WARNING  "Building RECOVERY")
+
+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"
+        )
+
+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)
+
+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}")

+ 0 - 0
components/platform_bluetooth/CMakeLists.txt → components/bluetooth/CMakeLists.txt


+ 0 - 0
components/platform_bluetooth/component.mk → components/bluetooth/component.mk


+ 0 - 0
components/platform_bluetooth/platform_bt_core.c → components/bluetooth/platform_bt_core.c


+ 0 - 0
components/platform_bluetooth/platform_bt_core.h → components/bluetooth/platform_bt_core.h


+ 0 - 0
components/platform_bluetooth/platform_bt_sink.c → components/bluetooth/platform_bt_sink.c


+ 0 - 0
components/platform_bluetooth/platform_bt_sink.h → components/bluetooth/platform_bt_sink.h


+ 0 - 0
components/platform_bluetooth/platform_bt_source.c → components/bluetooth/platform_bt_source.c


+ 1 - 0
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)

+ 1 - 1
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
 )
 

+ 2 - 21
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 <stdio.h>
 #include <string.h>
@@ -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");

+ 15 - 3
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 )
-						
+						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 $<IF:${recovery_build}, ${build_dir}/esp-idf/app_recovery/libapp_recovery.a,${build_dir}/esp-idf/app_squeezelite/libapp_squeezelite.a >	)
+message($<TARGET_PROPERTY:RECOVERY_PREFIX>)
+
+target_link_libraries(__idf_platform_console ${build_dir}/esp-idf/$<TARGET_PROPERTY:RECOVERY_PREFIX>/lib$<TARGET_PROPERTY:RECOVERY_PREFIX>.a 	)
+#target_link_libraries(__idf_platform_console $<NOT ${recovery_build}:${build_dir}/esp-idf/app_squeezelite/libapp_squeezelite )

+ 13 - 0
components/platform_console/app_recovery/CMakeLists.txt

@@ -0,0 +1,13 @@
+idf_component_register( SRC_DIRS .
+						INCLUDE_DIRS .   
+ )
+#idf_build_get_property(IS_RECOVERY  0 )
+#target_link_options(__idf_platform_console PUBLIC $<$<EQUAL:${IS_RECOVERY},1>:${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 $<LINK_ONLY:console>)
+#
+#
+#add_library(librecovery STATIC recovery.c )
+#target_link_options(${COMPONENT_LIB} PUBLIC $<IF:${IS_RECOVERY},librecovery.a,libcmd_squeezelite.a>)						 

+ 5 - 0
components/platform_console/app_recovery/recovery.c

@@ -0,0 +1,5 @@
+int main(int argc, char **argv){
+	return 1;
+}
+void register_squeezelite(){
+}

+ 4 - 0
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)
+

+ 0 - 5
components/platform_console/cmd_squeezelite.c → 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 <stdio.h>
 #include <string.h>
-#include "cmd_decl.h"
 
 #include "esp_log.h"
 #include "esp_console.h"

+ 0 - 13
components/platform_console/cmd_squeezelite.h

@@ -1,13 +0,0 @@
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// Register WiFi functions
-void register_squeezelite();
-
-#ifdef __cplusplus
-}
-#endif
-

+ 4 - 3
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);

+ 34 - 40
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.

+ 1 - 1
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 
 					  )
 
 

+ 14 - 15
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 <time.h>
 #include <sys/time.h>
 #include <stdarg.h>
 #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
 }

+ 1 - 10
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

+ 1 - 1
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   

+ 1 - 1
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
 

+ 1 - 1
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();

+ 0 - 2
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
-
-
 )
  

+ 3 - 3
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) {
 
 
 

+ 3 - 3
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();
 
 
 

+ 7 - 9
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);
 						}

+ 5 - 5
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 */

+ 1 - 5
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"));

+ 0 - 12
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.

+ 18 - 13
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);
 	}
 }

+ 0 - 1
mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt

@@ -1 +0,0 @@
-cmd=''

+ 0 - 1
mconf-idf-prefix/tmp/mconf-idf-cfgcmd.txt.in

@@ -1 +0,0 @@
-cmd='@cmd@'