]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Application/AndroidFastboot/AndroidBootImg.c
BaseTools/Capsule: Do not support -o with --dump-info
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidFastboot / AndroidBootImg.c
1 /** @file
2
3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
4
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
9
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.
12
13 **/
14
15 #include "AndroidFastbootApp.h"
16
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.
23 EFI_STATUS
24 ParseAndroidBootImg (
25 IN VOID *BootImg,
26 OUT VOID **Kernel,
27 OUT UINTN *KernelSize,
28 OUT VOID **Ramdisk,
29 OUT UINTN *RamdiskSize,
30 OUT CHAR8 *KernelArgs
31 )
32 {
33 ANDROID_BOOTIMG_HEADER *Header;
34 UINT8 *BootImgBytePtr;
35
36 // Cast to UINT8 so we can do pointer arithmetic
37 BootImgBytePtr = (UINT8 *) BootImg;
38
39 Header = (ANDROID_BOOTIMG_HEADER *) BootImg;
40
41 if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC,
42 ANDROID_BOOT_MAGIC_LENGTH) != 0) {
43 return EFI_INVALID_PARAMETER;
44 }
45
46 if (Header->KernelSize == 0) {
47 return EFI_NOT_FOUND;
48 }
49
50 ASSERT (IS_VALID_ANDROID_PAGE_SIZE (Header->PageSize));
51
52 *KernelSize = Header->KernelSize;
53 *Kernel = BootImgBytePtr + Header->PageSize;
54 *RamdiskSize = Header->RamdiskSize;
55
56 if (Header->RamdiskSize != 0) {
57 *Ramdisk = (VOID *) (BootImgBytePtr
58 + Header->PageSize
59 + ALIGN_VALUE (Header->KernelSize, Header->PageSize));
60 }
61
62 AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs,
63 ANDROID_BOOTIMG_KERNEL_ARGS_SIZE);
64
65 return EFI_SUCCESS;
66 }