Przeglądaj źródła

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.
Angus Gratton 5 lat temu
rodzic
commit
26efc5a6d0
4 zmienionych plików z 75 dodań i 11 usunięć
  1. 25 9
      CMakeLists.txt
  2. 4 1
      Kconfig
  3. 25 0
      components/bootloader/Kconfig.projbuild
  4. 21 1
      make/project.mk

+ 25 - 9
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()
 

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

+ 25 - 0
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

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