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 |
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()
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 --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()
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(+)