diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-15 21:04:28 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-24 18:05:53 +0100 |
commit | c876d3bbefe0dc00c27ca0c12d29da5874946962 (patch) | |
tree | 69f468a185a369b01998314bc3ecc19b70f4fcaa /utils/jztool/include | |
parent | 6c6f0757d7a902feb293be165d1490c42bc8e7ad (diff) | |
download | rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.tar.gz rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.zip |
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be
considered part of utils too. Having it in a separate folder is an
arbitrary split that doesn't help anymore these days, so merge them.
This also allows other utils to easily use libtools.make without the
need to navigate to a different folder.
Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
Diffstat (limited to 'utils/jztool/include')
-rw-r--r-- | utils/jztool/include/jztool.h | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/utils/jztool/include/jztool.h b/utils/jztool/include/jztool.h new file mode 100644 index 0000000000..9d3c08c5bc --- /dev/null +++ b/utils/jztool/include/jztool.h | |||
@@ -0,0 +1,202 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
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 | #ifndef JZTOOL_H | ||
23 | #define JZTOOL_H | ||
24 | |||
25 | #include <stdint.h> | ||
26 | #include <stddef.h> | ||
27 | |||
28 | #ifdef __cplusplus | ||
29 | extern "C" { | ||
30 | #endif | ||
31 | |||
32 | /****************************************************************************** | ||
33 | * Types, enumerations, etc | ||
34 | */ | ||
35 | |||
36 | #define JZ_CPUINFO_BUFLEN 9 | ||
37 | |||
38 | typedef struct jz_context jz_context; | ||
39 | typedef struct jz_usbdev jz_usbdev; | ||
40 | typedef struct jz_device_info jz_device_info; | ||
41 | typedef struct jz_cpu_info jz_cpu_info; | ||
42 | typedef struct jz_buffer jz_buffer; | ||
43 | |||
44 | typedef enum jz_error jz_error; | ||
45 | typedef enum jz_identify_error jz_identify_error; | ||
46 | typedef enum jz_log_level jz_log_level; | ||
47 | typedef enum jz_device_type jz_device_type; | ||
48 | typedef enum jz_cpu_type jz_cpu_type; | ||
49 | |||
50 | typedef void(*jz_log_cb)(jz_log_level, const char*); | ||
51 | |||
52 | enum jz_error { | ||
53 | JZ_SUCCESS = 0, | ||
54 | JZ_ERR_OUT_OF_MEMORY = -1, | ||
55 | JZ_ERR_OPEN_FILE = -2, | ||
56 | JZ_ERR_FILE_IO = -3, | ||
57 | JZ_ERR_USB = -4, | ||
58 | JZ_ERR_NO_DEVICE = -5, | ||
59 | JZ_ERR_BAD_FILE_FORMAT = -6, | ||
60 | JZ_ERR_FLASH_ERROR = -7, | ||
61 | JZ_ERR_OTHER = -99, | ||
62 | }; | ||
63 | |||
64 | enum jz_identify_error { | ||
65 | JZ_IDERR_OTHER = -1, | ||
66 | JZ_IDERR_WRONG_SIZE = -2, | ||
67 | JZ_IDERR_BAD_HEADER = -3, | ||
68 | JZ_IDERR_BAD_CHECKSUM = -4, | ||
69 | JZ_IDERR_UNRECOGNIZED_MODEL = -5, | ||
70 | }; | ||
71 | |||
72 | enum jz_log_level { | ||
73 | JZ_LOG_IGNORE = -1, | ||
74 | JZ_LOG_ERROR = 0, | ||
75 | JZ_LOG_WARNING = 1, | ||
76 | JZ_LOG_NOTICE = 2, | ||
77 | JZ_LOG_DETAIL = 3, | ||
78 | JZ_LOG_DEBUG = 4, | ||
79 | }; | ||
80 | |||
81 | enum jz_device_type { | ||
82 | JZ_DEVICE_FIIOM3K, | ||
83 | JZ_DEVICE_SHANLINGQ1, | ||
84 | JZ_DEVICE_EROSQ, | ||
85 | JZ_NUM_DEVICES, | ||
86 | }; | ||
87 | |||
88 | enum jz_cpu_type { | ||
89 | JZ_CPU_X1000, | ||
90 | JZ_NUM_CPUS, | ||
91 | }; | ||
92 | |||
93 | struct jz_device_info { | ||
94 | /* internal device name and file extension */ | ||
95 | const char* name; | ||
96 | const char* file_ext; | ||
97 | |||
98 | /* human-readable name */ | ||
99 | const char* description; | ||
100 | |||
101 | /* device and CPU type */ | ||
102 | jz_device_type device_type; | ||
103 | jz_cpu_type cpu_type; | ||
104 | |||
105 | /* USB IDs of the device in mass storage mode */ | ||
106 | uint16_t vendor_id; | ||
107 | uint16_t product_id; | ||
108 | }; | ||
109 | |||
110 | struct jz_cpu_info { | ||
111 | /* CPU info string, as reported by the boot ROM */ | ||
112 | const char* info_str; | ||
113 | |||
114 | /* USB IDs of the boot ROM */ | ||
115 | uint16_t vendor_id; | ||
116 | uint16_t product_id; | ||
117 | |||
118 | /* default addresses for running binaries */ | ||
119 | uint32_t stage1_load_addr; | ||
120 | uint32_t stage1_exec_addr; | ||
121 | uint32_t stage2_load_addr; | ||
122 | uint32_t stage2_exec_addr; | ||
123 | }; | ||
124 | |||
125 | struct jz_buffer { | ||
126 | size_t size; | ||
127 | uint8_t* data; | ||
128 | }; | ||
129 | |||
130 | /****************************************************************************** | ||
131 | * Library context and general functions | ||
132 | */ | ||
133 | |||
134 | jz_context* jz_context_create(void); | ||
135 | void jz_context_destroy(jz_context* jz); | ||
136 | |||
137 | void jz_context_set_user_data(jz_context* jz, void* ptr); | ||
138 | void* jz_context_get_user_data(jz_context* jz); | ||
139 | |||
140 | void jz_context_set_log_cb(jz_context* jz, jz_log_cb cb); | ||
141 | void jz_context_set_log_level(jz_context* jz, jz_log_level lev); | ||
142 | |||
143 | void jz_log(jz_context* jz, jz_log_level lev, const char* fmt, ...); | ||
144 | void jz_log_cb_stderr(jz_log_level lev, const char* msg); | ||
145 | |||
146 | void jz_sleepms(int ms); | ||
147 | |||
148 | /****************************************************************************** | ||
149 | * Device and file info | ||
150 | */ | ||
151 | |||
152 | const jz_device_info* jz_get_device_info(jz_device_type type); | ||
153 | const jz_device_info* jz_get_device_info_named(const char* name); | ||
154 | const jz_device_info* jz_get_device_info_indexed(int index); | ||
155 | |||
156 | const jz_cpu_info* jz_get_cpu_info(jz_cpu_type type); | ||
157 | const jz_cpu_info* jz_get_cpu_info_named(const char* info_str); | ||
158 | |||
159 | int jz_identify_x1000_spl(const void* data, size_t len); | ||
160 | int jz_identify_scramble_image(const void* data, size_t len); | ||
161 | |||
162 | /****************************************************************************** | ||
163 | * USB boot ROM protocol | ||
164 | */ | ||
165 | |||
166 | int jz_usb_open(jz_context* jz, jz_usbdev** devptr, uint16_t vend_id, uint16_t prod_id); | ||
167 | void jz_usb_close(jz_usbdev* dev); | ||
168 | |||
169 | int jz_usb_send(jz_usbdev* dev, uint32_t addr, size_t len, const void* data); | ||
170 | int jz_usb_recv(jz_usbdev* dev, uint32_t addr, size_t len, void* data); | ||
171 | int jz_usb_start1(jz_usbdev* dev, uint32_t addr); | ||
172 | int jz_usb_start2(jz_usbdev* dev, uint32_t addr); | ||
173 | int jz_usb_flush_caches(jz_usbdev* dev); | ||
174 | int jz_usb_get_cpu_info(jz_usbdev* dev, char* buffer, size_t buflen); | ||
175 | |||
176 | /****************************************************************************** | ||
177 | * Rockbox loader (all functions are model-specific, see docs) | ||
178 | */ | ||
179 | |||
180 | int jz_x1000_boot(jz_usbdev* dev, jz_device_type type, const char* filename); | ||
181 | |||
182 | /****************************************************************************** | ||
183 | * Buffer API and other functions | ||
184 | */ | ||
185 | |||
186 | jz_buffer* jz_buffer_alloc(size_t size, const void* data); | ||
187 | void jz_buffer_free(jz_buffer* buf); | ||
188 | |||
189 | int jz_buffer_load(jz_buffer** buf, const char* filename); | ||
190 | int jz_buffer_save(jz_buffer* buf, const char* filename); | ||
191 | |||
192 | jz_buffer* jz_ucl_unpack(const uint8_t* src, uint32_t src_len, uint32_t* dst_len); | ||
193 | |||
194 | /****************************************************************************** | ||
195 | * END | ||
196 | */ | ||
197 | |||
198 | #ifdef __cplusplus | ||
199 | } | ||
200 | #endif | ||
201 | |||
202 | #endif /* JZTOOL_H */ | ||