[U-Boot] [PATCH] include: define bool type in a more portable way

Masahiro Yamada yamada.m at jp.panasonic.com
Mon Nov 18 11:21:45 CET 2013


Currently U-boot defins bool type by including <stdbool.h>
rather than defining directly.
But it does not work for some cross compilers.

This commit changes header files to define
bool, true, false in the same way as Linux Kernel does.

Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
---

Refer to include/linux/types.h and include/linux/stddef.h
of Linux Kernel.



When I compile Blackfin boards, I use this crosstool:
http://dev.gentoo.org/~vapier/u-boot/bfin.tar.xz

But with this crosstool, I cannot build bct-brettl2 board.

For the current u-boot/master,
compiling bct-brettl2 failed with a error

$ LANG=C CROSS_COMPILE=bfin-elf-  ./MAKEALL bct-brettl2
Configuring for bct-brettl2 board...
/home/yamada/u-boot/arch/blackfin/include/asm/blackfin_local.h:54: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'bfin_os_log_check'
make[1]: *** [cmd_test.o] Error 1
make: *** [common/built-in.o] Error 2
bfin-elf-size: './u-boot': No such file
In file included from /home/yamada/u-boot/arch/blackfin/include/asm/serial.h:48,
                 from initcode.c:19:
/home/yamada/u-boot/arch/blackfin/include/asm/serial1.h: In function 'uart_init':
/home/yamada/u-boot/arch/blackfin/include/asm/serial1.h:238: warning: implicit declaration of function 'BUG'
initcode.c: In function 'serial_init':
initcode.c:150: warning: unused variable 'uart_base'
initcode.c: In function 'initcode':
initcode.c:743: warning: 'sdivB' is used uninitialized in this function
initcode.c:1004: note: 'sdivB' was declared here
initcode.c:743: warning: 'divB' is used uninitialized in this function
initcode.c:1004: note: 'divB' was declared here
initcode.c:744: warning: 'vcoB' is used uninitialized in this function
initcode.c:1004: note: 'vcoB' was declared here
In file included from /home/yamada/u-boot/arch/blackfin/include/asm/blackfin.h:13,
                 from /home/yamada/u-boot/include/common.h:92,
                 from cmd_test.c:17:
/home/yamada/u-boot/arch/blackfin/include/asm/blackfin_local.h:54: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'bfin_os_log_check'
make[1]: *** [cmd_test.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [common/built-in.o] Error 2
make: *** Waiting for unfinished jobs....

  --------------------- SUMMARY ----------------------------
  Boards compiled: 1
  Boards with errors: 1 ( bct-brettl2 )
  ----------------------------------------------------------

After applying this patch, I still have warnings but I can get u-boot binary.

$ CROSS_COMPILE=bfin-elf- ./MAKEALL bct-brettl2
Configuring for bct-brettl2 board...
   text	   data	    bss	    dec	    hex	filename
 180664	   6018	  61896	 248578	  3cb02	./u-boot
In file included from /home/yamada/u-boot/arch/blackfin/include/asm/serial.h:48,
                 from initcode.c:19:
/home/yamada/u-boot/arch/blackfin/include/asm/serial1.h: In function ‘uart_init’:
/home/yamada/u-boot/arch/blackfin/include/asm/serial1.h:238: warning: implicit declaration of function ‘BUG’
initcode.c: In function ‘serial_init’:
initcode.c:150: warning: unused variable ‘uart_base’
initcode.c: In function ‘initcode’:
initcode.c:743: warning: ‘sdivB’ is used uninitialized in this function
initcode.c:1004: note: ‘sdivB’ was declared here
initcode.c:743: warning: ‘divB’ is used uninitialized in this function
initcode.c:1004: note: ‘divB’ was declared here
initcode.c:744: warning: ‘vcoB’ is used uninitialized in this function
initcode.c:1004: note: ‘vcoB’ was declared here

  --------------------- SUMMARY ----------------------------
  Boards compiled: 1
  Boards with warnings but no errors: 1 ( bct-brettl2 )
  ----------------------------------------------------------

I think this patch will not give a bad impact to the other boards.
I did build test for all target boards.
(But output binaries differ. And I did not check run-time test.)




 arch/arm/cpu/armv7/mx6/soc.c | 1 -
 include/galileo/core.h       | 2 +-
 include/linux/stddef.h       | 5 +++++
 include/linux/types.h        | 3 ++-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/armv7/mx6/soc.c b/arch/arm/cpu/armv7/mx6/soc.c
index a390296..54ef447 100644
--- a/arch/arm/cpu/armv7/mx6/soc.c
+++ b/arch/arm/cpu/armv7/mx6/soc.c
@@ -15,7 +15,6 @@
 #include <asm/arch/sys_proto.h>
 #include <asm/imx-common/boot_mode.h>
 #include <asm/imx-common/dma.h>
-#include <stdbool.h>
 #include <asm/arch/mxc_hdmi.h>
 #include <asm/arch/crm_regs.h>
 
diff --git a/include/galileo/core.h b/include/galileo/core.h
index 95013fa..2d1b2ed 100644
--- a/include/galileo/core.h
+++ b/include/galileo/core.h
@@ -14,7 +14,7 @@ space). The macros take care of Big/Little endian conversions.
 
 /* includes */
 #include "gt64260R.h"
-#include <stdbool.h>
+#include <linux/types.h>
 
 extern unsigned int INTERNAL_REG_BASE_ADDR;
 
diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index c540f61..5893ec9 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -12,6 +12,11 @@
 #include <linux/types.h>
 #endif
 
+enum {
+	false	= 0,
+	true	= 1
+};
+
 #ifndef __CHECKER__
 #undef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
diff --git a/include/linux/types.h b/include/linux/types.h
index 9aebc4e..157e1ae 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -3,7 +3,6 @@
 
 #include <linux/posix_types.h>
 #include <asm/types.h>
-#include <stdbool.h>
 
 #ifndef __KERNEL_STRICT_NAMES
 
@@ -18,6 +17,8 @@ typedef __kernel_daddr_t	daddr_t;
 typedef __kernel_key_t		key_t;
 typedef __kernel_suseconds_t	suseconds_t;
 
+typedef _Bool			bool;
+
 #ifdef __KERNEL__
 typedef __kernel_uid32_t	uid_t;
 typedef __kernel_gid32_t	gid_t;
-- 
1.8.3.2



More information about the U-Boot mailing list