Home | History | Annotate | Download | only in bootimg
      1 /* tools/mkbootimg/bootimg.h
      2 **
      3 ** Copyright 2007, The Android Open Source Project
      4 **
      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
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     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
     15 ** limitations under the License.
     16 */
     17 
     18 #include <stdint.h>
     19 
     20 #ifndef _BOOT_IMAGE_H_
     21 #define _BOOT_IMAGE_H_
     22 
     23 #define BOOT_MAGIC "ANDROID!"
     24 #define BOOT_MAGIC_SIZE 8
     25 #define BOOT_NAME_SIZE 16
     26 #define BOOT_ARGS_SIZE 512
     27 #define BOOT_EXTRA_ARGS_SIZE 1024
     28 
     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 {
     35     uint8_t magic[BOOT_MAGIC_SIZE];
     36 
     37     uint32_t kernel_size; /* size in bytes */
     38     uint32_t kernel_addr; /* physical load addr */
     39 
     40     uint32_t ramdisk_size; /* size in bytes */
     41     uint32_t ramdisk_addr; /* physical load addr */
     42 
     43     uint32_t second_size; /* size in bytes */
     44     uint32_t second_addr; /* physical load addr */
     45 
     46     uint32_t tags_addr; /* physical addr for kernel tags */
     47     uint32_t page_size; /* flash page size we assume */
     48     /*
     49      * version for the boot image header.
     50      */
     51     uint32_t header_version;
     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;
     59 
     60     uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
     61 
     62     uint8_t cmdline[BOOT_ARGS_SIZE];
     63 
     64     uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
     65 
     66     /* Supplemental command line data; kept here to maintain
     67      * binary compatibility with older versions of mkbootimg */
     68     uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
     69 } __attribute__((packed));
     70 
     71 /*
     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 */
    110     uint64_t recovery_dtbo_offset; /* offset to recovery dtbo in boot image */
    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)
    137  * 4. load each element (kernel, ramdisk, second) at
    138  *    the specified physical address (kernel_addr, etc)
    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
    143  *    appended to the kernel commandline in the tags.
    144  * 7. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
    145  * 8. if second_size != 0: jump to second_addr
    146  *    else: jump to kernel_addr
    147  */
    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
    168