summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-02-01 08:53:13 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-02-01 08:53:13 +0000
commit08441fd6924c375f6ac62663a1920ff301dd3531 (patch)
treee2940e654049a6b6ad4d972192662c3b5dbe6d5b
parente33cb951b7d8af4358b6fd861968a5064f22db13 (diff)
parent4f2fa8444202eddc6ab0a5aa0390d189b0e2b558 (diff)
downloadedk2-pie-s2-release.tar.gz
Snap for 4579913 from 4f2fa8444202eddc6ab0a5aa0390d189b0e2b558 to pi-releaseandroid-wear-9.0.0_r9android-wear-9.0.0_r8android-wear-9.0.0_r7android-wear-9.0.0_r6android-wear-9.0.0_r5android-wear-9.0.0_r4android-wear-9.0.0_r34android-wear-9.0.0_r33android-wear-9.0.0_r32android-wear-9.0.0_r31android-wear-9.0.0_r30android-wear-9.0.0_r3android-wear-9.0.0_r29android-wear-9.0.0_r28android-wear-9.0.0_r27android-wear-9.0.0_r26android-wear-9.0.0_r25android-wear-9.0.0_r24android-wear-9.0.0_r23android-wear-9.0.0_r22android-wear-9.0.0_r21android-wear-9.0.0_r20android-wear-9.0.0_r2android-wear-9.0.0_r19android-wear-9.0.0_r18android-wear-9.0.0_r17android-wear-9.0.0_r16android-wear-9.0.0_r15android-wear-9.0.0_r14android-wear-9.0.0_r13android-wear-9.0.0_r12android-wear-9.0.0_r11android-wear-9.0.0_r10android-wear-9.0.0_r1android-vts-9.0_r9android-vts-9.0_r8android-vts-9.0_r7android-vts-9.0_r6android-vts-9.0_r5android-vts-9.0_r4android-vts-9.0_r19android-vts-9.0_r18android-vts-9.0_r17android-vts-9.0_r16android-vts-9.0_r15android-vts-9.0_r14android-vts-9.0_r13android-vts-9.0_r12android-vts-9.0_r11android-vts-9.0_r10android-security-9.0.0_r76android-security-9.0.0_r75android-security-9.0.0_r74android-security-9.0.0_r73android-security-9.0.0_r72android-security-9.0.0_r71android-security-9.0.0_r70android-security-9.0.0_r69android-security-9.0.0_r68android-security-9.0.0_r67android-security-9.0.0_r66android-security-9.0.0_r65android-security-9.0.0_r64android-security-9.0.0_r63android-security-9.0.0_r62android-cts-9.0_r9android-cts-9.0_r8android-cts-9.0_r7android-cts-9.0_r6android-cts-9.0_r5android-cts-9.0_r4android-cts-9.0_r3android-cts-9.0_r20android-cts-9.0_r2android-cts-9.0_r19android-cts-9.0_r18android-cts-9.0_r17android-cts-9.0_r16android-cts-9.0_r15android-cts-9.0_r14android-cts-9.0_r13android-cts-9.0_r12android-cts-9.0_r11android-cts-9.0_r10android-cts-9.0_r1android-9.0.0_r9android-9.0.0_r8android-9.0.0_r7android-9.0.0_r61android-9.0.0_r60android-9.0.0_r6android-9.0.0_r59android-9.0.0_r58android-9.0.0_r57android-9.0.0_r56android-9.0.0_r55android-9.0.0_r54android-9.0.0_r53android-9.0.0_r52android-9.0.0_r51android-9.0.0_r50android-9.0.0_r5android-9.0.0_r49android-9.0.0_r48android-9.0.0_r3android-9.0.0_r2android-9.0.0_r18android-9.0.0_r17android-9.0.0_r10android-9.0.0_r1security-pi-releasepie-vts-releasepie-security-releasepie-s2-releasepie-release-2pie-releasepie-r2-s2-releasepie-r2-s1-releasepie-r2-releasepie-platform-releasepie-gsipie-cuttlefish-testingpie-cts-release
Change-Id: I4990a1e195d66ccc06aa4ca6fd56b1437c8fb4f1
-rw-r--r--EmbeddedPkg/Library/AbootimgLib/AbootimgLib.c130
1 files changed, 91 insertions, 39 deletions
diff --git a/EmbeddedPkg/Library/AbootimgLib/AbootimgLib.c b/EmbeddedPkg/Library/AbootimgLib/AbootimgLib.c
index 1d8a81a75..a8db3ac1a 100644
--- a/EmbeddedPkg/Library/AbootimgLib/AbootimgLib.c
+++ b/EmbeddedPkg/Library/AbootimgLib/AbootimgLib.c
@@ -95,12 +95,19 @@ UncompressKernel (
OUT UINTN *KernelSize
)
{
- INTN err;
-
- *Kernel = AllocatePages (EFI_SIZE_TO_PAGES (DEFAULT_UNCOMPRESS_BUFFER_SIZE));
- if (*Kernel == NULL) {
- return EFI_BUFFER_TOO_SMALL;
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS Address;
+ INTN err;
+
+ Status = gBS->AllocatePages (
+ AllocateAnyPages, EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (DEFAULT_UNCOMPRESS_BUFFER_SIZE),
+ &Address
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
}
+ *Kernel = (VOID *)(UINTN)Address;
*KernelSize = DEFAULT_UNCOMPRESS_BUFFER_SIZE;
err = GzipDecompress (Source, SourceSize, *Kernel, KernelSize);
if (err) {
@@ -240,15 +247,56 @@ GetAttachedFdt (
STATIC
EFI_STATUS
+AllocateRamdisk (
+ IN VOID *BootImg,
+ IN OUT VOID *KernelArgs
+ )
+{
+ EFI_STATUS Status;
+ ANDROID_BOOTIMG_HEADER *Header;
+ EFI_PHYSICAL_ADDRESS Address;
+ UINT8 *BootImgBytePtr;
+ VOID *Source;
+
+ Header = (ANDROID_BOOTIMG_HEADER *) BootImg;
+ // Cast to UINT8 so we can do pointer arithmetic
+ BootImgBytePtr = (UINT8 *) BootImg;
+
+ if (AsciiStrnCmp (Header->BootMagic, BOOT_MAGIC, BOOT_MAGIC_LENGTH) != 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ASSERT (IS_POWER_OF_2 (Header->PageSize));
+
+ Address = (EFI_PHYSICAL_ADDRESS)(UINTN)Header->RamdiskAddress;
+ Status = gBS->AllocatePages (
+ AllocateAddress, EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (Header->RamdiskSize), &Address);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Source = (VOID *) (BootImgBytePtr + Header->PageSize +
+ ALIGN_VALUE (Header->KernelSize, Header->PageSize));
+ CopyMem ((VOID *)(UINTN)Address, Source, Header->RamdiskSize);
+ // Set the ramdisk in command line arguments
+ if (KernelArgs != NULL) {
+ UnicodeSPrint (
+ (CHAR16 *)KernelArgs + StrLen (KernelArgs), BOOTIMG_KERNEL_ARGS_SIZE,
+ L" initrd=0x%x,0x%x",
+ (UINTN)Address, Header->RamdiskSize
+ );
+ }
+ return Status;
+}
+
+STATIC
+EFI_STATUS
InstallFdt (
IN VOID *BootImg,
IN EFI_PHYSICAL_ADDRESS FdtBase,
IN OUT VOID *KernelArgs
)
{
- VOID *NewRamdisk;
- VOID *Ramdisk;
- UINTN RamdiskSize;
CHAR8 ImgKernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];
INTN err;
EFI_STATUS Status;
@@ -259,14 +307,6 @@ InstallFdt (
return Status;
}
- Status = GetRamdiskInfo (
- BootImg,
- &Ramdisk,
- &RamdiskSize
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
Status = GetKernelArgs (
BootImg,
ImgKernelArgs
@@ -275,27 +315,19 @@ InstallFdt (
return Status;
}
- NewRamdisk = AllocateReservedPool (RamdiskSize);
- if (NewRamdisk == NULL) {
- return EFI_BUFFER_TOO_SMALL;
- }
- CopyMem (NewRamdisk, Ramdisk, RamdiskSize);
if (ImgKernelArgs != NULL) {
// Get kernel arguments from Android boot image
AsciiStrToUnicodeStrS (ImgKernelArgs, KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE);
- // Set the ramdisk in command line arguments
- UnicodeSPrint (
- (CHAR16 *)KernelArgs + StrLen (KernelArgs), BOOTIMG_KERNEL_ARGS_SIZE,
- L" initrd=0x%x,0x%x",
- (UINTN)NewRamdisk, (UINTN)RamdiskSize
- );
-
// Append platform kernel arguments
Status = mAbootimg->AppendArgs (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE);
if (EFI_ERROR (Status)) {
return Status;
}
}
+ Status = AllocateRamdisk (BootImg, KernelArgs);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
Status = mAbootimg->UpdateDtb (FdtBase, &NewFdtBase);
if (EFI_ERROR (Status)) {
@@ -385,6 +417,7 @@ LoadBootImage (
EFI_STATUS Status;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
UINTN BootImageSize = 0;
+ EFI_PHYSICAL_ADDRESS Address;
if ((Buffer == NULL) || (BufferSize == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -395,10 +428,15 @@ LoadBootImage (
return Status;
}
// Read both image header and kernel header
- *Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BlockIo->Media->BlockSize * BOOTIMG_HEADER_BLOCKS));
- if (Buffer == NULL) {
- return EFI_BUFFER_TOO_SMALL;
+ Status = gBS->AllocatePages (
+ AllocateAnyPages, EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (BlockIo->Media->BlockSize * BOOTIMG_HEADER_BLOCKS),
+ &Address
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
}
+ *Buffer = (VOID *)(UINTN)Address;
Status = BlockIo->ReadBlocks (
BlockIo,
BlockIo->Media->MediaId,
@@ -416,15 +454,22 @@ LoadBootImage (
DEBUG ((DEBUG_ERROR, "Failed to get Abootimg Size: %r\n", Status));
return Status;
}
- FreePages (*Buffer, EFI_SIZE_TO_PAGES (BlockIo->Media->BlockSize * BOOTIMG_HEADER_BLOCKS));
+ gBS->FreePages (
+ (EFI_PHYSICAL_ADDRESS)(UINTN)*Buffer,
+ EFI_SIZE_TO_PAGES (BlockIo->Media->BlockSize * BOOTIMG_HEADER_BLOCKS)
+ );
BootImageSize = ALIGN_VALUE (BootImageSize, BlockIo->Media->BlockSize);
/* Both PartitionStart and PartitionSize are counted as block size. */
- *Buffer = AllocatePages (EFI_SIZE_TO_PAGES (BootImageSize));
- if (Buffer == NULL) {
- return EFI_BUFFER_TOO_SMALL;
+ Status = gBS->AllocatePages (
+ AllocateAnyPages, EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (BootImageSize), &Address
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
}
+ *Buffer = (VOID *)(UINTN)Address;
/* Load the full boot.img */
Status = BlockIo->ReadBlocks (
BlockIo,
@@ -666,12 +711,19 @@ AbootimgBootRam (
EFI_HANDLE ImageHandle;
VOID *NewKernelArgs;
EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
+ EFI_PHYSICAL_ADDRESS Address;
- NewKernelArgs = AllocateZeroPool (BOOTIMG_KERNEL_ARGS_SIZE << 1);
- if (NewKernelArgs == NULL) {
- DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
- return EFI_OUT_OF_RESOURCES;
+ Status = gBS->AllocatePages (
+ AllocateAnyPages, EfiBootServicesData,
+ EFI_SIZE_TO_PAGES (BOOTIMG_KERNEL_ARGS_SIZE << 1),
+ &Address
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to allocate memory for kernel args: %r\n", Status));
+ return Status;
}
+ NewKernelArgs = (VOID *)(UINTN)Address;
+ SetMem (NewKernelArgs, EFI_SIZE_TO_PAGES (BOOTIMG_KERNEL_ARGS_SIZE << 1), 0);
Status = BootFromRam (Buffer, BootPathStr, FdtPathStr, NewKernelArgs, &Kernel, &KernelSize);
if (EFI_ERROR (Status)) {