1 /*
2  * Copyright (c) 2014 Brian Swetland
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 
9 #pragma once
10 
11 #include <stdint.h>
12 
13 typedef struct {
14     uint32_t kind;
15     uint32_t type;
16     uint32_t offset;    /* byte offset from start of file */
17     uint32_t length;    /* length in bytes */
18     uint8_t name[16];
19     uint8_t sha256[32];
20 } __attribute__ ((packed)) bootentry_file;
21 
22 typedef struct {
23     uint32_t kind;
24     union {
25         uint32_t u[15];
26         uint8_t b[60];
27     } __attribute__((packed)) u;
28 } __attribute__((packed)) bootentry_data;
29 
30 typedef struct {
31     uint32_t kind;
32     uint32_t version;       /* bootimage version */
33     uint32_t image_size;    /* byte size of entire image */
34     uint32_t entry_count;   /* number of valid bootentries */
35     uint32_t reserved[12];
36 } __attribute__((packed)) bootentry_info;
37 
38 typedef union {
39     uint32_t kind;
40     bootentry_file file;
41     bootentry_data data;
42     bootentry_info info;
43 } bootentry;
44 
45 #define BOOT_VERSION 0x00010000     /* 1.0 */
46 
47 #define BOOT_MAGIC "<lk-boot-image>"
48 #define BOOT_MAGIC_LENGTH 16
49 
50 // header (bootentry_file, but special):
51 
52 // bootentry kinds:
53 #define KIND_FILE           0x656c6966  // 'file'
54 #define KIND_BOOT_INFO      0x6f666e69  // 'info'
55 #define KIND_BOARD          0x67726174  // 'targ' board id string
56 #define KIND_BUILD          0x706d7473  // 'stmp' build id string
57 
58 // bootentry_file types:
59 #define TYPE_BOOT_IMAGE     0x746f6f62  // 'boot'
60 #define TYPE_LK             0x6b6c6b6c  // 'lklk'
61 #define TYPE_FPGA_IMAGE     0x61677066  // 'fpga'
62 #define TYPE_LINUX_KERNEL   0x6b78636c  // 'lcxk'
63 #define TYPE_LINUX_INITRD   0x64697264  // 'drid'
64 #define TYPE_DEVICE_TREE    0x74766564  // 'devt'
65 #define TYPE_SYSPARAMS      0x70737973  // 'sysp'
66 #define TYPE_UNKNOWN        0x6e6b6e75  // 'unkn'
67 
68 // first entry must be:
69 //   kind: KIND_FILE
70 //   type: TYPE_BOOT_IMAGE
71 //   offset: 0
72 //   length: 4096
73 //   name: BOOT_MAGIC
74 //   sha256: of bootentry[1..63]
75 
76 // second entry must be:
77 //   kind: KIND_BOOT_INFO
78 
79 // offsets should be multiple-of-4096
80