]>
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 | |
f6755908 OM |
17 | // Find the kernel and ramdisk in an Android boot.img.\r |
18 | // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have the\r | |
19 | // right magic value),\r | |
20 | // return EFI_NOT_FOUND if there was no kernel in the boot.img.\r | |
21 | // Note that the Ramdisk is optional - *Ramdisk won't be touched if it isn't\r | |
22 | // present, but RamdiskSize will be set to 0.\r | |
23 | EFI_STATUS\r | |
24 | ParseAndroidBootImg (\r | |
25 | IN VOID *BootImg,\r | |
26 | OUT VOID **Kernel,\r | |
27 | OUT UINTN *KernelSize,\r | |
28 | OUT VOID **Ramdisk,\r | |
29 | OUT UINTN *RamdiskSize,\r | |
30 | OUT CHAR8 *KernelArgs\r | |
31 | )\r | |
32 | {\r | |
33 | ANDROID_BOOTIMG_HEADER *Header;\r | |
34 | UINT8 *BootImgBytePtr;\r | |
35 | \r | |
36 | // Cast to UINT8 so we can do pointer arithmetic\r | |
37 | BootImgBytePtr = (UINT8 *) BootImg;\r | |
38 | \r | |
39 | Header = (ANDROID_BOOTIMG_HEADER *) BootImg;\r | |
40 | \r | |
6e414300 JN |
41 | if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC,\r |
42 | ANDROID_BOOT_MAGIC_LENGTH) != 0) {\r | |
f6755908 OM |
43 | return EFI_INVALID_PARAMETER;\r |
44 | }\r | |
45 | \r | |
46 | if (Header->KernelSize == 0) {\r | |
47 | return EFI_NOT_FOUND;\r | |
48 | }\r | |
49 | \r | |
6e414300 | 50 | ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));\r |
f6755908 OM |
51 | \r |
52 | *KernelSize = Header->KernelSize;\r | |
53 | *Kernel = BootImgBytePtr + Header->PageSize;\r | |
54 | *RamdiskSize = Header->RamdiskSize;\r | |
55 | \r | |
56 | if (Header->RamdiskSize != 0) {\r | |
57 | *Ramdisk = (VOID *) (BootImgBytePtr\r | |
58 | + Header->PageSize\r | |
59 | + ALIGN_VALUE (Header->KernelSize, Header->PageSize));\r | |
60 | }\r | |
61 | \r | |
6e414300 JN |
62 | AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs,\r |
63 | ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);\r | |
f6755908 OM |
64 | \r |
65 | return EFI_SUCCESS;\r | |
66 | }\r |