include: define bool type in the same way as Linux
PATCH v2 1/1 include: define bool type in the same way as Linux
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.
---
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(-)
arch/arm/cpu/armv7/mx6/soc.c +0 -1
@@ -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>
common/cmd_test.c +0 -9
@@ -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>
include/galileo/core.h +1 -1
@@ -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 ;
include/linux/stddef.h +5 -0
@@ -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)
include/linux/types.h +2 -1
@@ -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 ;
Signature · 1 line
1.8.3.2
PATCH v2 1/1 include: define bool type in the same way as Linux
Dear Masahiro Yamada,
Quoted 2 lines · In message <[email protected]> you…
Before this commit, U-Boot included <
stdbool.h>
in order to define bool, true and false.
...
Quoted 2 lines
This commit changes header files to define bool, true and false in the same way as Linux Kernel does.
I'm not happy with this modification. I feel we should leave the compiler provided implementation as is, and rather fix the root cause of the problem.
See the example patch I jut posted in the other thread -
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/174351
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Extended Epstein-Heisenberg Principle: In an R & D orbit, only 2 of the existing 3 parameters can be defined simultaneously. The parame- ters are: task, time and resources ($).