[edk2-devel] [PATCH v2 03/14] OvmfPkg: introduce QemuLoadImageLib library class

Ard Biesheuvel posted 14 patches 5 years, 11 months ago
There is a newer version of this series
[edk2-devel] [PATCH v2 03/14] OvmfPkg: introduce QemuLoadImageLib library class
Posted by Ard Biesheuvel 5 years, 11 months ago
Introduce the QemuLoadImageLib library class that we will instantiate
to load the kernel image passed via the QEMU command line using the
standard LoadImage boot service.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/Include/Library/QemuLoadImageLib.h | 84 ++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                        |  5 ++
 2 files changed, 89 insertions(+)

diff --git a/OvmfPkg/Include/Library/QemuLoadImageLib.h b/OvmfPkg/Include/Library/QemuLoadImageLib.h
new file mode 100644
index 000000000000..694905a6421b
--- /dev/null
+++ b/OvmfPkg/Include/Library/QemuLoadImageLib.h
@@ -0,0 +1,84 @@
+/** @file
+  Load a kernel image and command line passed to QEMU via
+  the command line
+
+  Copyright (C) 2020, Arm, Limited.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef QEMU_LOAD_IMAGE_LIB_H__
+#define QEMU_LOAD_IMAGE_LIB_H__
+
+#include <Uefi/UefiBaseType.h>
+#include <Base.h>
+
+#include <Protocol/LoadedImage.h>
+
+/**
+  Download the kernel, the initial ramdisk, and the kernel command line from
+  QEMU's fw_cfg. The kernel will be instructed via its command line to load
+  the initrd from the same Simple FileSystem where the kernel was loaded from.
+
+  @param[out] ImageHandle       The image handle that was allocated for
+                                loading the image
+
+  @retval EFI_SUCCESS           The image was loaded successfully.
+  @retval EFI_NOT_FOUND         Kernel image was not found.
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
+  @retval EFI_PROTOCOL_ERROR    Unterminated kernel command line.
+  @retval EFI_ACCESS_DENIED     The underlying LoadImage boot service call
+                                returned EFI_SECURITY_VIOLATION, and the image
+                                was unloaded again.
+
+  @return                       Error codes from any of the underlying
+                                functions.
+**/
+EFI_STATUS
+EFIAPI
+QemuLoadKernelImage (
+  OUT EFI_HANDLE          *ImageHandle
+  );
+
+/**
+  Transfer control to a kernel image loaded with QemuLoadKernelImage ()
+
+  @param[in,out]  ImageHandle     Handle of image to be started. May assume a
+                                  different value on return if the image was
+                                  reloaded.
+
+  @retval EFI_INVALID_PARAMETER   ImageHandle is either an invalid image handle
+                                  or the image has already been initialized with
+                                  StartImage
+  @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the
+                                  image should not be started.
+
+  @return                         Error codes returned by the started image.
+                                  On success, the function doesn't return.
+**/
+EFI_STATUS
+EFIAPI
+QemuStartKernelImage (
+  IN  OUT EFI_HANDLE          *ImageHandle
+  );
+
+/**
+  Unloads an image loaded with QemuLoadKernelImage ().
+
+  @param  ImageHandle             Handle that identifies the image to be
+                                  unloaded.
+
+  @retval EFI_SUCCESS             The image has been unloaded.
+  @retval EFI_UNSUPPORTED         The image has been started, and does not
+                                  support unload.
+  @retval EFI_INVALID_PARAMETER   ImageHandle is not a valid image handle.
+
+  @return                         Exit code from the image’s unload function.
+**/
+EFI_STATUS
+EFIAPI
+QemuUnloadKernelImage (
+  IN  EFI_HANDLE          ImageHandle
+  );
+
+#endif
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index a21b279d140a..055caaa43041 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -58,6 +58,11 @@ [LibraryClasses]
   #
   QemuBootOrderLib|Include/Library/QemuBootOrderLib.h
 
+  ##  @libraryclass  Load a kernel image and command line passed to QEMU via
+  #                  the command line
+  #
+  QemuLoadImageLib|Include/Library/QemuLoadImageLib.h
+
   ##  @libraryclass  Serialize (and deserialize) variables
   #
   SerializeVariablesLib|Include/Library/SerializeVariablesLib.h
-- 
2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55384): https://edk2.groups.io/g/devel/message/55384
Mute This Topic: https://groups.io/mt/71722796/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2 03/14] OvmfPkg: introduce QemuLoadImageLib library class
Posted by Laszlo Ersek 5 years, 11 months ago
On 03/04/20 10:52, Ard Biesheuvel wrote:
> Introduce the QemuLoadImageLib library class that we will instantiate
> to load the kernel image passed via the QEMU command line using the
> standard LoadImage boot service.
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  OvmfPkg/Include/Library/QemuLoadImageLib.h | 84 ++++++++++++++++++++
>  OvmfPkg/OvmfPkg.dec                        |  5 ++
>  2 files changed, 89 insertions(+)
> 
> diff --git a/OvmfPkg/Include/Library/QemuLoadImageLib.h b/OvmfPkg/Include/Library/QemuLoadImageLib.h
> new file mode 100644
> index 000000000000..694905a6421b
> --- /dev/null
> +++ b/OvmfPkg/Include/Library/QemuLoadImageLib.h
> @@ -0,0 +1,84 @@
> +/** @file
> +  Load a kernel image and command line passed to QEMU via
> +  the command line
> +
> +  Copyright (C) 2020, Arm, Limited.
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +**/
> +
> +#ifndef QEMU_LOAD_IMAGE_LIB_H__
> +#define QEMU_LOAD_IMAGE_LIB_H__
> +
> +#include <Uefi/UefiBaseType.h>
> +#include <Base.h>
> +
> +#include <Protocol/LoadedImage.h>
> +
> +/**
> +  Download the kernel, the initial ramdisk, and the kernel command line from
> +  QEMU's fw_cfg. The kernel will be instructed via its command line to load
> +  the initrd from the same Simple FileSystem where the kernel was loaded from.
> +
> +  @param[out] ImageHandle       The image handle that was allocated for
> +                                loading the image
> +
> +  @retval EFI_SUCCESS           The image was loaded successfully.
> +  @retval EFI_NOT_FOUND         Kernel image was not found.
> +  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
> +  @retval EFI_PROTOCOL_ERROR    Unterminated kernel command line.
> +  @retval EFI_ACCESS_DENIED     The underlying LoadImage boot service call
> +                                returned EFI_SECURITY_VIOLATION, and the image
> +                                was unloaded again.
> +
> +  @return                       Error codes from any of the underlying
> +                                functions.
> +**/
> +EFI_STATUS
> +EFIAPI
> +QemuLoadKernelImage (
> +  OUT EFI_HANDLE          *ImageHandle
> +  );
> +
> +/**
> +  Transfer control to a kernel image loaded with QemuLoadKernelImage ()
> +
> +  @param[in,out]  ImageHandle     Handle of image to be started. May assume a
> +                                  different value on return if the image was
> +                                  reloaded.
> +
> +  @retval EFI_INVALID_PARAMETER   ImageHandle is either an invalid image handle
> +                                  or the image has already been initialized with
> +                                  StartImage
> +  @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the
> +                                  image should not be started.
> +
> +  @return                         Error codes returned by the started image.
> +                                  On success, the function doesn't return.
> +**/
> +EFI_STATUS
> +EFIAPI
> +QemuStartKernelImage (
> +  IN  OUT EFI_HANDLE          *ImageHandle
> +  );
> +
> +/**
> +  Unloads an image loaded with QemuLoadKernelImage ().
> +
> +  @param  ImageHandle             Handle that identifies the image to be
> +                                  unloaded.
> +
> +  @retval EFI_SUCCESS             The image has been unloaded.
> +  @retval EFI_UNSUPPORTED         The image has been started, and does not
> +                                  support unload.
> +  @retval EFI_INVALID_PARAMETER   ImageHandle is not a valid image handle.
> +
> +  @return                         Exit code from the image’s unload function.

(1) The above apostrophe (in the "image’s" expression) is U+2019 ("RIGHT
SINGLE QUOTATION MARK"). Please replace it with a normal ASCII 0x27
character (U+0027, "APOSTROPHE") when you push the series.

Thanks
Laszlo


> +**/
> +EFI_STATUS
> +EFIAPI
> +QemuUnloadKernelImage (
> +  IN  EFI_HANDLE          ImageHandle
> +  );
> +
> +#endif
> diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
> index a21b279d140a..055caaa43041 100644
> --- a/OvmfPkg/OvmfPkg.dec
> +++ b/OvmfPkg/OvmfPkg.dec
> @@ -58,6 +58,11 @@ [LibraryClasses]
>    #
>    QemuBootOrderLib|Include/Library/QemuBootOrderLib.h
>  
> +  ##  @libraryclass  Load a kernel image and command line passed to QEMU via
> +  #                  the command line
> +  #
> +  QemuLoadImageLib|Include/Library/QemuLoadImageLib.h
> +
>    ##  @libraryclass  Serialize (and deserialize) variables
>    #
>    SerializeVariablesLib|Include/Library/SerializeVariablesLib.h
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55487): https://edk2.groups.io/g/devel/message/55487
Mute This Topic: https://groups.io/mt/71722796/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2 03/14] OvmfPkg: introduce QemuLoadImageLib library class
Posted by Laszlo Ersek 5 years, 11 months ago
On 03/05/20 10:37, Laszlo Ersek wrote:
> On 03/04/20 10:52, Ard Biesheuvel wrote:
>> Introduce the QemuLoadImageLib library class that we will instantiate
>> to load the kernel image passed via the QEMU command line using the
>> standard LoadImage boot service.
>>
>> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>> ---
>>  OvmfPkg/Include/Library/QemuLoadImageLib.h | 84 ++++++++++++++++++++
>>  OvmfPkg/OvmfPkg.dec                        |  5 ++
>>  2 files changed, 89 insertions(+)
>>
>> diff --git a/OvmfPkg/Include/Library/QemuLoadImageLib.h b/OvmfPkg/Include/Library/QemuLoadImageLib.h
>> new file mode 100644
>> index 000000000000..694905a6421b
>> --- /dev/null
>> +++ b/OvmfPkg/Include/Library/QemuLoadImageLib.h
>> @@ -0,0 +1,84 @@
>> +/** @file
>> +  Load a kernel image and command line passed to QEMU via
>> +  the command line
>> +
>> +  Copyright (C) 2020, Arm, Limited.
>> +
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +**/
>> +
>> +#ifndef QEMU_LOAD_IMAGE_LIB_H__
>> +#define QEMU_LOAD_IMAGE_LIB_H__
>> +
>> +#include <Uefi/UefiBaseType.h>
>> +#include <Base.h>
>> +
>> +#include <Protocol/LoadedImage.h>
>> +
>> +/**
>> +  Download the kernel, the initial ramdisk, and the kernel command line from
>> +  QEMU's fw_cfg. The kernel will be instructed via its command line to load
>> +  the initrd from the same Simple FileSystem where the kernel was loaded from.
>> +
>> +  @param[out] ImageHandle       The image handle that was allocated for
>> +                                loading the image
>> +
>> +  @retval EFI_SUCCESS           The image was loaded successfully.
>> +  @retval EFI_NOT_FOUND         Kernel image was not found.
>> +  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
>> +  @retval EFI_PROTOCOL_ERROR    Unterminated kernel command line.
>> +  @retval EFI_ACCESS_DENIED     The underlying LoadImage boot service call
>> +                                returned EFI_SECURITY_VIOLATION, and the image
>> +                                was unloaded again.
>> +
>> +  @return                       Error codes from any of the underlying
>> +                                functions.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +QemuLoadKernelImage (
>> +  OUT EFI_HANDLE          *ImageHandle
>> +  );
>> +
>> +/**
>> +  Transfer control to a kernel image loaded with QemuLoadKernelImage ()
>> +
>> +  @param[in,out]  ImageHandle     Handle of image to be started. May assume a
>> +                                  different value on return if the image was
>> +                                  reloaded.
>> +
>> +  @retval EFI_INVALID_PARAMETER   ImageHandle is either an invalid image handle
>> +                                  or the image has already been initialized with
>> +                                  StartImage
>> +  @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the
>> +                                  image should not be started.
>> +
>> +  @return                         Error codes returned by the started image.
>> +                                  On success, the function doesn't return.
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +QemuStartKernelImage (
>> +  IN  OUT EFI_HANDLE          *ImageHandle
>> +  );
>> +
>> +/**
>> +  Unloads an image loaded with QemuLoadKernelImage ().
>> +
>> +  @param  ImageHandle             Handle that identifies the image to be
>> +                                  unloaded.
>> +
>> +  @retval EFI_SUCCESS             The image has been unloaded.
>> +  @retval EFI_UNSUPPORTED         The image has been started, and does not
>> +                                  support unload.
>> +  @retval EFI_INVALID_PARAMETER   ImageHandle is not a valid image handle.
>> +
>> +  @return                         Exit code from the image’s unload function.
> 
> (1) The above apostrophe (in the "image’s" expression) is U+2019 ("RIGHT
> SINGLE QUOTATION MARK"). Please replace it with a normal ASCII 0x27
> character (U+0027, "APOSTROPHE") when you push the series.

Please also sync the comment in the lib instances too.

Laszlo


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55488): https://edk2.groups.io/g/devel/message/55488
Mute This Topic: https://groups.io/mt/71722796/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2 03/14] OvmfPkg: introduce QemuLoadImageLib library class
Posted by Ard Biesheuvel 5 years, 11 months ago
On Thu, 5 Mar 2020 at 10:39, Laszlo Ersek <lersek@redhat.com> wrote:
>
> On 03/05/20 10:37, Laszlo Ersek wrote:
> > On 03/04/20 10:52, Ard Biesheuvel wrote:
> >> Introduce the QemuLoadImageLib library class that we will instantiate
> >> to load the kernel image passed via the QEMU command line using the
> >> standard LoadImage boot service.
> >>
> >> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566
> >> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> >> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> >> ---
> >>  OvmfPkg/Include/Library/QemuLoadImageLib.h | 84 ++++++++++++++++++++
> >>  OvmfPkg/OvmfPkg.dec                        |  5 ++
> >>  2 files changed, 89 insertions(+)
> >>
> >> diff --git a/OvmfPkg/Include/Library/QemuLoadImageLib.h b/OvmfPkg/Include/Library/QemuLoadImageLib.h
> >> new file mode 100644
> >> index 000000000000..694905a6421b
> >> --- /dev/null
> >> +++ b/OvmfPkg/Include/Library/QemuLoadImageLib.h
> >> @@ -0,0 +1,84 @@
> >> +/** @file
> >> +  Load a kernel image and command line passed to QEMU via
> >> +  the command line
> >> +
> >> +  Copyright (C) 2020, Arm, Limited.
> >> +
> >> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >> +**/
> >> +
> >> +#ifndef QEMU_LOAD_IMAGE_LIB_H__
> >> +#define QEMU_LOAD_IMAGE_LIB_H__
> >> +
> >> +#include <Uefi/UefiBaseType.h>
> >> +#include <Base.h>
> >> +
> >> +#include <Protocol/LoadedImage.h>
> >> +
> >> +/**
> >> +  Download the kernel, the initial ramdisk, and the kernel command line from
> >> +  QEMU's fw_cfg. The kernel will be instructed via its command line to load
> >> +  the initrd from the same Simple FileSystem where the kernel was loaded from.
> >> +
> >> +  @param[out] ImageHandle       The image handle that was allocated for
> >> +                                loading the image
> >> +
> >> +  @retval EFI_SUCCESS           The image was loaded successfully.
> >> +  @retval EFI_NOT_FOUND         Kernel image was not found.
> >> +  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
> >> +  @retval EFI_PROTOCOL_ERROR    Unterminated kernel command line.
> >> +  @retval EFI_ACCESS_DENIED     The underlying LoadImage boot service call
> >> +                                returned EFI_SECURITY_VIOLATION, and the image
> >> +                                was unloaded again.
> >> +
> >> +  @return                       Error codes from any of the underlying
> >> +                                functions.
> >> +**/
> >> +EFI_STATUS
> >> +EFIAPI
> >> +QemuLoadKernelImage (
> >> +  OUT EFI_HANDLE          *ImageHandle
> >> +  );
> >> +
> >> +/**
> >> +  Transfer control to a kernel image loaded with QemuLoadKernelImage ()
> >> +
> >> +  @param[in,out]  ImageHandle     Handle of image to be started. May assume a
> >> +                                  different value on return if the image was
> >> +                                  reloaded.
> >> +
> >> +  @retval EFI_INVALID_PARAMETER   ImageHandle is either an invalid image handle
> >> +                                  or the image has already been initialized with
> >> +                                  StartImage
> >> +  @retval EFI_SECURITY_VIOLATION  The current platform policy specifies that the
> >> +                                  image should not be started.
> >> +
> >> +  @return                         Error codes returned by the started image.
> >> +                                  On success, the function doesn't return.
> >> +**/
> >> +EFI_STATUS
> >> +EFIAPI
> >> +QemuStartKernelImage (
> >> +  IN  OUT EFI_HANDLE          *ImageHandle
> >> +  );
> >> +
> >> +/**
> >> +  Unloads an image loaded with QemuLoadKernelImage ().
> >> +
> >> +  @param  ImageHandle             Handle that identifies the image to be
> >> +                                  unloaded.
> >> +
> >> +  @retval EFI_SUCCESS             The image has been unloaded.
> >> +  @retval EFI_UNSUPPORTED         The image has been started, and does not
> >> +                                  support unload.
> >> +  @retval EFI_INVALID_PARAMETER   ImageHandle is not a valid image handle.
> >> +
> >> +  @return                         Exit code from the image’s unload function.
> >
> > (1) The above apostrophe (in the "image’s" expression) is U+2019 ("RIGHT
> > SINGLE QUOTATION MARK"). Please replace it with a normal ASCII 0x27
> > character (U+0027, "APOSTROPHE") when you push the series.
>
> Please also sync the comment in the lib instances too.
>

OK

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#55495): https://edk2.groups.io/g/devel/message/55495
Mute This Topic: https://groups.io/mt/71722796/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-