diff mbox series

[3/7] efi: test: Create a disk image with and EFI app in it

Message ID 20231121113557.800353-4-sjg@chromium.org
State RFC
Delegated to: Tom Rini
Headers show
Series efi: Partial attempt at a test for EFI bootmeth | expand

Commit Message

Simon Glass Nov. 21, 2023, 11:35 a.m. UTC
Create a new disk for use with test, which contains the sandbox
helloworld app. This will be used to test the EFI boot bootmeth.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/py/tests/test_ut.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Heinrich Schuchardt Nov. 21, 2023, 5:32 p.m. UTC | #1
On 11/21/23 12:35, Simon Glass wrote:
> Create a new disk for use with test, which contains the sandbox
> helloworld app. This will be used to test the EFI boot bootmeth.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   test/py/tests/test_ut.py | 32 ++++++++++++++++++++++++++++++++
>   1 file changed, 32 insertions(+)
>
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index 1d9149a3f683..f6220c05238a 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -468,6 +468,37 @@ def test_ut_dm_init(u_boot_console):
>       with open(fn, 'wb') as fh:
>           fh.write(data)
>
> +
> +def setup_efi_image(cons):
> +    """Create a 20MB disk image with an EFI app on it"""
> +    mmc_dev = 7
> +    fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)

If you would set the partition type GUID to ESP, U-Boot would stop to
complain about EFI variable that cannot be persisted.

There is a pending patch that wants to make the failure to persist EFI
variable fatal.

[RESEND,v2] efi_loader: Fix UEFI variable error handling
https://patchwork.ozlabs.org/project/uboot/patch/20231113161031.138304-1-o451686892@gmail.com/

Best regards

Heinrich

> +
> +    loop = None
> +    mounted = False
> +    try:
> +        loop = mount_image(cons, fname, mnt, 'ext4')
> +        mounted = True
> +        efi_dir = os.path.join(mnt, 'efi')
> +        mkdir_cond(efi_dir)
> +        bootdir = os.path.join(efi_dir, 'boot')
> +        mkdir_cond(bootdir)
> +        efi_src = os.path.join(cons.config.build_dir,
> +                               f'lib/efi_loader/helloworld.efi')
> +        efi_dst = os.path.join(bootdir, 'bootsbox.efi')
> +        with open(efi_src, 'rb') as inf:
> +            with open(efi_dst, 'wb') as outf:
> +                outf.write(inf.read())
> +
> +    finally:
> +        if mounted:
> +            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
> +        if loop:
> +            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
> +
> +
> +
> +
>   @pytest.mark.buildconfigspec('cmd_bootflow')
>   def test_ut_dm_init_bootstd(u_boot_console):
>       """Initialise data for bootflow tests"""
> @@ -476,6 +507,7 @@ def test_ut_dm_init_bootstd(u_boot_console):
>       setup_bootmenu_image(u_boot_console)
>       setup_cedit_file(u_boot_console)
>       setup_cros_image(u_boot_console)
> +    setup_efi_image(u_boot_console)
>
>       # Restart so that the new mmc1.img is picked up
>       u_boot_console.restart_uboot()
Simon Glass Nov. 21, 2023, 10:10 p.m. UTC | #2
Hi Heinrich,

On Tue, 21 Nov 2023 at 10:37, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 11/21/23 12:35, Simon Glass wrote:
> > Create a new disk for use with test, which contains the sandbox
> > helloworld app. This will be used to test the EFI boot bootmeth.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >   test/py/tests/test_ut.py | 32 ++++++++++++++++++++++++++++++++
> >   1 file changed, 32 insertions(+)
> >
> > diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> > index 1d9149a3f683..f6220c05238a 100644
> > --- a/test/py/tests/test_ut.py
> > +++ b/test/py/tests/test_ut.py
> > @@ -468,6 +468,37 @@ def test_ut_dm_init(u_boot_console):
> >       with open(fn, 'wb') as fh:
> >           fh.write(data)
> >
> > +
> > +def setup_efi_image(cons):
> > +    """Create a 20MB disk image with an EFI app on it"""
> > +    mmc_dev = 7
> > +    fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)
>
> If you would set the partition type GUID to ESP, U-Boot would stop to
> complain about EFI variable that cannot be persisted.

Doesn't that need a GPT partition type?

We do use that for the ChromeOS bootmeth (in setup_cros_image) so we
could use it here too.

>
> There is a pending patch that wants to make the failure to persist EFI
> variable fatal.
>
> [RESEND,v2] efi_loader: Fix UEFI variable error handling
> https://patchwork.ozlabs.org/project/uboot/patch/20231113161031.138304-1-o451686892@gmail.com/

Regards,
Simon
diff mbox series

Patch

diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
index 1d9149a3f683..f6220c05238a 100644
--- a/test/py/tests/test_ut.py
+++ b/test/py/tests/test_ut.py
@@ -468,6 +468,37 @@  def test_ut_dm_init(u_boot_console):
     with open(fn, 'wb') as fh:
         fh.write(data)
 
+
+def setup_efi_image(cons):
+    """Create a 20MB disk image with an EFI app on it"""
+    mmc_dev = 7
+    fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)
+
+    loop = None
+    mounted = False
+    try:
+        loop = mount_image(cons, fname, mnt, 'ext4')
+        mounted = True
+        efi_dir = os.path.join(mnt, 'efi')
+        mkdir_cond(efi_dir)
+        bootdir = os.path.join(efi_dir, 'boot')
+        mkdir_cond(bootdir)
+        efi_src = os.path.join(cons.config.build_dir,
+                               f'lib/efi_loader/helloworld.efi')
+        efi_dst = os.path.join(bootdir, 'bootsbox.efi')
+        with open(efi_src, 'rb') as inf:
+            with open(efi_dst, 'wb') as outf:
+                outf.write(inf.read())
+
+    finally:
+        if mounted:
+            u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
+        if loop:
+            u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+
+
+
+
 @pytest.mark.buildconfigspec('cmd_bootflow')
 def test_ut_dm_init_bootstd(u_boot_console):
     """Initialise data for bootflow tests"""
@@ -476,6 +507,7 @@  def test_ut_dm_init_bootstd(u_boot_console):
     setup_bootmenu_image(u_boot_console)
     setup_cedit_file(u_boot_console)
     setup_cros_image(u_boot_console)
+    setup_efi_image(u_boot_console)
 
     # Restart so that the new mmc1.img is picked up
     u_boot_console.restart_uboot()