android_image.h 4.7 KB

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