[U-Boot] [PATCH v2] include: define bool type in the same way as Linux
Masahiro Yamada
yamada.m at jp.panasonic.com
Tue Nov 19 05:22:57 CET 2013
Before this commit, U-Boot included <stdbool.h>
in order to define bool, true and false.
The header <stdbool.h> of gcc generally defines
them as macros as follows:
#define bool _Bool
#define true 1
#define false 0
But this gave a bad imapct on common/cmd_test.c,
which implements "true" and "false" commands:
U_BOOT_CMD(
true, CONFIG_SYS_MAXARGS, 1, do_true,
"do nothing, successfully",
NULL
);
In order to work around this problem,
common/cmd_test.c defined _STDBOOL_H at the top
in order to avoid including <stdbool.h>.
But this caused another problem: build error on Blackfin boards.
arch/blackfin/include/asm/blackfin_local.h uses bool type here:
extern bool bfin_os_log_check(void);
This commit changes header files to define bool, true and false
in the same way as Linux Kernel does.
This change also resolves the build error of common/cmd_test.c
on Blackfin boards.
Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
---
For example, when I try to compile bct-brettl2 board,
I got an error like follows at compiling common/cmd_test.c.
bfin-uclinux-gcc -g -Os -ffixed-P3 -fomit-frame-pointer -mno-fdpic
-ffunction-sections -fdata-sections -mcpu=bf536-0.3 -D__KERNEL__
-I/home/yamada/u-boot/include -I/home/yamada/u-boot/arch/blackfin/include
-fno-builtin -ffreestanding -nostdinc
-isystem /opt/gcc-4.6.3-nolibc/bfin-uclinux/bin/../lib/gcc/bfin-uclinux/4.6.3/include
-pipe -DCONFIG_BLACKFIN -Wall -Wstrict-prototypes -fno-stack-protector
-Wno-format-nonliteral -Wno-format-security -o cmd_test.o cmd_test.c -c
In file included from /home/yamada/u-boot/arch/blackfin/include/asm/blackfin.h:13:0,
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:1: error: unknown type name 'bool'
make[2]: *** [cmd_test.o] Error 1
make[2]: Leaving directory `/home/yamada/u-boot/common'
make[1]: *** [common/built-in.o] Error 2
make[1]: Leaving directory `/home/yamada/u-boot'
make: *** [bct-brettl2] Error 2
I think this patch will not break the other boards.
I did build test for all target boards.
I did run-time test only on sandbox.
I confirmed that "true" and "false" commonds worked.
Changes in v2:
- Change subject and commit log
because it turned out the error is __not__ the compiler issue.
- Delete the tweak in common/cmd_test.c
because we will not include <stdbool.h>
arch/arm/cpu/armv7/mx6/soc.c | 1 -
common/cmd_test.c | 9 ---------
include/galileo/core.h | 2 +-
include/linux/stddef.h | 5 +++++
include/linux/types.h | 3 ++-
5 files changed, 8 insertions(+), 12 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/common/cmd_test.c b/common/cmd_test.c
index bacc368..76b62c4 100644
--- a/common/cmd_test.c
+++ b/common/cmd_test.c
@@ -5,15 +5,6 @@
* SPDX-License-Identifier: GPL-2.0+
*/
-/*
- * Define _STDBOOL_H here to avoid macro expansion of true and false.
- * If the future code requires macro true or false, remove this define
- * and undef true and false before U_BOOT_CMD. This define and comment
- * shall be removed if change to U_BOOT_CMD is made to take string
- * instead of stringifying it.
- */
-#define _STDBOOL_H
-
#include <common.h>
#include <command.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