summaryrefslogtreecommitdiff
path: root/rbutil/mks5lboot/mkdfu.c
diff options
context:
space:
mode:
authorCástor Muñoz <cmvidal@gmail.com>2017-05-04 10:52:03 +0200
committerCástor Muñoz <cmvidal@gmail.com>2017-06-19 02:00:30 +0200
commitfbbba9292b07d91916d330b31e7f8644d65ff91a (patch)
tree191d6ad03986d3e469a1dc32c11f2d423601dec7 /rbutil/mks5lboot/mkdfu.c
parentcf168d4636b81e414f11ef2c69b1430302d33c3b (diff)
downloadrockbox-fbbba9292b07d91916d330b31e7f8644d65ff91a.tar.gz
rockbox-fbbba9292b07d91916d330b31e7f8644d65ff91a.zip
mks5lboot: updates
- fix Makefile to allow cross compilation - Windows: use Sleep() instead of nanosleep() - Windows: libusb now is optional - OS X: use IOKit instead of libusb - small rework on the DFU API Change-Id: Ia4b07012c098ad608594e15f6effe9c9d2164b9b
Diffstat (limited to 'rbutil/mks5lboot/mkdfu.c')
-rw-r--r--rbutil/mks5lboot/mkdfu.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/rbutil/mks5lboot/mkdfu.c b/rbutil/mks5lboot/mkdfu.c
index 6ac0daf1ac..bb1929bffd 100644
--- a/rbutil/mks5lboot/mkdfu.c
+++ b/rbutil/mks5lboot/mkdfu.c
@@ -117,7 +117,7 @@ static void put_uint32le(unsigned char* p, uint32_t x)
117 p[3] = (x >> 24) & 0xff; 117 p[3] = (x >> 24) & 0xff;
118} 118}
119 119
120#define ERROR(format, ...) \ 120#define _ERR(format, ...) \
121 do { \ 121 do { \
122 snprintf(errstr, errstrsize, "[ERR] "format, __VA_ARGS__); \ 122 snprintf(errstr, errstrsize, "[ERR] "format, __VA_ARGS__); \
123 goto error; \ 123 goto error; \
@@ -135,16 +135,16 @@ static unsigned char *load_file(char *filename, int *bufsize,
135 135
136 fd = open(filename, O_RDONLY|O_BINARY); 136 fd = open(filename, O_RDONLY|O_BINARY);
137 if (fd < 0) 137 if (fd < 0)
138 ERROR("Could not open %s for reading", filename); 138 _ERR("Could not open %s for reading", filename);
139 139
140 if (fstat(fd, &s) < 0) 140 if (fstat(fd, &s) < 0)
141 ERROR("Checking filesize of input file %s", filename); 141 _ERR("Checking filesize of input file %s", filename);
142 *bufsize = s.st_size; 142 *bufsize = s.st_size;
143 143
144 if (is_rbbl) { 144 if (is_rbbl) {
145 /* Read Rockbox header */ 145 /* Read Rockbox header */
146 if (read(fd, header, sizeof(header)) != sizeof(header)) 146 if (read(fd, header, sizeof(header)) != sizeof(header))
147 ERROR("Could not read file %s", filename); 147 _ERR("Could not read file %s", filename);
148 *bufsize -= sizeof(header); 148 *bufsize -= sizeof(header);
149 149
150 for (i = 0; i < NUM_MODELS; i++) 150 for (i = 0; i < NUM_MODELS; i++)
@@ -152,7 +152,7 @@ static unsigned char *load_file(char *filename, int *bufsize,
152 break; 152 break;
153 153
154 if (i == NUM_MODELS) 154 if (i == NUM_MODELS)
155 ERROR("Model name \"%4.4s\" unknown. " 155 _ERR("Model name \"%4.4s\" unknown. "
156 "Is this really a rockbox bootloader?", header + 4); 156 "Is this really a rockbox bootloader?", header + 4);
157 157
158 *model = &ipod_identity[i]; 158 *model = &ipod_identity[i];
@@ -160,10 +160,10 @@ static unsigned char *load_file(char *filename, int *bufsize,
160 160
161 buf = malloc(*bufsize); 161 buf = malloc(*bufsize);
162 if (buf == NULL) 162 if (buf == NULL)
163 ERROR("Could not allocate memory for %s", filename); 163 _ERR("Could not allocate memory for %s", filename);
164 164
165 if (read(fd, buf, *bufsize) != *bufsize) 165 if (read(fd, buf, *bufsize) != *bufsize)
166 ERROR("Could not read file %s", filename); 166 _ERR("Could not read file %s", filename);
167 167
168 if (is_rbbl) { 168 if (is_rbbl) {
169 /* Check checksum */ 169 /* Check checksum */
@@ -173,7 +173,7 @@ static unsigned char *load_file(char *filename, int *bufsize,
173 sum += buf[i]; 173 sum += buf[i];
174 } 174 }
175 if (sum != get_uint32be(header)) 175 if (sum != get_uint32be(header))
176 ERROR("Checksum mismatch in %s", filename); 176 _ERR("Checksum mismatch in %s", filename);
177 } 177 }
178 178
179 close(fd); 179 close(fd);
@@ -223,7 +223,7 @@ unsigned char *mkdfu(int dfu_type, char *dfu_arg, int* dfu_size,
223 } 223 }
224 } 224 }
225 if (!model) 225 if (!model)
226 ERROR("Platform name \"%s\" unknown", dfu_arg); 226 _ERR("Platform name \"%s\" unknown", dfu_arg);
227 227
228 *dfu_size = BIN_OFFSET + model->dualboot_uninstall_size; 228 *dfu_size = BIN_OFFSET + model->dualboot_uninstall_size;
229 dfu_desc = "BL uninstaller"; 229 dfu_desc = "BL uninstaller";
@@ -255,11 +255,11 @@ unsigned char *mkdfu(int dfu_type, char *dfu_arg, int* dfu_size,
255 } 255 }
256 256
257 if (*dfu_size > DFU_MAXSIZE) 257 if (*dfu_size > DFU_MAXSIZE)
258 ERROR("DFU image (%d bytes) too big", *dfu_size); 258 _ERR("DFU image (%d bytes) too big", *dfu_size);
259 259
260 dfu_buf = calloc(*dfu_size, 1); 260 dfu_buf = calloc(*dfu_size, 1);
261 if (!dfu_buf) 261 if (!dfu_buf)
262 ERROR("Could not allocate %d bytes for DFU image", *dfu_size); 262 _ERR("Could not allocate %d bytes for DFU image", *dfu_size);
263 263
264 cert_off = get_uint32le(s5l8702hdr.u.enc34.cert_off); 264 cert_off = get_uint32le(s5l8702hdr.u.enc34.cert_off);
265 cert_sz = get_uint32le(s5l8702hdr.u.enc34.cert_sz); 265 cert_sz = get_uint32le(s5l8702hdr.u.enc34.cert_sz);