diff mbox

[U-Boot,RFC] efi_loader: Add test to boot OpenBSD's efi bootloader

Message ID 20170806161033.21144-1-robdclark@gmail.com
State Deferred
Delegated to: Alexander Graf
Headers show

Commit Message

Rob Clark Aug. 6, 2017, 4:10 p.m. UTC
Signed-off-by: Rob Clark <robdclark@gmail.com>
---
Kinda works, but since we don't have an 'exit' command like grub, we
have to reboot, which leaves the "board" in a bad state (I guess,
since the next test fails).  I haven't tackled the travis bits to get
travis to download OpenBSD's bootloader, or other little details like
that.

So suggestions welcome ;-)

 test/py/tests/test_efi_loader.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Mark Kettenis Aug. 6, 2017, 6:54 p.m. UTC | #1
> From: Rob Clark <robdclark@gmail.com>
> Date: Sun,  6 Aug 2017 12:10:28 -0400
> 
> Signed-off-by: Rob Clark <robdclark@gmail.com>
> ---
> Kinda works, but since we don't have an 'exit' command like grub, we
> have to reboot, which leaves the "board" in a bad state (I guess,
> since the next test fails).  I haven't tackled the travis bits to get
> travis to download OpenBSD's bootloader, or other little details like
> that.

What does the grub "exit" command do?  Simply call EFI_BOOT_SERVICE.Exit()?
Wouldn't be too difficult for me to add a command that does this.

The OpenBSD bootloader currently just executes an illegal instruction
as EFI_RUNTIME_SERVICES.ResetSystem() didn't work at the time I wrote
the code.  Perhaps I should revisit that issue now.

>  test/py/tests/test_efi_loader.py | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
> index 5d7f5dbfb2..376f6442a3 100644
> --- a/test/py/tests/test_efi_loader.py
> +++ b/test/py/tests/test_efi_loader.py
> @@ -193,3 +193,22 @@ def test_efi_grub_net(u_boot_console):
>  
>      # And give us our U-Boot prompt back
>      u_boot_console.run_command('')
> +
> +@pytest.mark.buildconfigspec('cmd_bootefi')
> +def test_efi_openbsd_net(u_boot_console):
> +    """Run OpenBSD's bootloader via TFTP.
> +
> +    The bootaa64.efi file is downloaded from the TFTP server and
> +    gets executed.
> +    """
> +
> +    addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_openbsd_file')
> +
> +    u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
> +
> +    # Check that bootloader loads properly:
> +    u_boot_console.wait_for('boot>')
> +
> +    # There is no exit, but there is a reboot cmd.. maybe we need to do
> +    # more than this to get u-boot running again??
> +    u_boot_console.run_command('reboot', wait_for_prompt=False, wait_for_echo=False)
> -- 
> 2.13.0
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
> 
>
Rob Clark Aug. 6, 2017, 7:06 p.m. UTC | #2
On Sun, Aug 6, 2017 at 2:54 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> From: Rob Clark <robdclark@gmail.com>
>> Date: Sun,  6 Aug 2017 12:10:28 -0400
>>
>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>> ---
>> Kinda works, but since we don't have an 'exit' command like grub, we
>> have to reboot, which leaves the "board" in a bad state (I guess,
>> since the next test fails).  I haven't tackled the travis bits to get
>> travis to download OpenBSD's bootloader, or other little details like
>> that.
>
> What does the grub "exit" command do?  Simply call EFI_BOOT_SERVICE.Exit()?
> Wouldn't be too difficult for me to add a command that does this.

Yeah, I think just calls BS->Exit().. that would be quite useful.

BR,
-R

> The OpenBSD bootloader currently just executes an illegal instruction
> as EFI_RUNTIME_SERVICES.ResetSystem() didn't work at the time I wrote
> the code.  Perhaps I should revisit that issue now.
>
>>  test/py/tests/test_efi_loader.py | 19 +++++++++++++++++++
>>  1 file changed, 19 insertions(+)
>>
>> diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
>> index 5d7f5dbfb2..376f6442a3 100644
>> --- a/test/py/tests/test_efi_loader.py
>> +++ b/test/py/tests/test_efi_loader.py
>> @@ -193,3 +193,22 @@ def test_efi_grub_net(u_boot_console):
>>
>>      # And give us our U-Boot prompt back
>>      u_boot_console.run_command('')
>> +
>> +@pytest.mark.buildconfigspec('cmd_bootefi')
>> +def test_efi_openbsd_net(u_boot_console):
>> +    """Run OpenBSD's bootloader via TFTP.
>> +
>> +    The bootaa64.efi file is downloaded from the TFTP server and
>> +    gets executed.
>> +    """
>> +
>> +    addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_openbsd_file')
>> +
>> +    u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
>> +
>> +    # Check that bootloader loads properly:
>> +    u_boot_console.wait_for('boot>')
>> +
>> +    # There is no exit, but there is a reboot cmd.. maybe we need to do
>> +    # more than this to get u-boot running again??
>> +    u_boot_console.run_command('reboot', wait_for_prompt=False, wait_for_echo=False)
>> --
>> 2.13.0
>>
>> _______________________________________________
>> U-Boot mailing list
>> U-Boot@lists.denx.de
>> https://lists.denx.de/listinfo/u-boot
>>
>>
Stephen Warren Aug. 7, 2017, 4:25 p.m. UTC | #3
On 08/06/2017 10:10 AM, Rob Clark wrote:
> Signed-off-by: Rob Clark <robdclark@gmail.com>
> ---
> Kinda works, but since we don't have an 'exit' command like grub, we
> have to reboot, which leaves the "board" in a bad state (I guess,
> since the next test fails).  I haven't tackled the travis bits to get
> travis to download OpenBSD's bootloader, or other little details like
> that.

> +    # There is no exit, but there is a reboot cmd.. maybe we need to do
> +    # more than this to get u-boot running again??
> +    u_boot_console.run_command('reboot', wait_for_prompt=False, wait_for_echo=False)

Assuming that 'reboot' works here, and actually resets the system, it'll 
probably end up booting whatever code is in flash/storage, which isn't 
necessarily the version of U-Boot that's being tested; the version under 
test may not be in flash, but might be downloaded at boot time e.g. over 
serial/USB to avoid flash wear. So yes, this test certainly needs to do 
something different to restart U-Boot if the test can't simply exit back 
to the previous running instance.

There's a core test/py function cons.restart_uboot() that should do 
everything required to restart the target system. test/test_vboot.py 
already uses it, in particular at the tail end of test_with_algo() in 
order to return the target back to the expected state that the next test 
expects.

I also recall writing down some ideas about how to add Linux-booting 
testing into U-Boot, along with actually running some tests in Linux 
mode to validate the boot without having to manually code up all the 
command-line request/response logic. That was in an email to the U-Boot 
list, perhaps during a conversation with Heiko. However, Google can't 
find it right now:-( Still, I don't think it would improve things for 
the test you're proposing right now since it's so simple, and it was 
mostly just thinking about how to do it rather than actual code anyway.
Jonathan Gray Aug. 10, 2017, 3:43 a.m. UTC | #4
On Sun, Aug 06, 2017 at 03:06:17PM -0400, Rob Clark wrote:
> On Sun, Aug 6, 2017 at 2:54 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
> >> From: Rob Clark <robdclark@gmail.com>
> >> Date: Sun,  6 Aug 2017 12:10:28 -0400
> >>
> >> Signed-off-by: Rob Clark <robdclark@gmail.com>
> >> ---
> >> Kinda works, but since we don't have an 'exit' command like grub, we
> >> have to reboot, which leaves the "board" in a bad state (I guess,
> >> since the next test fails).  I haven't tackled the travis bits to get
> >> travis to download OpenBSD's bootloader, or other little details like
> >> that.
> >
> > What does the grub "exit" command do?  Simply call EFI_BOOT_SERVICE.Exit()?
> > Wouldn't be too difficult for me to add a command that does this.
> 
> Yeah, I think just calls BS->Exit().. that would be quite useful.

Mark committed the change for this and snapshots now have "machine exit"
and "machine poweroff".

https://ftp.openbsd.org/pub/OpenBSD/snapshots/armv7/BOOTARM.EFI
https://ftp.openbsd.org/pub/OpenBSD/snapshots/arm64/BOOTAA64.EFI
Rob Clark Aug. 10, 2017, 10:41 a.m. UTC | #5
On Wed, Aug 9, 2017 at 11:43 PM, Jonathan Gray <jsg@jsg.id.au> wrote:
> On Sun, Aug 06, 2017 at 03:06:17PM -0400, Rob Clark wrote:
>> On Sun, Aug 6, 2017 at 2:54 PM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
>> >> From: Rob Clark <robdclark@gmail.com>
>> >> Date: Sun,  6 Aug 2017 12:10:28 -0400
>> >>
>> >> Signed-off-by: Rob Clark <robdclark@gmail.com>
>> >> ---
>> >> Kinda works, but since we don't have an 'exit' command like grub, we
>> >> have to reboot, which leaves the "board" in a bad state (I guess,
>> >> since the next test fails).  I haven't tackled the travis bits to get
>> >> travis to download OpenBSD's bootloader, or other little details like
>> >> that.
>> >
>> > What does the grub "exit" command do?  Simply call EFI_BOOT_SERVICE.Exit()?
>> > Wouldn't be too difficult for me to add a command that does this.
>>
>> Yeah, I think just calls BS->Exit().. that would be quite useful.
>
> Mark committed the change for this and snapshots now have "machine exit"
> and "machine poweroff".
>
> https://ftp.openbsd.org/pub/OpenBSD/snapshots/armv7/BOOTARM.EFI
> https://ftp.openbsd.org/pub/OpenBSD/snapshots/arm64/BOOTAA64.EFI

Excellent.. I'll update my patch and give this a spin today.

BR,
-R
Alexander Graf Aug. 11, 2017, 9:46 a.m. UTC | #6
On 06.08.17 17:10, Rob Clark wrote:
> Signed-off-by: Rob Clark <robdclark@gmail.com>
> ---
> Kinda works, but since we don't have an 'exit' command like grub, we
> have to reboot, which leaves the "board" in a bad state (I guess,
> since the next test fails).  I haven't tackled the travis bits to get
> travis to download OpenBSD's bootloader, or other little details like
> that.

I think it's a very good addition to the tests - we should definitely 
try and test the OpenBSD bootloader as well.

Adding the travis bits to download it should be a matter of wget'ing it 
into the right directory.

As for the reboot - I think you only have to get yourself back to a boot 
prompt and check for that. That's basically what ensure_spawned() does too.


Alex

> 
> So suggestions welcome ;-)
> 
>   test/py/tests/test_efi_loader.py | 19 +++++++++++++++++++
>   1 file changed, 19 insertions(+)
> 
> diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
> index 5d7f5dbfb2..376f6442a3 100644
> --- a/test/py/tests/test_efi_loader.py
> +++ b/test/py/tests/test_efi_loader.py
> @@ -193,3 +193,22 @@ def test_efi_grub_net(u_boot_console):
>   
>       # And give us our U-Boot prompt back
>       u_boot_console.run_command('')
> +
> +@pytest.mark.buildconfigspec('cmd_bootefi')
> +def test_efi_openbsd_net(u_boot_console):
> +    """Run OpenBSD's bootloader via TFTP.
> +
> +    The bootaa64.efi file is downloaded from the TFTP server and
> +    gets executed.
> +    """
> +
> +    addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_openbsd_file')
> +
> +    u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
> +
> +    # Check that bootloader loads properly:
> +    u_boot_console.wait_for('boot>')
> +
> +    # There is no exit, but there is a reboot cmd.. maybe we need to do
> +    # more than this to get u-boot running again??
> +    u_boot_console.run_command('reboot', wait_for_prompt=False, wait_for_echo=False)
>
diff mbox

Patch

diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
index 5d7f5dbfb2..376f6442a3 100644
--- a/test/py/tests/test_efi_loader.py
+++ b/test/py/tests/test_efi_loader.py
@@ -193,3 +193,22 @@  def test_efi_grub_net(u_boot_console):
 
     # And give us our U-Boot prompt back
     u_boot_console.run_command('')
+
+@pytest.mark.buildconfigspec('cmd_bootefi')
+def test_efi_openbsd_net(u_boot_console):
+    """Run OpenBSD's bootloader via TFTP.
+
+    The bootaa64.efi file is downloaded from the TFTP server and
+    gets executed.
+    """
+
+    addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_openbsd_file')
+
+    u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
+
+    # Check that bootloader loads properly:
+    u_boot_console.wait_for('boot>')
+
+    # There is no exit, but there is a reboot cmd.. maybe we need to do
+    # more than this to get u-boot running again??
+    u_boot_console.run_command('reboot', wait_for_prompt=False, wait_for_echo=False)