Rename sbinfo to sbtools and sbinfo.c to sbtoelf.c; preparing for future elftosb
[kugel-rb.git] / utils / sbtools / sb.h
blob29b7d7d894a14ee04b3ff246ed667942393577fe
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #define _ISOC99_SOURCE /* snprintf() */
23 #include <sys/types.h>
24 #include <sys/stat.h>
26 #define BLOCK_SIZE 16
28 struct sb_version_t
30 uint16_t major;
31 uint16_t pad0;
32 uint16_t minor;
33 uint16_t pad1;
34 uint16_t revision;
35 uint16_t pad2;
38 struct sb_header_t
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));
61 struct sb_section_header_t
63 uint32_t identifier;
64 uint32_t offset; /* In blocks */
65 uint32_t size; /* In blocks */
66 uint32_t flags;
67 } __attribute__((packed));
69 struct sb_key_dictionary_entry_t
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));
75 #define IMAGE_MAJOR_VERSION 1
76 #define IMAGE_MINOR_VERSION 1
78 #define SECTION_BOOTABLE (1 << 0)
79 #define SECTION_CLEARTEXT (1 << 1)
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
89 struct sb_instruction_header_t
91 uint8_t checksum;
92 uint8_t opcode;
93 uint16_t zero_except_for_tag;
94 } __attribute__((packed));
96 struct sb_instruction_load_t
98 struct sb_instruction_header_t hdr;
99 uint32_t addr;
100 uint32_t len;
101 uint32_t crc;
102 } __attribute__((packed));
104 struct sb_instruction_fill_t
106 struct sb_instruction_header_t hdr;
107 uint32_t addr;
108 uint32_t len;
109 uint32_t pattern;
110 } __attribute__((packed));
112 struct sb_instruction_call_t
114 struct sb_instruction_header_t hdr;
115 uint32_t addr;
116 uint32_t zero;
117 uint32_t arg;
118 } __attribute__((packed));