1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2012 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 ****************************************************************************/
29 #define SECTOR_SIZE 512
31 /* All fields are in big-endian BCD */
47 uint32_t userdata_offset
;
49 uint8_t signature
[4]; /* Signature "STMP" */
50 struct sb1_version_t product_ver
;
51 struct sb1_version_t component_ver
;
53 } __attribute__((packed
));
55 struct sb1_cmd_header_t
57 uint32_t cmd
; // 31:21=cmd size, 20=critical, 19:6=size 5:4=datatype, 3:0=boot cmd
59 } __attribute__((packed
));
61 #define SB1_CMD_MAX_SIZE 0x1ff8
63 #define SB1_CMD_SIZE(cmd) ((cmd) >> 21)
64 #define SB1_CMD_CRITICAL(cmd) !!(cmd & (1 << 20))
65 #define SB1_CMD_BYTES(cmd) (((cmd) >> 6) & 0x3fff)
66 #define SB1_CMD_DATATYPE(cmd) (((cmd) >> 4) & 0x3)
67 #define SB1_CMD_BOOT(cmd) ((cmd) & 0xf)
69 #define SB1_ADDR_SDRAM_CS(addr) ((addr) & 0x3)
70 #define SB1_ADDR_SDRAM_SZ(addr) ((addr) >> 16)
72 int sb1_sdram_size_by_index(int index
); // returns - 1 on error
73 int sb1_sdram_index_by_size(int size
); // returns -1 on error
75 #define SB1_INST_LOAD 0x1
76 #define SB1_INST_FILL 0x2
77 #define SB1_INST_JUMP 0x3
78 #define SB1_INST_CALL 0x4
79 #define SB1_INST_MODE 0x5
80 #define SB1_INST_SDRAM 0x6
82 #define SB1_DATATYPE_UINT32 0
83 #define SB1_DATATYPE_UINT16 1
84 #define SB1_DATATYPE_UINT8 2
113 uint32_t rom_version
;
114 uint32_t pad2
; // unknown meaning but copy it anyway !
116 struct sb1_version_t product_ver
;
117 struct sb1_version_t component_ver
;
119 struct sb1_inst_t
*insts
;
130 SB1_WRITE_ERROR
= -4,
131 SB1_FORMAT_ERROR
= -5,
132 SB1_CHECKSUM_ERROR
= -6,
133 SB1_NO_VALID_KEY
= -7,
134 SB1_FIRST_CRYPTO_ERROR
= -8,
135 SB1_LAST_CRYPTO_ERROR
= SB1_FIRST_CRYPTO_ERROR
- CRYPTO_NUM_ERRORS
,
138 enum sb1_error_t
sb1_write_file(struct sb1_file_t
*sb
, const char *filename
);
140 typedef void (*sb1_color_printf
)(void *u
, bool err
, color_t c
, const char *f
, ...);
141 struct sb1_file_t
*sb1_read_file(const char *filename
, void *u
,
142 sb1_color_printf printf
, enum sb1_error_t
*err
);
143 /* use size_t(-1) to use maximum size */
144 struct sb1_file_t
*sb1_read_file_ex(const char *filename
, size_t offset
, size_t size
,
145 void *u
, sb1_color_printf printf
, enum sb1_error_t
*err
);
146 struct sb1_file_t
*sb1_read_memory(void *buffer
, size_t size
, void *u
,
147 sb1_color_printf printf
, enum sb1_error_t
*err
);
149 void sb1_dump(struct sb1_file_t
*file
, void *u
, sb1_color_printf printf
);
150 void sb1_free(struct sb1_file_t
*file
);
152 #endif /* __SB1_H__ */