From patchwork Fri Jun 5 08:36:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 241776 List-Id: U-Boot discussion From: rasmus.villemoes at prevas.dk (Rasmus Villemoes) Date: Fri, 5 Jun 2020 10:36:50 +0200 Subject: [RFC PATCH] allow choosing -Os/-O2 separately for SPL and TPL Message-ID: <20200605083650.30048-1-rasmus.villemoes@prevas.dk> It can be useful to build U-Boot proper with -O2, but still optimize the SPL for size. So add separate config options for SPL and TPL. I had to move the Makefile logic to config.mk, since otherwise SPL_TPL_ didn't seem to be known. Unfortunately, the SPL translation units end up getting both -O2 and -Os passed (assuming CC_OPTIMIZE_FOR_SIZE=n, SPL_CC_OPTIMIZE_FOR_SIZE=y) - it ends up with the intended effect, but it is still not very pretty. My Kbuild fu is pretty weak; I wonder how the two uses of $(SPL_) in the main Makefile works when apparently $(SPL_TPL_) didn't. Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- Kconfig | 20 ++++++++++++++++++++ Makefile | 6 ------ config.mk | 6 ++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Kconfig b/Kconfig index f698e0a94f..0468bd0089 100644 --- a/Kconfig +++ b/Kconfig @@ -66,6 +66,26 @@ config CC_OPTIMIZE_FOR_SIZE This option is enabled by default for U-Boot. +config SPL_CC_OPTIMIZE_FOR_SIZE + bool "Optimize SPL for size" + default y + depends on SPL + help + Enabling this option will pass "-Os" instead of "-O2" to gcc + resulting in a smaller U-Boot SPL image. + + This option is enabled by default for U-Boot SPL. + +config TPL_CC_OPTIMIZE_FOR_SIZE + bool "Optimize TPL for size" + default y + depends on TPL + help + Enabling this option will pass "-Os" instead of "-O2" to gcc + resulting in a smaller U-Boot TPL image. + + This option is enabled by default for U-Boot TPL. + config CC_COVERAGE bool "Enable code coverage analysis" depends on SANDBOX diff --git a/Makefile b/Makefile index 7c2067f35e..586d5d687a 100644 --- a/Makefile +++ b/Makefile @@ -645,12 +645,6 @@ ifeq ($(CONFIG_XTENSA),) LDPPFLAGS += -ansi endif -ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE -KBUILD_CFLAGS += -Os -else -KBUILD_CFLAGS += -O2 -endif - KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector) KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks) diff --git a/config.mk b/config.mk index caf0dd9b81..a3eb3f941e 100644 --- a/config.mk +++ b/config.mk @@ -70,6 +70,12 @@ RELFLAGS := $(PLATFORM_RELFLAGS) PLATFORM_CPPFLAGS += $(RELFLAGS) PLATFORM_CPPFLAGS += -pipe +ifeq ($(CONFIG_$(SPL_TPL_)CC_OPTIMIZE_FOR_SIZE),y) +KBUILD_CFLAGS += -Os +else +KBUILD_CFLAGS += -O2 +endif + LDFLAGS += $(PLATFORM_LDFLAGS) LDFLAGS_FINAL += -Bstatic