Patches to reduce TPL code size
Subsystems (3)
v2 cover Patches to reduce TPL code size
With the rockchip 'rock' board some build and code size problems have come to light with TPL. This series provides a few ideas to improve things.
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name it CONFIG_SPL_TINY_MEMSET)
- Add a new patch to enable CONFIG_SPL_TINY_MEMSET
- Add new patch to allow driver model to be disabled for TPL
- Add new patch to allow driver-model serial to be disabled for TPL
Simon Glass (5):
string: Provide a slimmed-down memset()
rockchip: rock: Enable CONFIG_SPL_TINY_MEMSET
Makefile: Provide an option to select SPL or TPL
dm: core: Allow driver model to be disabled for TPL
dm: serial: Allow driver-model serial to be disabled for TPL
configs/rock_defconfig | 1 + drivers/Makefile | 2 +- drivers/core/Kconfig | 14 ++++++++++++++ drivers/serial/Kconfig | 20 ++++++++++++++++++++ drivers/serial/Makefile | 2 +- lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- scripts/Kbuild.include | 6 ++++++ scripts/Makefile.spl | 6 ++++++ 9 files changed, 61 insertions(+), 4 deletions(-)
Signature · 1 line
2.12.2.564.g063fe858b8-goog
PATCH v2 1/5 string: Provide a slimmed-down memset()
Most of the time the optimised memset() is what we want. For extreme situations such as TPL it may be too large. For example on the 'rock' board, using a simple loop saves a useful 48 bytes. With gcc 4.9 and the rodata bug, this patch is enough to reduce the TPL image below the limit.
---
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name it CONFIG_SPL_TINY_MEMSET)
lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
lib/Kconfig +8 -0
@@ -52,6 +52,14 @@ config LIB_RAND help This library provides pseudo-random number generator functions. +config SPL_TINY_MEMSET + bool "Use a very small memset() in SPL" + help + The faster memset() is the arch-specific one (if available) enabled + by CONFIG_USE_ARCH_MEMSET. If that is not enabled, we can still get + better performance by write a word at a time. Enable this option + to reduce code size slightly at the cost of some speed. + source lib/dhry/Kconfig source lib/rsa/Kconfig
lib/string.c +4 -2
@@ -437,8 +437,10 @@ char *strswab(const char *s)void *memset (void * s,int c,size_t count) {unsigned long *sl = (unsigned long *) s; -unsigned long cl =0 ;char *s8; + +#if !CONFIG_IS_ENABLED (TINY_MEMSET ) +unsigned long cl =0 ;int i;/* do it one word at a time (32 bits or 64 bits) while possible */
@@ -452,7 +454,7 @@ void * memset(void * s,int c,size_t count) count -= sizeof(*sl); } } -/* fill 8 bits at a time */ +#endif /* fill 8 bits at a time */ s8 = (char *)sl;while (count--) *s8++ = c;
Signature · 1 line
2.12.2.564.g063fe858b8-goog
PATCH v2 1/5 string: Provide a slimmed-down memset()
Am Sonntag, 2. April 2017, 09:50:28 CEST schrieb Simon Glass:
Quoted 22 lines
Most of the time the optimised
memset()is what we want. For extreme situations such as TPL it may be too large. For example on the 'rock' board, using a simple loop saves a useful 48 bytes. With gcc 4.9 and the rodata bug, this patch is enough to reduce the TPL image below the limit.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name itCONFIG_SPL_TINY_MEMSET)lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-)lib/Kconfig +0
-0
lib/Kconfig config LIB_RAND · line 61
Quoted 10 lines
lib/Kconfig +7
-0@@ -52,6 +52,14 @@ config LIB_RAND help This library provides pseudo-random number generator functions. +config SPL_TINY_MEMSET + bool "Use a very small memset() in SPL" + help + The faster memset() is the arch-specific one (if available) enabled + by CONFIG_USE_ARCH_MEMSET. If that is not enabled, we can still get + better performance by write a word at a time. Enable this option + to reduce code size slightly at the cost of some speed.
Wording sounds off, I guess we could do something like
[...better performance by] writing a word at a time. In very size-constrained environments even this may be to big though. [Enable this option...]
Otherwise
Quoted 29 lines
lib/Kconfig +1
-0+ source lib/dhry/Kconfig source lib/rsa/Kconfiglib/string.c +4
-2@@ -437,8 +437,10 @@ char *strswab(const char *s)void *memset (void * s,int c,size_t count) {unsigned long *sl = (unsigned long *) s; -unsigned long cl =0 ;char *s8; + +#if !CONFIG_IS_ENABLED (TINY_MEMSET ) +unsigned long cl =0 ;int i;/* do it one word at a time (32 bits or 64 bits) while possible */ @@ -452,7 +454,7 @@ void * memset(void * s,int c,size_t count) count -= sizeof(*sl); } } -/* fill 8 bits at a time */ +#endif /* fill 8 bits at a time */ s8 = (char *)sl;while (count--) *s8++ = c;
PATCH v2 1/5 string: Provide a slimmed-down memset()
Quoted 37 lines · Heiko Stübner
Am Sonntag, 2. April 2017, 09:50:28 CEST schrieb Simon Glass:
Quoted 22 lines
Most of the time the optimised
memset()is what we want. For extreme situations such as TPL it may be too large. For example on the 'rock' board, using a simple loop saves a useful 48 bytes. With gcc 4.9 and the rodata bug, this patch is enough to reduce the TPL image below the limit.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name itCONFIG_SPL_TINY_MEMSET)lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-)lib/Kconfig +0
-0lib/Kconfig config LIB_RAND · line 61
Quoted 10 lines
lib/Kconfig +7
-0@@ -52,6 +52,14 @@ config LIB_RAND help This library provides pseudo-random number generator functions. +config SPL_TINY_MEMSET + bool "Use a very small memset() in SPL" + help + The faster memset() is the arch-specific one (if available) enabled + by CONFIG_USE_ARCH_MEMSET. If that is not enabled, we can still get + better performance by write a word at a time. Enable this option + to reduce code size slightly at the cost of some speed.Wording sounds off, I guess we could do something like
Quoted 5 lines
[...better performance by] writing a word at a time. In very size-constrained environments even this may be to big though. [Enable this option...]
Otherwise
Reviewed-by Heiko Stuebner <[email protected]>
I am going to apply this one now and leave the rest of the series until it has had a bit more review. But this one is needed for me to enable the rock board.
Fixed this and:
Applied to u-boot-rockchip
PATCH v2 2/5 rockchip: rock: Enable CONFIG_SPL_TINY_MEMSET
In reply to Simon GlassEnable this option to shrink memset() a little. This is needed for TPL.
---
Changes in v2:
- Add a new patch to enable CONFIG_SPL_TINY_MEMSET
configs/rock_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/rock_defconfig +1 -0
@@ -60,3 +60,4 @@ CONFIG_DEBUG_UART_NS16550=y CONFIG_SYS_NS16550=y CONFIG_CMD_DHRYSTONE=y CONFIG_ERRNO_STR=y +CONFIG_SPL_TINY_MEMSET=y
Signature · 1 line
2.12.2.564.g063fe858b8-goog
PATCH v2 3/5 Makefile: Provide an option to select SPL or TPL
In reply to Simon GlassAt present we have SPL_ which can be used in Makefiles to select between normal and SPL CONFIGs like this:
obj-$(CONFIG_$(SPL_)DM) += core/
When TPL is being built, SPL_ has the value 'SPL' which is generally a good idea since they tend to follow each other. But in extreme situations we may want to distinugish between SPL and TPL. For example we may not want to enable CONFIG_DM with TPL.
Add a new SPL_TPL_ variable which is set to either empty (for U-Boot proper), 'SPL' or 'TPL'. This may prove useful with TPL-specific options.
---
Changes in v2: None
scripts/Kbuild.include | 6 ++++++ scripts/Makefile.spl | 6 ++++++ 2 files changed, 12 insertions(+)
scripts/Kbuild.include +6 -0
@@ -321,6 +321,12 @@ endif ifdef CONFIG_SPL_BUILD SPL_ := SPL_ +ifeq ($(CONFIG_TPL_BUILD),y) +SPL_TPL_ := TPL_ +else +SPL_TPL_ := SPL_ +endif else SPL_ := +SPL_TPL_ := endif
scripts/Makefile.spl +6 -0
@@ -37,8 +37,14 @@ endif ifdef CONFIG_SPL_BUILD SPL_ := SPL_ +ifeq ($(CONFIG_TPL_BUILD),y) +SPL_TPL_ := TPL_ +else +SPL_TPL_ := SPL_ +endif else SPL_ := +SPL_TPL_ := endif include $(srctree)/config.mk
Signature · 1 line
2.12.2.564.g063fe858b8-goog
PATCH v2 3/5 Makefile: Provide an option to select SPL or TPL
Quoted 10 lines · Simon Glass
At present we have
SPL_which can be used in Makefiles to select between normal and SPL CONFIGs like this:obj-$(CONFIG_$(SPL_)DM) += core/When TPL is being built,
SPL_has the value 'SPL' which is generally a good idea since they tend to follow each other. But in extreme situations we may want to distinugish between SPL and TPL. For example we may not want to enableCONFIG_DMwith TPL.
Quoted 4 lines
Add a new
SPL_TPL_variable which is set to either empty (for U-Boot proper), 'SPL' or 'TPL'. This may prove useful with TPL-specific options.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170406/52411974/attachment.sig>
PATCH v2 4/5 dm: core: Allow driver model to be disabled for TPL
In reply to Simon GlassSince TPL often needs to be very very small it may not make sense to enable driver model. Add an option for this.
This changes brings the 'rock' board under the TPL limit with gcc 4.9.
---
Changes in v2:
- Add new patch to allow driver model to be disabled for TPL
drivers/Makefile | 2 +- drivers/core/Kconfig | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/Makefile +1 -1
@@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-2.0+ # -obj-$(CONFIG_$(SPL_)DM) += core/ +obj-$(CONFIG_$(SPL_TPL_)DM) += core/ obj-$(CONFIG_$(SPL_)CLK) += clk/ obj-$(CONFIG_$(SPL_)LED) += led/ obj-$(CONFIG_$(SPL_)PINCTRL) += pinctrl/
drivers/core/Kconfig +14 -0
@@ -21,6 +21,20 @@ config SPL_DM and devices in SPL, so 1KB should be enable. See CONFIG_SYS_MALLOC_F_LEN for more details on how to enable it. +config TPL_DM + bool "Enable Driver Model for TPL" + depends on DM && TPL + help + Enable driver model in TPL. You will need to provide a + suitable malloc() implementation. If you are not using the + full malloc() enabled by CONFIG_SYS_SPL_MALLOC_START, + consider using CONFIG_SYS_MALLOC_SIMPLE. In that case you + must provide CONFIG_SYS_MALLOC_F_LEN to set the size. + In most cases driver model will only allocate a few uclasses + and devices in SPL, so 1KB should be enough. See + CONFIG_SYS_MALLOC_F_LEN for more details on how to enable it. + Disable this for very small implementations. + config DM_WARN bool "Enable warnings in driver model" depends on DM
Signature · 1 line
2.12.2.564.g063fe858b8-goog
PATCH v2 4/5 dm: core: Allow driver model to be disabled for TPL
Quoted 6 lines · Simon Glass
Since TPL often needs to be very very small it may not make sense to enable driver model. Add an option for this.
This changes brings the 'rock' board under the TPL limit with gcc 4.9.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170406/3b96b955/attachment.sig>
PATCH v2 5/5 dm: serial: Allow driver-model serial to be disabled for TPL
In reply to Simon GlassAdd separate enable/disable controls for driver-model serial. While this is generally enabled in SPL it may not be in TPL, since serial output can be obtained with the debug UART with minimal code size.
---
Changes in v2:
- Add new patch to allow driver-model serial to be disabled for TPL
drivers/serial/Kconfig | 20 ++++++++++++++++++++ drivers/serial/Makefile | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/serial/Kconfig +20 -0
@@ -53,6 +53,26 @@ config DM_SERIAL implements serial_putc() etc. The uclass interface is defined in include/serial.h. +config SPL_DM_SERIAL + bool "Enable Driver Model for serial drivers" + depends on DM_SERIAL + default y if SPL && DM_SERIAL + help + Enable driver model for serial in SPL. This replaces + drivers/serial/serial.c with the serial uclass, which + implements serial_putc() etc. The uclass interface is + defined in include/serial.h. + +config TPL_DM_SERIAL + bool "Enable Driver Model for serial drivers" + depends on DM_SERIAL + default y if TPL && DM_SERIAL + help + Enable driver model for serial in TPL. This replaces + drivers/serial/serial.c with the serial uclass, which + implements serial_putc() etc. The uclass interface is + defined in include/serial.h. + config DEBUG_UART bool "Enable an early debug UART for debugging" help
drivers/serial/Makefile +1 -1
@@ -6,7 +6,7 @@ # ifdef CONFIG_DM_SERIAL -obj-y += serial-uclass.o +obj-$(CONFIG_$(SPL_TPL_)DM_SERIAL) += serial-uclass.o obj-$(CONFIG_PL01X_SERIAL) += serial_pl01x.o else obj-y += serial.o
Signature · 1 line
2.12.2.564.g063fe858b8-goog
PATCH v2 5/5 dm: serial: Allow driver-model serial to be disabled for TPL
Quoted 5 lines · Simon Glass
Add separate enable/disable controls for driver-model serial. While this is generally enabled in SPL it may not be in TPL, since serial output can be obtained with the debug UART with minimal code size.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170406/36bf735f/attachment.sig>
v2 cover Patches to reduce TPL code size
In reply to Simon GlassAm Sonntag, 2. April 2017, 09:50:27 CEST schrieb Simon Glass:
Quoted 2 lines
With the rockchip 'rock' board some build and code size problems have come to light with TPL. This series provides a few ideas to improve things.
great stuff!
With these patches applied, rk3188-rock still boots and the TPL has come down to 616byte on gcc-4.9 and 592bytes on gcc-6.3, so
We have like vast amounts of free space in tpl now ;-)
I guess I should fold your TINY_MEMSET option into my rock board, once you've applied the core patch?
Heiko
Quoted 25 lines
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name itCONFIG_SPL_TINY_MEMSET)
- Add a new patch to enableCONFIG_SPL_TINY_MEMSET
- Add new patch to allow driver model to be disabled for TPL
- Add new patch to allow driver-model serial to be disabled for TPLSimon Glass (5):
string: Provide a slimmed-downmemset()
rockchip: rock: EnableCONFIG_SPL_TINY_MEMSET
Makefile: Provide an option to select SPL or TPL
dm: core: Allow driver model to be disabled for TPL
dm: serial: Allow driver-model serial to be disabled for TPLconfigs/rock_defconfig | 1 + drivers/Makefile | 2 +- drivers/core/Kconfig | 14 ++++++++++++++ drivers/serial/Kconfig | 20 ++++++++++++++++++++ drivers/serial/Makefile | 2 +- lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- scripts/Kbuild.include | 6 ++++++ scripts/Makefile.spl | 6 ++++++ 9 files changed, 61 insertions(+), 4 deletions(-)
v2 cover Patches to reduce TPL code size
Am Dienstag, 4. April 2017, 11:34:52 CEST schrieb Heiko Stübner:
Quoted 8 lines
Am Sonntag, 2. April 2017, 09:50:27 CEST schrieb Simon Glass:
Quoted 2 lines
With the rockchip 'rock' board some build and code size problems have come to light with TPL. This series provides a few ideas to improve things.
great stuff!
With these patches applied, rk3188-rock still boots and the TPL has come down to 616byte on gcc-4.9 and 592bytes on gcc-6.3, so
Actually, after finding out that I should add a
# CONFIG_TPL_DM_SERIAL is not set
to my defconfig, the size goes down even more - to 488 bytes on both gcc-4.9 and gcc-6.3.
Still works and all.
Quoted 38 lines
Tested-by Heiko Stuebner <[email protected]>We have like vast amounts of free space in tpl now ;-)
I guess I should fold your
TINY_MEMSEToption into my rock board, once you've applied the core patch?Heiko
Quoted 25 lines
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name itCONFIG_SPL_TINY_MEMSET)
- Add a new patch to enableCONFIG_SPL_TINY_MEMSET
- Add new patch to allow driver model to be disabled for TPL
- Add new patch to allow driver-model serial to be disabled for TPLSimon Glass (5):
string: Provide a slimmed-downmemset()
rockchip: rock: EnableCONFIG_SPL_TINY_MEMSET
Makefile: Provide an option to select SPL or TPL
dm: core: Allow driver model to be disabled for TPL
dm: serial: Allow driver-model serial to be disabled for TPLconfigs/rock_defconfig | 1 + drivers/Makefile | 2 +- drivers/core/Kconfig | 14 ++++++++++++++ drivers/serial/Kconfig | 20 ++++++++++++++++++++ drivers/serial/Makefile | 2 +- lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- scripts/Kbuild.include | 6 ++++++ scripts/Makefile.spl | 6 ++++++ 9 files changed, 61 insertions(+), 4 deletions(-)
v2 cover Patches to reduce TPL code size
Hi Heiko,
Quoted 10 lines · Heiko Stuebner
Am Dienstag, 4. April 2017, 11:34:52 CEST schrieb Heiko Stübner:
Quoted 8 lines
Am Sonntag, 2. April 2017, 09:50:27 CEST schrieb Simon Glass:
Quoted 2 lines
With the rockchip 'rock' board some build and code size problems have come to light with TPL. This series provides a few ideas to improve things.
great stuff!
With these patches applied, rk3188-rock still boots and the TPL has come down to 616byte on gcc-4.9 and 592bytes on gcc-6.3, so
Quoted 6 lines
Actually, after finding out that I should add a
#CONFIG_TPL_DM_SERIALis not set
to my defconfig, the size goes down even more - to 488 bytes on both gcc-4.9 and gcc-6.3.Still works and all.
OK great thanks for the report.
Regards,
Simon
Quoted 42 lines
Quoted 40 lines
Tested-by Heiko Stuebner <[email protected]>We have like vast amounts of free space in tpl now ;-)
I guess I should fold your
TINY_MEMSEToption into my rock board, once you've applied the core patch?Heiko
Quoted 25 lines
Changes in v2:
- Adjust the option to be SPL-only
- Change the option to default to off (name itCONFIG_SPL_TINY_MEMSET)
- Add a new patch to enableCONFIG_SPL_TINY_MEMSET
- Add new patch to allow driver model to be disabled for TPL
- Add new patch to allow driver-model serial to be disabled for TPLSimon Glass (5):
string: Provide a slimmed-downmemset()
rockchip: rock: EnableCONFIG_SPL_TINY_MEMSET
Makefile: Provide an option to select SPL or TPL
dm: core: Allow driver model to be disabled for TPL
dm: serial: Allow driver-model serial to be disabled for TPLconfigs/rock_defconfig | 1 + drivers/Makefile | 2 +- drivers/core/Kconfig | 14 ++++++++++++++ drivers/serial/Kconfig | 20 ++++++++++++++++++++ drivers/serial/Makefile | 2 +- lib/Kconfig | 8 ++++++++ lib/string.c | 6 ++++-- scripts/Kbuild.include | 6 ++++++ scripts/Makefile.spl | 6 ++++++ 9 files changed, 61 insertions(+), 4 deletions(-)