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
32typedef 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
39struct 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    unsigned char cmdline[BOOT_ARGS_SIZE];
58
59    unsigned id[8]; /* timestamp / checksum / sha1 / etc */
60};
61
62/*
63** +-----------------+
64** | boot header     | 1 page
65** +-----------------+
66** | kernel          | n pages
67** +-----------------+
68** | ramdisk         | m pages
69** +-----------------+
70** | second stage    | o pages
71** +-----------------+
72**
73** n = (kernel_size + page_size - 1) / page_size
74** m = (ramdisk_size + page_size - 1) / page_size
75** o = (second_size + page_size - 1) / page_size
76**
77** 0. all entities are page_size aligned in flash
78** 1. kernel and ramdisk are required (size != 0)
79** 2. second is optional (second_size == 0 -> no second)
80** 3. load each element (kernel, ramdisk, second) at
81**    the specified physical address (kernel_addr, etc)
82** 4. prepare tags at tag_addr.  kernel_args[] is
83**    appended to the kernel commandline in the tags.
84** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
85** 6. if second_size != 0: jump to second_addr
86**    else: jump to kernel_addr
87*/
88
89boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
90                        void *ramdisk, unsigned ramdisk_size,
91                        void *second, unsigned second_size,
92                        unsigned page_size,
93                        unsigned *bootimg_size);
94
95void bootimg_set_cmdline(boot_img_hdr *hdr, const char *cmdline);
96#endif
97