summaryrefslogtreecommitdiff
path: root/rbutil/jztool/include/jztool.h
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/jztool/include/jztool.h')
-rw-r--r--rbutil/jztool/include/jztool.h200
1 files changed, 200 insertions, 0 deletions
diff --git a/rbutil/jztool/include/jztool.h b/rbutil/jztool/include/jztool.h
new file mode 100644
index 0000000000..e16bc9765f
--- /dev/null
+++ b/rbutil/jztool/include/jztool.h
@@ -0,0 +1,200 @@
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
36typedef struct jz_context jz_context;
37typedef struct jz_usbdev jz_usbdev;
38typedef struct jz_device_info jz_device_info;
39typedef struct jz_buffer jz_buffer;
40typedef struct jz_paramlist jz_paramlist;
41
42typedef enum jz_error jz_error;
43typedef enum jz_identify_error jz_identify_error;
44typedef enum jz_log_level jz_log_level;
45typedef enum jz_device_type jz_device_type;
46typedef enum jz_cpu_type jz_cpu_type;
47
48typedef void(*jz_log_cb)(jz_log_level, const char*);
49typedef int(*jz_device_action_fn)(jz_context*, jz_paramlist*);
50
51enum jz_error {
52 JZ_SUCCESS = 0,
53 JZ_ERR_OUT_OF_MEMORY = -1,
54 JZ_ERR_OPEN_FILE = -2,
55 JZ_ERR_FILE_IO = -3,
56 JZ_ERR_USB = -4,
57 JZ_ERR_NO_DEVICE = -5,
58 JZ_ERR_BAD_FILE_FORMAT = -6,
59 JZ_ERR_FLASH_ERROR = -7,
60 JZ_ERR_OTHER = -99,
61};
62
63enum jz_identify_error {
64 JZ_IDERR_OTHER = -1,
65 JZ_IDERR_WRONG_SIZE = -2,
66 JZ_IDERR_BAD_HEADER = -3,
67 JZ_IDERR_BAD_CHECKSUM = -4,
68 JZ_IDERR_UNRECOGNIZED_MODEL = -5,
69};
70
71enum jz_log_level {
72 JZ_LOG_IGNORE = -1,
73 JZ_LOG_ERROR = 0,
74 JZ_LOG_WARNING = 1,
75 JZ_LOG_NOTICE = 2,
76 JZ_LOG_DETAIL = 3,
77 JZ_LOG_DEBUG = 4,
78};
79
80enum jz_device_type {
81 JZ_DEVICE_FIIOM3K,
82};
83
84enum jz_cpu_type {
85 JZ_CPU_X1000,
86};
87
88struct jz_device_info {
89 const char* name;
90 const char* description;
91 jz_device_type device_type;
92 jz_cpu_type cpu_type;
93 uint16_t vendor_id;
94 uint16_t product_id;
95 int num_actions;
96 const char* const* action_names;
97 const jz_device_action_fn* action_funcs;
98 const char* const* const* action_params;
99};
100
101struct jz_buffer {
102 size_t size;
103 uint8_t* data;
104};
105
106/******************************************************************************
107 * Library context and general functions
108 */
109
110jz_context* jz_context_create(void);
111void jz_context_destroy(jz_context* jz);
112
113void jz_context_set_user_data(jz_context* jz, void* ptr);
114void* jz_context_get_user_data(jz_context* jz);
115
116void jz_context_set_log_cb(jz_context* jz, jz_log_cb cb);
117void jz_context_set_log_level(jz_context* jz, jz_log_level lev);
118
119void jz_log(jz_context* jz, jz_log_level lev, const char* fmt, ...);
120void jz_log_cb_stderr(jz_log_level lev, const char* msg);
121
122void jz_sleepms(int ms);
123
124/******************************************************************************
125 * Device and file info
126 */
127
128int jz_get_num_device_info(void);
129const jz_device_info* jz_get_device_info(jz_device_type type);
130const jz_device_info* jz_get_device_info_named(const char* name);
131const jz_device_info* jz_get_device_info_indexed(int index);
132
133int jz_identify_x1000_spl(const void* data, size_t len);
134int jz_identify_scramble_image(const void* data, size_t len);
135int jz_identify_fiiom3k_bootimage(const void* data, size_t len);
136
137/******************************************************************************
138 * USB boot ROM protocol
139 */
140
141int jz_usb_open(jz_context* jz, jz_usbdev** devptr, uint16_t vend_id, uint16_t prod_id);
142void jz_usb_close(jz_usbdev* dev);
143
144int jz_usb_send(jz_usbdev* dev, uint32_t addr, size_t len, const void* data);
145int jz_usb_recv(jz_usbdev* dev, uint32_t addr, size_t len, void* data);
146int jz_usb_start1(jz_usbdev* dev, uint32_t addr);
147int jz_usb_start2(jz_usbdev* dev, uint32_t addr);
148int jz_usb_flush_caches(jz_usbdev* dev);
149
150/******************************************************************************
151 * X1000 flash protocol
152 */
153
154int jz_x1000_setup(jz_usbdev* dev, size_t spl_len, const void* spl_data);
155int jz_x1000_read_flash(jz_usbdev* dev, uint32_t addr, size_t len, void* data);
156int jz_x1000_write_flash(jz_usbdev* dev, uint32_t addr, size_t len, const void* data);
157int jz_x1000_boot_rockbox(jz_usbdev* dev);
158
159/******************************************************************************
160 * FiiO M3K bootloader backup/installation
161 */
162
163int jz_fiiom3k_readboot(jz_usbdev* dev, jz_buffer** bufptr);
164int jz_fiiom3k_writeboot(jz_usbdev* dev, size_t image_size, const void* image_buf);
165int jz_fiiom3k_patchboot(jz_context* jz, void* image_buf, size_t image_size,
166 const void* spl_buf, size_t spl_size,
167 const void* boot_buf, size_t boot_size);
168
169int jz_fiiom3k_install(jz_context* jz, jz_paramlist* pl);
170int jz_fiiom3k_backup(jz_context* jz, jz_paramlist* pl);
171int jz_fiiom3k_restore(jz_context* jz, jz_paramlist* pl);
172
173/******************************************************************************
174 * Simple buffer API
175 */
176
177jz_buffer* jz_buffer_alloc(size_t size, const void* data);
178void jz_buffer_free(jz_buffer* buf);
179
180int jz_buffer_load(jz_buffer** buf, const char* filename);
181int jz_buffer_save(jz_buffer* buf, const char* filename);
182
183/******************************************************************************
184 * Parameter list
185 */
186
187jz_paramlist* jz_paramlist_new(void);
188void jz_paramlist_free(jz_paramlist* pl);
189int jz_paramlist_set(jz_paramlist* pl, const char* param, const char* value);
190const char* jz_paramlist_get(jz_paramlist* pl, const char* param);
191
192/******************************************************************************
193 * END
194 */
195
196#ifdef __cplusplus
197}
198#endif
199
200#endif /* JZTOOL_H */