diff mbox series

[RFC] allow choosing -Os/-O2 separately for SPL and TPL

Message ID 20200605083650.30048-1-rasmus.villemoes@prevas.dk
State New
Headers show
Series [RFC] allow choosing -Os/-O2 separately for SPL and TPL | expand

Commit Message

Rasmus Villemoes June 5, 2020, 8:36 a.m. UTC
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 <rasmus.villemoes at prevas.dk>
---
 Kconfig   | 20 ++++++++++++++++++++
 Makefile  |  6 ------
 config.mk |  6 ++++++
 3 files changed, 26 insertions(+), 6 deletions(-)

Comments

Simon Glass June 16, 2020, 11:37 p.m. UTC | #1
On Fri, 5 Jun 2020 at 02:37, Rasmus Villemoes
<rasmus.villemoes at prevas.dk> wrote:
>
> 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.

They are defined in Makefile.spl and Kbuild/include.

But SPL_TPL_ is never defined unless CONFIG_SPL_BUILD is defined, i.e.
only in Makefile.spl I think.

+Masahiro Yamada who may know

>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
> ---
>  Kconfig   | 20 ++++++++++++++++++++
>  Makefile  |  6 ------
>  config.mk |  6 ++++++
>  3 files changed, 26 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

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