summaryrefslogtreecommitdiff
path: root/utils/sbtools/sb.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/sbtools/sb.h')
-rw-r--r--utils/sbtools/sb.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/utils/sbtools/sb.h b/utils/sbtools/sb.h
new file mode 100644
index 0000000000..29b7d7d894
--- /dev/null
+++ b/utils/sbtools/sb.h
@@ -0,0 +1,118 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#define _ISOC99_SOURCE /* snprintf() */
23#include <sys/types.h>
24#include <sys/stat.h>
25
26#define BLOCK_SIZE 16
27
28struct sb_version_t
29{
30 uint16_t major;
31 uint16_t pad0;
32 uint16_t minor;
33 uint16_t pad1;
34 uint16_t revision;
35 uint16_t pad2;
36};
37
38struct sb_header_t
39{
40 uint8_t sha1_header[20]; /* SHA-1 of the rest of the header */
41 uint8_t signature[4]; /* Signature "STMP" */
42 uint8_t major_ver; /* Should be 1 */
43 uint8_t minor_ver; /* Should be 1 */
44 uint16_t flags;
45 uint32_t image_size; /* In blocks (=16bytes) */
46 uint32_t first_boot_tag_off; /* Offset in blocks */
47 uint32_t first_boot_sec_id; /* First bootable section ID */
48 uint16_t nr_keys; /* Number of encryption keys */
49 uint16_t key_dict_off; /* Offset to key dictionary (in blocks) */
50 uint16_t header_size; /* In blocks */
51 uint16_t nr_sections; /* Number of sections */
52 uint16_t sec_hdr_size; /* Section header size (in blocks) */
53 uint8_t rand_pad0[6]; /* Random padding */
54 uint64_t timestamp; /* In microseconds since 2000/1/1 00:00:00 */
55 struct sb_version_t product_ver;
56 struct sb_version_t component_ver;
57 uint16_t drive_tag; /* Unknown meaning */
58 uint8_t rand_pad1[6]; /* Random padding */
59} __attribute__((packed));
60
61struct sb_section_header_t
62{
63 uint32_t identifier;
64 uint32_t offset; /* In blocks */
65 uint32_t size; /* In blocks */
66 uint32_t flags;
67} __attribute__((packed));
68
69struct sb_key_dictionary_entry_t
70{
71 uint8_t hdr_cbc_mac[16]; /* CBC-MAC of the header */
72 uint8_t key[16]; /* Actual AES Key (encrypted by the global key) */
73} __attribute__((packed));
74
75#define IMAGE_MAJOR_VERSION 1
76#define IMAGE_MINOR_VERSION 1
77
78#define SECTION_BOOTABLE (1 << 0)
79#define SECTION_CLEARTEXT (1 << 1)
80
81#define SB_INST_NOP 0x0
82#define SB_INST_TAG 0x1
83#define SB_INST_LOAD 0x2
84#define SB_INST_FILL 0x3
85#define SB_INST_JUMP 0x4
86#define SB_INST_CALL 0x5
87#define SB_INST_MODE 0x6
88
89struct sb_instruction_header_t
90{
91 uint8_t checksum;
92 uint8_t opcode;
93 uint16_t zero_except_for_tag;
94} __attribute__((packed));
95
96struct sb_instruction_load_t
97{
98 struct sb_instruction_header_t hdr;
99 uint32_t addr;
100 uint32_t len;
101 uint32_t crc;
102} __attribute__((packed));
103
104struct sb_instruction_fill_t
105{
106 struct sb_instruction_header_t hdr;
107 uint32_t addr;
108 uint32_t len;
109 uint32_t pattern;
110} __attribute__((packed));
111
112struct sb_instruction_call_t
113{
114 struct sb_instruction_header_t hdr;
115 uint32_t addr;
116 uint32_t zero;
117 uint32_t arg;
118} __attribute__((packed));