Allow boot from container component

This patch added support to boot from a component inside a container
from OsLoader. Now a boot option for SPI/memory device can be used
to boot from container component by specifying the boot image name
as '!AAAA/BBBB' format. AAAA is the container name and BBBB is
the component name. This component can be FV/TE/PE image format.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
This commit is contained in:
Maurice Ma 2020-08-13 14:59:01 -07:00
parent 4bee65a8f6
commit 90ca0f11dd
3 changed files with 170 additions and 113 deletions

View File

@ -53,10 +53,31 @@ GetBootImageFromRawPartition (
UINT8 SwPart;
UINT64 Address;
CONTAINER_HDR *ContainerHdr;
CHAR8 *FileName;
SwPart = BootOption->Image[LoadedImage->LoadImageType].LbaImage.SwPart;
LbaAddr = BootOption->Image[LoadedImage->LoadImageType].LbaImage.LbaAddr;
FileName = (CHAR8 *)BootOption->Image[LoadedImage->LoadImageType].FileName;
if ((FileName[0] == '!') && (LbaAddr == 0)) {
// Load file from internal container path instead
Status = EFI_NOT_FOUND;
if ((AsciiStrLen(FileName) > 9) && (FileName[0] == '!') && (FileName[5] == '/')) {
Buffer = NULL;
ImageSize = 0;
Status = LoadComponent (
*(UINT32 *)(FileName + 1),
*(UINT32 *)(FileName + 6),
(VOID **)&Buffer,
(UINT32 *)&ImageSize
);
}
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Load component '%a' error - %r\n", FileName, Status));
return Status;
}
LoadedImage->Flags |= LOADED_IMAGE_COMPONENT;
} else {
//
// The image_B partition number, is image_A partition number + 1
// They share same LBA offset address.
@ -71,13 +92,13 @@ GetBootImageFromRawPartition (
DEBUG ((DEBUG_INFO, "Load image from SwPart (0x%x), LbaAddr(0x%llx)\n", SwPart, LbaAddr));
Status = GetLogicalPartitionInfo (SwPart, LoadedImage->HwPartHandle, &LogicBlkDev);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Get logical partition error, Status = %r\n", Status));
DEBUG ((DEBUG_INFO, "Get logical partition error - %r\n", Status));
return Status;
}
Status = MediaGetMediaInfo (BootOption->HwPart, &BlockInfo);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "GetMediaInfo Error %r\n", Status));
DEBUG ((DEBUG_INFO, "Get media info error - %r\n", Status));
return Status;
}
@ -109,7 +130,7 @@ GetBootImageFromRawPartition (
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Read image error, Status = %r\n", Status));
DEBUG ((DEBUG_INFO, "Read image error - %r\n", Status));
return Status;
}
@ -176,10 +197,11 @@ GetBootImageFromRawPartition (
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Read rest of image error, Status = %r\n", Status));
DEBUG ((DEBUG_INFO, "Read rest of image error - %r\n", Status));
FreePages (Buffer, EFI_SIZE_TO_PAGES (AlignedImageSize));
return Status;
}
}
LoadedImage->ImageData.Addr = Buffer;
LoadedImage->ImageData.Size = (UINT32)ImageSize;

View File

@ -178,7 +178,7 @@ UpdateLoadedImage (
@param[in] BootOption Current boot option
@param[in, out] LoadedImage Loaded Image information.
@retval RETURN_SUCCESS Parse IAS image successfully
@retval RETURN_SUCCESS Parse container image successfully
@retval Others There is error when parsing IAS image.
**/
EFI_STATUS
@ -260,6 +260,37 @@ ParseContainerImage (
return Status;
}
/**
Parse a single component image
This function will parse a single image.
This image could be TE/PE/FV or multi-boot format.
@param[in] BootOption Current boot option
@param[in, out] LoadedImage Loaded Image information.
@retval RETURN_SUCCESS Parse component image successfully
@retval Others There is error when parsing IAS image.
**/
EFI_STATUS
ParseComponentImage (
IN OS_BOOT_OPTION *BootOption,
IN OUT LOADED_IMAGE *LoadedImage
)
{
IMAGE_DATA File;
EFI_STATUS Status;
File.Addr = LoadedImage->ImageData.Addr;
File.Size = LoadedImage->ImageData.Size;
File.AllocType = ImageAllocateTypePointer;
Status = UpdateLoadedImage (1, &File, LoadedImage, 0);
if (EFI_ERROR (Status)) {
UnloadLoadedImage (LoadedImage);
}
return Status;
}
/**
Parse IAS image
@ -783,16 +814,17 @@ InitBootFileSystem (
{
EFI_STATUS Status;
UINT32 SwPart;
UINT32 FsType;
UINT32 DevType;
INT32 BootSlot;
OS_FILE_SYSTEM_TYPE FsType;
ASSERT (OsBootOption != NULL);
SwPart = OsBootOption->SwPart;
FsType = OsBootOption->FsType;
DevType = OsBootOption->DevType;
DEBUG ((DEBUG_INFO, "Init File system\n"));
if ((OS_FILE_SYSTEM_TYPE)FsType < EnumFileSystemMax) {
if ((DevType != OsBootDeviceSpi) && (DevType != OsBootDeviceMemory) && (FsType < EnumFileSystemMax)) {
Status = InitFileSystem (SwPart, FsType, HwPartHandle, FsHandle);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "No partitions found, Status = %r\n", Status));
@ -859,6 +891,8 @@ ParseBootImages (
}
} else if ((LoadedImage->Flags & LOADED_IMAGE_IAS) != 0) {
Status = ParseIasImage (OsBootOption, LoadedImage);
} else if ((LoadedImage->Flags & LOADED_IMAGE_COMPONENT) != 0) {
Status = ParseComponentImage (OsBootOption, LoadedImage);
}
if (EFI_ERROR (Status)) {

View File

@ -78,6 +78,7 @@
#define LOADED_IMAGE_PE32 BIT3
#define LOADED_IMAGE_FV BIT4
#define LOADED_IMAGE_CONTAINER BIT5
#define LOADED_IMAGE_COMPONENT BIT6
#define MAX_EXTRA_FILE_NUMBER 16