android_image.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * This is from the Android Project,
  4. * Repository: https://android.googlesource.com/platform/system/tools/mkbootimg
  5. * File: include/bootimg/bootimg.h
  6. * Commit: e55998a0f2b61b685d5eb4a486ca3a0c680b1a2f
  7. *
  8. * Copyright (C) 2007 The Android Open Source Project
  9. */
  10. #ifndef _ANDROID_IMAGE_H_
  11. #define _ANDROID_IMAGE_H_
  12. #define ANDR_BOOT_MAGIC "ANDROID!"
  13. #define ANDR_BOOT_MAGIC_SIZE 8
  14. #define ANDR_BOOT_NAME_SIZE 16
  15. #define ANDR_BOOT_ARGS_SIZE 512
  16. #define ANDR_BOOT_EXTRA_ARGS_SIZE 1024
  17. /*
  18. * It is expected that callers would explicitly specify which version of the
  19. * boot image header they need to use.
  20. */
  21. typedef struct andr_img_hdr andr_img_hdr;
  22. /* The bootloader expects the structure of andr_img_hdr with header
  23. * version 0 to be as follows: */
  24. struct andr_img_hdr {
  25. /* Must be ANDR_BOOT_MAGIC. */
  26. char magic[ANDR_BOOT_MAGIC_SIZE];
  27. u32 kernel_size; /* size in bytes */
  28. u32 kernel_addr; /* physical load addr */
  29. u32 ramdisk_size; /* size in bytes */
  30. u32 ramdisk_addr; /* physical load addr */
  31. u32 second_size; /* size in bytes */
  32. u32 second_addr; /* physical load addr */
  33. u32 tags_addr; /* physical addr for kernel tags */
  34. u32 page_size; /* flash page size we assume */
  35. /* Version of the boot image header. */
  36. u32 header_version;
  37. /* Operating system version and security patch level.
  38. * For version "A.B.C" and patch level "Y-M-D":
  39. * (7 bits for each of A, B, C; 7 bits for (Y-2000), 4 bits for M)
  40. * os_version = A[31:25] B[24:18] C[17:11] (Y-2000)[10:4] M[3:0] */
  41. u32 os_version;
  42. char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */
  43. char cmdline[ANDR_BOOT_ARGS_SIZE];
  44. u32 id[8]; /* timestamp / checksum / sha1 / etc */
  45. /* Supplemental command line data; kept here to maintain
  46. * binary compatibility with older versions of mkbootimg. */
  47. char extra_cmdline[ANDR_BOOT_EXTRA_ARGS_SIZE];
  48. /* Fields in boot_img_hdr_v1 and newer. */
  49. u32 recovery_dtbo_size; /* size in bytes for recovery DTBO/ACPIO image */
  50. u64 recovery_dtbo_offset; /* offset to recovery dtbo/acpio in boot image */
  51. u32 header_size;
  52. /* Fields in boot_img_hdr_v2 and newer. */
  53. u32 dtb_size; /* size in bytes for DTB image */
  54. u64 dtb_addr; /* physical load address for DTB image */
  55. } __attribute__((packed));
  56. /* When a boot header is of version 0, the structure of boot image is as
  57. * follows:
  58. *
  59. * +-----------------+
  60. * | boot header | 1 page
  61. * +-----------------+
  62. * | kernel | n pages
  63. * +-----------------+
  64. * | ramdisk | m pages
  65. * +-----------------+
  66. * | second stage | o pages
  67. * +-----------------+
  68. *
  69. * n = (kernel_size + page_size - 1) / page_size
  70. * m = (ramdisk_size + page_size - 1) / page_size
  71. * o = (second_size + page_size - 1) / page_size
  72. *
  73. * 0. all entities are page_size aligned in flash
  74. * 1. kernel and ramdisk are required (size != 0)
  75. * 2. second is optional (second_size == 0 -> no second)
  76. * 3. load each element (kernel, ramdisk, second) at
  77. * the specified physical address (kernel_addr, etc)
  78. * 4. prepare tags at tag_addr. kernel_args[] is
  79. * appended to the kernel commandline in the tags.
  80. * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
  81. * 6. if second_size != 0: jump to second_addr
  82. * else: jump to kernel_addr
  83. */
  84. /* When the boot image header has a version of 2, the structure of the boot
  85. * image is as follows:
  86. *
  87. * +---------------------+
  88. * | boot header | 1 page
  89. * +---------------------+
  90. * | kernel | n pages
  91. * +---------------------+
  92. * | ramdisk | m pages
  93. * +---------------------+
  94. * | second stage | o pages
  95. * +---------------------+
  96. * | recovery dtbo/acpio | p pages
  97. * +---------------------+
  98. * | dtb | q pages
  99. * +---------------------+
  100. * n = (kernel_size + page_size - 1) / page_size
  101. * m = (ramdisk_size + page_size - 1) / page_size
  102. * o = (second_size + page_size - 1) / page_size
  103. * p = (recovery_dtbo_size + page_size - 1) / page_size
  104. * q = (dtb_size + page_size - 1) / page_size
  105. *
  106. * 0. all entities are page_size aligned in flash
  107. * 1. kernel, ramdisk and DTB are required (size != 0)
  108. * 2. recovery_dtbo/recovery_acpio is required for recovery.img in non-A/B
  109. * devices(recovery_dtbo_size != 0)
  110. * 3. second is optional (second_size == 0 -> no second)
  111. * 4. load each element (kernel, ramdisk, second, dtb) at
  112. * the specified physical address (kernel_addr, etc)
  113. * 5. If booting to recovery mode in a non-A/B device, extract recovery
  114. * dtbo/acpio and apply the correct set of overlays on the base device tree
  115. * depending on the hardware/product revision.
  116. * 6. prepare tags at tag_addr. kernel_args[] is
  117. * appended to the kernel commandline in the tags.
  118. * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
  119. * 8. if second_size != 0: jump to second_addr
  120. * else: jump to kernel_addr
  121. */
  122. #endif