TianoCore EDK2 master
Loading...
Searching...
No Matches
AndroidBootImg.c
Go to the documentation of this file.
1
10
11// Find the kernel and ramdisk in an Android boot.img.
12// return EFI_INVALID_PARAMETER if the boot.img is invalid (i.e. doesn't have the
13// right magic value),
14// return EFI_NOT_FOUND if there was no kernel in the boot.img.
15// Note that the Ramdisk is optional - *Ramdisk won't be touched if it isn't
16// present, but RamdiskSize will be set to 0.
18ParseAndroidBootImg (
19 IN VOID *BootImg,
20 OUT VOID **Kernel,
21 OUT UINTN *KernelSize,
22 OUT VOID **Ramdisk,
23 OUT UINTN *RamdiskSize,
24 OUT CHAR8 *KernelArgs
25 )
26{
28 UINT8 *BootImgBytePtr;
29
30 // Cast to UINT8 so we can do pointer arithmetic
31 BootImgBytePtr = (UINT8 *)BootImg;
32
33 Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
34
35 if (AsciiStrnCmp (
36 (CONST CHAR8 *)Header->BootMagic,
37 ANDROID_BOOT_MAGIC,
38 ANDROID_BOOT_MAGIC_LENGTH
39 ) != 0)
40 {
41 return EFI_INVALID_PARAMETER;
42 }
43
44 if (Header->KernelSize == 0) {
45 return EFI_NOT_FOUND;
46 }
47
48 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
49
50 *KernelSize = Header->KernelSize;
51 *Kernel = BootImgBytePtr + Header->PageSize;
52 *RamdiskSize = Header->RamdiskSize;
53
54 if (Header->RamdiskSize != 0) {
55 *Ramdisk = (VOID *)(BootImgBytePtr
56 + Header->PageSize
57 + ALIGN_VALUE (Header->KernelSize, Header->PageSize));
58 }
59
61 KernelArgs,
62 ANDROID_BOOTIMG_KERNEL_ARGS_SIZE,
63 Header->KernelArgs,
64 ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
65 );
66
67 return EFI_SUCCESS;
68}
UINT64 UINTN
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
Definition: SafeString.c:1875
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
Definition: String.c:872
#define CONST
Definition: Base.h:259
#define ALIGN_VALUE(Value, Alignment)
Definition: Base.h:948
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112