mbox series

[v4,00/21] sandbox: efi_loader support

Message ID 20180618152315.34233-1-agraf@suse.de
Headers show
Series sandbox: efi_loader support | expand

Message

Alexander Graf June 18, 2018, 3:22 p.m. UTC
This patch set augments Simon's patch set for efi_loader support
in sandbox[1], but cuts off the memory allocation scheme at a different
point.

According to the UEFI spec, efi_allocate_pages() takes a uint64_t *
argument. Via this argument, we get a physical address as input, but
emit a pointer as output.

With this patch set in place, I can successfully run the selftest suite
as well as an aarch64 grub.efi binary. X86_64 grub.efi doesn't work
because that one requires inl instructions to work.

Alex

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=49832

v1 -> v2:

  - only compile efi_add_known_memory if efi_loader is enabled
  - clarify address vs pointer in fs_read patch
  - include mapmem.h

v2 -> v3:

  - removed: efi_loader: Pass address to fs_read()
  - new: fs: Convert fs_read/write to take buffer instead of address
  - new: efi_loader: Introduce ms abi vararg helpers
  - new: sandbox: Enable 1:1 map
  - new: distro: Move to compiler based target architecture determination
  - new: efi_loader: Move to compiler based target architecture determination
  - new: sandbox: Allow to execute from RAM
  - new: sandbox: Fix setjmp/longjmp

v3 -> v4:

  - remove 1:1 map again
  - switch to U-Boot addresses exposed in memory tables
  - new: elf: Move x86 reloc defines to common elf.h
  - new: sandbox: Always allocate aligned buffers
  - new: efi_loader: Expose U-Boot addresses in memory map for sandbox

Alexander Graf (16):
  efi_loader: Use compiler constants for image loader
  efi_loader: Use map_sysmem() in bootefi command
  efi.h: Do not use config options
  efi_loader: Allow SMBIOS tables in highmem
  sandbox: Map host memory for efi_loader
  efi_loader: Disable miniapps on sandbox
  fs: Convert fs_read/write to take buffer instead of address
  efi_loader: Introduce ms abi vararg helpers
  distro: Move to compiler based target architecture determination
  efi_loader: Move to compiler based target architecture determination
  sandbox: Fix setjmp/longjmp
  elf: Move x86 reloc defines to common elf.h
  efi_loader: Use common elf.h reloc defines
  sandbox: Allow to execute from RAM
  sandbox: Always allocate aligned buffers
  efi_loader: Expose U-Boot addresses in memory map for sandbox

Heinrich Schuchardt (1):
  efi_loader: efi_allocate_pages is too restrictive

Simon Glass (4):
  efi: sandbox: Add distroboot support
  efi: sandbox: Add relocation constants
  efi: sandbox: Enable EFI loader for sandbox
  efi: sandbox: Adjust memory usage for sandbox

 arch/sandbox/cpu/cpu.c                | 20 ++++++++++++----
 arch/sandbox/cpu/os.c                 | 39 +++++++++++++++---------------
 arch/sandbox/include/asm/setjmp.h     |  4 +++-
 arch/x86/include/asm/elf.h            | 45 -----------------------------------
 arch/x86/lib/reloc_ia32_efi.c         |  1 -
 arch/x86/lib/reloc_x86_64_efi.c       |  1 -
 board/BuR/common/common.c             |  2 +-
 board/gdsys/p1022/controlcenterd-id.c | 10 ++++----
 cmd/bootefi.c                         | 13 ++++++----
 cmd/mvebu/bubt.c                      |  4 ++--
 common/splash_source.c                |  4 +++-
 drivers/bootcount/bootcount_ext.c     | 12 +++++-----
 drivers/fpga/zynqpl.c                 |  8 ++++---
 fs/fs.c                               | 20 ++++++++--------
 include/config_distro_bootcmd.h       | 17 ++++++++-----
 include/efi.h                         | 25 ++++++++++---------
 include/elf.h                         | 35 +++++++++++++++++++++++++++
 include/fs.h                          | 12 +++++-----
 include/os.h                          | 19 +++++++++++++++
 lib/efi/Makefile                      |  4 ++--
 lib/efi_loader/Kconfig                |  2 +-
 lib/efi_loader/efi_boottime.c         | 36 ++++++++++++++--------------
 lib/efi_loader/efi_file.c             |  6 ++---
 lib/efi_loader/efi_image_loader.c     | 12 +++++-----
 lib/efi_loader/efi_memory.c           | 28 ++++++++++++++--------
 lib/efi_loader/efi_runtime.c          | 21 ++++++++--------
 lib/efi_loader/efi_smbios.c           | 11 +++++++--
 lib/efi_selftest/Makefile             |  2 +-
 28 files changed, 228 insertions(+), 185 deletions(-)
 delete mode 100644 arch/x86/include/asm/elf.h

Comments

Alexander Graf June 18, 2018, 3:53 p.m. UTC | #1
On 06/18/2018 05:22 PM, Alexander Graf wrote:
> This patch set augments Simon's patch set for efi_loader support
> in sandbox[1], but cuts off the memory allocation scheme at a different
> point.
>
> According to the UEFI spec, efi_allocate_pages() takes a uint64_t *
> argument. Via this argument, we get a physical address as input, but
> emit a pointer as output.
>
> With this patch set in place, I can successfully run the selftest suite
> as well as an aarch64 grub.efi binary. X86_64 grub.efi doesn't work
> because that one requires inl instructions to work.

I've assembled a quick grub.efi that does work in sandbox as it no 
longer accesses I/O ports directly. Patch for it is below.

   http://csgraf.de/tmp2/grub.efi

When building your own, make sure to exclude coreboot (cb*) modules - 
they seem to do something dirty and segfault for me. The other modules 
seem to work fine for me so far.


Alex


diff --git a/grub-core/kern/i386/tsc.c b/grub-core/kern/i386/tsc.c
index f266eb131..99fc9f7fb 100644
--- a/grub-core/kern/i386/tsc.c
+++ b/grub-core/kern/i386/tsc.c
@@ -68,7 +68,7 @@ grub_tsc_init (void)
  #ifdef GRUB_MACHINE_XEN
    (void) (grub_tsc_calibrate_from_xen () || calibrate_tsc_hardcode());
  #elif defined (GRUB_MACHINE_EFI)
-  (void) (grub_tsc_calibrate_from_pmtimer () || 
grub_tsc_calibrate_from_pit () || grub_tsc_calibrate_from_efi() || 
calibrate_tsc_hardcode());
+  (void) (grub_tsc_calibrate_from_efi() || calibrate_tsc_hardcode());
  #elif defined (GRUB_MACHINE_COREBOOT)
    (void) (grub_tsc_calibrate_from_pmtimer () || 
grub_tsc_calibrate_from_pit () || calibrate_tsc_hardcode());
  #else
diff --git a/include/grub/i386/io.h b/include/grub/i386/io.h
index ae12a3e3d..9fbeef916 100644
--- a/include/grub/i386/io.h
+++ b/include/grub/i386/io.h
@@ -26,47 +26,40 @@ typedef unsigned short int grub_port_t;
  static __inline unsigned char
  grub_inb (unsigned short int port)
  {
-  unsigned char _v;
+  unsigned char _v = 0;

-  __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
    return _v;
  }

  static __inline unsigned short int
  grub_inw (unsigned short int port)
  {
-  unsigned short _v;
+  unsigned short _v = 0;

-  __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
    return _v;
  }

  static __inline unsigned int
  grub_inl (unsigned short int port)
  {
-  unsigned int _v;
+  unsigned int _v = 0;

-  __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
    return _v;
  }

  static __inline void
  grub_outb (unsigned char value, unsigned short int port)
  {
-  __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
  }

  static __inline void
  grub_outw (unsigned short int value, unsigned short int port)
  {
-  __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
-
  }

  static __inline void
  grub_outl (unsigned int value, unsigned short int port)
  {
-  __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
  }

  #endif /* _SYS_IO_H */
Simon Glass June 21, 2018, 2:44 a.m. UTC | #2
Hi Alex,

On 18 June 2018 at 09:53, Alexander Graf <agraf@suse.de> wrote:
> On 06/18/2018 05:22 PM, Alexander Graf wrote:
>>
>> This patch set augments Simon's patch set for efi_loader support
>> in sandbox[1], but cuts off the memory allocation scheme at a different
>> point.
>>
>> According to the UEFI spec, efi_allocate_pages() takes a uint64_t *
>> argument. Via this argument, we get a physical address as input, but
>> emit a pointer as output.
>>
>> With this patch set in place, I can successfully run the selftest suite
>> as well as an aarch64 grub.efi binary. X86_64 grub.efi doesn't work
>> because that one requires inl instructions to work.
>
>
> I've assembled a quick grub.efi that does work in sandbox as it no longer
> accesses I/O ports directly. Patch for it is below.
>
>   http://csgraf.de/tmp2/grub.efi
>
> When building your own, make sure to exclude coreboot (cb*) modules - they
> seem to do something dirty and segfault for me. The other modules seem to
> work fine for me so far.

OK thanks for that. The binary says this for me:

efi_load_pe: Invalid DOS signature

I'm running on x86_64.

I tried the patch below but it still crashes, presumably because of
the coreboot modules. How do I actually exclude them? I cannot see
anything in ./configure --help

Regards,
Simon
Alexander Graf June 21, 2018, 9:47 a.m. UTC | #3
On 06/21/2018 04:44 AM, Simon Glass wrote:
> Hi Alex,
>
> On 18 June 2018 at 09:53, Alexander Graf <agraf@suse.de> wrote:
>> On 06/18/2018 05:22 PM, Alexander Graf wrote:
>>> This patch set augments Simon's patch set for efi_loader support
>>> in sandbox[1], but cuts off the memory allocation scheme at a different
>>> point.
>>>
>>> According to the UEFI spec, efi_allocate_pages() takes a uint64_t *
>>> argument. Via this argument, we get a physical address as input, but
>>> emit a pointer as output.
>>>
>>> With this patch set in place, I can successfully run the selftest suite
>>> as well as an aarch64 grub.efi binary. X86_64 grub.efi doesn't work
>>> because that one requires inl instructions to work.
>>
>> I've assembled a quick grub.efi that does work in sandbox as it no longer
>> accesses I/O ports directly. Patch for it is below.
>>
>>    http://csgraf.de/tmp2/grub.efi
>>
>> When building your own, make sure to exclude coreboot (cb*) modules - they
>> seem to do something dirty and segfault for me. The other modules seem to
>> work fine for me so far.
> OK thanks for that. The binary says this for me:
>
> efi_load_pe: Invalid DOS signature
>
> I'm running on x86_64.

Are you using my patch set or yours? In mine this should be fixed.

> I tried the patch below but it still crashes, presumably because of
> the coreboot modules. How do I actually exclude them? I cannot see
> anything in ./configure --help

When you call grub-mkimage you explicitly pass a list of modules to 
include. In that list, just omit any module that starts with cb :)


Alex
Simon Glass June 21, 2018, 7:45 p.m. UTC | #4
Hi Alex,

On 21 June 2018 at 03:47, Alexander Graf <agraf@suse.de> wrote:
> On 06/21/2018 04:44 AM, Simon Glass wrote:
>>
>> Hi Alex,
>>
>> On 18 June 2018 at 09:53, Alexander Graf <agraf@suse.de> wrote:
>>>
>>> On 06/18/2018 05:22 PM, Alexander Graf wrote:
>>>>
>>>> This patch set augments Simon's patch set for efi_loader support
>>>> in sandbox[1], but cuts off the memory allocation scheme at a different
>>>> point.
>>>>
>>>> According to the UEFI spec, efi_allocate_pages() takes a uint64_t *
>>>> argument. Via this argument, we get a physical address as input, but
>>>> emit a pointer as output.
>>>>
>>>> With this patch set in place, I can successfully run the selftest suite
>>>> as well as an aarch64 grub.efi binary. X86_64 grub.efi doesn't work
>>>> because that one requires inl instructions to work.
>>>
>>>
>>> I've assembled a quick grub.efi that does work in sandbox as it no longer
>>> accesses I/O ports directly. Patch for it is below.
>>>
>>>    http://csgraf.de/tmp2/grub.efi
>>>
>>> When building your own, make sure to exclude coreboot (cb*) modules -
>>> they
>>> seem to do something dirty and segfault for me. The other modules seem to
>>> work fine for me so far.
>>
>> OK thanks for that. The binary says this for me:
>>
>> efi_load_pe: Invalid DOS signature
>>
>> I'm running on x86_64.
>
>
> Are you using my patch set or yours? In mine this should be fixed.

I'm using the series at u-boot-dm/efi-working - am I missing something else?

>
>> I tried the patch below but it still crashes, presumably because of
>> the coreboot modules. How do I actually exclude them? I cannot see
>> anything in ./configure --help
>
>
> When you call grub-mkimage you explicitly pass a list of modules to include.
> In that list, just omit any module that starts with cb :)

In my case I am not specifying a list. I'll see if I can do that. I'm
worried there are a lot of modules to find and specify. I cannot find
documentation on what they are.

Regards,
Simon
Alexander Graf June 22, 2018, 9:44 a.m. UTC | #5
On 06/21/2018 09:45 PM, Simon Glass wrote:
> Hi Alex,
>
> On 21 June 2018 at 03:47, Alexander Graf <agraf@suse.de> wrote:
>> On 06/21/2018 04:44 AM, Simon Glass wrote:
>>> Hi Alex,
>>>
>>> On 18 June 2018 at 09:53, Alexander Graf <agraf@suse.de> wrote:
>>>> On 06/18/2018 05:22 PM, Alexander Graf wrote:
>>>>> This patch set augments Simon's patch set for efi_loader support
>>>>> in sandbox[1], but cuts off the memory allocation scheme at a different
>>>>> point.
>>>>>
>>>>> According to the UEFI spec, efi_allocate_pages() takes a uint64_t *
>>>>> argument. Via this argument, we get a physical address as input, but
>>>>> emit a pointer as output.
>>>>>
>>>>> With this patch set in place, I can successfully run the selftest suite
>>>>> as well as an aarch64 grub.efi binary. X86_64 grub.efi doesn't work
>>>>> because that one requires inl instructions to work.
>>>>
>>>> I've assembled a quick grub.efi that does work in sandbox as it no longer
>>>> accesses I/O ports directly. Patch for it is below.
>>>>
>>>>     http://csgraf.de/tmp2/grub.efi
>>>>
>>>> When building your own, make sure to exclude coreboot (cb*) modules -
>>>> they
>>>> seem to do something dirty and segfault for me. The other modules seem to
>>>> work fine for me so far.
>>> OK thanks for that. The binary says this for me:
>>>
>>> efi_load_pe: Invalid DOS signature
>>>
>>> I'm running on x86_64.
>>
>> Are you using my patch set or yours? In mine this should be fixed.
> I'm using the series at u-boot-dm/efi-working - am I missing something else?
>
>>> I tried the patch below but it still crashes, presumably because of
>>> the coreboot modules. How do I actually exclude them? I cannot see
>>> anything in ./configure --help
>>
>> When you call grub-mkimage you explicitly pass a list of modules to include.
>> In that list, just omit any module that starts with cb :)
> In my case I am not specifying a list. I'll see if I can do that. I'm
> worried there are a lot of modules to find and specify. I cannot find
> documentation on what they are.

./grub-mkimage -O x86_64-efi -o grub.efi $(cd grub-core; ls *mod | cut 
-d . -f 1)

is what I usually do to get all modules. In this case you have to | 
egrep -v '^cb' as well.


Alex