Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 5 | * Copyright (c) 2014,2016 The Linux Foundation. All rights reserved. |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 6 | * |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 21 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef _BOOT_IMAGE_H_ |
| 32 | #define _BOOT_IMAGE_H_ |
| 33 | |
| 34 | typedef struct boot_img_hdr boot_img_hdr; |
| 35 | |
| 36 | #define BOOT_MAGIC "ANDROID!" |
| 37 | #define BOOT_MAGIC_SIZE 8 |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 38 | #define BOOT_NAME_SIZE 16 |
| 39 | #define BOOT_ARGS_SIZE 512 |
| 40 | #define BOOT_IMG_MAX_PAGE_SIZE 4096 |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 41 | |
| 42 | struct boot_img_hdr |
| 43 | { |
| 44 | unsigned char magic[BOOT_MAGIC_SIZE]; |
| 45 | |
| 46 | unsigned kernel_size; /* size in bytes */ |
| 47 | unsigned kernel_addr; /* physical load addr */ |
| 48 | |
| 49 | unsigned ramdisk_size; /* size in bytes */ |
| 50 | unsigned ramdisk_addr; /* physical load addr */ |
| 51 | |
| 52 | unsigned second_size; /* size in bytes */ |
| 53 | unsigned second_addr; /* physical load addr */ |
| 54 | |
| 55 | unsigned tags_addr; /* physical addr for kernel tags */ |
| 56 | unsigned page_size; /* flash page size we assume */ |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 57 | #if OSVERSION_IN_BOOTIMAGE |
| 58 | uint32_t unused; /* future expansion: should be 0 */ |
| 59 | uint32_t os_version; /* version << 11 | patch_level */ |
| 60 | #else |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 61 | unsigned dt_size; /* device_tree in bytes */ |
| 62 | unsigned unused; /* future expansion: should be 0 */ |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 63 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 64 | unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */ |
| 65 | |
| 66 | unsigned char cmdline[BOOT_ARGS_SIZE]; |
| 67 | |
| 68 | unsigned id[8]; /* timestamp / checksum / sha1 / etc */ |
| 69 | }; |
| 70 | |
| 71 | /* |
| 72 | ** +-----------------+ |
| 73 | ** | boot header | 1 page |
| 74 | ** +-----------------+ |
| 75 | ** | kernel | n pages |
| 76 | ** +-----------------+ |
| 77 | ** | ramdisk | m pages |
| 78 | ** +-----------------+ |
| 79 | ** | second stage | o pages |
| 80 | ** +-----------------+ |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 81 | ** | device tree | p pages |
| 82 | ** +-----------------+ |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 83 | ** |
| 84 | ** n = (kernel_size + page_size - 1) / page_size |
| 85 | ** m = (ramdisk_size + page_size - 1) / page_size |
| 86 | ** o = (second_size + page_size - 1) / page_size |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 87 | ** p = (dt_size + page_size - 1) / page_size |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 88 | ** 0. all entities are page_size aligned in flash |
| 89 | ** 1. kernel and ramdisk are required (size != 0) |
| 90 | ** 2. second is optional (second_size == 0 -> no second) |
| 91 | ** 3. load each element (kernel, ramdisk, second) at |
| 92 | ** the specified physical address (kernel_addr, etc) |
| 93 | ** 4. prepare tags at tag_addr. kernel_args[] is |
| 94 | ** appended to the kernel commandline in the tags. |
| 95 | ** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr |
| 96 | ** 6. if second_size != 0: jump to second_addr |
| 97 | ** else: jump to kernel_addr |
| 98 | */ |
| 99 | |
| 100 | boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size, |
| 101 | void *ramdisk, unsigned ramdisk_size, |
| 102 | void *second, unsigned second_size, |
| 103 | unsigned page_size, |
| 104 | unsigned *bootimg_size); |
| 105 | |
| 106 | void bootimg_set_cmdline(boot_img_hdr *hdr, const char *cmdline); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 107 | |
| 108 | #define KERNEL64_HDR_MAGIC 0x644D5241 /* ARM64 */ |
| 109 | |
| 110 | struct kernel64_hdr |
| 111 | { |
| 112 | uint32_t insn; |
| 113 | uint32_t res1; |
| 114 | uint64_t text_offset; |
| 115 | uint64_t res2; |
| 116 | uint64_t res3; |
| 117 | uint64_t res4; |
| 118 | uint64_t res5; |
| 119 | uint64_t res6; |
| 120 | uint32_t magic_64; |
| 121 | uint32_t res7; |
| 122 | }; |
| 123 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 124 | enum |
| 125 | { |
| 126 | ERR_NO_BOOT_PTN =1, |
| 127 | ERR_NO_RECOVERY_PTN, |
| 128 | ERR_MMC_READ_FAIL, |
| 129 | ERR_INVALID_BOOT_MAGIC, |
| 130 | ERR_INVALID_PAGE_SIZE, |
| 131 | ERR_ABOOT_ADDR_OVERLAP, |
| 132 | ERR_SEND_ROT_FAIL, |
| 133 | ERR_DECOMPRESSION, |
| 134 | ERR_DT_PARSE, |
| 135 | ERR_BOOT_SIGNATURE_MISMATCH, |
| 136 | }; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 137 | #endif |