3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "AndroidFastbootApp.h"
17 #define BOOT_MAGIC "ANDROID!"
18 #define BOOT_MAGIC_LENGTH sizeof (BOOT_MAGIC) - 1
20 // Check Val (unsigned) is a power of 2 (has only one bit set)
21 #define IS_POWER_OF_2(Val) (Val != 0 && ((Val & (Val - 1)) == 0))
23 // No documentation for this really - sizes of fields has been determined
27 CHAR8 BootMagic
[BOOT_MAGIC_LENGTH
];
31 UINT32 RamdiskAddress
;
32 UINT32 SecondStageBootloaderSize
;
33 UINT32 SecondStageBootloaderAddress
;
34 UINT32 KernelTaggsAddress
;
37 CHAR8 ProductName
[16];
38 CHAR8 KernelArgs
[BOOTIMG_KERNEL_ARGS_SIZE
];
40 } ANDROID_BOOTIMG_HEADER
;
43 // Find the kernel and ramdisk in an Android boot.img.
44 // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have the
45 // right magic value),
46 // return EFI_NOT_FOUND if there was no kernel in the boot.img.
47 // Note that the Ramdisk is optional - *Ramdisk won't be touched if it isn't
48 // present, but RamdiskSize will be set to 0.
53 OUT UINTN
*KernelSize
,
55 OUT UINTN
*RamdiskSize
,
59 ANDROID_BOOTIMG_HEADER
*Header
;
60 UINT8
*BootImgBytePtr
;
62 // Cast to UINT8 so we can do pointer arithmetic
63 BootImgBytePtr
= (UINT8
*) BootImg
;
65 Header
= (ANDROID_BOOTIMG_HEADER
*) BootImg
;
67 if (AsciiStrnCmp (Header
->BootMagic
, BOOT_MAGIC
, BOOT_MAGIC_LENGTH
) != 0) {
68 return EFI_INVALID_PARAMETER
;
71 if (Header
->KernelSize
== 0) {
75 ASSERT (IS_POWER_OF_2 (Header
->PageSize
));
77 *KernelSize
= Header
->KernelSize
;
78 *Kernel
= BootImgBytePtr
+ Header
->PageSize
;
79 *RamdiskSize
= Header
->RamdiskSize
;
81 if (Header
->RamdiskSize
!= 0) {
82 *Ramdisk
= (VOID
*) (BootImgBytePtr
84 + ALIGN_VALUE (Header
->KernelSize
, Header
->PageSize
));
87 AsciiStrnCpy (KernelArgs
, Header
->KernelArgs
, BOOTIMG_KERNEL_ARGS_SIZE
);