From 3061ae40c0ef8902f3148a5c322bdc4f69902bf1 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 13 Sep 2016 13:46:51 +1000 Subject: [PATCH 1/2] bootloader: Add bootloader Kconfig Allow debug level & colour highlighting to be configured --- components/bootloader/Kconfig.projbuild | 33 +++++++++ components/bootloader/Makefile.projbuild | 3 + components/bootloader/src/Makefile | 7 +- .../bootloader/src/main/bootloader_log.h | 67 +++++++++++++------ .../bootloader/src/main/bootloader_start.c | 2 - 5 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 components/bootloader/Kconfig.projbuild diff --git a/components/bootloader/Kconfig.projbuild b/components/bootloader/Kconfig.projbuild new file mode 100644 index 000000000..74028b6e9 --- /dev/null +++ b/components/bootloader/Kconfig.projbuild @@ -0,0 +1,33 @@ +menu "Bootloader config" + +choice BOOTLOADER_LOG_LEVEL + bool "Bootloader log verbosity" + default BOOTLOADER_LOG_LEVEL_NOTICE + help + Specify how much output to see in the bootloader logs. + + Note that if MTDO is HIGH on reset, all early boot output + (including bootloader logs) are suppressed. +config BOOTLOADER_LOG_LEVEL_NONE + bool "No output" +config BOOTLOADER_LOG_LEVEL_ERROR + bool "Error" +config BOOTLOADER_LOG_LEVEL_WARN + bool "Warning" +config BOOTLOADER_LOG_LEVEL_INFO + bool "Info" +config BOOTLOADER_LOG_LEVEL_NOTICE + bool "Notice" +config BOOTLOADER_LOG_LEVEL_DEBUG + bool "Debug" +endchoice + +config BOOTLOADER_LOG_COLORS + bool "Use ANSI terminal colors in bootloader log output" + default "y" + help + Enable ANSI terminal color codes in bootloader output. + + In order to view these, your terminal program must support ANSI color codes. + +endmenu diff --git a/components/bootloader/Makefile.projbuild b/components/bootloader/Makefile.projbuild index 48c09d481..aaebd4d26 100644 --- a/components/bootloader/Makefile.projbuild +++ b/components/bootloader/Makefile.projbuild @@ -8,6 +8,7 @@ # basically runs Make in the src/ directory but it needs to zero some variables # the ESP-IDF project.mk makefile exports first, to not let them interfere. # +ifeq ("$(IS_BOOTLOADER_BUILD)","") BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH) BOOTLOADER_BUILD_DIR=$(BUILD_DIR_BASE)/bootloader @@ -47,3 +48,5 @@ $(COMPONENT_PATH)/src/sdkconfig: $(PROJECT_PATH)/sdkconfig # bootloader-flash calls flash in the bootloader dummy project bootloader-flash: $(BOOTLOADER_BIN) $(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src flash MAKEFLAGS= V=$(V) + +endif diff --git a/components/bootloader/src/Makefile b/components/bootloader/src/Makefile index 191fbef11..b6b0c1af0 100644 --- a/components/bootloader/src/Makefile +++ b/components/bootloader/src/Makefile @@ -4,7 +4,12 @@ # PROJECT_NAME := bootloader -COMPONENTS := esptool_py +COMPONENTS := esptool_py bootloader + +# The bootloader pseudo-component is also included in this build, for its Kconfig.projbuild to be included. +# +# IS_BOOTLOADER_BUILD tells the component Makefile.projbuild to be a no-op +IS_BOOTLOADER_BUILD := 1 #We cannot include the esp32 component directly but we need its includes. This is fixed by #adding it in the main/Makefile directory. diff --git a/components/bootloader/src/main/bootloader_log.h b/components/bootloader/src/main/bootloader_log.h index 32bc4852e..1f7ec62ad 100644 --- a/components/bootloader/src/main/bootloader_log.h +++ b/components/bootloader/src/main/bootloader_log.h @@ -19,39 +19,64 @@ extern "C" { #endif +#include "sdkconfig.h" +#define BOOT_LOG_LEVEL_NONE (0) #define BOOT_LOG_LEVEL_ERROR (1) #define BOOT_LOG_LEVEL_WARN (2) #define BOOT_LOG_LEVEL_INFO (3) #define BOOT_LOG_LEVEL_NOTICE (4) #define BOOT_LOG_LEVEL_DEBUG (5) -#define Black 0;30 -#define Red 0;31 -#define Green 0;32 -#define Brown 0;33 -#define Blue 0;34 -#define Purple 0;35 -#define Cyan 0;36 +#define Black "30" +#define Red "31" +#define Green "32" +#define Brown "33" +#define Blue "34" +#define Purple "35" +#define Cyan "36" -// TODO: move BOOT_LOG_LEVEL into menuconfig -//#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_ERROR -#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_NOTICE +#if CONFIG_BOOTLOADER_LOG_COLORS +#define LOG_COLOR(COLOR) "\033[0;"COLOR"m" +#define LOG_BOLD(COLOR) "\033[1;"COLOR"m" +#define LOG_RESET_COLOR "\033[0m" +#else +#define LOG_COLOR(...) +#define LOG_BOLD(...) +#define LOG_RESET_COLOR "" +#endif + +// BOOT_LOG_LEVEL defined by make menuconfig +#if CONFIG_BOOTLOADER_LOG_LEVEL_NONE +#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_NONE +#elif CONFIG_BOOTLOADER_LOG_LEVEL_ERROR +#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_ERROR +#elif CONFIG_BOOTLOADER_LOG_LEVEL_WARN +#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_WARN +#elif CONFIG_BOOTLOADER_LOG_LEVEL_INFO +#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO +#elif CONFIG_BOOTLOADER_LOG_LEVEL_NOTICE +#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_NOTICE +#elif CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG +#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_DEBUG +#else +#error "No bootloader log level set in menuconfig!" +#endif //printf("\033[0;36m[NOTICE][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); #define log_notice(format, ...) \ do{\ if(BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_NOTICE){\ - ets_printf("\033[0;36m" format "\r\n", ##__VA_ARGS__);\ - ets_printf("\033[0m"); \ + ets_printf(LOG_COLOR(Cyan) format "\r\n", ##__VA_ARGS__); \ + ets_printf(LOG_RESET_COLOR); \ }\ }while(0) #define log_info(format, ...) \ do{\ if(BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_INFO){\ - ets_printf("\033[1;36m" format "\r\n", ##__VA_ARGS__);\ - ets_printf("\033[0m"); \ + ets_printf(LOG_BOLD(Cyan) format "\r\n", ##__VA_ARGS__); \ + ets_printf(LOG_RESET_COLOR); \ }\ }while(0) @@ -59,8 +84,8 @@ extern "C" #define log_error(format, ...) \ do{\ if(BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_ERROR){\ - ets_printf("\033[0;31m[ERROR][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ - ets_printf("\033[0m"); \ + ets_printf(LOG_COLOR(Red) "[ERROR][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + ets_printf(LOG_RESET_COLOR); \ }\ }while(0) @@ -68,8 +93,8 @@ extern "C" #define log_warn(format, ...) \ do{\ if(BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_WARN){\ - ets_printf("\033[1;33m[WARN][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);\ - ets_printf("\033[0m"); \ + ets_printf(LOG_BOLD(Brown) "[WARN][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + ets_printf(LOG_RESET_COLOR); \ }\ }while(0) @@ -77,8 +102,8 @@ extern "C" #define log_debug(format, ...) \ do{\ if(BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_DEBUG){\ - ets_printf("\033[1;32m[DEBUG][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ - ets_printf("\033[0m"); \ + ets_printf(LOG_BOLD(Green) "[DEBUG][%s][%s][%d]\n" format "\r\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + ets_printf(LOG_RESET_COLOR); \ }\ }while(0) @@ -86,4 +111,4 @@ extern "C" } #endif -#endif /* __BOOT_LOGGING_H__ */ \ No newline at end of file +#endif /* __BOOT_LOGGING_H__ */ diff --git a/components/bootloader/src/main/bootloader_start.c b/components/bootloader/src/main/bootloader_start.c index a25a266c0..2dbf0e826 100644 --- a/components/bootloader/src/main/bootloader_start.c +++ b/components/bootloader/src/main/bootloader_start.c @@ -276,8 +276,6 @@ void bootloader_main() { //Run start routine. /*ESP32 2ND bootload start here*/ - - log_info( "\n" ); log_info( "**************************************" ); log_info( "* hello espressif ESP32! *" ); From 7ba471d53149635891fe58160ade22dbba9ee7e7 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 13 Sep 2016 13:48:28 +1000 Subject: [PATCH 2/2] esp32 cpu_start: Include rom/uart.h, remove inline ROM function declarations --- components/esp32/cpu_start.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 85d3009ef..5d0b81e01 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -18,6 +18,7 @@ #include "esp_err.h" #include "rom/ets_sys.h" +#include "rom/uart.h" #include "soc/dport_reg.h" #include "soc/io_mux_reg.h" @@ -59,11 +60,6 @@ We arrive here after the bootloader finished loading the program from flash. The flash cache is down and the app CPU is in reset. We do have a stack, so we can do the initialization in C. */ -void Uart_Init(int no); -void uartAttach(); -void ets_set_appcpu_boot_addr(uint32_t ent); -int ets_getAppEntry(); - static bool app_cpu_started = false; void IRAM_ATTR call_user_start_cpu0() {