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