This application uses QEMU's FwCfg interface to read a kernel
specified on the QEMU command line. (See -kernel, -initrd, -append)

The application uses the LoadLinuxLib to boot the kernel image.

Signed-off-by: Jordan Justen <jordan.l.jus...@intel.com>
---
 OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.c  |  161 ++++++++++++++++++++
 .../Application/QemuKernelDxe/QemuKernelDxe.inf    |   47 ++++++
 OvmfPkg/OvmfPkgIa32.dsc                            |    3 +
 OvmfPkg/OvmfPkgIa32.fdf                            |    2 +
 OvmfPkg/OvmfPkgIa32X64.dsc                         |    3 +
 OvmfPkg/OvmfPkgIa32X64.fdf                         |    2 +
 OvmfPkg/OvmfPkgX64.dsc                             |    3 +
 OvmfPkg/OvmfPkgX64.fdf                             |    2 +
 8 files changed, 223 insertions(+)
 create mode 100644 OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.c
 create mode 100644 OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf

diff --git a/OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.c 
b/OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.c
new file mode 100644
index 0000000..f9b7092
--- /dev/null
+++ b/OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.c
@@ -0,0 +1,161 @@
+/** @file
+
+  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Uefi.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/LoadLinuxLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/QemuFwCfgLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+
+/**
+  Loads and boots UEFI Linux via the FwCfg interface.
+
+  @retval    EFI_NOT_FOUND - The Linux kernel was not found
+
+**/
+EFI_STATUS
+EFIAPI
+QemuFwCfgLoadLinux (
+  VOID
+  )
+{
+  EFI_STATUS                Status;
+  UINTN                     KernelSize;
+  UINTN                     KernelInitialSize;
+  VOID                      *KernelBuf;
+  UINTN                     SetupSize;
+  VOID                      *SetupBuf;
+  UINTN                     CommandLineSize;
+  CHAR8                     *CommandLine;
+  UINTN                     InitrdSize;
+  VOID*                     InitrdData;
+  struct boot_params        *Bp;
+
+  if (!QemuFwCfgIsAvailable ()) {
+    return EFI_NOT_FOUND;
+  }
+
+  QemuFwCfgSelectItem (QemuFwCfgItemKernelSize);
+  KernelSize = (UINTN) QemuFwCfgRead64 ();
+  DEBUG ((EFI_D_INFO, "Kernel size: 0x%x\n", KernelSize));
+
+  QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize);
+  SetupSize = (UINTN) QemuFwCfgRead64 ();
+  DEBUG ((EFI_D_INFO, "Setup size: 0x%x\n", SetupSize));
+
+  if (KernelSize == 0 || SetupSize == 0) {
+    DEBUG ((EFI_D_INFO, "qemu -kernel was not used.\n"));
+    return EFI_NOT_FOUND;
+  }
+
+  SetupBuf = LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (SetupSize));
+  if (SetupBuf == NULL) {
+    DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel setup!\n"));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  DEBUG ((EFI_D_INFO, "Reading kernel setup image ..."));
+  QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData);
+  QemuFwCfgReadBytes (SetupSize, SetupBuf);
+  DEBUG ((EFI_D_INFO, " [done]\n"));
+
+  Status = LoadLinuxCheckKernelSetup (SetupBuf, SetupSize);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  KernelInitialSize = LoadLinuxGetKernelSize (SetupBuf, KernelSize);
+  if (KernelInitialSize == 0) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Bp = (struct boot_params*) SetupBuf;
+
+  KernelBuf = LoadLinuxAllocateKernelPages (
+                SetupBuf,
+                EFI_SIZE_TO_PAGES (KernelInitialSize));
+  if (KernelBuf == NULL) {
+    DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel!\n"));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  DEBUG ((EFI_D_INFO, "Reading kernel image ..."));
+  QemuFwCfgSelectItem (QemuFwCfgItemKernelData);
+  QemuFwCfgReadBytes (KernelSize, KernelBuf);
+  DEBUG ((EFI_D_INFO, " [done]\n"));
+
+  QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize);
+  CommandLineSize = (UINTN) QemuFwCfgRead64 ();
+  DEBUG ((EFI_D_INFO, "Command line size: 0x%x\n", CommandLineSize));
+
+  if (CommandLineSize > 0) {
+    CommandLine = LoadLinuxAllocateCommandLinePages (
+                    EFI_SIZE_TO_PAGES (CommandLineSize));
+    QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData);
+    QemuFwCfgReadBytes (CommandLineSize, CommandLine);
+  } else {
+    CommandLine = NULL;
+  }
+
+  Status = LoadLinuxSetCommandLine (SetupBuf, CommandLine);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize);
+  InitrdSize = (UINTN) QemuFwCfgRead64 ();
+  DEBUG ((EFI_D_INFO, "Initrd size: 0x%x\n", InitrdSize));
+
+  if (InitrdSize > 0) {
+    InitrdData = LoadLinuxAllocateInitrdPages (EFI_SIZE_TO_PAGES (InitrdSize));
+    DEBUG ((EFI_D_INFO, "Reading initrd image ..."));
+    QemuFwCfgSelectItem (QemuFwCfgItemInitrdData);
+    QemuFwCfgReadBytes (InitrdSize, InitrdData);
+    DEBUG ((EFI_D_INFO, " [done]\n"));
+  } else {
+    InitrdData = NULL;
+  }
+
+  Status = LoadLinuxSetInitrd (SetupBuf, InitrdData, InitrdSize);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  return LoadLinux (KernelBuf, SetupBuf);
+}
+
+
+/**
+
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
+  @param[in] SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+  @retval other             Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+UefiMain (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  QemuFwCfgLoadLinux ();
+
+  return EFI_SUCCESS;
+}
diff --git a/OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf 
b/OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
new file mode 100644
index 0000000..ea929bb
--- /dev/null
+++ b/OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
@@ -0,0 +1,47 @@
+## @file
+#  QEMU Kernel boot application
+#
+#  This application implements support for QEMU's -kernel parameter.
+#
+#  Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD 
License
+#  which accompanies this distribution. The full text of the license may be 
found at
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = QemuKernelDxe
+  FILE_GUID                      = 3f588f11-b6b2-4859-b867-9d4ccc2f9865
+  MODULE_TYPE                    = UEFI_APPLICATION
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = UefiMain
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  QemuKernelDxe.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  LoadLinuxLib
+  MemoryAllocationLib
+  QemuFwCfgLib
+  UefiApplicationEntryPoint
+  UefiBootServicesTableLib
+
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index c99cee3..6412a64 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -533,3 +533,6 @@
   }
   OvmfPkg/SecureBootConfigDxe/SecureBootConfigDxe.inf
 !endif
+
+  OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
+
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 36c9756..5a2c040 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -285,6 +285,8 @@ INF  RuleOverride=CSM OvmfPkg/Csm/Csm16/Csm16.inf
 
 INF  OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
 
+INF  OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
+
 
################################################################################
 
 [FV.FVMAIN_COMPACT]
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 9173aae..879c91d 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -540,3 +540,6 @@
   }
   OvmfPkg/SecureBootConfigDxe/SecureBootConfigDxe.inf
 !endif
+
+  OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
+
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index a762dc9..2d81500 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -285,6 +285,8 @@ INF  RuleOverride=CSM OvmfPkg/Csm/Csm16/Csm16.inf
 
 INF  OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
 
+INF  OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
+
 
################################################################################
 
 [FV.FVMAIN_COMPACT]
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index dce9ce1..b129568 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -538,3 +538,6 @@
   }
   OvmfPkg/SecureBootConfigDxe/SecureBootConfigDxe.inf
 !endif
+
+  OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
+
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index fcdac03..5705939 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -285,6 +285,8 @@ INF  RuleOverride=CSM OvmfPkg/Csm/Csm16/Csm16.inf
 
 INF  OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
 
+INF  OvmfPkg/Application/QemuKernelDxe/QemuKernelDxe.inf
+
 
################################################################################
 
 [FV.FVMAIN_COMPACT]
-- 
1.7.9.5


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to