[U-Boot] [RFC] General purpose utilities - cleanup

Michael Zaidman michael.zaidman at gmail.com
Wed May 12 14:24:42 CEST 2010


While looking for more appropriate place for the BUILD_BUG_ON macros
than its ubi_uboot.h current location (see the
http://lists.denx.de/pipermail/u-boot/2010-April/069391.html thread) I
realized the following:
1.	There is necessity in general purpose utilities like those that
Linux defines in its kernel.h
2.	Both - u-boot and tools code should be able to benefit from these
utilities. Currently, some of these utilities are located in common.h
which is not included by the tools. The only common file is the
compiler.h which does not seems to be appropriate place for such
things.
3.	There are many duplications in the code for utilities  not defined
in the common.h (such as min_t, max_t, abs, …)
4.	In the min/max utilities borrowed from Linux for some reason was
omitted strict type checking instead of bringing min_t/max_t
especially destined for this purpose. My try to use an original Linux
min/max ended up by huge number of compilation warnings like:
“comparison of distinct pointer types lacks a cast”

I suggest cleaning this up in the following way:
1.	Move general purpose utilities from common.h into new genutils.h
file which will be shared between u-boot and tools code. It will be
included by common.h and by every tool which want to derive this
functionality.
2.	Remove all redundant local definitions for min_t, max_t, abs, etc…
moving them into genutils.h
3.	Extend the genutils.h with useful stuff from kernel.h  such as
PTR_ALIGN, IS_ALIGNED, clamp, clamp_t, clamp_val, typecheck,
typecheck_fn, BUILD_BUG_ON, BUILD_BUG_ON_ZERO, ...
4.	Revive the strict type checking for the min/max. Replace the
min/max with the min_t/max_t usage for the cases where type checking
is not appropriate.

Comments?

Thanks,
Michael


More information about the U-Boot mailing list