All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wic: add UEFI kernel as UEFI stub
@ 2020-01-04 20:07 Maxim Uvarov
  2020-01-05 14:52 ` Richard Purdie
  2020-01-13 13:56 ` Paul Barker
  0 siblings, 2 replies; 6+ messages in thread
From: Maxim Uvarov @ 2020-01-04 20:07 UTC (permalink / raw)
  To: openembedded-core

Linux kernel can be compiled as UEFI stub and loaded directly
with UEFI firmware without grub or other UEFI shell.

Tested with wic file:
bootloader  --ptable gpt --timeout=0  --append="rootwait"
part /boot --source bootimg-efi --sourceparams="loader=kernel" \
 --ondisk sda  --fstype=vfat --label bootfs \
  --active --align 1024 --use-uuid
part / --source rootfs --fstype=ext4 --label rootfs \
  --align 1024 --exclude-path boot/ --use-label
The same wic file for armv7, armv8 and x86_64.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 scripts/lib/wic/plugins/source/bootimg-efi.py | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py b/scripts/lib/wic/plugins/source/bootimg-efi.py
index 2cfdc10ecd..a39d852f6a 100644
--- a/scripts/lib/wic/plugins/source/bootimg-efi.py
+++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
@@ -13,6 +13,7 @@
 import logging
 import os
 import shutil
+import re
 
 from wic import WicError
 from wic.engine import get_custom_config
@@ -204,6 +205,8 @@ class BootimgEFIPlugin(SourcePlugin):
                 cls.do_configure_grubefi(hdddir, creator, cr_workdir, source_params)
             elif source_params['loader'] == 'systemd-boot':
                 cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params)
+            elif source_params['loader'] == 'kernel':
+                return
             else:
                 raise WicError("unrecognized bootimg-efi loader: %s" % source_params['loader'])
         except KeyError:
@@ -243,6 +246,7 @@ class BootimgEFIPlugin(SourcePlugin):
             if source_params['loader'] == 'grub-efi':
                 shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
                                 "%s/grub.cfg" % cr_workdir)
+
                 for mod in [x for x in os.listdir(kernel_dir) if x.startswith("grub-efi-")]:
                     cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[9:])
                     exec_cmd(cp_cmd, True)
@@ -252,6 +256,29 @@ class BootimgEFIPlugin(SourcePlugin):
                 for mod in [x for x in os.listdir(kernel_dir) if x.startswith("systemd-")]:
                     cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[8:])
                     exec_cmd(cp_cmd, True)
+            elif source_params['loader'] == 'kernel':
+                kernel = get_bitbake_var("KERNEL_IMAGETYPE")
+                if not kernel:
+                    raise WicError("Empty KERNEL_IMAGETYPE %s\n" % target)
+                target = get_bitbake_var("TARGET_SYS")
+                if not target:
+                    raise WicError("Unknown arch (TARGET_SYS) %s\n" % target)
+
+                if re.match("x86_64", target):
+                    kernel_efi_image = "bootx64.efi"
+                elif re.match('i.86', target):
+                    kernel_efi_image = "bootia32.efi"
+                elif re.match('aarch64', target):
+                    kernel_efi_image = "bootaa64.efi"
+                elif re.match('arm', target):
+                    kernel_efi_image = "bootarm.efi"
+                else:
+                    raise WicError("kernel efi is incompatible with target %s" % target)
+
+                for mod in [x for x in os.listdir(kernel_dir) if x.startswith(kernel)]:
+                    cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, kernel_efi_image)
+                    WicError("cp_cmd = %s" % cp_cmd);
+                    exec_cmd(cp_cmd, True)
             else:
                 raise WicError("unrecognized bootimg-efi loader: %s" %
                                source_params['loader'])
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] wic: add UEFI kernel as UEFI stub
  2020-01-04 20:07 [PATCH] wic: add UEFI kernel as UEFI stub Maxim Uvarov
@ 2020-01-05 14:52 ` Richard Purdie
  2020-01-09 11:47   ` Maxim Uvarov
  2020-01-13 13:56 ` Paul Barker
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Purdie @ 2020-01-05 14:52 UTC (permalink / raw)
  To: Maxim Uvarov, openembedded-core

On Sat, 2020-01-04 at 23:07 +0300, Maxim Uvarov wrote:
> Linux kernel can be compiled as UEFI stub and loaded directly
> with UEFI firmware without grub or other UEFI shell.
> 
> Tested with wic file:
> bootloader  --ptable gpt --timeout=0  --append="rootwait"
> part /boot --source bootimg-efi --sourceparams="loader=kernel" \
>  --ondisk sda  --fstype=vfat --label bootfs \
>   --active --align 1024 --use-uuid
> part / --source rootfs --fstype=ext4 --label rootfs \
>   --align 1024 --exclude-path boot/ --use-label
> The same wic file for armv7, armv8 and x86_64.
> 
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  scripts/lib/wic/plugins/source/bootimg-efi.py | 27
> +++++++++++++++++++
>  1 file changed, 27 insertions(+)

wic has fairly complete tests, do we need to add a test for the new
functionality?

("oe-selftest -r wic")

Cheers,

Richard



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] wic: add UEFI kernel as UEFI stub
  2020-01-05 14:52 ` Richard Purdie
@ 2020-01-09 11:47   ` Maxim Uvarov
  2020-01-13 13:14     ` Maxim Uvarov
  0 siblings, 1 reply; 6+ messages in thread
From: Maxim Uvarov @ 2020-01-09 11:47 UTC (permalink / raw)
  To: Richard Purdie; +Cc: openembedded-core

On Sun, 5 Jan 2020 at 17:52, Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> On Sat, 2020-01-04 at 23:07 +0300, Maxim Uvarov wrote:
> > Linux kernel can be compiled as UEFI stub and loaded directly
> > with UEFI firmware without grub or other UEFI shell.
> >
> > Tested with wic file:
> > bootloader  --ptable gpt --timeout=0  --append="rootwait"
> > part /boot --source bootimg-efi --sourceparams="loader=kernel" \
> >  --ondisk sda  --fstype=vfat --label bootfs \
> >   --active --align 1024 --use-uuid
> > part / --source rootfs --fstype=ext4 --label rootfs \
> >   --align 1024 --exclude-path boot/ --use-label
> > The same wic file for armv7, armv8 and x86_64.
> >
> > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> > ---
> >  scripts/lib/wic/plugins/source/bootimg-efi.py | 27
> > +++++++++++++++++++
> >  1 file changed, 27 insertions(+)
>
> wic has fairly complete tests, do we need to add a test for the new
> functionality?
>
> ("oe-selftest -r wic")
>
> Cheers,
>
> Richard
>
I'm currently looking to zeus branch and it looks like test uses this file:
openembedded-core/meta-selftest/./recipes-test/images/wic-image-minimal.wks

I think it will be good to add test for --source bootimg-efi
--sourceparams="loader=kernel".
Do you want to change wic-image-minimal.wks? Or just put this file to
openembedded-core/meta-selftest/wic/
directory and somehow it will be tested?

Maxim.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] wic: add UEFI kernel as UEFI stub
  2020-01-09 11:47   ` Maxim Uvarov
@ 2020-01-13 13:14     ` Maxim Uvarov
  0 siblings, 0 replies; 6+ messages in thread
From: Maxim Uvarov @ 2020-01-13 13:14 UTC (permalink / raw)
  To: Richard Purdie; +Cc: openembedded-core

Can this patch be applied without embedded test?

On Thu, 9 Jan 2020 at 14:47, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>
> On Sun, 5 Jan 2020 at 17:52, Richard Purdie
> <richard.purdie@linuxfoundation.org> wrote:
> >
> > On Sat, 2020-01-04 at 23:07 +0300, Maxim Uvarov wrote:
> > > Linux kernel can be compiled as UEFI stub and loaded directly
> > > with UEFI firmware without grub or other UEFI shell.
> > >
> > > Tested with wic file:
> > > bootloader  --ptable gpt --timeout=0  --append="rootwait"
> > > part /boot --source bootimg-efi --sourceparams="loader=kernel" \
> > >  --ondisk sda  --fstype=vfat --label bootfs \
> > >   --active --align 1024 --use-uuid
> > > part / --source rootfs --fstype=ext4 --label rootfs \
> > >   --align 1024 --exclude-path boot/ --use-label
> > > The same wic file for armv7, armv8 and x86_64.
> > >
> > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> > > ---
> > >  scripts/lib/wic/plugins/source/bootimg-efi.py | 27
> > > +++++++++++++++++++
> > >  1 file changed, 27 insertions(+)
> >
> > wic has fairly complete tests, do we need to add a test for the new
> > functionality?
> >
> > ("oe-selftest -r wic")
> >
> > Cheers,
> >
> > Richard
> >
> I'm currently looking to zeus branch and it looks like test uses this file:
> openembedded-core/meta-selftest/./recipes-test/images/wic-image-minimal.wks
>
> I think it will be good to add test for --source bootimg-efi
> --sourceparams="loader=kernel".
> Do you want to change wic-image-minimal.wks? Or just put this file to
> openembedded-core/meta-selftest/wic/
> directory and somehow it will be tested?
>
> Maxim.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] wic: add UEFI kernel as UEFI stub
  2020-01-04 20:07 [PATCH] wic: add UEFI kernel as UEFI stub Maxim Uvarov
  2020-01-05 14:52 ` Richard Purdie
@ 2020-01-13 13:56 ` Paul Barker
  2020-01-13 15:23   ` Maxim Uvarov
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Barker @ 2020-01-13 13:56 UTC (permalink / raw)
  To: Maxim Uvarov, OE Core

On Sat, 4 Jan 2020, at 20:07, Maxim Uvarov wrote:
> Linux kernel can be compiled as UEFI stub and loaded directly
> with UEFI firmware without grub or other UEFI shell.
> 
> Tested with wic file:
> bootloader  --ptable gpt --timeout=0  --append="rootwait"
> part /boot --source bootimg-efi --sourceparams="loader=kernel" \
>  --ondisk sda  --fstype=vfat --label bootfs \
>   --active --align 1024 --use-uuid
> part / --source rootfs --fstype=ext4 --label rootfs \
>   --align 1024 --exclude-path boot/ --use-label
> The same wic file for armv7, armv8 and x86_64.
> 
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  scripts/lib/wic/plugins/source/bootimg-efi.py | 27 +++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py 
> b/scripts/lib/wic/plugins/source/bootimg-efi.py
> index 2cfdc10ecd..a39d852f6a 100644
> --- a/scripts/lib/wic/plugins/source/bootimg-efi.py
> +++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
> @@ -13,6 +13,7 @@
>  import logging
>  import os
>  import shutil
> +import re
>  
>  from wic import WicError
>  from wic.engine import get_custom_config
> @@ -204,6 +205,8 @@ class BootimgEFIPlugin(SourcePlugin):
>                  cls.do_configure_grubefi(hdddir, creator, cr_workdir, 
> source_params)
>              elif source_params['loader'] == 'systemd-boot':
>                  cls.do_configure_systemdboot(hdddir, creator, 
> cr_workdir, source_params)
> +            elif source_params['loader'] == 'kernel':
> +                return
>              else:
>                  raise WicError("unrecognized bootimg-efi loader: %s" % 
> source_params['loader'])
>          except KeyError:
> @@ -243,6 +246,7 @@ class BootimgEFIPlugin(SourcePlugin):
>              if source_params['loader'] == 'grub-efi':
>                  shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % 
> cr_workdir,
>                                  "%s/grub.cfg" % cr_workdir)
> +
>                  for mod in [x for x in os.listdir(kernel_dir) if 
> x.startswith("grub-efi-")]:
>                      cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, 
> mod, hdddir, mod[9:])
>                      exec_cmd(cp_cmd, True)
> @@ -252,6 +256,29 @@ class BootimgEFIPlugin(SourcePlugin):
>                  for mod in [x for x in os.listdir(kernel_dir) if 
> x.startswith("systemd-")]:
>                      cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, 
> mod, hdddir, mod[8:])
>                      exec_cmd(cp_cmd, True)
> +            elif source_params['loader'] == 'kernel':

How about "uefi-stub" instead of just "kernel" here so it's more explicit?

> +                kernel = get_bitbake_var("KERNEL_IMAGETYPE")
> +                if not kernel:
> +                    raise WicError("Empty KERNEL_IMAGETYPE %s\n" % 
> target)
> +                target = get_bitbake_var("TARGET_SYS")
> +                if not target:
> +                    raise WicError("Unknown arch (TARGET_SYS) %s\n" % 
> target)
> +
> +                if re.match("x86_64", target):
> +                    kernel_efi_image = "bootx64.efi"
> +                elif re.match('i.86', target):
> +                    kernel_efi_image = "bootia32.efi"
> +                elif re.match('aarch64', target):
> +                    kernel_efi_image = "bootaa64.efi"
> +                elif re.match('arm', target):
> +                    kernel_efi_image = "bootarm.efi"
> +                else:
> +                    raise WicError("kernel efi is incompatible with 
> target %s" % target)

Perhaps call this "UEFI stub kernel" instead of just "kernel efi" to make things clearer.

> +
> +                for mod in [x for x in os.listdir(kernel_dir) if 
> x.startswith(kernel)]:
> +                    cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, 
> mod, hdddir, kernel_efi_image)
> +                    WicError("cp_cmd = %s" % cp_cmd);

What's this WicError created here for?

> +                    exec_cmd(cp_cmd, True)

Wouldn't this result in the destination file being overwritten each time through this loop? I guess you're just copying from the grub-efi implementation above though.

>              else:
>                  raise WicError("unrecognized bootimg-efi loader: %s" %
>                                 source_params['loader'])
> -- 
> 2.17.1

-- 
Paul Barker


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] wic: add UEFI kernel as UEFI stub
  2020-01-13 13:56 ` Paul Barker
@ 2020-01-13 15:23   ` Maxim Uvarov
  0 siblings, 0 replies; 6+ messages in thread
From: Maxim Uvarov @ 2020-01-13 15:23 UTC (permalink / raw)
  To: Paul Barker; +Cc: OE Core

On Mon, 13 Jan 2020 at 16:57, Paul Barker <paul@betafive.co.uk> wrote:
>
> On Sat, 4 Jan 2020, at 20:07, Maxim Uvarov wrote:
> > Linux kernel can be compiled as UEFI stub and loaded directly
> > with UEFI firmware without grub or other UEFI shell.
> >
> > Tested with wic file:
> > bootloader  --ptable gpt --timeout=0  --append="rootwait"
> > part /boot --source bootimg-efi --sourceparams="loader=kernel" \
> >  --ondisk sda  --fstype=vfat --label bootfs \
> >   --active --align 1024 --use-uuid
> > part / --source rootfs --fstype=ext4 --label rootfs \
> >   --align 1024 --exclude-path boot/ --use-label
> > The same wic file for armv7, armv8 and x86_64.
> >
> > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> > ---
> >  scripts/lib/wic/plugins/source/bootimg-efi.py | 27 +++++++++++++++++++
> >  1 file changed, 27 insertions(+)
> >
> > diff --git a/scripts/lib/wic/plugins/source/bootimg-efi.py
> > b/scripts/lib/wic/plugins/source/bootimg-efi.py
> > index 2cfdc10ecd..a39d852f6a 100644
> > --- a/scripts/lib/wic/plugins/source/bootimg-efi.py
> > +++ b/scripts/lib/wic/plugins/source/bootimg-efi.py
> > @@ -13,6 +13,7 @@
> >  import logging
> >  import os
> >  import shutil
> > +import re
> >
> >  from wic import WicError
> >  from wic.engine import get_custom_config
> > @@ -204,6 +205,8 @@ class BootimgEFIPlugin(SourcePlugin):
> >                  cls.do_configure_grubefi(hdddir, creator, cr_workdir,
> > source_params)
> >              elif source_params['loader'] == 'systemd-boot':
> >                  cls.do_configure_systemdboot(hdddir, creator,
> > cr_workdir, source_params)
> > +            elif source_params['loader'] == 'kernel':
> > +                return
> >              else:
> >                  raise WicError("unrecognized bootimg-efi loader: %s" %
> > source_params['loader'])
> >          except KeyError:
> > @@ -243,6 +246,7 @@ class BootimgEFIPlugin(SourcePlugin):
> >              if source_params['loader'] == 'grub-efi':
> >                  shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" %
> > cr_workdir,
> >                                  "%s/grub.cfg" % cr_workdir)
> > +
> >                  for mod in [x for x in os.listdir(kernel_dir) if
> > x.startswith("grub-efi-")]:
> >                      cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir,
> > mod, hdddir, mod[9:])
> >                      exec_cmd(cp_cmd, True)
> > @@ -252,6 +256,29 @@ class BootimgEFIPlugin(SourcePlugin):
> >                  for mod in [x for x in os.listdir(kernel_dir) if
> > x.startswith("systemd-")]:
> >                      cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir,
> > mod, hdddir, mod[8:])
> >                      exec_cmd(cp_cmd, True)
> > +            elif source_params['loader'] == 'kernel':
>
> How about "uefi-stub" instead of just "kernel" here so it's more explicit?
>

It's the same file were other uefi stubs are defined (grub and
systemd), so I named kernel uefi stub as kernel.

> > +                kernel = get_bitbake_var("KERNEL_IMAGETYPE")
> > +                if not kernel:
> > +                    raise WicError("Empty KERNEL_IMAGETYPE %s\n" %
> > target)
> > +                target = get_bitbake_var("TARGET_SYS")
> > +                if not target:
> > +                    raise WicError("Unknown arch (TARGET_SYS) %s\n" %
> > target)
> > +
> > +                if re.match("x86_64", target):
> > +                    kernel_efi_image = "bootx64.efi"
> > +                elif re.match('i.86', target):
> > +                    kernel_efi_image = "bootia32.efi"
> > +                elif re.match('aarch64', target):
> > +                    kernel_efi_image = "bootaa64.efi"
> > +                elif re.match('arm', target):
> > +                    kernel_efi_image = "bootarm.efi"
> > +                else:
> > +                    raise WicError("kernel efi is incompatible with
> > target %s" % target)
>
> Perhaps call this "UEFI stub kernel" instead of just "kernel efi" to make things clearer.
>

Ok.

> > +
> > +                for mod in [x for x in os.listdir(kernel_dir) if
> > x.startswith(kernel)]:
> > +                    cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir,
> > mod, hdddir, kernel_efi_image)
> > +                    WicError("cp_cmd = %s" % cp_cmd);
>
> What's this WicError created here for?
>

Good catch. Debug print. Will send v2.

> > +                    exec_cmd(cp_cmd, True)
>
> Wouldn't this result in the destination file being overwritten each time through this loop? I guess you're just copying from the grub-efi implementation above though.
>

It's expected that there are no other uefi stubs and I just copy
kernel to /EFI/BOOT/bootxxx.efi.

Maxim.

> >              else:
> >                  raise WicError("unrecognized bootimg-efi loader: %s" %
> >                                 source_params['loader'])
> > --
> > 2.17.1
>
> --
> Paul Barker


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-13 15:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-04 20:07 [PATCH] wic: add UEFI kernel as UEFI stub Maxim Uvarov
2020-01-05 14:52 ` Richard Purdie
2020-01-09 11:47   ` Maxim Uvarov
2020-01-13 13:14     ` Maxim Uvarov
2020-01-13 13:56 ` Paul Barker
2020-01-13 15:23   ` Maxim Uvarov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.