blob: 832047007dd27e3a4da71004786a9ffc8f252b86 [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 *
Abhimanyu Kapur0f79d572014-02-19 22:03:02 -08005 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
6 *
Brian Swetland9c4c0752009-01-25 16:23:50 -08007 * 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
34typedef struct boot_img_hdr boot_img_hdr;
35
36#define BOOT_MAGIC "ANDROID!"
37#define BOOT_MAGIC_SIZE 8
Abhimanyu Kapur0f79d572014-02-19 22:03:02 -080038#define BOOT_NAME_SIZE 16
39#define BOOT_ARGS_SIZE 512
40#define BOOT_IMG_MAX_PAGE_SIZE 4096
Brian Swetland9c4c0752009-01-25 16:23:50 -080041
42struct 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 */
Neeti Desai465491e2012-07-31 12:53:35 -070057 unsigned dt_size; /* device_tree in bytes */
58 unsigned unused; /* future expansion: should be 0 */
Brian Swetland9c4c0752009-01-25 16:23:50 -080059
60 unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
61
62 unsigned char cmdline[BOOT_ARGS_SIZE];
63
64 unsigned id[8]; /* timestamp / checksum / sha1 / etc */
65};
66
67/*
68** +-----------------+
69** | boot header | 1 page
70** +-----------------+
71** | kernel | n pages
72** +-----------------+
73** | ramdisk | m pages
74** +-----------------+
75** | second stage | o pages
76** +-----------------+
Neeti Desai465491e2012-07-31 12:53:35 -070077** | device tree | p pages
78** +-----------------+
Brian Swetland9c4c0752009-01-25 16:23:50 -080079**
80** n = (kernel_size + page_size - 1) / page_size
81** m = (ramdisk_size + page_size - 1) / page_size
82** o = (second_size + page_size - 1) / page_size
Neeti Desai465491e2012-07-31 12:53:35 -070083** p = (dt_size + page_size - 1) / page_size
Brian Swetland9c4c0752009-01-25 16:23:50 -080084** 0. all entities are page_size aligned in flash
85** 1. kernel and ramdisk are required (size != 0)
86** 2. second is optional (second_size == 0 -> no second)
87** 3. load each element (kernel, ramdisk, second) at
88** the specified physical address (kernel_addr, etc)
89** 4. prepare tags at tag_addr. kernel_args[] is
90** appended to the kernel commandline in the tags.
91** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
92** 6. if second_size != 0: jump to second_addr
93** else: jump to kernel_addr
94*/
95
96boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
97 void *ramdisk, unsigned ramdisk_size,
98 void *second, unsigned second_size,
99 unsigned page_size,
100 unsigned *bootimg_size);
101
102void bootimg_set_cmdline(boot_img_hdr *hdr, const char *cmdline);
Abhimanyu Kapur0f79d572014-02-19 22:03:02 -0800103
104#define KERNEL64_HDR_MAGIC 0x644D5241 /* ARM64 */
105
106struct kernel64_hdr
107{
108 uint32_t insn;
109 uint32_t res1;
110 uint64_t text_offset;
111 uint64_t res2;
112 uint64_t res3;
113 uint64_t res4;
114 uint64_t res5;
115 uint64_t res6;
116 uint32_t magic_64;
117 uint32_t res7;
118};
119
Brian Swetland9c4c0752009-01-25 16:23:50 -0800120#endif