summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/sb1.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/imxtools/sbtools/sb1.h')
-rw-r--r--utils/imxtools/sbtools/sb1.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/utils/imxtools/sbtools/sb1.h b/utils/imxtools/sbtools/sb1.h
new file mode 100644
index 0000000000..f0a7a4ebc8
--- /dev/null
+++ b/utils/imxtools/sbtools/sb1.h
@@ -0,0 +1,111 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2012 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#ifndef __SB1_H__
22#define __SB1_H__
23
24#include <stdint.h>
25#include <stdbool.h>
26
27#include "misc.h"
28
29#define SECTOR_SIZE 512
30
31/* All fields are in big-endian BCD */
32struct sb1_version_t
33{
34 uint16_t major;
35 uint16_t pad0;
36 uint16_t minor;
37 uint16_t pad1;
38 uint16_t revision;
39 uint16_t pad2;
40};
41
42struct sb1_header_t
43{
44 uint32_t rom_version;
45 uint32_t image_size;
46 uint32_t header_size;
47 uint32_t userdata_offset;
48 uint32_t pad2;
49 uint8_t signature[4]; /* Signature "STMP" */
50 struct sb1_version_t product_ver;
51 struct sb1_version_t component_ver;
52 uint32_t drive_tag;
53} __attribute__((packed));
54
55struct sb1_cmd_header_t
56{
57 uint32_t cmd; // 31:21=cmd size, 20=critical, 19:6=size 5:4=datatype, 3:0=boot cmd
58 uint32_t addr;
59} __attribute__((packed));
60
61#define SB1_CMD_SIZE(cmd) ((cmd) >> 21)
62#define SB1_CMD_CRITICAL(cmd) !!(cmd & (1 << 20))
63#define SB1_CMD_BYTES(cmd) (((cmd) >> 6) & 0x3fff)
64#define SB1_CMD_DATATYPE(cmd) (((cmd) >> 4) & 0x3)
65#define SB1_CMD_BOOT(cmd) ((cmd) & 0xf)
66
67#define SB1_INST_LOAD 0x1
68#define SB1_INST_FILL 0x2
69#define SB1_INST_JUMP 0x3
70#define SB1_INST_CALL 0x4
71#define SB1_INST_MODE 0x5
72#define SB1_INST_SDRAM 0x6
73
74struct sb1_file_t
75{
76 struct sb1_version_t product_ver;
77 struct sb1_version_t component_ver;
78 void *data;
79 int data_size;
80};
81
82enum sb1_error_t
83{
84 SB1_SUCCESS = 0,
85 SB1_ERROR = -1,
86 SB1_OPEN_ERROR = -2,
87 SB1_READ_ERROR = -3,
88 SB1_WRITE_ERROR = -4,
89 SB1_FORMAT_ERROR = -5,
90 SB1_CHECKSUM_ERROR = -6,
91 SB1_NO_VALID_KEY = -7,
92 SB1_FIRST_CRYPTO_ERROR = -8,
93 SB1_LAST_CRYPTO_ERROR = SB1_FIRST_CRYPTO_ERROR - CRYPTO_NUM_ERRORS,
94};
95
96enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename);
97
98typedef void (*sb1_color_printf)(void *u, bool err, color_t c, const char *f, ...);
99struct sb1_file_t *sb1_read_file(const char *filename, void *u,
100 sb1_color_printf printf, enum sb1_error_t *err);
101/* use size_t(-1) to use maximum size */
102struct sb1_file_t *sb1_read_file_ex(const char *filename, size_t offset, size_t size,
103 void *u, sb1_color_printf printf, enum sb1_error_t *err);
104struct sb1_file_t *sb1_read_memory(void *buffer, size_t size, void *u,
105 sb1_color_printf printf, enum sb1_error_t *err);
106
107void sb1_dump(struct sb1_file_t *file, void *u, sb1_color_printf printf);
108void sb1_free(struct sb1_file_t *file);
109
110#endif /* __SB1_H__ */
111