3 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/LoadLinuxLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/QemuFwCfgLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/UefiLib.h>
26 TryRunningQemuKernel (
32 UINTN KernelInitialSize
;
36 UINTN CommandLineSize
;
44 KernelInitialSize
= 0;
50 if (!QemuFwCfgIsAvailable ()) {
54 QemuFwCfgSelectItem (QemuFwCfgItemKernelSize
);
55 KernelSize
= (UINTN
) QemuFwCfgRead64 ();
57 QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize
);
58 SetupSize
= (UINTN
) QemuFwCfgRead64 ();
60 if (KernelSize
== 0 || SetupSize
== 0) {
61 DEBUG ((EFI_D_INFO
, "qemu -kernel was not used.\n"));
65 SetupBuf
= LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (SetupSize
));
66 if (SetupBuf
== NULL
) {
67 DEBUG ((EFI_D_ERROR
, "Unable to allocate memory for kernel setup!\n"));
68 return EFI_OUT_OF_RESOURCES
;
71 DEBUG ((EFI_D_INFO
, "Setup size: 0x%x\n", (UINT32
) SetupSize
));
72 DEBUG ((EFI_D_INFO
, "Reading kernel setup image ..."));
73 QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData
);
74 QemuFwCfgReadBytes (SetupSize
, SetupBuf
);
75 DEBUG ((EFI_D_INFO
, " [done]\n"));
77 Status
= LoadLinuxCheckKernelSetup (SetupBuf
, SetupSize
);
78 if (EFI_ERROR (Status
)) {
82 Status
= LoadLinuxInitializeKernelSetup (SetupBuf
);
83 if (EFI_ERROR (Status
)) {
87 KernelInitialSize
= LoadLinuxGetKernelSize (SetupBuf
, KernelSize
);
88 if (KernelInitialSize
== 0) {
89 Status
= EFI_UNSUPPORTED
;
93 KernelBuf
= LoadLinuxAllocateKernelPages (
95 EFI_SIZE_TO_PAGES (KernelInitialSize
));
96 if (KernelBuf
== NULL
) {
97 DEBUG ((EFI_D_ERROR
, "Unable to allocate memory for kernel!\n"));
98 Status
= EFI_OUT_OF_RESOURCES
;
102 DEBUG ((EFI_D_INFO
, "Kernel size: 0x%x\n", (UINT32
) KernelSize
));
103 DEBUG ((EFI_D_INFO
, "Reading kernel image ..."));
104 QemuFwCfgSelectItem (QemuFwCfgItemKernelData
);
105 QemuFwCfgReadBytes (KernelSize
, KernelBuf
);
106 DEBUG ((EFI_D_INFO
, " [done]\n"));
108 QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize
);
109 CommandLineSize
= (UINTN
) QemuFwCfgRead64 ();
111 if (CommandLineSize
> 0) {
112 CommandLine
= LoadLinuxAllocateCommandLinePages (
113 EFI_SIZE_TO_PAGES (CommandLineSize
));
114 QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData
);
115 QemuFwCfgReadBytes (CommandLineSize
, CommandLine
);
120 Status
= LoadLinuxSetCommandLine (SetupBuf
, CommandLine
);
121 if (EFI_ERROR (Status
)) {
125 QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize
);
126 InitrdSize
= (UINTN
) QemuFwCfgRead64 ();
128 if (InitrdSize
> 0) {
129 InitrdData
= LoadLinuxAllocateInitrdPages (
131 EFI_SIZE_TO_PAGES (InitrdSize
)
133 DEBUG ((EFI_D_INFO
, "Initrd size: 0x%x\n", (UINT32
) InitrdSize
));
134 DEBUG ((EFI_D_INFO
, "Reading initrd image ..."));
135 QemuFwCfgSelectItem (QemuFwCfgItemInitrdData
);
136 QemuFwCfgReadBytes (InitrdSize
, InitrdData
);
137 DEBUG ((EFI_D_INFO
, " [done]\n"));
142 Status
= LoadLinuxSetInitrd (SetupBuf
, InitrdData
, InitrdSize
);
143 if (EFI_ERROR (Status
)) {
148 // Signal the EVT_SIGNAL_READY_TO_BOOT event
150 EfiSignalEventReadyToBoot();
152 Status
= LoadLinux (KernelBuf
, SetupBuf
);
155 if (SetupBuf
!= NULL
) {
156 FreePages (SetupBuf
, EFI_SIZE_TO_PAGES (SetupSize
));
158 if (KernelBuf
!= NULL
) {
159 FreePages (KernelBuf
, EFI_SIZE_TO_PAGES (KernelInitialSize
));
161 if (CommandLine
!= NULL
) {
162 FreePages (CommandLine
, EFI_SIZE_TO_PAGES (CommandLineSize
));
164 if (InitrdData
!= NULL
) {
165 FreePages (InitrdData
, EFI_SIZE_TO_PAGES (InitrdSize
));