24#define FDT_ADDITIONAL_ENTRIES_SIZE 0x400
57 END_ENTIRE_DEVICE_PATH_SUBTYPE,
70 LINUX_EFI_INITRD_MEDIA_GUID
74 END_ENTIRE_DEVICE_PATH_SUBTYPE,
113 IN BOOLEAN BootPolicy,
115 IN VOID *Buffer OPTIONAL
120 if ((This ==
NULL) ||
121 (BufferSize ==
NULL) ||
122 (FilePath ==
NULL) ||
125 return EFI_INVALID_PARAMETER;
129 return EFI_UNSUPPORTED;
134 if (mRamdiskSize == 0) {
135 return EFI_NOT_FOUND;
138 if ((Buffer ==
NULL) || (*BufferSize < mRamdiskSize)) {
139 *BufferSize = mRamdiskSize;
140 return EFI_BUFFER_TOO_SMALL;
144 CopyMem (Buffer, mRamdiskData, mRamdiskSize);
145 *BufferSize = mRamdiskSize;
158AndroidBootImgGetImgSize (
168 (
CONST CHAR8 *)Header->BootMagic,
170 ANDROID_BOOT_MAGIC_LENGTH
173 return EFI_INVALID_PARAMETER;
177 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
180 *ImgSize =
ALIGN_VALUE (Header->KernelSize, Header->PageSize) +
181 ALIGN_VALUE (Header->RamdiskSize, Header->PageSize) +
182 ALIGN_VALUE (Header->SecondStageBootloaderSize, Header->PageSize) +
188AndroidBootImgGetKernelInfo (
199 (
CONST CHAR8 *)Header->BootMagic,
201 ANDROID_BOOT_MAGIC_LENGTH
204 return EFI_INVALID_PARAMETER;
207 if (Header->KernelSize == 0) {
208 return EFI_NOT_FOUND;
211 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
213 *KernelSize = Header->KernelSize;
214 *Kernel = (VOID *)((
UINTN)BootImg + Header->PageSize);
219AndroidBootImgGetRamdiskInfo (
230 (
CONST CHAR8 *)Header->BootMagic,
232 ANDROID_BOOT_MAGIC_LENGTH
235 return EFI_INVALID_PARAMETER;
238 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
240 *RamdiskSize = Header->RamdiskSize;
242 if (Header->RamdiskSize != 0) {
243 *Ramdisk = (VOID *)((
INTN)BootImg
245 +
ALIGN_VALUE (Header->KernelSize, Header->PageSize));
252AndroidBootImgGetSecondBootLoaderInfo (
263 (
CONST CHAR8 *)Header->BootMagic,
265 ANDROID_BOOT_MAGIC_LENGTH
268 return EFI_INVALID_PARAMETER;
271 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
273 *SecondSize = Header->SecondStageBootloaderSize;
275 if (Header->SecondStageBootloaderSize != 0) {
276 *Second = (VOID *)((
UINTN)BootImg
278 +
ALIGN_VALUE (Header->KernelSize, Header->PageSize)
279 +
ALIGN_VALUE (Header->RamdiskSize, Header->PageSize));
286AndroidBootImgGetKernelArgs (
288 OUT CHAR8 *KernelArgs
296 ANDROID_BOOTIMG_KERNEL_ARGS_SIZE,
298 ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
305AndroidBootImgGetFdt (
310 UINTN SecondLoaderSize;
315 Status = AndroidBootImgGetSecondBootLoaderInfo (
324AndroidBootImgUpdateArgs (
326 OUT VOID **KernelArgs
329 CHAR8 ImageKernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
331 UINT32 NewKernelArgSize;
334 Status = AndroidBootImgGetKernelArgs (BootImg, ImageKernelArgs);
335 if (EFI_ERROR (Status)) {
339 NewKernelArgSize = ANDROID_BOOTIMG_KERNEL_ARGS_SIZE +
PcdGet32 (PcdAndroidKernelCommandLineOverflow);
341 if (*KernelArgs ==
NULL) {
342 DEBUG ((DEBUG_ERROR,
"Fail to allocate memory\n"));
343 return EFI_OUT_OF_RESOURCES;
352 if (mAndroidBootImg->AppendArgs) {
353 Status = mAndroidBootImg->AppendArgs (
363AndroidBootImgInstallLoadFile2 (
364 IN VOID *RamdiskData,
368 mRamDiskLoadFileHandle =
NULL;
369 mRamdiskData = RamdiskData;
370 mRamdiskSize = RamdiskSize;
371 return gBS->InstallMultipleProtocolInterfaces (
372 &mRamDiskLoadFileHandle,
373 &gEfiLoadFile2ProtocolGuid,
375 &gEfiDevicePathProtocolGuid,
382AndroidBootImgUninstallLoadFile2 (
391 if (mRamDiskLoadFileHandle !=
NULL) {
392 Status =
gBS->UninstallMultipleProtocolInterfaces (
393 mRamDiskLoadFileHandle,
394 &gEfiLoadFile2ProtocolGuid,
396 &gEfiDevicePathProtocolGuid,
400 mRamDiskLoadFileHandle =
NULL;
407AndroidBootImgAcpiSupported (
415 return !EFI_ERROR (Status);
419AndroidBootImgLocateFdt (
428 if (!EFI_ERROR (Status)) {
432 Status = AndroidBootImgGetFdt (BootImg, FdtBase);
433 if (EFI_ERROR (Status)) {
437 Err = fdt_check_header (*FdtBase);
441 "ERROR: Device Tree header not valid (Err:%d)\n",
444 return EFI_INVALID_PARAMETER;
451AndroidBootImgGetChosenNode (
457 ChosenNode = fdt_subnode_offset ((
CONST VOID *)UpdatedFdtBase, 0,
"chosen");
458 if (ChosenNode < 0) {
459 ChosenNode = fdt_add_subnode ((VOID *)UpdatedFdtBase, 0,
"chosen");
460 if (ChosenNode < 0) {
461 DEBUG ((DEBUG_ERROR,
"Fail to find fdt node chosen!\n"));
470AndroidBootImgSetProperty64 (
473 IN CHAR8 *PropertyName,
481 Property = fdt_get_property_w (
482 (VOID *)UpdatedFdtBase,
487 if ((
NULL == Property) && (Len == -FDT_ERR_NOTFOUND)) {
488 Val = cpu_to_fdt64 (Val);
489 Err = fdt_appendprop (
490 (VOID *)UpdatedFdtBase,
497 DEBUG ((DEBUG_ERROR,
"fdt_appendprop() fail: %a\n", fdt_strerror (Err)));
498 return EFI_INVALID_PARAMETER;
500 }
else if (Property !=
NULL) {
501 Err = fdt_setprop_u64 (
502 (VOID *)UpdatedFdtBase,
508 DEBUG ((DEBUG_ERROR,
"fdt_setprop_u64() fail: %a\n", fdt_strerror (Err)));
509 return EFI_INVALID_PARAMETER;
512 DEBUG ((DEBUG_ERROR,
"Failed to set fdt Property %a\n", PropertyName));
513 return EFI_INVALID_PARAMETER;
520AndroidBootImgUpdateFdt (
523 IN VOID *RamdiskData,
527 INTN ChosenNode, Err, NewFdtSize;
531 NewFdtSize = (
UINTN)fdt_totalsize (FdtBase)
532 + FDT_ADDITIONAL_ENTRIES_SIZE;
533 Status =
gBS->AllocatePages (
539 if (EFI_ERROR (Status)) {
542 "Warning: Failed to reallocate FDT, err %d.\n",
549 Err = fdt_open_into (FdtBase, (VOID *)(
INTN)UpdatedFdtBase, NewFdtSize);
551 DEBUG ((DEBUG_ERROR,
"fdt_open_into(): %a\n", fdt_strerror (Err)));
552 Status = EFI_INVALID_PARAMETER;
557 Status = AndroidBootImgInstallLoadFile2 (RamdiskData, RamdiskSize);
558 if (EFI_ERROR (Status)) {
562 ChosenNode = AndroidBootImgGetChosenNode (UpdatedFdtBase);
567 Status = AndroidBootImgSetProperty64 (
570 "linux,initrd-start",
573 if (EFI_ERROR (Status)) {
577 Status = AndroidBootImgSetProperty64 (
581 (
UINTN)RamdiskData + RamdiskSize
583 if (EFI_ERROR (Status)) {
588 if (mAndroidBootImg->UpdateDtb) {
589 Status = mAndroidBootImg->UpdateDtb (UpdatedFdtBase, &NewFdtBase);
590 if (EFI_ERROR (Status)) {
594 NewFdtBase = UpdatedFdtBase;
597 Status =
gBS->InstallConfigurationTable (
599 (VOID *)(
UINTN)NewFdtBase
602 if (!EFI_ERROR (Status)) {
628 if ((Buffer ==
NULL) || (BufferSize == 0)) {
629 return EFI_INVALID_PARAMETER;
635 Status =
gBS->LocateProtocol (
636 &gAndroidBootImgProtocolGuid,
638 (VOID **)&mAndroidBootImg
640 if (EFI_ERROR (Status)) {
644 Status = AndroidBootImgGetKernelInfo (
649 if (EFI_ERROR (Status)) {
653 Status = AndroidBootImgUpdateArgs (Buffer, &NewKernelArg);
654 if (EFI_ERROR (Status)) {
658 Status = AndroidBootImgGetRamdiskInfo (
663 if (EFI_ERROR (Status)) {
667 if (AndroidBootImgAcpiSupported ()) {
668 Status = AndroidBootImgInstallLoadFile2 (RamdiskData, RamdiskSize);
669 if (EFI_ERROR (Status)) {
673 Status = AndroidBootImgLocateFdt (Buffer, &FdtBase);
674 if (EFI_ERROR (Status)) {
678 Status = AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, RamdiskSize);
679 if (EFI_ERROR (Status)) {
684 KernelDevicePath = mMemoryDevicePathTemplate;
690 Status =
gBS->LoadImage (
694 (VOID *)(
UINTN)Kernel,
698 if (EFI_ERROR (Status)) {
703 Status =
gBS->HandleProtocol (
705 &gEfiLoadedImageProtocolGuid,
708 if (EFI_ERROR (Status)) {
716 gBS->SetWatchdogTimer (5 * 60, 0x10000, 0,
NULL);
718 Status =
gBS->StartImage (ImageHandle,
NULL,
NULL);
720 gBS->SetWatchdogTimer (0, 0x10000, 0,
NULL);
724 if (ImageHandle !=
NULL) {
725 gBS->UnloadImage (ImageHandle);
729 if (EFI_ERROR (Status)) {
730 if (NewKernelArg !=
NULL) {
736 AndroidBootImgUninstallLoadFile2 ();
STATIC EFI_LOAD_FILE2_PROTOCOL mAndroidBootImgLoadFile2
EFI_STATUS EFIAPI AndroidBootImgLoadFile2(IN EFI_LOAD_FILE2_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN BOOLEAN BootPolicy, IN OUT UINTN *BufferSize, IN VOID *Buffer OPTIONAL)
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
RETURN_STATUS EFIAPI AsciiStrToUnicodeStrS(IN CONST CHAR8 *Source, OUT CHAR16 *Destination, IN UINTN DestMax)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define HARDWARE_DEVICE_PATH
#define MEDIA_VENDOR_DP
Media vendor device path subtype.
BOOLEAN EFIAPI IsDevicePathValid(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN MaxSize)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ALIGN_VALUE(Value, Alignment)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
#define FeaturePcdGet(TokenName)
VOID EFIAPI Exit(IN EFI_STATUS Status)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
VOID * LoadOptions
A pointer to the image's binary load options.
UINT32 LoadOptionsSize
The size in bytes of LoadOptions.
EFI_PHYSICAL_ADDRESS StartingAddress
EFI_PHYSICAL_ADDRESS EndingAddress