
The ctype implementation (isdigit() & friends) works with an array of 256 Bytes - one for each character. This is pretty big in SPL terms, so let's replace this "bloated" implementation with a tiny version using C statements. This only implements the functions that the SPL requires and confines this change only to an actual SPL build. Saves about 200 Bytes from the SPL code size.
Signed-off-by: Andre Przywara andre.przywara@arm.com --- Hi,
some people voiced concerns about running out of SPL code space when adding new features. In this particular case this was an issue when looking at the SPL FIT extension series[1]. This patch here on top of this series saves more space than the SPL FIT series consumed, so I trade this as a bait to people wrestling with this problem ;-)
Cheers, Andre.
[1] http://lists.denx.de/pipermail/u-boot/2017-January/278772.html
include/linux/tiny_ctype.h | 12 ++++++++++++ lib/Makefile | 2 ++ lib/strto.c | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 include/linux/tiny_ctype.h
diff --git a/include/linux/tiny_ctype.h b/include/linux/tiny_ctype.h new file mode 100644 index 0000000..4910412 --- /dev/null +++ b/include/linux/tiny_ctype.h @@ -0,0 +1,12 @@ +#ifndef _LINUX_CTYPE_H +#define _LINUX_CTYPE_H + +#define isdigit(c) (((c) >= '0') && ((c) <= '9')) +#define isxdigit(c) (isdigit(c) || \ + ((c) >= 'A' && (c) <= 'F') || \ + ((c) >= 'a' && (c) <= 'f')) +#define islower(c) ((((c) >= 'a') && ((c) <= 'z')) || ((c) >= 223)) + +#define toupper(c) ((((c) >= 'a') && ((c) <= 'z')) ? (c) - 32 : (c)) + +#endif diff --git a/lib/Makefile b/lib/Makefile index 23e9f1e..15385fd 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -66,7 +66,9 @@ obj-y += display_options.o CFLAGS_display_options.o := $(if $(BUILD_TAG),-DBUILD_TAG='"$(BUILD_TAG)"') obj-$(CONFIG_BCH) += bch.o obj-y += crc32.o +ifndef CONFIG_SPL_BUILD obj-y += ctype.o +endif obj-y += div64.o obj-y += hang.o obj-y += linux_compat.o diff --git a/lib/strto.c b/lib/strto.c index e93a4f5..9e9ba75 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -11,7 +11,11 @@
#include <common.h> #include <errno.h> +#ifdef CONFIG_SPL_BUILD +#include <linux/tiny_ctype.h> +#else #include <linux/ctype.h> +#endif
unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)