1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
|
/** @file
Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
Copyright (c) 2017, Linaro. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/AndroidBootImgLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/FdtLib.h>
#include <Library/PrintLib.h>
#include <Library/DevicePathLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Protocol/AndroidBootImg.h>
#include <Protocol/LoadFile2.h>
#include <Protocol/LoadedImage.h>
#include <Guid/LinuxEfiInitrdMedia.h>
#define FDT_ADDITIONAL_ENTRIES_SIZE 0x400
typedef struct {
MEMMAP_DEVICE_PATH Node1;
EFI_DEVICE_PATH_PROTOCOL End;
} MEMORY_DEVICE_PATH;
typedef struct {
VENDOR_DEVICE_PATH VendorMediaNode;
EFI_DEVICE_PATH_PROTOCOL EndNode;
} RAMDISK_DEVICE_PATH;
STATIC ANDROID_BOOTIMG_PROTOCOL *mAndroidBootImg;
STATIC VOID *mRamdiskData = NULL;
STATIC UINTN mRamdiskSize = 0;
STATIC EFI_HANDLE mRamDiskLoadFileHandle = NULL;
STATIC CONST MEMORY_DEVICE_PATH mMemoryDevicePathTemplate =
{
{
{
HARDWARE_DEVICE_PATH,
HW_MEMMAP_DP,
{
(UINT8)(sizeof (MEMMAP_DEVICE_PATH)),
(UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8),
},
}, // Header
0, // StartingAddress (set at runtime)
0 // EndingAddress (set at runtime)
}, // Node1
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{ sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
} // End
};
STATIC CONST RAMDISK_DEVICE_PATH mRamdiskDevicePath =
{
{
{
MEDIA_DEVICE_PATH,
MEDIA_VENDOR_DP,
{ sizeof (VENDOR_DEVICE_PATH), 0 }
},
LINUX_EFI_INITRD_MEDIA_GUID
},
{
END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE,
{ sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
}
};
/**
Causes the driver to load a specified file.
@param This Protocol instance pointer.
@param FilePath The device specific path of the file to load.
@param BootPolicy Should always be FALSE.
@param BufferSize On input the size of Buffer in bytes. On output with a return
code of EFI_SUCCESS, the amount of data transferred to
Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL,
the size of Buffer required to retrieve the requested file.
@param Buffer The memory buffer to transfer the file to. IF Buffer is NULL,
then no the size of the requested file is returned in
BufferSize.
@retval EFI_SUCCESS The file was loaded.
@retval EFI_UNSUPPORTED BootPolicy is TRUE.
@retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or
BufferSize is NULL.
@retval EFI_NO_MEDIA No medium was present to load the file.
@retval EFI_DEVICE_ERROR The file was not loaded due to a device error.
@retval EFI_NO_RESPONSE The remote system did not respond.
@retval EFI_NOT_FOUND The file was not found
@retval EFI_ABORTED The file load process was manually canceled.
@retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current
directory entry. BufferSize has been updated with
the size needed to complete the request.
**/
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
)
{
// Verify if the valid parameters
if ((This == NULL) ||
(BufferSize == NULL) ||
(FilePath == NULL) ||
!IsDevicePathValid (FilePath, 0))
{
return EFI_INVALID_PARAMETER;
}
if (BootPolicy) {
return EFI_UNSUPPORTED;
}
// Check if the given buffer size is big enough
// EFI_BUFFER_TOO_SMALL to allow caller to allocate a bigger buffer
if (mRamdiskSize == 0) {
return EFI_NOT_FOUND;
}
if ((Buffer == NULL) || (*BufferSize < mRamdiskSize)) {
*BufferSize = mRamdiskSize;
return EFI_BUFFER_TOO_SMALL;
}
// Copy InitRd
CopyMem (Buffer, mRamdiskData, mRamdiskSize);
*BufferSize = mRamdiskSize;
return EFI_SUCCESS;
}
///
/// Load File Protocol instance
///
STATIC EFI_LOAD_FILE2_PROTOCOL mAndroidBootImgLoadFile2 = {
AndroidBootImgLoadFile2
};
EFI_STATUS
AndroidBootImgGetImgSize (
IN VOID *BootImg,
OUT UINTN *ImgSize
)
{
ANDROID_BOOTIMG_HEADER *Header;
Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp (
(CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER;
}
/* The page size is not specified, but it should be power of 2 at least */
ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
/* Get real size of abootimg */
*ImgSize = ALIGN_VALUE (Header->KernelSize, Header->PageSize) +
ALIGN_VALUE (Header->RamdiskSize, Header->PageSize) +
ALIGN_VALUE (Header->SecondStageBootloaderSize, Header->PageSize) +
Header->PageSize;
return EFI_SUCCESS;
}
EFI_STATUS
AndroidBootImgGetKernelInfo (
IN VOID *BootImg,
OUT VOID **Kernel,
OUT UINTN *KernelSize
)
{
ANDROID_BOOTIMG_HEADER *Header;
Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp (
(CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER;
}
if (Header->KernelSize == 0) {
return EFI_NOT_FOUND;
}
ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
*KernelSize = Header->KernelSize;
*Kernel = (VOID *)((UINTN)BootImg + Header->PageSize);
return EFI_SUCCESS;
}
EFI_STATUS
AndroidBootImgGetRamdiskInfo (
IN VOID *BootImg,
OUT VOID **Ramdisk,
OUT UINTN *RamdiskSize
)
{
ANDROID_BOOTIMG_HEADER *Header;
Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp (
(CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER;
}
ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
*RamdiskSize = Header->RamdiskSize;
if (Header->RamdiskSize != 0) {
*Ramdisk = (VOID *)((INTN)BootImg
+ Header->PageSize
+ ALIGN_VALUE (Header->KernelSize, Header->PageSize));
}
return EFI_SUCCESS;
}
EFI_STATUS
AndroidBootImgGetSecondBootLoaderInfo (
IN VOID *BootImg,
OUT VOID **Second,
OUT UINTN *SecondSize
)
{
ANDROID_BOOTIMG_HEADER *Header;
Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp (
(CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER;
}
ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
*SecondSize = Header->SecondStageBootloaderSize;
if (Header->SecondStageBootloaderSize != 0) {
*Second = (VOID *)((UINTN)BootImg
+ Header->PageSize
+ ALIGN_VALUE (Header->KernelSize, Header->PageSize)
+ ALIGN_VALUE (Header->RamdiskSize, Header->PageSize));
}
return EFI_SUCCESS;
}
EFI_STATUS
AndroidBootImgGetKernelArgs (
IN VOID *BootImg,
OUT CHAR8 *KernelArgs
)
{
ANDROID_BOOTIMG_HEADER *Header;
Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
AsciiStrnCpyS (
KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE,
Header->KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
);
return EFI_SUCCESS;
}
EFI_STATUS
AndroidBootImgGetFdt (
IN VOID *BootImg,
IN VOID **FdtBase
)
{
UINTN SecondLoaderSize;
EFI_STATUS Status;
/* Check whether FDT is located in second boot region as some vendor do so,
* because second loader is never used as far as I know. */
Status = AndroidBootImgGetSecondBootLoaderInfo (
BootImg,
FdtBase,
&SecondLoaderSize
);
return Status;
}
EFI_STATUS
AndroidBootImgUpdateArgs (
IN VOID *BootImg,
OUT VOID **KernelArgs
)
{
CHAR8 ImageKernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
EFI_STATUS Status;
UINT32 NewKernelArgSize;
// Get kernel arguments from Android boot image
Status = AndroidBootImgGetKernelArgs (BootImg, ImageKernelArgs);
if (EFI_ERROR (Status)) {
return Status;
}
NewKernelArgSize = ANDROID_BOOTIMG_KERNEL_ARGS_SIZE + PcdGet32 (PcdAndroidKernelCommandLineOverflow);
*KernelArgs = AllocateZeroPool (sizeof (CHAR16) * NewKernelArgSize);
if (*KernelArgs == NULL) {
DEBUG ((DEBUG_ERROR, "Fail to allocate memory\n"));
return EFI_OUT_OF_RESOURCES;
}
AsciiStrToUnicodeStrS (
ImageKernelArgs,
*KernelArgs,
NewKernelArgSize
);
// Append platform kernel arguments
if (mAndroidBootImg->AppendArgs) {
Status = mAndroidBootImg->AppendArgs (
*KernelArgs,
NewKernelArgSize
);
}
return Status;
}
EFI_STATUS
AndroidBootImgInstallLoadFile2 (
IN VOID *RamdiskData,
IN UINTN RamdiskSize
)
{
mRamDiskLoadFileHandle = NULL;
mRamdiskData = RamdiskData;
mRamdiskSize = RamdiskSize;
return gBS->InstallMultipleProtocolInterfaces (
&mRamDiskLoadFileHandle,
&gEfiLoadFile2ProtocolGuid,
&mAndroidBootImgLoadFile2,
&gEfiDevicePathProtocolGuid,
&mRamdiskDevicePath,
NULL
);
}
EFI_STATUS
AndroidBootImgUninstallLoadFile2 (
VOID
)
{
EFI_STATUS Status;
Status = EFI_SUCCESS;
mRamdiskData = NULL;
mRamdiskSize = 0;
if (mRamDiskLoadFileHandle != NULL) {
Status = gBS->UninstallMultipleProtocolInterfaces (
mRamDiskLoadFileHandle,
&gEfiLoadFile2ProtocolGuid,
&mAndroidBootImgLoadFile2,
&gEfiDevicePathProtocolGuid,
&mRamdiskDevicePath,
NULL
);
mRamDiskLoadFileHandle = NULL;
}
return Status;
}
BOOLEAN
AndroidBootImgAcpiSupported (
VOID
)
{
EFI_STATUS Status;
VOID *AcpiTable;
Status = EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, &AcpiTable);
return !EFI_ERROR (Status);
}
EFI_STATUS
AndroidBootImgLocateFdt (
IN VOID *BootImg,
IN VOID **FdtBase
)
{
INTN Err;
EFI_STATUS Status;
Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, FdtBase);
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
}
Status = AndroidBootImgGetFdt (BootImg, FdtBase);
if (EFI_ERROR (Status)) {
return Status;
}
Err = FdtCheckHeader (*FdtBase);
if (Err != 0) {
DEBUG ((
DEBUG_ERROR,
"ERROR: Device Tree header not valid (Err:%d)\n",
Err
));
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
INTN
AndroidBootImgGetChosenNode (
IN INTN UpdatedFdtBase
)
{
INTN ChosenNode;
ChosenNode = FdtSubnodeOffset ((CONST VOID *)UpdatedFdtBase, 0, "chosen");
if (ChosenNode < 0) {
ChosenNode = FdtAddSubnode ((VOID *)UpdatedFdtBase, 0, "chosen");
if (ChosenNode < 0) {
DEBUG ((DEBUG_ERROR, "Fail to find fdt node chosen!\n"));
return 0;
}
}
return ChosenNode;
}
EFI_STATUS
AndroidBootImgSetProperty64 (
IN INTN UpdatedFdtBase,
IN INTN ChosenNode,
IN CHAR8 *PropertyName,
IN UINT64 Val
)
{
INTN Err;
CONST FDT_PROPERTY *Property;
int Len;
Property = FdtGetPropertyW (
(VOID *)UpdatedFdtBase,
ChosenNode,
PropertyName,
&Len
);
if ((NULL == Property) && (Len == -FDT_ERR_NOTFOUND)) {
Val = CpuToFdt64 (Val);
Err = FdtAppendProp (
(VOID *)UpdatedFdtBase,
ChosenNode,
PropertyName,
&Val,
sizeof (UINT64)
);
if (Err) {
DEBUG ((DEBUG_ERROR, "FdtAppendProp() fail: %a\n", FdtStrerror (Err)));
return EFI_INVALID_PARAMETER;
}
} else if (Property != NULL) {
Err = FdtSetPropU64 (
(VOID *)UpdatedFdtBase,
ChosenNode,
PropertyName,
Val
);
if (Err) {
DEBUG ((DEBUG_ERROR, "FdtSetpropU64() fail: %a\n", FdtStrerror (Err)));
return EFI_INVALID_PARAMETER;
}
} else {
DEBUG ((DEBUG_ERROR, "Failed to set fdt Property %a\n", PropertyName));
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
EFI_STATUS
AndroidBootImgUpdateFdt (
IN VOID *BootImg,
IN VOID *FdtBase,
IN VOID *RamdiskData,
IN UINTN RamdiskSize
)
{
INTN ChosenNode, Err, NewFdtSize;
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS UpdatedFdtBase, NewFdtBase;
NewFdtSize = (UINTN)FdtTotalSize (FdtBase)
+ FDT_ADDITIONAL_ENTRIES_SIZE;
Status = gBS->AllocatePages (
AllocateAnyPages,
EfiBootServicesData,
EFI_SIZE_TO_PAGES (NewFdtSize),
&UpdatedFdtBase
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_WARN,
"Warning: Failed to reallocate FDT, err %d.\n",
Status
));
return Status;
}
// Load the Original FDT tree into the new region
Err = FdtOpenInto (FdtBase, (VOID *)(INTN)UpdatedFdtBase, NewFdtSize);
if (Err) {
DEBUG ((DEBUG_ERROR, "FdtOpenInto(): %a\n", FdtStrerror (Err)));
Status = EFI_INVALID_PARAMETER;
goto Fdt_Exit;
}
if (FeaturePcdGet (PcdAndroidBootLoadFile2)) {
Status = AndroidBootImgInstallLoadFile2 (RamdiskData, RamdiskSize);
if (EFI_ERROR (Status)) {
goto Fdt_Exit;
}
} else {
ChosenNode = AndroidBootImgGetChosenNode (UpdatedFdtBase);
if (!ChosenNode) {
goto Fdt_Exit;
}
Status = AndroidBootImgSetProperty64 (
UpdatedFdtBase,
ChosenNode,
"linux,initrd-start",
(UINTN)RamdiskData
);
if (EFI_ERROR (Status)) {
goto Fdt_Exit;
}
Status = AndroidBootImgSetProperty64 (
UpdatedFdtBase,
ChosenNode,
"linux,initrd-end",
(UINTN)RamdiskData + RamdiskSize
);
if (EFI_ERROR (Status)) {
goto Fdt_Exit;
}
}
if (mAndroidBootImg->UpdateDtb) {
Status = mAndroidBootImg->UpdateDtb (UpdatedFdtBase, &NewFdtBase);
if (EFI_ERROR (Status)) {
goto Fdt_Exit;
}
} else {
NewFdtBase = UpdatedFdtBase;
}
Status = gBS->InstallConfigurationTable (
&gFdtTableGuid,
(VOID *)(UINTN)NewFdtBase
);
if (!EFI_ERROR (Status)) {
return EFI_SUCCESS;
}
Fdt_Exit:
gBS->FreePages (UpdatedFdtBase, EFI_SIZE_TO_PAGES (NewFdtSize));
return Status;
}
EFI_STATUS
AndroidBootImgBoot (
IN VOID *Buffer,
IN UINTN BufferSize
)
{
EFI_STATUS Status;
VOID *Kernel;
UINTN KernelSize;
MEMORY_DEVICE_PATH KernelDevicePath;
EFI_HANDLE ImageHandle;
VOID *NewKernelArg;
EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
VOID *RamdiskData;
UINTN RamdiskSize;
IN VOID *FdtBase;
if ((Buffer == NULL) || (BufferSize == 0)) {
return EFI_INVALID_PARAMETER;
}
NewKernelArg = NULL;
ImageHandle = NULL;
Status = gBS->LocateProtocol (
&gAndroidBootImgProtocolGuid,
NULL,
(VOID **)&mAndroidBootImg
);
if (EFI_ERROR (Status)) {
goto Exit;
}
Status = AndroidBootImgGetKernelInfo (
Buffer,
&Kernel,
&KernelSize
);
if (EFI_ERROR (Status)) {
goto Exit;
}
Status = AndroidBootImgUpdateArgs (Buffer, &NewKernelArg);
if (EFI_ERROR (Status)) {
goto Exit;
}
Status = AndroidBootImgGetRamdiskInfo (
Buffer,
&RamdiskData,
&RamdiskSize
);
if (EFI_ERROR (Status)) {
goto Exit;
}
if (AndroidBootImgAcpiSupported ()) {
Status = AndroidBootImgInstallLoadFile2 (RamdiskData, RamdiskSize);
if (EFI_ERROR (Status)) {
goto Exit;
}
} else {
Status = AndroidBootImgLocateFdt (Buffer, &FdtBase);
if (EFI_ERROR (Status)) {
goto Exit;
}
Status = AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, RamdiskSize);
if (EFI_ERROR (Status)) {
goto Exit;
}
}
KernelDevicePath = mMemoryDevicePathTemplate;
KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Kernel;
KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Kernel
+ KernelSize;
Status = gBS->LoadImage (
TRUE,
gImageHandle,
(EFI_DEVICE_PATH *)&KernelDevicePath,
(VOID *)(UINTN)Kernel,
KernelSize,
&ImageHandle
);
if (EFI_ERROR (Status)) {
goto Exit;
}
// Set kernel arguments
Status = gBS->HandleProtocol (
ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **)&ImageInfo
);
if (EFI_ERROR (Status)) {
goto Exit;
}
ImageInfo->LoadOptions = NewKernelArg;
ImageInfo->LoadOptionsSize = StrLen (NewKernelArg) * sizeof (CHAR16);
// Before calling the image, enable the Watchdog Timer for the 5 Minute period
gBS->SetWatchdogTimer (5 * 60, 0x10000, 0, NULL);
// Start the image
Status = gBS->StartImage (ImageHandle, NULL, NULL);
// Clear the Watchdog Timer if the image returns
gBS->SetWatchdogTimer (0, 0x10000, 0, NULL);
Exit:
// Unload image as it will not be used anymore
if (ImageHandle != NULL) {
gBS->UnloadImage (ImageHandle);
ImageHandle = NULL;
}
if (EFI_ERROR (Status)) {
if (NewKernelArg != NULL) {
FreePool (NewKernelArg);
NewKernelArg = NULL;
}
}
AndroidBootImgUninstallLoadFile2 ();
return Status;
}
|