mbox series

[U-Boot,v9,00/18] efi: Enable sandbox support for EFI loader

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

Message

Simon Glass Aug. 8, 2018, 9:54 a.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.

Also included in v8 is support for running the full EFI self tests. These
run OK with some tweaks to a few parts of the code.

With v9, various EFI patches have been applied which change things. This
series includes a partial review of one, which makes 'bootefi test' work.
But there are still problems with 'bootefi selftest':

$ sandbox/u-boot -D -c "bootefi selftest"
...
Executing 'block device'
/home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_block_device.c(385):
TODO: Wrong volume label 'xxa1', expected 'U-BOOT TEST'
map_to_sysmem: Added map from 00007ffd0782d2a0 to 8000000
phys_to_virt: Used map from 8000000 to 00007ffd0782d2a0
writing /u-boot.txt
find_tag: Used map from 00007ffd0782d2a0 to 8000000
phys_to_virt: Used map from 8000000 to 00007ffd0782d2a0
/home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_block_device.c(458):
ERROR: Unexpected file content
/home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest.c(109):
ERROR: Executing 'block device' failed

...

Executing 'simple network protocol'
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
DHCP Discover
/home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_snp.c(311):
ERROR: Timeout occurred
/home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest.c(109):
ERROR: Executing 'simple network protocol' failed

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

Changes in v9:
- Add comments to bootefi_test_prepare() about the memset()s
- Add revert for "efi_loader: Rename sections to allow for implicit data"
- Drop fdt_end variable in efi_install_fdt()
- Fix 'thi' typo

Changes in v8:
- Drop 'efi: Adjust memory handling to support sandbox'
- Drop 'efi: sandbox: Add relocation constants'
- Drop 'sandbox: smbios: Update to support sandbox'
- Expand series substantially to support bootefi selftest
- Rebase to master
- Rebase to master, bringing in all EFI changes

Changes in v7:
- Drop an unnecessary comment
- Drop patch "efi: Init the 'rows' and 'cols' variables"
- Drop patches previous applied
- Update patch subject s/builder/build/

Changes in v6:
- Warn about building sandbox EFI support on something other than __x86_64__

Changes in v5:
- Add new patch to disallow CMD_BOOTEFI_SELFTEST on sandbox
- Drop call to efi_init_obj_list() which is now done in do_bootefi()
- Introduce load_options_path to specifyc U-Boot env var for load_options_path
- Rebase to master

Changes in v4:
- Rebase to master
- Update SPDX tags

Changes in v3:
- 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
- Init the 'rows' and 'cols' vars to avoid a compiler error (gcc 4.8.4)
- Rebase to master

Changes in v2:
- Rebase to master

Alexander Graf (1):
  efi_loader: Pass address to fs_read()

Simon Glass (17):
  Revert "efi_loader: Rename sections to allow for implicit data"
  efi: Don't allow CMD_BOOTEFI_SELFTEST on sandbox
  efi: sandbox: Add distroboot support
  efi: sandbox: Enable EFI loader build 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()
  sandbox: Align RAM buffer to the machine page size
  sandbox: Try to start the RAM buffer at a particular address
  sandbox: Add support for calling abort()
  sandbox: Enhance map_to_sysmem() to handle foreign pointers
  efi: Add a call to exit() along with why we can't use it
  efi: Relocate FDT to 127MB instead of 128MB
  efi: sandbox: Tidy up copy_fdt() to work with sandbox
  efi: Add more debugging for memory allocations
  efi: sandbox: Enable selftest command

 arch/sandbox/config.mk           |   3 -
 arch/sandbox/cpu/cpu.c           | 141 ++++++++++++++++--
 arch/sandbox/cpu/os.c            |  17 ++-
 arch/sandbox/cpu/state.c         |   8 +
 arch/sandbox/cpu/u-boot.lds      |   9 +-
 arch/sandbox/include/asm/state.h |  21 +++
 cmd/bootefi.c                    | 242 +++++++++++++++++++++----------
 configs/sandbox_defconfig        |   1 +
 include/config_distro_bootcmd.h  |  11 ++
 include/efi_loader.h             |   3 +
 include/os.h                     |   4 +
 lib/efi_loader/Kconfig           |  12 +-
 lib/efi_loader/Makefile          |   1 +
 lib/efi_loader/efi_boottime.c    |  15 ++
 lib/efi_loader/efi_file.c        |   5 +-
 lib/efi_loader/efi_memory.c      |  22 ++-
 lib/efi_loader/efi_test.c        |  26 ++++
 17 files changed, 439 insertions(+), 102 deletions(-)
 create mode 100644 lib/efi_loader/efi_test.c

Comments

Alexander Graf Aug. 26, 2018, 5:28 p.m. UTC | #1
On 08.08.18 11:54, 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.
> 
> Also included in v8 is support for running the full EFI self tests. These
> run OK with some tweaks to a few parts of the code.
> 
> With v9, various EFI patches have been applied which change things. This
> series includes a partial review of one, which makes 'bootefi test' work.
> But there are still problems with 'bootefi selftest':
> 
> $ sandbox/u-boot -D -c "bootefi selftest"
> ...
> Executing 'block device'
> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_block_device.c(385):
> TODO: Wrong volume label 'xxa1', expected 'U-BOOT TEST'
> map_to_sysmem: Added map from 00007ffd0782d2a0 to 8000000
> phys_to_virt: Used map from 8000000 to 00007ffd0782d2a0
> writing /u-boot.txt
> find_tag: Used map from 00007ffd0782d2a0 to 8000000
> phys_to_virt: Used map from 8000000 to 00007ffd0782d2a0
> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_block_device.c(458):
> ERROR: Unexpected file content
> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest.c(109):
> ERROR: Executing 'block device' failed
> 
> ...
> 
> Executing 'simple network protocol'
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> DHCP Discover
> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_snp.c(311):
> ERROR: Timeout occurred
> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest.c(109):
> ERROR: Executing 'simple network protocol' failed
> 
> This series is at u-boot-dm/efi-working

Thanks a lot again for pushing this forward.

My ultimate goal is that sandbox is not a special case, but just "yet
another" target we support.

That means things like a special "bootefi test" command really don't
make any sense and should just go.

The other thing we need to make sure is that every divergence we find
between sandbox and non-sandbox behavior potentially hints at a real
problem:

  - If exit doesn't work, don't just disable it, instead please debug
why and resolve it for real.

  - If tests are failing that really shouldn't fail, please figure out
why. Maybe they used the stack in some cases which breaks your mapping
logic?

At the end of the day, I want to have as little divergence between the
sandbox target and a real x86_64 QEMU target for example. As long as we
don't exit boot services, both should really behave the same.


Alex
Simon Glass Sept. 14, 2018, 3:46 p.m. UTC | #2
Hi Alex,

On 26 August 2018 at 19:28, Alexander Graf <agraf@suse.de> wrote:
>
>
> On 08.08.18 11:54, 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.
>>
>> Also included in v8 is support for running the full EFI self tests. These
>> run OK with some tweaks to a few parts of the code.
>>
>> With v9, various EFI patches have been applied which change things. This
>> series includes a partial review of one, which makes 'bootefi test' work.
>> But there are still problems with 'bootefi selftest':
>>
>> $ sandbox/u-boot -D -c "bootefi selftest"
>> ...
>> Executing 'block device'
>> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_block_device.c(385):
>> TODO: Wrong volume label 'xxa1', expected 'U-BOOT TEST'
>> map_to_sysmem: Added map from 00007ffd0782d2a0 to 8000000
>> phys_to_virt: Used map from 8000000 to 00007ffd0782d2a0
>> writing /u-boot.txt
>> find_tag: Used map from 00007ffd0782d2a0 to 8000000
>> phys_to_virt: Used map from 8000000 to 00007ffd0782d2a0
>> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_block_device.c(458):
>> ERROR: Unexpected file content
>> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest.c(109):
>> ERROR: Executing 'block device' failed

I was able to fix this one.

>>
>> ...
>>
>> Executing 'simple network protocol'
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> DHCP Discover
>> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest_snp.c(311):
>> ERROR: Timeout occurred
>> /home/sjg/c/src/third_party/u-boot/files/lib/efi_selftest/efi_selftest.c(109):
>> ERROR: Executing 'simple network protocol' failed

I am not sure what is going on here. I think it is best that Heinrich
takes a look once this stuff lands and before we enable the tests on
travis-ci.

>>
>> This series is at u-boot-dm/efi-working
>
> Thanks a lot again for pushing this forward.
>
> My ultimate goal is that sandbox is not a special case, but just "yet
> another" target we support.
>
> That means things like a special "bootefi test" command really don't
> make any sense and should just go.

I've renamed this to 'bootefi ping'. While I understand your POV, I
feel that a simple sanity check is useful. At present 'bootefi
selftest' quits sandbox when it finishes, so itis not really working
the way it should anyway.

>
> The other thing we need to make sure is that every divergence we find
> between sandbox and non-sandbox behavior potentially hints at a real
> problem:
>
>   - If exit doesn't work, don't just disable it, instead please debug
> why and resolve it for real.
>
>   - If tests are failing that really shouldn't fail, please figure out
> why. Maybe they used the stack in some cases which breaks your mapping
> logic?

Please see above. The tests all used to pass 6 months ago when I
revised this work. I think we should get something in and then do some
more work.

>
> At the end of the day, I want to have as little divergence between the
> sandbox target and a real x86_64 QEMU target for example. As long as we
> don't exit boot services, both should really behave the same.

Fair enough, but Rome wasn't built in a day. I think that's my main
problem with this painful year-long process, that you want everything
to be done in one series, instead of collaboratively moving towards
the ultimate end goal. We would have had this running a long time ago
if we have just taken an incremental approach.

Regards,
Simon