1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2011 Amaury Pouly
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 /* All fields are in big-endian BCD */
39 uint8_t sha1_header
[20]; /* SHA-1 of the rest of the header */
40 uint8_t signature
[4]; /* Signature "STMP" */
41 uint8_t major_ver
; /* Should be 1 */
42 uint8_t minor_ver
; /* Should be 1 */
44 uint32_t image_size
; /* In blocks (=16bytes) */
45 uint32_t first_boot_tag_off
; /* Offset in blocks */
46 uint32_t first_boot_sec_id
; /* First bootable section ID */
47 uint16_t nr_keys
; /* Number of encryption keys */
48 uint16_t key_dict_off
; /* Offset to key dictionary (in blocks) */
49 uint16_t header_size
; /* In blocks */
50 uint16_t nr_sections
; /* Number of sections */
51 uint16_t sec_hdr_size
; /* Section header size (in blocks) */
52 uint8_t rand_pad0
[6]; /* Random padding */
53 uint64_t timestamp
; /* In microseconds since 2000/1/1 00:00:00 */
54 struct sb_version_t product_ver
;
55 struct sb_version_t component_ver
;
56 uint16_t drive_tag
; /* first tag to boot ? */
57 uint8_t rand_pad1
[6]; /* Random padding */
58 } __attribute__((packed
));
60 struct sb_section_header_t
63 uint32_t offset
; /* In blocks */
64 uint32_t size
; /* In blocks */
66 } __attribute__((packed
));
68 struct sb_key_dictionary_entry_t
70 uint8_t hdr_cbc_mac
[16]; /* CBC-MAC of the header */
71 uint8_t key
[16]; /* Actual AES Key (encrypted by the global key) */
72 } __attribute__((packed
));
74 #define IMAGE_MAJOR_VERSION 1
75 #define IMAGE_MINOR_VERSION 1
77 #define SECTION_BOOTABLE (1 << 0)
78 #define SECTION_CLEARTEXT (1 << 1)
80 #define SB_INST_NOP 0x0
81 #define SB_INST_TAG 0x1
82 #define SB_INST_LOAD 0x2
83 #define SB_INST_FILL 0x3
84 #define SB_INST_JUMP 0x4
85 #define SB_INST_CALL 0x5
86 #define SB_INST_MODE 0x6
89 #define SB_INST_LAST_TAG 1 /* for TAG */
90 #define SB_INST_LOAD_DCD 1 /* for LOAD */
91 #define SB_INST_FILL_BYTE 0 /* for FILL */
92 #define SB_INST_FILL_HWORD 1 /* for FILL */
93 #define SB_INST_FILL_WORD 2 /* for FILL */
94 #define SB_INST_HAB_EXEC 1 /* for JUMP/CALL */
96 struct sb_instruction_header_t
101 } __attribute__((packed
));
103 struct sb_instruction_common_t
105 struct sb_instruction_header_t hdr
;
109 } __attribute__((packed
));
111 struct sb_instruction_load_t
113 struct sb_instruction_header_t hdr
;
117 } __attribute__((packed
));
119 struct sb_instruction_fill_t
121 struct sb_instruction_header_t hdr
;
125 } __attribute__((packed
));
127 struct sb_instruction_mode_t
129 struct sb_instruction_header_t hdr
;
133 } __attribute__((packed
));
135 struct sb_instruction_call_t
137 struct sb_instruction_header_t hdr
;
141 } __attribute__((packed
));
143 struct sb_instruction_tag_t
145 struct sb_instruction_header_t hdr
;
146 uint32_t identifier
; /* section identifier */
147 uint32_t len
; /* length of the section */
148 uint32_t flags
; /* section flags */
149 } __attribute__((packed
));