diff mbox series

[1/6] efi.h: Do not use config options

Message ID 1529656712-3660-2-git-send-email-bmeng.cn@gmail.com
State Superseded
Headers show
Series [1/6] efi.h: Do not use config options | expand

Commit Message

Bin Meng June 22, 2018, 8:38 a.m. UTC
From: Alexander Graf <agraf@suse.de>

Currently efi.h determines a few bits of its environment according to
config options. This falls apart with the efi stub support which may
result in efi.h getting pulled into the stub as well as real U-Boot
code. In that case, one may be 32bit while the other one is 64bit.

This patch changes the conditionals to use compiler provided defines
instead. That way we always adhere to the build environment we're in
and the definitions adjust automatically.

Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
[bmeng: added some comments to describe the __x86_64__ check]
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

---

 include/efi.h    | 24 +++++++++++-------------
 lib/efi/Makefile |  4 ++--
 2 files changed, 13 insertions(+), 15 deletions(-)

Comments

Simon Glass June 23, 2018, 2:21 p.m. UTC | #1
On 22 June 2018 at 02:38, Bin Meng <bmeng.cn@gmail.com> wrote:
> From: Alexander Graf <agraf@suse.de>
>
> Currently efi.h determines a few bits of its environment according to
> config options. This falls apart with the efi stub support which may
> result in efi.h getting pulled into the stub as well as real U-Boot
> code. In that case, one may be 32bit while the other one is 64bit.
>
> This patch changes the conditionals to use compiler provided defines
> instead. That way we always adhere to the build environment we're in
> and the definitions adjust automatically.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Tested-by: Bin Meng <bmeng.cn@gmail.com>
> [bmeng: added some comments to describe the __x86_64__ check]
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>
> ---
>
>  include/efi.h    | 24 +++++++++++-------------
>  lib/efi/Makefile |  4 ++--
>  2 files changed, 13 insertions(+), 15 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Bin Meng June 24, 2018, 12:53 a.m. UTC | #2
On Sat, Jun 23, 2018 at 10:21 PM, Simon Glass <sjg@chromium.org> wrote:
> On 22 June 2018 at 02:38, Bin Meng <bmeng.cn@gmail.com> wrote:
>> From: Alexander Graf <agraf@suse.de>
>>
>> Currently efi.h determines a few bits of its environment according to
>> config options. This falls apart with the efi stub support which may
>> result in efi.h getting pulled into the stub as well as real U-Boot
>> code. In that case, one may be 32bit while the other one is 64bit.
>>
>> This patch changes the conditionals to use compiler provided defines
>> instead. That way we always adhere to the build environment we're in
>> and the definitions adjust automatically.
>>
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>> Tested-by: Bin Meng <bmeng.cn@gmail.com>
>> [bmeng: added some comments to describe the __x86_64__ check]
>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>>
>> ---
>>
>>  include/efi.h    | 24 +++++++++++-------------
>>  lib/efi/Makefile |  4 ++--
>>  2 files changed, 13 insertions(+), 15 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/include/efi.h b/include/efi.h
index 2448dde..0fe15e6 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -19,12 +19,19 @@ 
 #include <linux/string.h>
 #include <linux/types.h>
 
-#if CONFIG_EFI_STUB_64BIT || (!defined(CONFIG_EFI_STUB) && defined(__x86_64__))
-/* EFI uses the Microsoft ABI which is not the default for GCC */
+/*
+ * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
+ *
+ * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
+ * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
+ * Either needs to be properly built with the '-m64' compiler flag, and hence
+ * it is enough to only check the compiler provided define __x86_64__ here.
+ */
+#ifdef __x86_64__
 #define EFIAPI __attribute__((ms_abi))
 #else
 #define EFIAPI asmlinkage
-#endif
+#endif /* __x86_64__ */
 
 struct efi_device_path;
 
@@ -32,16 +39,7 @@  typedef struct {
 	u8 b[16];
 } efi_guid_t;
 
-#define EFI_BITS_PER_LONG	BITS_PER_LONG
-
-/*
- * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set
- * in lib/efi/Makefile, when building the stub.
- */
-#if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
-#undef EFI_BITS_PER_LONG
-#define EFI_BITS_PER_LONG	64
-#endif
+#define EFI_BITS_PER_LONG	(sizeof(long) * 8)
 
 /* Bit mask for EFI status code with error */
 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
diff --git a/lib/efi/Makefile b/lib/efi/Makefile
index f1a3929..a790d2d 100644
--- a/lib/efi/Makefile
+++ b/lib/efi/Makefile
@@ -7,11 +7,11 @@  obj-$(CONFIG_EFI_STUB) += efi_info.o
 
 CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
-CFLAGS_efi_stub.o := -fpic -fshort-wchar -DEFI_STUB \
+CFLAGS_efi_stub.o := -fpic -fshort-wchar \
 	$(if $(CONFIG_EFI_STUB_64BIT),-m64)
 CFLAGS_REMOVE_efi.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
-CFLAGS_efi.o := -fpic -fshort-wchar -DEFI_STUB \
+CFLAGS_efi.o := -fpic -fshort-wchar \
 	$(if $(CONFIG_EFI_STUB_64BIT),-m64)
 
 extra-$(CONFIG_EFI_STUB) += efi_stub.o efi.o