blob: f9966a18998a45f1eaeb289004c4a4d5644d862d [file] [log] [blame]
Brian Swetland9c4c0752009-01-25 16:23:50 -08001/*
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 */
Neeti Desai465491e2012-07-31 12:53:35 -070054 unsigned dt_size; /* device_tree in bytes */
55 unsigned unused; /* future expansion: should be 0 */
Brian Swetland9c4c0752009-01-25 16:23:50 -080056
57 unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
58
59 unsigned char cmdline[BOOT_ARGS_SIZE];
60
61 unsigned id[8]; /* timestamp / checksum / sha1 / etc */
62};
63
64/*
65** +-----------------+
66** | boot header | 1 page
67** +-----------------+
68** | kernel | n pages
69** +-----------------+
70** | ramdisk | m pages
71** +-----------------+
72** | second stage | o pages
73** +-----------------+
Neeti Desai465491e2012-07-31 12:53:35 -070074** | device tree | p pages
75** +-----------------+
Brian Swetland9c4c0752009-01-25 16:23:50 -080076**
77** n = (kernel_size + page_size - 1) / page_size
78** m = (ramdisk_size + page_size - 1) / page_size
79** o = (second_size + page_size - 1) / page_size
Neeti Desai465491e2012-07-31 12:53:35 -070080** p = (dt_size + page_size - 1) / page_size
Brian Swetland9c4c0752009-01-25 16:23:50 -080081** 0. all entities are page_size aligned in flash
82** 1. kernel and ramdisk are required (size != 0)
83** 2. second is optional (second_size == 0 -> no second)
84** 3. load each element (kernel, ramdisk, second) at
85** the specified physical address (kernel_addr, etc)
86** 4. prepare tags at tag_addr. kernel_args[] is
87** appended to the kernel commandline in the tags.
88** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
89** 6. if second_size != 0: jump to second_addr
90** else: jump to kernel_addr
91*/
92
93boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
94 void *ramdisk, unsigned ramdisk_size,
95 void *second, unsigned second_size,
96 unsigned page_size,
97 unsigned *bootimg_size);
98
99void bootimg_set_cmdline(boot_img_hdr *hdr, const char *cmdline);
100#endif