Skip to content

Commit b1f028e

Browse files
Merge pull request #2 from osresearch/kexec-ramdisk
kexec uefi ramdisk support
2 parents 4f01068 + 76d653c commit b1f028e

7 files changed

Lines changed: 111 additions & 11 deletions

File tree

MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ RamDiskDxeEntryPoint (
154154
goto ErrorExit;
155155
}
156156

157+
//
158+
// Initialize the list of registered RAM disks maintained by the driver
159+
// before installing the protocol
160+
//
161+
InitializeListHead (&RegisteredRamDisks);
162+
157163
//
158164
// Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
159165
// new handle
@@ -170,11 +176,6 @@ RamDiskDxeEntryPoint (
170176
goto ErrorExit;
171177
}
172178

173-
//
174-
// Initialize the list of registered RAM disks maintained by the driver
175-
//
176-
InitializeListHead (&RegisteredRamDisks);
177-
178179
Status = EfiCreateEventReadyToBootEx (
179180
TPL_CALLBACK,
180181
RamDiskAcpiCheck,

UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
**/
99
#include "BlSupportDxe.h"
1010

11+
#include <Protocol/DevicePath.h>
12+
#include <Library/DevicePathLib.h>
13+
#include <Protocol/RamDisk.h>
14+
#include <Library/MemoryAllocationLib.h>
15+
1116
/**
1217
Reserve MMIO/IO resource in GCD
1318
@@ -80,6 +85,54 @@ ReserveResourceInGcd (
8085
}
8186

8287

88+
static void EFIAPI ramdisk_callback(EFI_EVENT event, void * context)
89+
{
90+
const SYSTEM_TABLE_INFO *SystemTableInfo = context;
91+
const unsigned char * ramdisk_base = (const void*) SystemTableInfo->RamDiskBase;
92+
const UINTN ramdisk_size = SystemTableInfo->RamDiskSize;
93+
94+
if (!ramdisk_base || !ramdisk_size)
95+
return;
96+
97+
EFI_STATUS Status;
98+
EFI_RAM_DISK_PROTOCOL *RamDisk;
99+
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
100+
EFI_GUID *RamDiskType = &gEfiVirtualDiskGuid;
101+
102+
Status = gBS->LocateProtocol(&gEfiRamDiskProtocolGuid, NULL, (VOID**) &RamDisk);
103+
// if there is no protocol, we've been signalled too early. we'll try again later
104+
if (EFI_ERROR (Status))
105+
return;
106+
107+
// it is necessary to copy the ramdisk from the kexec allocated memory to uefi allocated
108+
// memory. otherwise the memory will be reclaimed during the boot process, leading to
109+
// a corrupt BCD hive or other propblems.
110+
const unsigned char * ramdisk_copy = AllocateCopyPool(ramdisk_size, (const void*) ramdisk_base);
111+
if (!ramdisk_copy)
112+
{
113+
DEBUG((EFI_D_ERROR, "allocate %d bytes for ramdisk copy failed\n", ramdisk_size));
114+
return;
115+
}
116+
117+
Status = RamDisk->Register(
118+
(UINTN) ramdisk_copy,
119+
ramdisk_size,
120+
RamDiskType,
121+
NULL,
122+
&DevicePath
123+
);
124+
125+
if (EFI_ERROR (Status)) {
126+
DEBUG ((EFI_D_ERROR, "ramdisk_setup: Failed to register RAM Disk - %r\n", Status));
127+
return;
128+
}
129+
130+
VOID * Temp = ConvertDevicePathToText(DevicePath, TRUE, TRUE);
131+
DEBUG ((EFI_D_INFO, "ramdisk_setup: ram disk %p + %x: device path %S\n", ramdisk_copy, ramdisk_size, Temp));
132+
FreePool(Temp);
133+
}
134+
135+
83136
/**
84137
Main entry for the bootloader support DXE module.
85138
@@ -180,5 +233,16 @@ BlDxeEntryPoint (
180233
ASSERT_EFI_ERROR (Status);
181234
}
182235

236+
// Wait for the RamDiskProtocol to become available
237+
static EFI_EVENT ramdisk_event;
238+
static void * ramdisk_registration;
239+
240+
Status = gBS->CreateEvent(EVT_NOTIFY_SIGNAL, TPL_CALLBACK, ramdisk_callback, SystemTableInfo, &ramdisk_event);
241+
ASSERT_EFI_ERROR(Status);
242+
Status = gBS->RegisterProtocolNotify(&gEfiRamDiskProtocolGuid, ramdisk_event, &ramdisk_registration);
243+
ASSERT_EFI_ERROR(Status);
244+
Status = gBS->SignalEvent(ramdisk_event);
245+
ASSERT_EFI_ERROR(Status);
246+
183247
return EFI_SUCCESS;
184248
}

UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
BaseMemoryLib
4141
UefiLib
4242
HobLib
43+
DevicePathLib
4344

4445
[Guids]
4546
gEfiAcpiTableGuid
@@ -48,6 +49,10 @@
4849
gUefiSystemTableInfoGuid
4950
gUefiAcpiBoardInfoGuid
5051
gEfiGraphicsInfoHobGuid
52+
gEfiVirtualDiskGuid ## CONSUMES
53+
54+
[Protocols]
55+
gEfiRamDiskProtocolGuid ## SOMETIMES_CONSUMES
5156

5257
[Pcd]
5358
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution

UefiPayloadPkg/Include/Guid/SystemTableInfoGuid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ typedef struct {
2121
UINT32 AcpiTableSize;
2222
UINT64 SmbiosTableBase;
2323
UINT32 SmbiosTableSize;
24+
UINT64 RamDiskBase;
25+
UINT32 RamDiskSize;
2426
} SYSTEM_TABLE_INFO;
2527

2628
#endif

UefiPayloadPkg/Library/LbParseLib/LbParseLib.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ const UefiPayloadConfig* GetUefiPayLoadConfig() {
5555

5656
DEBUG((DEBUG_ERROR, "Expect payload config version %016lx or %016lx, but get %016lx\n",
5757
UEFI_PAYLOAD_CONFIG_VERSION1, UEFI_PAYLOAD_CONFIG_VERSION2, config->Version));
58-
CpuDeadLoop ();
59-
while(1)
60-
;
58+
return NULL;
6159
}
6260

6361
// Align the address and add memory rang to MemInfoCallback
@@ -189,7 +187,8 @@ ParseMemoryInfo(IN BL_MEM_INFO_CALLBACK MemInfoCallback, IN VOID* Params) {
189187
// look for the mem=start,end,type
190188
while((cmdline = cmdline_next(cmdline, &option)))
191189
{
192-
if (strncmp(option, "mem=", 4) != 0)
190+
if (strncmp(option, "mem=", 4) != 0
191+
&& strncmp(option, "ramdisk=", 8) != 0)
193192
continue;
194193

195194
if (cmdline_ints(option, args, 3) != 3)
@@ -243,7 +242,7 @@ ParseSystemTable(OUT SYSTEM_TABLE_INFO* SystemTableInfo) {
243242
{
244243
const char * cmdline = config->config.v2.cmdline;
245244
const char * option;
246-
uint64_t args[2];
245+
uint64_t args[3];
247246

248247
// look for the acpi config
249248
while((cmdline = cmdline_next(cmdline, &option)))
@@ -277,6 +276,21 @@ ParseSystemTable(OUT SYSTEM_TABLE_INFO* SystemTableInfo) {
277276
if (count > 1)
278277
SystemTableInfo->SmbiosTableSize = args[1];
279278
}
279+
280+
if (strncmp(option, "ramdisk=", 8) == 0)
281+
{
282+
const int count = cmdline_ints(option, args, 3);
283+
if (count < 0)
284+
{
285+
DEBUG((DEBUG_ERROR, "Parse error: '%a'\n", option));
286+
continue;
287+
}
288+
289+
if (count > 0)
290+
SystemTableInfo->RamDiskBase = args[0];
291+
if (count > 1)
292+
SystemTableInfo->RamDiskSize = args[1];
293+
}
280294
}
281295
}
282296

UefiPayloadPkg/UefiPayloadPkg.dsc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@
358358
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
359359
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3
360360

361+
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId|0x29c0
362+
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase|0x0
363+
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoSize|0x0
364+
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Base|0x0
365+
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size|0x0
366+
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base|0x0
367+
361368
## This PCD defines the video horizontal resolution.
362369
# This PCD could be set to 0 then video resolution could be at highest resolution.
363370
gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|0
@@ -471,6 +478,7 @@
471478
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
472479
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
473480
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
481+
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
474482
FatPkg/EnhancedFatDxe/Fat.inf
475483
MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf
476484
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf
@@ -523,6 +531,9 @@
523531
!endif
524532
UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf
525533

534+
OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
535+
536+
526537
#------------------------------
527538
# Build the shell
528539
#------------------------------

UefiPayloadPkg/UefiPayloadPkg.fdf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ INF MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KeyboardDxe.inf
138138
!endif
139139

140140
#
141-
# Console Support
141+
# Console Support (including Qemu graphics)
142142
#
143143
INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
144144
INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
@@ -147,13 +147,16 @@ INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
147147
INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
148148
!endif
149149
INF UefiPayloadPkg/GraphicsOutputDxe/GraphicsOutputDxe.inf
150+
INF OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
151+
150152

151153
#
152154
# SCSI/ATA/IDE/DISK Support
153155
#
154156
INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
155157
INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
156158
INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
159+
INF MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
157160
INF MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf
158161
INF MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf
159162
INF MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.inf

0 commit comments

Comments
 (0)