The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* tools/mkbootimg/bootimg.h |
| 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
Jayant Chowdhary | f4bda9a | 2018-03-28 18:45:35 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 8 | ** |
Jayant Chowdhary | f4bda9a | 2018-03-28 18:45:35 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 10 | ** |
Jayant Chowdhary | f4bda9a | 2018-03-28 18:45:35 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 20 | #ifndef _BOOT_IMAGE_H_ |
| 21 | #define _BOOT_IMAGE_H_ |
| 22 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 23 | #define BOOT_MAGIC "ANDROID!" |
| 24 | #define BOOT_MAGIC_SIZE 8 |
| 25 | #define BOOT_NAME_SIZE 16 |
| 26 | #define BOOT_ARGS_SIZE 512 |
Andrew Boie | d35ce35 | 2013-08-21 15:48:40 -0700 | [diff] [blame] | 27 | #define BOOT_EXTRA_ARGS_SIZE 1024 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 28 | |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 29 | #define BOOT_HEADER_VERSION_ZERO 0 |
| 30 | /* |
| 31 | * Bootloader expects the structure of boot_img_hdr with header version |
| 32 | * BOOT_HEADER_VERSION_ZERO to be as follows: |
| 33 | */ |
| 34 | struct boot_img_hdr_v0 { |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 35 | uint8_t magic[BOOT_MAGIC_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 36 | |
Jayant Chowdhary | f4bda9a | 2018-03-28 18:45:35 -0700 | [diff] [blame] | 37 | uint32_t kernel_size; /* size in bytes */ |
| 38 | uint32_t kernel_addr; /* physical load addr */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 39 | |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 40 | uint32_t ramdisk_size; /* size in bytes */ |
| 41 | uint32_t ramdisk_addr; /* physical load addr */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 42 | |
Jayant Chowdhary | f4bda9a | 2018-03-28 18:45:35 -0700 | [diff] [blame] | 43 | uint32_t second_size; /* size in bytes */ |
| 44 | uint32_t second_addr; /* physical load addr */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 45 | |
Jayant Chowdhary | f4bda9a | 2018-03-28 18:45:35 -0700 | [diff] [blame] | 46 | uint32_t tags_addr; /* physical addr for kernel tags */ |
| 47 | uint32_t page_size; /* flash page size we assume */ |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 48 | /* |
| 49 | * version for the boot image header. |
| 50 | */ |
| 51 | uint32_t header_version; |
Sami Tolvanen | d162828 | 2016-03-14 09:08:59 -0700 | [diff] [blame] | 52 | |
| 53 | /* operating system version and security patch level; for |
| 54 | * version "A.B.C" and patch level "Y-M-D": |
| 55 | * ver = A << 14 | B << 7 | C (7 bits for each of A, B, C) |
| 56 | * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M) |
| 57 | * os_version = ver << 11 | lvl */ |
| 58 | uint32_t os_version; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 59 | |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 60 | uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */ |
Andrew Boie | d35ce35 | 2013-08-21 15:48:40 -0700 | [diff] [blame] | 61 | |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 62 | uint8_t cmdline[BOOT_ARGS_SIZE]; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 63 | |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 64 | uint32_t id[8]; /* timestamp / checksum / sha1 / etc */ |
Andrew Boie | d35ce35 | 2013-08-21 15:48:40 -0700 | [diff] [blame] | 65 | |
| 66 | /* Supplemental command line data; kept here to maintain |
| 67 | * binary compatibility with older versions of mkbootimg */ |
Rom Lemarchand | dfff829 | 2015-05-07 14:08:31 -0700 | [diff] [blame] | 68 | uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE]; |
| 69 | } __attribute__((packed)); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 70 | |
| 71 | /* |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 72 | * It is expected that callers would explicitly specify which version of the |
| 73 | * boot image header they need to use. |
| 74 | */ |
| 75 | typedef struct boot_img_hdr_v0 boot_img_hdr; |
| 76 | |
| 77 | /* When a boot header is of version BOOT_HEADER_VERSION_ZERO, the structure of boot image is as |
| 78 | * follows: |
| 79 | * |
| 80 | * +-----------------+ |
| 81 | * | boot header | 1 page |
| 82 | * +-----------------+ |
| 83 | * | kernel | n pages |
| 84 | * +-----------------+ |
| 85 | * | ramdisk | m pages |
| 86 | * +-----------------+ |
| 87 | * | second stage | o pages |
| 88 | * +-----------------+ |
| 89 | * |
| 90 | * n = (kernel_size + page_size - 1) / page_size |
| 91 | * m = (ramdisk_size + page_size - 1) / page_size |
| 92 | * o = (second_size + page_size - 1) / page_size |
| 93 | * |
| 94 | * 0. all entities are page_size aligned in flash |
| 95 | * 1. kernel and ramdisk are required (size != 0) |
| 96 | * 2. second is optional (second_size == 0 -> no second) |
| 97 | * 3. load each element (kernel, ramdisk, second) at |
| 98 | * the specified physical address (kernel_addr, etc) |
| 99 | * 4. prepare tags at tag_addr. kernel_args[] is |
| 100 | * appended to the kernel commandline in the tags. |
| 101 | * 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 102 | * 6. if second_size != 0: jump to second_addr |
| 103 | * else: jump to kernel_addr |
| 104 | */ |
| 105 | |
| 106 | #define BOOT_HEADER_VERSION_ONE 1 |
| 107 | |
| 108 | struct boot_img_hdr_v1 : public boot_img_hdr_v0 { |
| 109 | uint32_t recovery_dtbo_size; /* size in bytes for recovery DTBO image */ |
Hridya Valsaraju | 59ef43e | 2018-05-30 10:57:18 -0700 | [diff] [blame^] | 110 | uint64_t recovery_dtbo_offset; /* offset to recovery dtbo in boot image */ |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 111 | uint32_t header_size; |
| 112 | } __attribute__((packed)); |
| 113 | |
| 114 | /* When the boot image header has a version of BOOT_HEADER_VERSION_ONE, the structure of the boot |
| 115 | * image is as follows: |
| 116 | * |
| 117 | * +-----------------+ |
| 118 | * | boot header | 1 page |
| 119 | * +-----------------+ |
| 120 | * | kernel | n pages |
| 121 | * +-----------------+ |
| 122 | * | ramdisk | m pages |
| 123 | * +-----------------+ |
| 124 | * | second stage | o pages |
| 125 | * +-----------------+ |
| 126 | * | recovery dtbo | p pages |
| 127 | * +-----------------+ |
| 128 | * n = (kernel_size + page_size - 1) / page_size |
| 129 | * m = (ramdisk_size + page_size - 1) / page_size |
| 130 | * o = (second_size + page_size - 1) / page_size |
| 131 | * p = (recovery_dtbo_size + page_size - 1) / page_size |
| 132 | * |
| 133 | * 0. all entities are page_size aligned in flash |
| 134 | * 1. kernel and ramdisk are required (size != 0) |
| 135 | * 2. recovery_dtbo is required for recovery.img in non-A/B devices(recovery_dtbo_size != 0) |
| 136 | * 3. second is optional (second_size == 0 -> no second) |
Hridya Valsaraju | 59ef43e | 2018-05-30 10:57:18 -0700 | [diff] [blame^] | 137 | * 4. load each element (kernel, ramdisk, second) at |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 138 | * the specified physical address (kernel_addr, etc) |
Hridya Valsaraju | 59ef43e | 2018-05-30 10:57:18 -0700 | [diff] [blame^] | 139 | * 5. If booting to recovery mode in a non-A/B device, extract recovery dtbo and |
| 140 | * apply the correct set of overlays on the base device tree depending on the |
| 141 | * hardware/product revision. |
| 142 | * 6. prepare tags at tag_addr. kernel_args[] is |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 143 | * appended to the kernel commandline in the tags. |
Hridya Valsaraju | 59ef43e | 2018-05-30 10:57:18 -0700 | [diff] [blame^] | 144 | * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 145 | * 8. if second_size != 0: jump to second_addr |
Hridya Valsaraju | 6bacea2 | 2018-03-20 15:26:00 -0700 | [diff] [blame] | 146 | * else: jump to kernel_addr |
| 147 | */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 148 | |
| 149 | #if 0 |
| 150 | typedef struct ptentry ptentry; |
| 151 | |
| 152 | struct ptentry { |
| 153 | char name[16]; /* asciiz partition name */ |
| 154 | unsigned start; /* starting block number */ |
| 155 | unsigned length; /* length in blocks */ |
| 156 | unsigned flags; /* set to zero */ |
| 157 | }; |
| 158 | |
| 159 | /* MSM Partition Table ATAG |
| 160 | ** |
| 161 | ** length: 2 + 7 * n |
| 162 | ** atag: 0x4d534d70 |
| 163 | ** <ptentry> x n |
| 164 | */ |
| 165 | #endif |
| 166 | |
| 167 | #endif |