mbox series

[U-Boot,v4,00/16] efi: Enable basic sandbox support for EFI loader

Message ID 20180516154233.21457-1-sjg@chromium.org
Headers show
Series efi: Enable basic sandbox support for EFI loader | expand

Message

Simon Glass May 16, 2018, 3:42 p.m. UTC
A limitation of the EFI loader at present is that it does not build with
sandbox. This makes it hard to write tests, since sandbox is used for most
testing in U-Boot.

This series enables the EFI loader feature. It allows sandbox to build and
run a trivial function which calls the EFI API to output a message.

This series is at u-boot-dm/efi-working

Changes in v4:
- Fix up the sizeof() operations on jmp_buf
- Move the fix to query_console_serial()
- Rebase to master
- Remove code already applied
- Update SPDX tags
- Update subject

Changes in v3:
- Add comments on aligment
- Add new patch to init the 'rows' and 'cols' variables
- Add new patch to rename bootefi_test_finish() to bootefi_run_finish()
- Add new patch to split out test init/uninit into functions
- Add patch to create a function to set up for running EFI code
- Drop incorrect map_sysmem() in write_smbios_table()
- Init the 'rows' and 'cols' vars to avoid a compiler error (gcc 4.8.4)
- Rebase to master
- Return error value of efi_allocate_pages()
- Update function comment for write_smbios_table()

Changes in v2:
- Rebase to master
- Update return type of efi_smbios_register() to efi_status_t
- Update to use mapmem instead of a cast
- Use return value of efi_install_configuration_table

Simon Glass (16):
  efi: Init the 'rows' and 'cols' variables
  efi: Update some comments related to smbios tables
  efi: sandbox: Adjust memory usage for sandbox
  sandbox: smbios: Update to support sandbox
  sandbox: Add a setjmp() implementation
  efi: sandbox: Add required linker sections
  efi: sandbox: Add distroboot support
  Define board_quiesce_devices() in a shared location
  Add a comment for board_quiesce_devices()
  efi: sandbox: Add relocation constants
  efi: Add a comment about duplicated ELF constants
  efi: sandbox: Enable EFI loader builder for sandbox
  efi: Split out test init/uninit into functions
  efi: sandbox: Add a simple 'bootefi test' command
  efi: Create a function to set up for running EFI code
  efi: Rename bootefi_test_finish() to bootefi_run_finish()

 arch/arm/include/asm/u-boot-arm.h |   1 -
 arch/sandbox/cpu/cpu.c            |  13 +++
 arch/sandbox/cpu/os.c             |  23 +++++
 arch/sandbox/cpu/u-boot.lds       |  29 ++++++
 arch/sandbox/include/asm/setjmp.h |  30 ++++++
 arch/sandbox/lib/Makefile         |   2 +-
 arch/sandbox/lib/sections.c       |  12 +++
 arch/x86/include/asm/u-boot-x86.h |   1 -
 arch/x86/lib/bootm.c              |   4 -
 cmd/bootefi.c                     | 158 +++++++++++++++++++++---------
 common/bootm.c                    |   4 +
 include/bootm.h                   |   8 ++
 include/config_distro_bootcmd.h   |   2 +-
 include/efi_loader.h              |  10 ++
 include/os.h                      |  21 ++++
 include/smbios.h                  |   5 +-
 lib/efi_loader/Kconfig            |  12 ++-
 lib/efi_loader/Makefile           |   1 +
 lib/efi_loader/efi_console.c      |   5 +-
 lib/efi_loader/efi_memory.c       |  31 +++---
 lib/efi_loader/efi_runtime.c      |   7 ++
 lib/efi_loader/efi_smbios.c       |   7 +-
 lib/efi_loader/efi_test.c         |  16 +++
 lib/smbios.c                      |  32 ++++--
 24 files changed, 351 insertions(+), 83 deletions(-)
 create mode 100644 arch/sandbox/include/asm/setjmp.h
 create mode 100644 arch/sandbox/lib/sections.c
 create mode 100644 lib/efi_loader/efi_test.c

Comments

Heinrich Schuchardt May 16, 2018, 5:13 p.m. UTC | #1
On 05/16/2018 05:42 PM, Simon Glass wrote:
> A limitation of the EFI loader at present is that it does not build with
> sandbox. This makes it hard to write tests, since sandbox is used for most
> testing in U-Boot.
> 
> This series enables the EFI loader feature. It allows sandbox to build and
> run a trivial function which calls the EFI API to output a message.
> 
> This series is at u-boot-dm/efi-working

I applied you patch series

make sandbox_defconfig
CONFIG_CMD_BOOTEFI_SELFTEST=y
make -j6

results in:

ld.bfd: read in flex scanner failed
scripts/Makefile.lib:407: recipe for target
'lib/efi_selftest/efi_selftest_miniapp_exit_efi.so' failed
make[2]: *** [lib/efi_selftest/efi_selftest_miniapp_exit_efi.so] Error 1
rm lib/efi_selftest/efi_selftest_miniapp_exit.o
lib/efi_selftest/efi_selftest_miniapp_return.o
scripts/Makefile.build:423: recipe for target 'lib/efi_selftest' failed
make[1]: *** [lib/efi_selftest] Error 2
make[1]: *** Waiting for unfinished jobs....

Please, change /lib/efi_selftest/Makefile
-ifeq ($(CONFIG_X86_64),)
+ifeq ($(CONFIG_X86_64)$(CONFIG_SANDBOX),)

Now running ./u-boot

bootefi selftest
Found 0 disks
WARNING: booting without device tree

Testing EFI API implementation

Number of tests to execute: 17

Setting up 'block device'
Setting up 'block device' succeeded

Executing 'block device'
lib/efi_selftest/efi_selftest_block_device.c(378):
TODO: Wrong volume label 'xxa1', expected 'U-BOOT TEST'
FAT: Misaligned buffer address (00007ff70aafe658)
Segmentation fault

Please, fix the alignment fault. You have to ensure that the memory that
Sandbox has retrieved via malloc is reduced to 4k aligned pages before
being published to the EFI implementation in lib/efi_loader/efi_memory.c

Best regards

Heinrich



> 
> Changes in v4:
> - Fix up the sizeof() operations on jmp_buf
> - Move the fix to query_console_serial()
> - Rebase to master
> - Remove code already applied
> - Update SPDX tags
> - Update subject
> 
> Changes in v3:
> - Add comments on aligment
> - Add new patch to init the 'rows' and 'cols' variables
> - Add new patch to rename bootefi_test_finish() to bootefi_run_finish()
> - Add new patch to split out test init/uninit into functions
> - Add patch to create a function to set up for running EFI code
> - Drop incorrect map_sysmem() in write_smbios_table()
> - Init the 'rows' and 'cols' vars to avoid a compiler error (gcc 4.8.4)
> - Rebase to master
> - Return error value of efi_allocate_pages()
> - Update function comment for write_smbios_table()
> 
> Changes in v2:
> - Rebase to master
> - Update return type of efi_smbios_register() to efi_status_t
> - Update to use mapmem instead of a cast
> - Use return value of efi_install_configuration_table
> 
> Simon Glass (16):
>   efi: Init the 'rows' and 'cols' variables
>   efi: Update some comments related to smbios tables
>   efi: sandbox: Adjust memory usage for sandbox
>   sandbox: smbios: Update to support sandbox
>   sandbox: Add a setjmp() implementation
>   efi: sandbox: Add required linker sections
>   efi: sandbox: Add distroboot support
>   Define board_quiesce_devices() in a shared location
>   Add a comment for board_quiesce_devices()
>   efi: sandbox: Add relocation constants
>   efi: Add a comment about duplicated ELF constants
>   efi: sandbox: Enable EFI loader builder for sandbox
>   efi: Split out test init/uninit into functions
>   efi: sandbox: Add a simple 'bootefi test' command
>   efi: Create a function to set up for running EFI code
>   efi: Rename bootefi_test_finish() to bootefi_run_finish()
> 
>  arch/arm/include/asm/u-boot-arm.h |   1 -
>  arch/sandbox/cpu/cpu.c            |  13 +++
>  arch/sandbox/cpu/os.c             |  23 +++++
>  arch/sandbox/cpu/u-boot.lds       |  29 ++++++
>  arch/sandbox/include/asm/setjmp.h |  30 ++++++
>  arch/sandbox/lib/Makefile         |   2 +-
>  arch/sandbox/lib/sections.c       |  12 +++
>  arch/x86/include/asm/u-boot-x86.h |   1 -
>  arch/x86/lib/bootm.c              |   4 -
>  cmd/bootefi.c                     | 158 +++++++++++++++++++++---------
>  common/bootm.c                    |   4 +
>  include/bootm.h                   |   8 ++
>  include/config_distro_bootcmd.h   |   2 +-
>  include/efi_loader.h              |  10 ++
>  include/os.h                      |  21 ++++
>  include/smbios.h                  |   5 +-
>  lib/efi_loader/Kconfig            |  12 ++-
>  lib/efi_loader/Makefile           |   1 +
>  lib/efi_loader/efi_console.c      |   5 +-
>  lib/efi_loader/efi_memory.c       |  31 +++---
>  lib/efi_loader/efi_runtime.c      |   7 ++
>  lib/efi_loader/efi_smbios.c       |   7 +-
>  lib/efi_loader/efi_test.c         |  16 +++
>  lib/smbios.c                      |  32 ++++--
>  24 files changed, 351 insertions(+), 83 deletions(-)
>  create mode 100644 arch/sandbox/include/asm/setjmp.h
>  create mode 100644 arch/sandbox/lib/sections.c
>  create mode 100644 lib/efi_loader/efi_test.c
>
Heinrich Schuchardt May 17, 2018, 5:31 a.m. UTC | #2
On 05/16/2018 07:13 PM, Heinrich Schuchardt wrote:
> On 05/16/2018 05:42 PM, Simon Glass wrote:
>> A limitation of the EFI loader at present is that it does not build with
>> sandbox. This makes it hard to write tests, since sandbox is used for most
>> testing in U-Boot.
>>
>> This series enables the EFI loader feature. It allows sandbox to build and
>> run a trivial function which calls the EFI API to output a message.
>>
>> This series is at u-boot-dm/efi-working
> 
> I applied you patch series
> 
> make sandbox_defconfig
> CONFIG_CMD_BOOTEFI_SELFTEST=y
> make -j6
> 
> results in:
> 
> ld.bfd: read in flex scanner failed
> scripts/Makefile.lib:407: recipe for target
> 'lib/efi_selftest/efi_selftest_miniapp_exit_efi.so' failed
> make[2]: *** [lib/efi_selftest/efi_selftest_miniapp_exit_efi.so] Error 1
> rm lib/efi_selftest/efi_selftest_miniapp_exit.o
> lib/efi_selftest/efi_selftest_miniapp_return.o
> scripts/Makefile.build:423: recipe for target 'lib/efi_selftest' failed
> make[1]: *** [lib/efi_selftest] Error 2
> make[1]: *** Waiting for unfinished jobs....
> 
> Please, change /lib/efi_selftest/Makefile
> -ifeq ($(CONFIG_X86_64),)
> +ifeq ($(CONFIG_X86_64)$(CONFIG_SANDBOX),)

A better solution would be to define EFI_LDS, EFI_CRT0, and EFI_RELOC in
file arch/sandbox/config.mk in accordance with the host architecture.

Best regards

Heinrich
Alexander Graf May 24, 2018, 12:40 p.m. UTC | #3
On 16.05.18 17:42, Simon Glass wrote:
> A limitation of the EFI loader at present is that it does not build with
> sandbox. This makes it hard to write tests, since sandbox is used for most
> testing in U-Boot.
> 
> This series enables the EFI loader feature. It allows sandbox to build and
> run a trivial function which calls the EFI API to output a message.
> 
> This series is at u-boot-dm/efi-working

I've picked a few patches that were obviously correct and made sense.
Overall, I think we should allow for real UEFI binaries to run in
sandbox and the only way to get there is to have sandboxed U-Boot live
in the same address space as what it thinks it lives in.

For the selftest bits I'd like to see acks from Heinrich, so I didn't
pick those up yet. They seem to make good sense to me though.


Alex
Simon Glass June 12, 2018, 5:27 a.m. UTC | #4
Hi Heinrich,

On 16 May 2018 at 23:31, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> On 05/16/2018 07:13 PM, Heinrich Schuchardt wrote:
>> On 05/16/2018 05:42 PM, Simon Glass wrote:
>>> A limitation of the EFI loader at present is that it does not build with
>>> sandbox. This makes it hard to write tests, since sandbox is used for most
>>> testing in U-Boot.
>>>
>>> This series enables the EFI loader feature. It allows sandbox to build and
>>> run a trivial function which calls the EFI API to output a message.
>>>
>>> This series is at u-boot-dm/efi-working
>>
>> I applied you patch series
>>
>> make sandbox_defconfig
>> CONFIG_CMD_BOOTEFI_SELFTEST=y
>> make -j6
>>
>> results in:
>>
>> ld.bfd: read in flex scanner failed
>> scripts/Makefile.lib:407: recipe for target
>> 'lib/efi_selftest/efi_selftest_miniapp_exit_efi.so' failed
>> make[2]: *** [lib/efi_selftest/efi_selftest_miniapp_exit_efi.so] Error 1
>> rm lib/efi_selftest/efi_selftest_miniapp_exit.o
>> lib/efi_selftest/efi_selftest_miniapp_return.o
>> scripts/Makefile.build:423: recipe for target 'lib/efi_selftest' failed
>> make[1]: *** [lib/efi_selftest] Error 2
>> make[1]: *** Waiting for unfinished jobs....
>>
>> Please, change /lib/efi_selftest/Makefile
>> -ifeq ($(CONFIG_X86_64),)
>> +ifeq ($(CONFIG_X86_64)$(CONFIG_SANDBOX),)
>
> A better solution would be to define EFI_LDS, EFI_CRT0, and EFI_RELOC in
> file arch/sandbox/config.mk in accordance with the host architecture.

I think we should get the patches in so that these tests can run, and
worry about CONFIG_CMD_BOOTEFI_SELFTEST later.

This work has been outstanding for a long time and it has been painful
to rebase on a tree that is changing quite regularly.

After all, the point of this series is to enable running the code from
EFI app directly within sandbox, not to run the .efi app itself.

I suspect you are right that with more work on the linker flags this
can be made to work. But it is not the subject of this series.

For now I'll add a patch to explicitly disable that option for
sandbox, so people know it is not supported.

Regards,
Simon