From 26efc5a6d005da33ecf64d255a7e9a722f74fe02 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 26 Feb 2020 14:19:32 +1100 Subject: [PATCH] bootloader: Set the bootloader optimization level separately to the app Change the default bootloader config to -Os to save size. This is a useful feature because it allows switching between debug and release configs in the app without also needing to account for a size change in the bootloader. --- CMakeLists.txt | 34 ++++++++++++++++++------- Kconfig | 5 +++- components/bootloader/Kconfig.projbuild | 25 ++++++++++++++++++ make/project.mk | 22 +++++++++++++++- 4 files changed, 75 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20b4f47b8..1c5de7151 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,15 +10,31 @@ unset(link_options) # Add the following build specifications here, since these seem to be dependent # on config values on the root Kconfig. -if(CONFIG_COMPILER_OPTIMIZATION_SIZE) - list(APPEND compile_options "-Os") - list(APPEND compile_options "-freorder-blocks") -elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT) - list(APPEND compile_options "-Og") -elseif(CONFIG_COMPILER_OPTIMIZATION_NONE) - list(APPEND compile_options "-O0") -elseif(CONFIG_COMPILER_OPTIMIZATION_PERF) - list(APPEND compile_options "-O2") +if(NOT BOOTLOADER_BUILD) + + if(CONFIG_COMPILER_OPTIMIZATION_SIZE) + list(APPEND compile_options "-Os") + list(APPEND compile_options "-freorder-blocks") + elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT) + list(APPEND compile_options "-Og") + elseif(CONFIG_COMPILER_OPTIMIZATION_NONE) + list(APPEND compile_options "-O0") + elseif(CONFIG_COMPILER_OPTIMIZATION_PERF) + list(APPEND compile_options "-O2") + endif() + +else() # BOOTLOADER_BUILD + + if(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE) + list(APPEND compile_options "-Os") + list(APPEND compile_options "-freorder-blocks") + elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG) + list(APPEND compile_options "-Og") + elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE) + list(APPEND compile_options "-O0") + elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF) + list(APPEND compile_options "-O2") + endif() endif() diff --git a/Kconfig b/Kconfig index 2c06a3157..cbf6e73d3 100644 --- a/Kconfig +++ b/Kconfig @@ -171,7 +171,7 @@ mainmenu "Espressif IoT Development Framework Configuration" prompt "Optimization Level" default COMPILER_OPTIMIZATION_DEFAULT help - This option sets compiler optimization level (gcc -O argument). + This option sets compiler optimization level (gcc -O argument) for the app. - The "Default" setting will add the -0g flag to CFLAGS. - The "Size" setting will add the -0s flag to CFLAGS. @@ -189,6 +189,9 @@ mainmenu "Espressif IoT Development Framework Configuration" Note that custom optimization levels may be unsupported. + Compiler optimization for the IDF bootloader is set separately, + see the BOOTLOADER_COMPILER_OPTIMIZATION setting. + config COMPILER_OPTIMIZATION_DEFAULT bool "Debug (-Og)" config COMPILER_OPTIMIZATION_SIZE diff --git a/components/bootloader/Kconfig.projbuild b/components/bootloader/Kconfig.projbuild index cc64d8996..9b06eceac 100644 --- a/components/bootloader/Kconfig.projbuild +++ b/components/bootloader/Kconfig.projbuild @@ -1,4 +1,29 @@ menu "Bootloader config" + + choice BOOTLOADER_COMPILER_OPTIMIZATION + prompt "Bootloader optimization Level" + default BOOTLOADER_COMPILER_OPTIMIZATION_SIZE + help + This option sets compiler optimization level (gcc -O argument) + for the bootloader. + + - The default "Size" setting will add the -0s flag to CFLAGS. + - The "Debug" setting will add the -Og flag to CFLAGS. + - The "Performance" setting will add the -O2 flag to CFLAGS. + - The "None" setting will add the -O0 flag to CFLAGS. + + Note that custom optimization levels may be unsupported. + + config BOOTLOADER_COMPILER_OPTIMIZATION_SIZE + bool "Size (-Os)" + config BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG + bool "Debug (-Og)" + config BOOTLOADER_COMPILER_OPTIMIZATION_PERF + bool "Optimize for performance (-O2)" + config BOOTLOADER_COMPILER_OPTIMIZATION_NONE + bool "Debug without optimization (-O0)" + endchoice + choice BOOTLOADER_LOG_LEVEL bool "Bootloader log verbosity" default BOOTLOADER_LOG_LEVEL_INFO diff --git a/make/project.mk b/make/project.mk index f6a036f19..bd40e64aa 100644 --- a/make/project.mk +++ b/make/project.mk @@ -425,7 +425,6 @@ endif ifdef CONFIG_COMPILER_STACK_CHECK_MODE_ALL COMMON_FLAGS += -fstack-protector-all endif -endif # Optimization flags are set based on menuconfig choice ifdef CONFIG_COMPILER_OPTIMIZATION_SIZE @@ -448,6 +447,27 @@ ifdef CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE CPPFLAGS += -DNDEBUG endif +else # IS_BOOTLOADER_BUILD + +ifdef CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE +OPTIMIZATION_FLAGS = -Os -freorder-blocks +endif + +ifdef CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG +OPTIMIZATION_FLAGS = -Og +endif + +ifdef CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE +OPTIMIZATION_FLAGS = -O0 +endif + +ifdef CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF +OPTIMIZATION_FLAGS = -O2 +endif + +endif # IS_BOOTLOADER_BUILD + + # IDF uses some GNU extension from libc CPPFLAGS += -D_GNU_SOURCE