Lines Matching refs:dfu

98 unsigned char *dfu_get_buf(struct dfu_entity *dfu)  in dfu_get_buf()  argument
112 if (dfu->max_buf_size && dfu_buf_size > dfu->max_buf_size) in dfu_get_buf()
113 dfu_buf_size = dfu->max_buf_size; in dfu_get_buf()
140 static int dfu_write_buffer_drain(struct dfu_entity *dfu) in dfu_write_buffer_drain() argument
146 w_size = dfu->i_buf - dfu->i_buf_start; in dfu_write_buffer_drain()
151 dfu_hash_algo->hash_update(dfu_hash_algo, &dfu->crc, in dfu_write_buffer_drain()
152 dfu->i_buf_start, w_size, 0); in dfu_write_buffer_drain()
154 ret = dfu->write_medium(dfu, dfu->offset, dfu->i_buf_start, &w_size); in dfu_write_buffer_drain()
159 dfu->i_buf = dfu->i_buf_start; in dfu_write_buffer_drain()
162 dfu->offset += w_size; in dfu_write_buffer_drain()
169 void dfu_transaction_cleanup(struct dfu_entity *dfu) in dfu_transaction_cleanup() argument
172 dfu->crc = 0; in dfu_transaction_cleanup()
173 dfu->offset = 0; in dfu_transaction_cleanup()
174 dfu->i_blk_seq_num = 0; in dfu_transaction_cleanup()
175 dfu->i_buf_start = dfu_get_buf(dfu); in dfu_transaction_cleanup()
176 dfu->i_buf_end = dfu->i_buf_start; in dfu_transaction_cleanup()
177 dfu->i_buf = dfu->i_buf_start; in dfu_transaction_cleanup()
178 dfu->r_left = 0; in dfu_transaction_cleanup()
179 dfu->b_left = 0; in dfu_transaction_cleanup()
180 dfu->bad_skip = 0; in dfu_transaction_cleanup()
182 dfu->inited = 0; in dfu_transaction_cleanup()
185 int dfu_transaction_initiate(struct dfu_entity *dfu, bool read) in dfu_transaction_initiate() argument
189 if (dfu->inited) in dfu_transaction_initiate()
192 dfu_transaction_cleanup(dfu); in dfu_transaction_initiate()
194 if (dfu->i_buf_start == NULL) in dfu_transaction_initiate()
197 dfu->i_buf_end = dfu->i_buf_start + dfu_get_buf_size(); in dfu_transaction_initiate()
200 ret = dfu->get_medium_size(dfu, &dfu->r_left); in dfu_transaction_initiate()
203 debug("%s: %s %lld [B]\n", __func__, dfu->name, dfu->r_left); in dfu_transaction_initiate()
206 dfu->inited = 1; in dfu_transaction_initiate()
211 int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) in dfu_flush() argument
215 ret = dfu_write_buffer_drain(dfu); in dfu_flush()
219 if (dfu->flush_medium) in dfu_flush()
220 ret = dfu->flush_medium(dfu); in dfu_flush()
224 dfu->crc); in dfu_flush()
226 dfu_transaction_cleanup(dfu); in dfu_flush()
231 int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) in dfu_write() argument
236 __func__, dfu->name, buf, size, blk_seq_num, dfu->offset, in dfu_write()
237 (unsigned long)(dfu->i_buf - dfu->i_buf_start)); in dfu_write()
239 ret = dfu_transaction_initiate(dfu, false); in dfu_write()
243 if (dfu->i_blk_seq_num != blk_seq_num) { in dfu_write()
245 __func__, dfu->i_blk_seq_num, blk_seq_num); in dfu_write()
246 dfu_transaction_cleanup(dfu); in dfu_write()
264 dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff; in dfu_write()
267 if ((dfu->i_buf + size) > dfu->i_buf_end) { in dfu_write()
268 ret = dfu_write_buffer_drain(dfu); in dfu_write()
270 dfu_transaction_cleanup(dfu); in dfu_write()
276 if ((dfu->i_buf + size) > dfu->i_buf_end) { in dfu_write()
277 pr_err("Buffer overflow! (0x%p + 0x%x > 0x%p)\n", dfu->i_buf, in dfu_write()
278 size, dfu->i_buf_end); in dfu_write()
279 dfu_transaction_cleanup(dfu); in dfu_write()
283 memcpy(dfu->i_buf, buf, size); in dfu_write()
284 dfu->i_buf += size; in dfu_write()
287 if (size == 0 || (dfu->i_buf + size) > dfu->i_buf_end) { in dfu_write()
288 ret = dfu_write_buffer_drain(dfu); in dfu_write()
290 dfu_transaction_cleanup(dfu); in dfu_write()
298 static int dfu_read_buffer_fill(struct dfu_entity *dfu, void *buf, int size) in dfu_read_buffer_fill() argument
306 chunk = min((long)size, dfu->b_left); in dfu_read_buffer_fill()
309 memcpy(buf, dfu->i_buf, chunk); in dfu_read_buffer_fill()
312 &dfu->crc, buf, in dfu_read_buffer_fill()
315 dfu->i_buf += chunk; in dfu_read_buffer_fill()
316 dfu->b_left -= chunk; in dfu_read_buffer_fill()
325 if (dfu->r_left == 0) in dfu_read_buffer_fill()
328 dfu->i_buf = dfu->i_buf_start; in dfu_read_buffer_fill()
329 dfu->b_left = dfu->i_buf_end - dfu->i_buf_start; in dfu_read_buffer_fill()
332 if (dfu->b_left > dfu->r_left) in dfu_read_buffer_fill()
333 dfu->b_left = dfu->r_left; in dfu_read_buffer_fill()
334 ret = dfu->read_medium(dfu, dfu->offset, dfu->i_buf, in dfu_read_buffer_fill()
335 &dfu->b_left); in dfu_read_buffer_fill()
340 dfu->offset += dfu->b_left; in dfu_read_buffer_fill()
341 dfu->r_left -= dfu->b_left; in dfu_read_buffer_fill()
350 int dfu_read(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) in dfu_read() argument
355 __func__, dfu->name, buf, size, blk_seq_num, dfu->i_buf); in dfu_read()
357 ret = dfu_transaction_initiate(dfu, true); in dfu_read()
361 if (dfu->i_blk_seq_num != blk_seq_num) { in dfu_read()
363 __func__, dfu->i_blk_seq_num, blk_seq_num); in dfu_read()
367 dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff; in dfu_read()
369 ret = dfu_read_buffer_fill(dfu, buf, size); in dfu_read()
377 debug("%s: %s %s: 0x%x\n", __func__, dfu->name, in dfu_read()
378 dfu_hash_algo->name, dfu->crc); in dfu_read()
381 dfu_transaction_cleanup(dfu); in dfu_read()
387 static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt, in dfu_fill_entity() argument
394 strcpy(dfu->name, st); in dfu_fill_entity()
396 dfu->alt = alt; in dfu_fill_entity()
397 dfu->max_buf_size = 0; in dfu_fill_entity()
398 dfu->free_entity = NULL; in dfu_fill_entity()
402 if (dfu_fill_entity_mmc(dfu, devstr, s)) in dfu_fill_entity()
405 if (dfu_fill_entity_nand(dfu, devstr, s)) in dfu_fill_entity()
408 if (dfu_fill_entity_ram(dfu, devstr, s)) in dfu_fill_entity()
411 if (dfu_fill_entity_sf(dfu, devstr, s)) in dfu_fill_entity()
418 dfu_get_buf(dfu); in dfu_fill_entity()
425 struct dfu_entity *dfu, *p, *t = NULL; in dfu_free_entities() local
428 list_for_each_entry_safe_reverse(dfu, p, &dfu_list, list) { in dfu_free_entities()
429 list_del(&dfu->list); in dfu_free_entities()
430 if (dfu->free_entity) in dfu_free_entities()
431 dfu->free_entity(dfu); in dfu_free_entities()
432 t = dfu; in dfu_free_entities()
443 struct dfu_entity *dfu; in dfu_config_entities() local
458 dfu = calloc(sizeof(*dfu), dfu_alt_num); in dfu_config_entities()
459 if (!dfu) in dfu_config_entities()
464 ret = dfu_fill_entity(&dfu[i], s, alt_num_cnt, interface, in dfu_config_entities()
471 list_add_tail(&dfu[i].list, &dfu_list); in dfu_config_entities()
493 struct dfu_entity *dfu; in dfu_show_entities() local
497 list_for_each_entry(dfu, &dfu_list, list) { in dfu_show_entities()
499 dfu_get_dev_type(dfu->dev_type), dfu->alt, in dfu_show_entities()
500 dfu->name, dfu_get_layout(dfu->layout)); in dfu_show_entities()
511 struct dfu_entity *dfu; in dfu_get_entity() local
513 list_for_each_entry(dfu, &dfu_list, list) { in dfu_get_entity()
514 if (dfu->alt == alt) in dfu_get_entity()
515 return dfu; in dfu_get_entity()
523 struct dfu_entity *dfu; in dfu_get_alt() local
526 list_for_each_entry(dfu, &dfu_list, list) { in dfu_get_alt()
527 if (dfu->name[0] != '/') { in dfu_get_alt()
528 if (!strncmp(dfu->name, name, strlen(dfu->name))) in dfu_get_alt()
529 return dfu->alt; in dfu_get_alt()
541 str = strstr(dfu->name, name); in dfu_get_alt()
549 if (strlen(dfu->name) == in dfu_get_alt()
550 ((str - dfu->name) + strlen(name))) in dfu_get_alt()
551 return dfu->alt; in dfu_get_alt()
558 int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size) in dfu_write_from_mem_addr() argument
569 dfu_get_buf(dfu); in dfu_write_from_mem_addr()
578 ret = dfu_write(dfu, dp, write, i); in dfu_write_from_mem_addr()
588 ret = dfu_flush(dfu, NULL, 0, i); in dfu_write_from_mem_addr()