All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 05/18] efi: Fix efi_uintn_t for 64-bit EFI payload
Date: Sun, 10 Jun 2018 20:17:05 +0200	[thread overview]
Message-ID: <c5a58be4-59af-6396-a7c4-ee8dce7acf04@gmx.de> (raw)
In-Reply-To: <CAEUhbmUaPHA__Sm7Af3nq_=yBBF7ETvbhFEH=sKs5PMiSOxCgQ@mail.gmail.com>

On 06/10/2018 04:30 PM, Bin Meng wrote:
> Hi Heinrich,
> 
> On Sun, Jun 10, 2018 at 10:02 PM, Heinrich Schuchardt
> <xypron.glpk@gmx.de> wrote:
>> On 06/10/2018 03:25 PM, Bin Meng wrote:
>>> Since commit bb0bb91cf0aa ("efi_stub: Use efi_uintn_t"), EFI x86
>>> 64-bit payload does not work anymore. The call to GetMemoryMap()
>>> in efi_stub.c fails with return code EFI_INVALID_PARAMETER. Since
>>> the payload itself is still 32-bit U-Boot
>>
>> Above you say 64-bit payload and now you say 32-bit?
>>
>> Why don't you compile U-Boot as 64-bit? How do you want to load a 64bit
>> Linux EFI stub from an 32-bit EFI implementation in U-Boot?
>>
> 
> U-Boot itself as the EFI pyaload is 32-bit. The EFI stub is 64-bit as
> it has to be loaded from the 64-bit EFI BIOS. Note in case you
> misunderstand: the generated u-boot-payload.efi is 64-bit stub codes
> (for 64-bit EFI BIOS) or 32-bit stub codes (for 32-bit EFI BIOS) plus
> 32-bit U-Boot payload. The payload is always 32-bit as of today as
> U-Boot on x86 is mainly on 32-bit. 64-bit support, as you see from
> README.x86, is far from mature yet.
> 
>>> , efi_uintn_t gets wrongly
>>> interpreted as int, but it should actually be long in a 64-bit EFI
>>> environment.
>>>
>>> Fixes: bb0bb91cf0aa ("efi_stub: Use efi_uintn_t")
>>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>>> ---
>>>
>>>  include/efi_api.h | 4 ++++
>>>  1 file changed, 4 insertions(+)
>>>
>>> diff --git a/include/efi_api.h b/include/efi_api.h
>>> index 64c27e4..d1158de 100644
>>> --- a/include/efi_api.h
>>> +++ b/include/efi_api.h
>>> @@ -28,7 +28,11 @@ enum efi_timer_delay {
>>>       EFI_TIMER_RELATIVE = 2
>>>  };
>>>
>>> +#if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
>>> +#define efi_uintn_t unsigned long
>>> +#else
>>>  #define efi_uintn_t size_t
>>
>> NAK
>>
>> This change will create a lot of build warnings if EFI_STUB and
>> EFI_LOADER are both configured.
>>
> 
> I don't see any build warnings when building efi-x86_payload32 or
> efi-x86_payload64. I see both EFI_STUB and EFI_LOADER are enabled with
> these two targets. AFAIK, only x86 supports EFI_STUB currently. I
> don't know where you see a lot of build warnings.

Currently you cannot build with EFI_LOADER=Y on 32 bit with a 64bit
stub. See lib/efi_loader/Kconfig. The problem is with the build scripts
for the stub using the same CONFIG variables as those used for other
binaries.

To emulate what would happen with your change once we can build with
EFI_LOADER=y and 64bit stub I made the following change:

--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -28,7 +28,8 @@ enum efi_timer_delay {
        EFI_TIMER_RELATIVE = 2
 };

-#define efi_uintn_t size_t
+#define efi_uintn_t unsigned long
 typedef uint16_t *efi_string_t;

And then I tried to build:
make qemu-x86_defconfig
make -j6

It gives me a bunch of errors like below.



  ^~~~~~~~~
include/efi_loader.h:31:8: warning: format ‘%zu’ expects argument of
type ‘size_t’, but argument 13 has type ‘long unsigned int’ [-Wformat=]
  debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
        ^
include/linux/printk.h:37:21: note: in definition of macro ‘pr_fmt’
 #define pr_fmt(fmt) fmt
                     ^~~
include/log.h:141:2: note: in expansion of macro ‘debug_cond’
  debug_cond(_DEBUG, fmt, ##args)
  ^~~~~~~~~~
include/efi_loader.h:31:2: note: in expansion of macro ‘debug’
  debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
  ^~~~~
lib/efi_loader/efi_gop.c:333:2: note: in expansion of macro ‘EFI_ENTRY’
  EFI_ENTRY("%p, %p, %u, %zu, %zu, %zu, %zu, %zu, %zu, %zu", this,
  ^~~~~~~~~
In file included from include/linux/bug.h:7:0,
                 from include/common.h:25,
                 from lib/efi_loader/efi_disk.c:8:
lib/efi_loader/efi_disk.c: In function ‘efi_disk_read_blocks’:
include/efi_loader.h:31:8: warning: format ‘%zx’ expects argument of
type ‘size_t’, but argument 7 has type ‘long unsigned int’ [-Wformat=]
  debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
        ^
include/linux/printk.h:37:21: note: in definition of macro ‘pr_fmt’
 #define pr_fmt(fmt) fmt
                     ^~~
include/log.h:141:2: note: in expansion of macro ‘debug_cond’
  debug_cond(_DEBUG, fmt, ##args)
  ^~~~~~~~~~
include/efi_loader.h:31:2: note: in expansion of macro ‘debug’
  debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
  ^~~~~
lib/efi_loader/efi_disk.c:114:2: note: in expansion of macro ‘EFI_ENTRY’
  EFI_ENTRY("%p, %x, %" PRIx64 ", %zx, %p", this, media_id, lba,
  ^~~~~~~~~
lib/efi_loader/efi_disk.c: In function ‘efi_disk_write_blocks’:
include/efi_loader.h:31:8: warning: format ‘%zx’ expects argument of
type ‘size_t’, but argument 7 has type ‘long unsigned int’ [-Wformat=]
  debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
        ^
include/linux/printk.h:37:21: note: in definition of macro ‘pr_fmt’
 #define pr_fmt(fmt) fmt
                     ^~~
include/log.h:141:2: note: in expansion of macro ‘debug_cond’
  debug_cond(_DEBUG, fmt, ##args)
  ^~~~~~~~~~
include/efi_loader.h:31:2: note: in expansion of macro ‘debug’
  debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \


So, please, do not change the type of efi_uintn_t.

What is needed is using different types in lib/efi_loader/ and in the
calls to the primary firmware if they have different bitness.

Best regards

Heinrich


> 
>> Could you, please, explain under which compiler settings size_t and
>> unsigned long have a different number of bits?
>>
> 
> As mentioned above, the EFI stub codes (efi_stub.c) are built for
> 64-bit, which expects 'efi_uintn_t' to be 64-bit. However, it is
> defined as size_t, which in U-Boot 32, will be 'unsigned int' (see
> arch/x86/include/asm/posix_types.h) - the bug here!
> 
>> Obviously we have the EFI API exposed by U-Boot which has the bitness of
>> U-Boot.
>>
>> If you want to consume an EFI API of another bitness I suggest that you
>> create separate interface definitions.
>>
> 
> Regards,
> Bin
> 

  reply	other threads:[~2018-06-10 18:17 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-10 13:24 [U-Boot] [PATCH 00/18] x86: efi: Fixes and enhancements to application and payload support Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 01/18] x86: doc: Fix reference to EFI doc in U-Boot Bin Meng
2018-06-10 13:39   ` Heinrich Schuchardt
2018-06-10 14:01     ` Bin Meng
2018-06-10 17:46       ` Heinrich Schuchardt
2018-06-10 13:25 ` [U-Boot] [PATCH 02/18] x86: Conditionally build the pinctrl_ich6 driver Bin Meng
2018-06-11 14:53   ` Simon Glass
2018-06-12 13:07     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 03/18] x86: efi: app: Fix broken EFI application Bin Meng
2018-06-11 14:53   ` Simon Glass
2018-06-12 13:07     ` Bin Meng
2018-06-11 17:18   ` Heinrich Schuchardt
2018-06-11 23:19     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 04/18] x86: efi: payload: Enforce toolchain to generate 64-bit EFI payload stub codes Bin Meng
2018-06-10 19:11   ` Alexander Graf
2018-06-11  2:34     ` Bin Meng
2018-06-11  5:55       ` Alexander Graf
2018-06-11  6:05         ` Bin Meng
2018-06-11 14:53   ` Simon Glass
2018-06-12 13:07     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 05/18] efi: Fix efi_uintn_t for 64-bit EFI payload Bin Meng
2018-06-10 14:02   ` Heinrich Schuchardt
2018-06-10 14:30     ` Bin Meng
2018-06-10 18:17       ` Heinrich Schuchardt [this message]
2018-06-10 23:36         ` Bin Meng
2018-06-11 15:31           ` Heinrich Schuchardt
2018-06-11 16:35             ` Bin Meng
2018-06-11 18:35               ` Heinrich Schuchardt
2018-06-11  9:11   ` Bin Meng
2018-06-11 19:43     ` Alexander Graf
2018-06-10 13:25 ` [U-Boot] [PATCH 06/18] dm: pci: Make ranges dt property optional Bin Meng
2018-06-11 14:53   ` Simon Glass
2018-06-12 13:07     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 07/18] dm: pci: Use a 1:1 mapping for bus <-> phy addresses Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-12 13:07     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 08/18] x86: efi: Refactor the directory of EFI app and payload support Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 09/18] x86: efi: payload: Add arch_cpu_init() Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 10/18] x86: efi: payload: Minor clean up on error message output Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-12 13:07     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 11/18] x86: Add generic EFI payload support Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 12/18] x86: Drop QEMU-specific " Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 13/18] x86: baytrail: Drop EFI-specific test logics Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 14/18] efi: stub: Pass EFI GOP information to U-Boot payload Bin Meng
2018-06-10 19:16   ` Alexander Graf
2018-06-10 23:29     ` Bin Meng
2018-06-11  5:52       ` Alexander Graf
2018-06-11  6:01         ` Bin Meng
2018-06-11  7:34           ` Alexander Graf
2018-06-11  7:44             ` Bin Meng
2018-06-11  8:33               ` Alexander Graf
2018-06-11  9:02                 ` Bin Meng
2018-06-11 14:53   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 15/18] dm: video: Add an EFI framebuffer driver Bin Meng
2018-06-10 15:52   ` Anatolij Gustschin
2018-06-10 13:25 ` [U-Boot] [PATCH 16/18] x86: efi: payload: Add EFI framebuffer driver support Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-10 13:25 ` [U-Boot] [PATCH 17/18] x86: Rename efi-x86 target to efi-x86_app Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-11 15:50     ` Bin Meng
2018-06-10 13:25 ` [U-Boot] [PATCH 18/18] x86: efi: app: Display correct CPU info during boot Bin Meng
2018-06-11 14:54   ` Simon Glass
2018-06-11 14:53 ` [U-Boot] [PATCH 00/18] x86: efi: Fixes and enhancements to application and payload support Simon Glass
2018-06-11 15:53   ` Bin Meng
2018-06-11 19:38     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c5a58be4-59af-6396-a7c4-ee8dce7acf04@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.