[U-Boot] [PATCH] add check infrastructure, default sparse

Add support for running source code checkers on u-boot source, e.g., using sparse to aid with typechecking. This comes in especially handy as SoC vendors mix and match cores and devices with different endianness, thus here we add CHECK_ENDIAN to the otherwise linux kernel default CHECKFLAGS.
Signed-off-by: Kim Phillips kim.phillips@freescale.com --- Makefile | 18 ++++++++++++++++++ config.mk | 9 +++++++++ 2 files changed, 27 insertions(+)
diff --git a/Makefile b/Makefile index 058fb53..6969763 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,24 @@ BUILD_DIR := $(O) endif endif
+# Call a source code checker (by default, "sparse") as part of the +# C compilation. +# +# Use 'make C=1' to enable checking of re-compiled files. +# +# See the linux kernel file "Documentation/sparse.txt" for more details, +# including where to get the "sparse" utility. + +ifdef C +ifeq ("$(origin C)", "command line") +CHECKSRC := $(C) +endif +endif +ifndef CHECKSRC + CHECKSRC = 0 +endif +export CHECKSRC + ifneq ($(BUILD_DIR),) saved-output := $(BUILD_DIR)
diff --git a/config.mk b/config.mk index c3822a2..e572902 100644 --- a/config.mk +++ b/config.mk @@ -148,6 +148,7 @@ OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump RANLIB = $(CROSS_COMPILE)RANLIB DTC = dtc +CHECK = sparse
#########################################################################
@@ -274,6 +275,10 @@ ifneq ($(CONFIG_SPL_TEXT_BASE),) LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE) endif
+# Linus' kernel sanity checking tool +CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ + -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF) + # Location of a usable BFD library, where we define "usable" as # "built for ${HOST}, supports ${TARGET}". Sensible values are # - When cross-compiling: the root of the cross-environment @@ -321,6 +326,9 @@ $(obj)%.s: %.S $(obj)%.o: %.S $(CC) $(ALL_AFLAGS) -o $@ $< -c $(obj)%.o: %.c +ifneq ($(CHECKSRC),0) + $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $< +endif $(CC) $(ALL_CFLAGS) -o $@ $< -c $(obj)%.i: %.c $(CPP) $(ALL_CFLAGS) -o $@ $< -c

On Fri, Sep 21, 2012 at 05:28:17PM -0500, Kim Phillips wrote:
Add support for running source code checkers on u-boot source, e.g., using sparse to aid with typechecking. This comes in especially handy as SoC vendors mix and match cores and devices with different endianness, thus here we add CHECK_ENDIAN to the otherwise linux kernel default CHECKFLAGS.
Signed-off-by: Kim Phillips kim.phillips@freescale.com
Can I get a follow-up patch that add -C/--checker to MAKEALL? Looking to put this on u-boot/next once I can also make all of my builds use it too.

thanks to Tom Rini for the good idea.
Signed-off-by: Kim Phillips kim.phillips@freescale.com --- MAKEALL | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/MAKEALL b/MAKEALL index 806f21f..fa7d010 100755 --- a/MAKEALL +++ b/MAKEALL @@ -19,6 +19,7 @@ usage() -l, --list List all targets to be built -m, --maintainers List all targets and maintainer email -M, --mails List all targets and all affilated emails + -C, --check Enable build checking -h, --help This help output
Selections by these options are logically ANDed; if the same option @@ -51,8 +52,8 @@ usage() exit ${ret} }
-SHORT_OPTS="ha:c:v:s:lmM" -LONG_OPTS="help,arch:,cpu:,vendor:,soc:,list,maintainers,mails" +SHORT_OPTS="ha:c:v:s:lmMC" +LONG_OPTS="help,arch:,cpu:,vendor:,soc:,list,maintainers,mails,check"
# Option processing based on util-linux-2.13/getopt-parse.bash
@@ -111,6 +112,9 @@ while true ; do fi SELECTED='y' shift 2 ;; + -C|--check) + CHECK='C=1' + shift ;; -l|--list) ONLY_LIST='y' shift ;; @@ -628,7 +632,7 @@ build_target() { ${MAKE} distclean >/dev/null ${MAKE} -s ${target}_config
- ${MAKE} ${JOBS} all \ + ${MAKE} ${JOBS} ${CHECK} all \ >${LOG_DIR}/$target.MAKELOG 2> ${LOG_DIR}/$target.ERR
# Check for 'make' errors

On Thu, Sep 27, 2012 at 02:57:34PM -0000, Kim Phillips wrote:
thanks to Tom Rini for the good idea.
Signed-off-by: Kim Phillips kim.phillips@freescale.com
Applied to u-boot/next, thanks!

On Fri, Sep 21, 2012 at 12:28:17PM -0000, Kim Phillips wrote:
Add support for running source code checkers on u-boot source, e.g., using sparse to aid with typechecking. This comes in especially handy as SoC vendors mix and match cores and devices with different endianness, thus here we add CHECK_ENDIAN to the otherwise linux kernel default CHECKFLAGS.
Signed-off-by: Kim Phillips kim.phillips@freescale.com
Applied to u-boot/next, thanks!
participants (2)
-
Kim Phillips
-
Tom Rini