summaryrefslogtreecommitdiffstats
path: root/EmbeddedPkg/Include/Library/AndroidBootImgLib.h
blob: d58a4d2d325c0ef668d4428fb661f1bd0e2bca16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** @file

  Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
  Copyright (c) 2017, Linaro.

  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef __ABOOTIMG_H__
#define __ABOOTIMG_H__

#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>

#include <Uefi/UefiBaseType.h>
#include <Uefi/UefiSpec.h>

#define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE  512

#define ANDROID_BOOT_MAGIC         "ANDROID!"
#define ANDROID_BOOT_MAGIC_LENGTH  (sizeof (ANDROID_BOOT_MAGIC) - 1)

// No documentation for this really - sizes of fields has been determined
// empirically.
#pragma pack(1)
/* https://android.googlesource.com/platform/system/core/+/master/mkbootimg/bootimg.h */
typedef struct {
  UINT8     BootMagic[ANDROID_BOOT_MAGIC_LENGTH];
  UINT32    KernelSize;
  UINT32    KernelAddress;
  UINT32    RamdiskSize;
  UINT32    RamdiskAddress;
  UINT32    SecondStageBootloaderSize;
  UINT32    SecondStageBootloaderAddress;
  UINT32    KernelTaggsAddress;
  UINT32    PageSize;
  UINT32    Reserved[2];
  CHAR8     ProductName[16];
  CHAR8     KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
  UINT32    Id[32];
} ANDROID_BOOTIMG_HEADER;
#pragma pack ()

/* Check Val (unsigned) is a power of 2 (has only one bit set) */
#define IS_POWER_OF_2(Val)  ((Val) != 0 && (((Val) & ((Val) - 1)) == 0))

/* Android boot image page size is not specified, but it should be power of 2
 * and larger than boot header */
#define IS_VALID_ANDROID_PAGE_SIZE(Val)   \
             (IS_POWER_OF_2(Val) && (Val > sizeof(ANDROID_BOOTIMG_HEADER)))

EFI_STATUS
AndroidBootImgGetImgSize (
  IN  VOID   *BootImg,
  OUT UINTN  *ImgSize
  );

EFI_STATUS
AndroidBootImgBoot (
  IN VOID   *Buffer,
  IN UINTN  BufferSize
  );

#endif /* __ABOOTIMG_H__ */