1
2
3
4
5
6
7
8#ifndef __MXSSB_H__
9#define __MXSSB_H__
10
11#include <stdint.h>
12#include <arpa/inet.h>
13
14#define SB_BLOCK_SIZE 16
15
16#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
17#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
18
19struct sb_boot_image_version {
20 uint16_t major;
21 uint16_t pad0;
22 uint16_t minor;
23 uint16_t pad1;
24 uint16_t revision;
25 uint16_t pad2;
26};
27
28struct sb_boot_image_header {
29 union {
30
31 uint8_t digest[20];
32 struct {
33
34 uint8_t iv[16];
35 uint8_t extra[4];
36 };
37 };
38
39 uint8_t signature1[4];
40
41 uint8_t major_version;
42
43 uint8_t minor_version;
44
45 uint16_t flags;
46
47 uint32_t image_blocks;
48
49 uint32_t first_boot_tag_block;
50
51 uint32_t first_boot_section_id;
52
53 uint16_t key_count;
54
55 uint16_t key_dictionary_block;
56
57 uint16_t header_blocks;
58
59 uint16_t section_count;
60
61 uint16_t section_header_size;
62
63 uint8_t padding0[2];
64
65 uint8_t signature2[4];
66
67 uint64_t timestamp_us;
68
69 struct sb_boot_image_version
70 product_version;
71
72 struct sb_boot_image_version
73 component_version;
74
75 uint16_t drive_tag;
76
77 uint8_t padding1[6];
78};
79
80#define SB_VERSION_MAJOR 1
81#define SB_VERSION_MINOR 1
82
83
84#define SB_IMAGE_FLAG_DISPLAY_PROGRESS (1 << 0)
85#define SB_IMAGE_FLAGS_MASK SB_IMAGE_FLAG_DISPLAY_PROGRESS
86
87struct sb_key_dictionary_key {
88
89 uint8_t cbc_mac[SB_BLOCK_SIZE];
90
91 uint8_t key[SB_BLOCK_SIZE];
92};
93
94struct sb_ivt_header {
95 uint32_t header;
96 uint32_t entry;
97 uint32_t reserved1;
98 uint32_t dcd;
99 uint32_t boot_data;
100 uint32_t self;
101 uint32_t csf;
102 uint32_t reserved2;
103};
104
105#define SB_HAB_IVT_TAG 0xd1UL
106#define SB_HAB_DCD_TAG 0xd2UL
107
108#define SB_HAB_VERSION 0x40UL
109
110
111
112
113
114
115static inline uint32_t sb_hab_ivt_header(void)
116{
117 uint32_t ret = 0;
118 ret |= SB_HAB_IVT_TAG << 24;
119 ret |= sizeof(struct sb_ivt_header) << 16;
120 ret |= SB_HAB_VERSION;
121 return htonl(ret);
122}
123
124struct sb_sections_header {
125
126 uint32_t section_number;
127
128 uint32_t section_offset;
129
130 uint32_t section_size;
131
132 uint32_t section_flags;
133};
134
135#define SB_SECTION_FLAG_BOOTABLE (1 << 0)
136
137struct sb_command {
138 struct {
139 uint8_t checksum;
140 uint8_t tag;
141 uint16_t flags;
142#define ROM_TAG_CMD_FLAG_ROM_LAST_TAG 0x1
143#define ROM_LOAD_CMD_FLAG_DCD_LOAD 0x1
144#define ROM_JUMP_CMD_FLAG_HAB 0x1
145#define ROM_CALL_CMD_FLAG_HAB 0x1
146 } header;
147
148 union {
149 struct {
150 uint32_t reserved[3];
151 } nop;
152 struct {
153 uint32_t section_number;
154 uint32_t section_length;
155 uint32_t section_flags;
156 } tag;
157 struct {
158 uint32_t address;
159 uint32_t count;
160 uint32_t crc32;
161 } load;
162 struct {
163 uint32_t address;
164 uint32_t count;
165 uint32_t pattern;
166 } fill;
167 struct {
168 uint32_t address;
169 uint32_t reserved;
170
171 uint32_t argument;
172 } jump;
173 struct {
174 uint32_t address;
175 uint32_t reserved;
176
177 uint32_t argument;
178 } call;
179 struct {
180 uint32_t reserved1;
181 uint32_t reserved2;
182 uint32_t mode;
183 } mode;
184
185 };
186};
187
188
189
190
191
192
193
194
195
196
197static const struct {
198 const char *name;
199 const char *altname;
200 const uint8_t mode;
201} modetable[] = {
202 { "USB", NULL, 0x00 },
203 { "I2C", NULL, 0x01 },
204 { "SPI2_FLASH", "SPI1_FLASH", 0x02 },
205 { "SPI3_FLASH", "SPI2_FLASH", 0x03 },
206 { "NAND_BCH", NULL, 0x04 },
207 { "JTAG", NULL, 0x06 },
208 { "SPI3_EEPROM", "SPI2_EEPROM", 0x08 },
209 { "SD_SSP0", NULL, 0x09 },
210 { "SD_SSP1", NULL, 0x0A }
211};
212
213enum sb_tag {
214 ROM_NOP_CMD = 0x00,
215 ROM_TAG_CMD = 0x01,
216 ROM_LOAD_CMD = 0x02,
217 ROM_FILL_CMD = 0x03,
218 ROM_JUMP_CMD = 0x04,
219 ROM_CALL_CMD = 0x05,
220 ROM_MODE_CMD = 0x06
221};
222
223struct sb_source_entry {
224 uint8_t tag;
225 uint32_t address;
226 uint32_t flags;
227 char *filename;
228};
229
230#endif
231