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 // Find the kernel and ramdisk in an Android boot.img.
18 // return EFI_INVALID_PARAMTER if the boot.img is invalid (i.e. doesn't have the
19 // right magic value),
20 // return EFI_NOT_FOUND if there was no kernel in the boot.img.
21 // Note that the Ramdisk is optional - *Ramdisk won't be touched if it isn't
22 // present, but RamdiskSize will be set to 0.
27 OUT UINTN
*KernelSize
,
29 OUT UINTN
*RamdiskSize
,
33 ANDROID_BOOTIMG_HEADER
*Header
;
34 UINT8
*BootImgBytePtr
;
36 // Cast to UINT8 so we can do pointer arithmetic
37 BootImgBytePtr
= (UINT8
*) BootImg
;
39 Header
= (ANDROID_BOOTIMG_HEADER
*) BootImg
;
41 if (AsciiStrnCmp ((CONST CHAR8
*)Header
->BootMagic
, ANDROID_BOOT_MAGIC
,
42 ANDROID_BOOT_MAGIC_LENGTH
) != 0) {
43 return EFI_INVALID_PARAMETER
;
46 if (Header
->KernelSize
== 0) {
50 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header
->PageSize
));
52 *KernelSize
= Header
->KernelSize
;
53 *Kernel
= BootImgBytePtr
+ Header
->PageSize
;
54 *RamdiskSize
= Header
->RamdiskSize
;
56 if (Header
->RamdiskSize
!= 0) {
57 *Ramdisk
= (VOID
*) (BootImgBytePtr
59 + ALIGN_VALUE (Header
->KernelSize
, Header
->PageSize
));
62 AsciiStrnCpyS (KernelArgs
, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
, Header
->KernelArgs
,
63 ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
);