Home | History | Annotate | Download | only in boot
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in
     12  *    the documentation and/or other materials provided with the
     13  *    distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _BOOT_IMAGE_H_
     30 #define _BOOT_IMAGE_H_
     31 
     32 typedef struct boot_img_hdr boot_img_hdr;
     33 
     34 #define BOOT_MAGIC "ANDROID!"
     35 #define BOOT_MAGIC_SIZE 8
     36 #define BOOT_NAME_SIZE 16
     37 #define BOOT_ARGS_SIZE 512
     38 
     39 struct boot_img_hdr
     40 {
     41     unsigned char magic[BOOT_MAGIC_SIZE];
     42 
     43     unsigned kernel_size;  /* size in bytes */
     44     unsigned kernel_addr;  /* physical load addr */
     45 
     46     unsigned ramdisk_size; /* size in bytes */
     47     unsigned ramdisk_addr; /* physical load addr */
     48 
     49     unsigned second_size;  /* size in bytes */
     50     unsigned second_addr;  /* physical load addr */
     51 
     52     unsigned tags_addr;    /* physical addr for kernel tags */
     53     unsigned page_size;    /* flash page size we assume */
     54     unsigned unused[2];    /* future expansion: should be 0 */
     55 
     56     unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
     57 
     58     unsigned char cmdline[BOOT_ARGS_SIZE];
     59 
     60     unsigned id[8]; /* timestamp / checksum / sha1 / etc */
     61 };
     62 
     63 /*
     64 ** +-----------------+
     65 ** | boot header     | 1 page
     66 ** +-----------------+
     67 ** | kernel          | n pages
     68 ** +-----------------+
     69 ** | ramdisk         | m pages
     70 ** +-----------------+
     71 ** | second stage    | o pages
     72 ** +-----------------+
     73 **
     74 ** n = (kernel_size + page_size - 1) / page_size
     75 ** m = (ramdisk_size + page_size - 1) / page_size
     76 ** o = (second_size + page_size - 1) / page_size
     77 **
     78 ** 0. all entities are page_size aligned in flash
     79 ** 1. kernel and ramdisk are required (size != 0)
     80 ** 2. second is optional (second_size == 0 -> no second)
     81 ** 3. load each element (kernel, ramdisk, second) at
     82 **    the specified physical address (kernel_addr, etc)
     83 ** 4. prepare tags at tag_addr.  kernel_args[] is
     84 **    appended to the kernel commandline in the tags.
     85 ** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
     86 ** 6. if second_size != 0: jump to second_addr
     87 **    else: jump to kernel_addr
     88 */
     89 
     90 boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
     91                         void *ramdisk, unsigned ramdisk_size,
     92                         void *second, unsigned second_size,
     93                         unsigned page_size,
     94                         unsigned *bootimg_size);
     95 
     96 void bootimg_set_cmdline(boot_img_hdr *hdr, const char *cmdline);
     97 #endif
     98