[U-Boot] [RFC PATCH] SPL: replace ctype implementation with tiny version
Andrew F. Davis
afd at ti.com
Sun Jan 22 23:10:35 CET 2017
On 01/22/2017 03:58 PM, Andrew F. Davis wrote:
> On 01/20/2017 04:33 PM, Andre Przywara wrote:
>> 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.
>>
>
> Saves us a very needed 256 bytes on AM335x!
>
> Acked-by: Andrew F. Davis <afd at ti.com>
>
> Thanks,
> Andrew
>
>> Signed-off-by: Andre Przywara <andre.przywara at 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
One minor note, this causes build failures for code that uses the
functions not defined here (or not including this header). Keeping the
same space saving technique, we could avoid those changes by moving the
SPL_BUILD check to inside ctype.h, then define a set of macros that
don't use the _ctype table. The linker would drop the table if it is not
needed without needing to have the Makefile change.
Andrew
>> 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)
>>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>
More information about the U-Boot
mailing list