diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-04-13 16:58:15 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-04-17 20:23:19 +0000 |
commit | b41d53792c4c4e4abd6d810b2765d865775f5104 (patch) | |
tree | ae3e02b961c655cd49b3c13bc895a18547ceeec1 /rbutil/jztool/include | |
parent | 1b8542490da3283dfa0ce0f3363f16eab0609815 (diff) | |
download | rockbox-b41d53792c4c4e4abd6d810b2765d865775f5104.tar.gz rockbox-b41d53792c4c4e4abd6d810b2765d865775f5104.zip |
jztool: New utility for installing a bootloader on FiiO M3K
At present, this is just a command line tool for Linux only.
Integrating this with the Rockbox utility and porting to other
platforms should be straightforward; the README contains more
information.
Change-Id: Ie66fc837a02ab13c878925360cabc9805597548a
Diffstat (limited to 'rbutil/jztool/include')
-rw-r--r-- | rbutil/jztool/include/jztool.h | 200 |
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 | ||
29 | extern "C" { | ||
30 | #endif | ||
31 | |||
32 | /****************************************************************************** | ||
33 | * Types, enumerations, etc | ||
34 | */ | ||
35 | |||
36 | typedef struct jz_context jz_context; | ||
37 | typedef struct jz_usbdev jz_usbdev; | ||
38 | typedef struct jz_device_info jz_device_info; | ||
39 | typedef struct jz_buffer jz_buffer; | ||
40 | typedef struct jz_paramlist jz_paramlist; | ||
41 | |||
42 | typedef enum jz_error jz_error; | ||
43 | typedef enum jz_identify_error jz_identify_error; | ||
44 | typedef enum jz_log_level jz_log_level; | ||
45 | typedef enum jz_device_type jz_device_type; | ||
46 | typedef enum jz_cpu_type jz_cpu_type; | ||
47 | |||
48 | typedef void(*jz_log_cb)(jz_log_level, const char*); | ||
49 | typedef int(*jz_device_action_fn)(jz_context*, jz_paramlist*); | ||
50 | |||
51 | enum 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 | |||
63 | enum 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 | |||
71 | enum 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 | |||
80 | enum jz_device_type { | ||
81 | JZ_DEVICE_FIIOM3K, | ||
82 | }; | ||
83 | |||
84 | enum jz_cpu_type { | ||
85 | JZ_CPU_X1000, | ||
86 | }; | ||
87 | |||
88 | struct 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 | |||
101 | struct jz_buffer { | ||
102 | size_t size; | ||
103 | uint8_t* data; | ||
104 | }; | ||
105 | |||
106 | /****************************************************************************** | ||
107 | * Library context and general functions | ||
108 | */ | ||
109 | |||
110 | jz_context* jz_context_create(void); | ||
111 | void jz_context_destroy(jz_context* jz); | ||
112 | |||
113 | void jz_context_set_user_data(jz_context* jz, void* ptr); | ||
114 | void* jz_context_get_user_data(jz_context* jz); | ||
115 | |||
116 | void jz_context_set_log_cb(jz_context* jz, jz_log_cb cb); | ||
117 | void jz_context_set_log_level(jz_context* jz, jz_log_level lev); | ||
118 | |||
119 | void jz_log(jz_context* jz, jz_log_level lev, const char* fmt, ...); | ||
120 | void jz_log_cb_stderr(jz_log_level lev, const char* msg); | ||
121 | |||
122 | void jz_sleepms(int ms); | ||
123 | |||
124 | /****************************************************************************** | ||
125 | * Device and file info | ||
126 | */ | ||
127 | |||
128 | int jz_get_num_device_info(void); | ||
129 | const jz_device_info* jz_get_device_info(jz_device_type type); | ||
130 | const jz_device_info* jz_get_device_info_named(const char* name); | ||
131 | const jz_device_info* jz_get_device_info_indexed(int index); | ||
132 | |||
133 | int jz_identify_x1000_spl(const void* data, size_t len); | ||
134 | int jz_identify_scramble_image(const void* data, size_t len); | ||
135 | int jz_identify_fiiom3k_bootimage(const void* data, size_t len); | ||
136 | |||
137 | /****************************************************************************** | ||
138 | * USB boot ROM protocol | ||
139 | */ | ||
140 | |||
141 | int jz_usb_open(jz_context* jz, jz_usbdev** devptr, uint16_t vend_id, uint16_t prod_id); | ||
142 | void jz_usb_close(jz_usbdev* dev); | ||
143 | |||
144 | int jz_usb_send(jz_usbdev* dev, uint32_t addr, size_t len, const void* data); | ||
145 | int jz_usb_recv(jz_usbdev* dev, uint32_t addr, size_t len, void* data); | ||
146 | int jz_usb_start1(jz_usbdev* dev, uint32_t addr); | ||
147 | int jz_usb_start2(jz_usbdev* dev, uint32_t addr); | ||
148 | int jz_usb_flush_caches(jz_usbdev* dev); | ||
149 | |||
150 | /****************************************************************************** | ||
151 | * X1000 flash protocol | ||
152 | */ | ||
153 | |||
154 | int jz_x1000_setup(jz_usbdev* dev, size_t spl_len, const void* spl_data); | ||
155 | int jz_x1000_read_flash(jz_usbdev* dev, uint32_t addr, size_t len, void* data); | ||
156 | int jz_x1000_write_flash(jz_usbdev* dev, uint32_t addr, size_t len, const void* data); | ||
157 | int jz_x1000_boot_rockbox(jz_usbdev* dev); | ||
158 | |||
159 | /****************************************************************************** | ||
160 | * FiiO M3K bootloader backup/installation | ||
161 | */ | ||
162 | |||
163 | int jz_fiiom3k_readboot(jz_usbdev* dev, jz_buffer** bufptr); | ||
164 | int jz_fiiom3k_writeboot(jz_usbdev* dev, size_t image_size, const void* image_buf); | ||
165 | int 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 | |||
169 | int jz_fiiom3k_install(jz_context* jz, jz_paramlist* pl); | ||
170 | int jz_fiiom3k_backup(jz_context* jz, jz_paramlist* pl); | ||
171 | int jz_fiiom3k_restore(jz_context* jz, jz_paramlist* pl); | ||
172 | |||
173 | /****************************************************************************** | ||
174 | * Simple buffer API | ||
175 | */ | ||
176 | |||
177 | jz_buffer* jz_buffer_alloc(size_t size, const void* data); | ||
178 | void jz_buffer_free(jz_buffer* buf); | ||
179 | |||
180 | int jz_buffer_load(jz_buffer** buf, const char* filename); | ||
181 | int jz_buffer_save(jz_buffer* buf, const char* filename); | ||
182 | |||
183 | /****************************************************************************** | ||
184 | * Parameter list | ||
185 | */ | ||
186 | |||
187 | jz_paramlist* jz_paramlist_new(void); | ||
188 | void jz_paramlist_free(jz_paramlist* pl); | ||
189 | int jz_paramlist_set(jz_paramlist* pl, const char* param, const char* value); | ||
190 | const 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 */ | ||