]>
Commit | Line | Data |
---|---|---|
f6755908 OM |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>\r | |
4 | \r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "AndroidFastbootApp.h"\r | |
16 | \r | |
17 | #define BOOT_MAGIC "ANDROID!"\r | |
18 | #define BOOT_MAGIC_LENGTH sizeof (BOOT_MAGIC) - 1\r | |
19 | \r | |
20 | // Check Val (unsigned) is a power of 2 (has only one bit set)\r | |
21 | #define IS_POWER_OF_2(Val) (Val != 0 && ((Val & (Val - 1)) == 0))\r | |
22 | \r | |
23 | // No documentation for this really - sizes of fields has been determined\r | |
24 | // empirically.\r | |
25 | #pragma pack(1)\r | |
26 | typedef struct {\r | |
27 | CHAR8 BootMagic[BOOT_MAGIC_LENGTH];\r | |
28 | UINT32 KernelSize;\r | |
29 | UINT32 KernelAddress;\r | |
30 | UINT32 RamdiskSize;\r | |
31 | UINT32 RamdiskAddress;\r | |
32 | UINT32 SecondStageBootloaderSize;\r | |
33 | UINT32 SecondStageBootloaderAddress;\r | |
34 | UINT32 KernelTaggsAddress;\r | |
35 | UINT32 PageSize;\r | |
36 | UINT32 Reserved[2];\r | |
37 | CHAR8 ProductName[16];\r | |
38 | CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];\r | |
39 | UINT32 Id[32];\r | |
40 | } ANDROID_BOOTIMG_HEADER;\r | |
41 | #pragma pack()\r | |
42 | \r | |
43 | // Find the kernel and ramdisk in an Android boot.img.\r | |
44 | // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have the\r | |
45 | // right magic value),\r | |
46 | // return EFI_NOT_FOUND if there was no kernel in the boot.img.\r | |
47 | // Note that the Ramdisk is optional - *Ramdisk won't be touched if it isn't\r | |
48 | // present, but RamdiskSize will be set to 0.\r | |
49 | EFI_STATUS\r | |
50 | ParseAndroidBootImg (\r | |
51 | IN VOID *BootImg,\r | |
52 | OUT VOID **Kernel,\r | |
53 | OUT UINTN *KernelSize,\r | |
54 | OUT VOID **Ramdisk,\r | |
55 | OUT UINTN *RamdiskSize,\r | |
56 | OUT CHAR8 *KernelArgs\r | |
57 | )\r | |
58 | {\r | |
59 | ANDROID_BOOTIMG_HEADER *Header;\r | |
60 | UINT8 *BootImgBytePtr;\r | |
61 | \r | |
62 | // Cast to UINT8 so we can do pointer arithmetic\r | |
63 | BootImgBytePtr = (UINT8 *) BootImg;\r | |
64 | \r | |
65 | Header = (ANDROID_BOOTIMG_HEADER *) BootImg;\r | |
66 | \r | |
67 | if (AsciiStrnCmp (Header->BootMagic, BOOT_MAGIC, BOOT_MAGIC_LENGTH) != 0) {\r | |
68 | return EFI_INVALID_PARAMETER;\r | |
69 | }\r | |
70 | \r | |
71 | if (Header->KernelSize == 0) {\r | |
72 | return EFI_NOT_FOUND;\r | |
73 | }\r | |
74 | \r | |
75 | ASSERT (IS_POWER_OF_2 (Header->PageSize));\r | |
76 | \r | |
77 | *KernelSize = Header->KernelSize;\r | |
78 | *Kernel = BootImgBytePtr + Header->PageSize;\r | |
79 | *RamdiskSize = Header->RamdiskSize;\r | |
80 | \r | |
81 | if (Header->RamdiskSize != 0) {\r | |
82 | *Ramdisk = (VOID *) (BootImgBytePtr\r | |
83 | + Header->PageSize\r | |
84 | + ALIGN_VALUE (Header->KernelSize, Header->PageSize));\r | |
85 | }\r | |
86 | \r | |
31090876 AB |
87 | AsciiStrnCpyS (KernelArgs, BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs,\r |
88 | BOOTIMG_KERNEL_ARGS_SIZE);\r | |
f6755908 OM |
89 | \r |
90 | return EFI_SUCCESS;\r | |
91 | }\r |