summaryrefslogtreecommitdiff
path: root/utils/jztool/include/jztool.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/jztool/include/jztool.h')
-rw-r--r--utils/jztool/include/jztool.h202
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
29extern "C" {
30#endif
31
32/******************************************************************************
33 * Types, enumerations, etc
34 */
35
36#define JZ_CPUINFO_BUFLEN 9
37
38typedef struct jz_context jz_context;
39typedef struct jz_usbdev jz_usbdev;
40typedef struct jz_device_info jz_device_info;
41typedef struct jz_cpu_info jz_cpu_info;
42typedef struct jz_buffer jz_buffer;
43
44typedef enum jz_error jz_error;
45typedef enum jz_identify_error jz_identify_error;
46typedef enum jz_log_level jz_log_level;
47typedef enum jz_device_type jz_device_type;
48typedef enum jz_cpu_type jz_cpu_type;
49
50typedef void(*jz_log_cb)(jz_log_level, const char*);
51
52enum 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
64enum 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
72enum 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
81enum jz_device_type {
82 JZ_DEVICE_FIIOM3K,
83 JZ_DEVICE_SHANLINGQ1,
84 JZ_DEVICE_EROSQ,
85 JZ_NUM_DEVICES,
86};
87
88enum jz_cpu_type {
89 JZ_CPU_X1000,
90 JZ_NUM_CPUS,
91};
92
93struct 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
110struct 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
125struct jz_buffer {
126 size_t size;
127 uint8_t* data;
128};
129
130/******************************************************************************
131 * Library context and general functions
132 */
133
134jz_context* jz_context_create(void);
135void jz_context_destroy(jz_context* jz);
136
137void jz_context_set_user_data(jz_context* jz, void* ptr);
138void* jz_context_get_user_data(jz_context* jz);
139
140void jz_context_set_log_cb(jz_context* jz, jz_log_cb cb);
141void jz_context_set_log_level(jz_context* jz, jz_log_level lev);
142
143void jz_log(jz_context* jz, jz_log_level lev, const char* fmt, ...);
144void jz_log_cb_stderr(jz_log_level lev, const char* msg);
145
146void jz_sleepms(int ms);
147
148/******************************************************************************
149 * Device and file info
150 */
151
152const jz_device_info* jz_get_device_info(jz_device_type type);
153const jz_device_info* jz_get_device_info_named(const char* name);
154const jz_device_info* jz_get_device_info_indexed(int index);
155
156const jz_cpu_info* jz_get_cpu_info(jz_cpu_type type);
157const jz_cpu_info* jz_get_cpu_info_named(const char* info_str);
158
159int jz_identify_x1000_spl(const void* data, size_t len);
160int jz_identify_scramble_image(const void* data, size_t len);
161
162/******************************************************************************
163 * USB boot ROM protocol
164 */
165
166int jz_usb_open(jz_context* jz, jz_usbdev** devptr, uint16_t vend_id, uint16_t prod_id);
167void jz_usb_close(jz_usbdev* dev);
168
169int jz_usb_send(jz_usbdev* dev, uint32_t addr, size_t len, const void* data);
170int jz_usb_recv(jz_usbdev* dev, uint32_t addr, size_t len, void* data);
171int jz_usb_start1(jz_usbdev* dev, uint32_t addr);
172int jz_usb_start2(jz_usbdev* dev, uint32_t addr);
173int jz_usb_flush_caches(jz_usbdev* dev);
174int 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
180int jz_x1000_boot(jz_usbdev* dev, jz_device_type type, const char* filename);
181
182/******************************************************************************
183 * Buffer API and other functions
184 */
185
186jz_buffer* jz_buffer_alloc(size_t size, const void* data);
187void jz_buffer_free(jz_buffer* buf);
188
189int jz_buffer_load(jz_buffer** buf, const char* filename);
190int jz_buffer_save(jz_buffer* buf, const char* filename);
191
192jz_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 */