Commit a2199afea169c1e13881ca90a02a28e4c9ffd114
Committed by
Marek Vasut
1 parent
2c072c958b
Exists in
v2017.01-smarct4x
and in
48 other branches
usb, dfu: extract flush code into seperate function
move the flushing code into an extra function dfu_flush(), so it can be used from other code. Signed-off-by: Heiko Schocher <hs@denx.de> Cc: Lukasz Majewski <l.majewski@samsung.com> Cc: Kyungmin Park <kyungmin.park@samsung.com> Cc: Marek Vasut <marex@denx.de> Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Showing 2 changed files with 25 additions and 18 deletions Side-by-side Diff
drivers/dfu/dfu.c
... | ... | @@ -126,6 +126,28 @@ |
126 | 126 | return ret; |
127 | 127 | } |
128 | 128 | |
129 | +int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) | |
130 | +{ | |
131 | + int ret = 0; | |
132 | + | |
133 | + if (dfu->flush_medium) | |
134 | + ret = dfu->flush_medium(dfu); | |
135 | + | |
136 | + printf("\nDFU complete CRC32: 0x%08x\n", dfu->crc); | |
137 | + | |
138 | + /* clear everything */ | |
139 | + dfu_free_buf(); | |
140 | + dfu->crc = 0; | |
141 | + dfu->offset = 0; | |
142 | + dfu->i_blk_seq_num = 0; | |
143 | + dfu->i_buf_start = dfu_buf; | |
144 | + dfu->i_buf_end = dfu_buf; | |
145 | + dfu->i_buf = dfu->i_buf_start; | |
146 | + dfu->inited = 0; | |
147 | + | |
148 | + return ret; | |
149 | +} | |
150 | + | |
129 | 151 | int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) |
130 | 152 | { |
131 | 153 | int ret = 0; |
... | ... | @@ -197,24 +219,8 @@ |
197 | 219 | } |
198 | 220 | |
199 | 221 | /* end? */ |
200 | - if (size == 0) { | |
201 | - /* Now try and flush to the medium if needed. */ | |
202 | - if (dfu->flush_medium) | |
203 | - ret = dfu->flush_medium(dfu); | |
204 | - printf("\nDFU complete CRC32: 0x%08x\n", dfu->crc); | |
205 | - | |
206 | - /* clear everything */ | |
207 | - dfu_free_buf(); | |
208 | - dfu->crc = 0; | |
209 | - dfu->offset = 0; | |
210 | - dfu->i_blk_seq_num = 0; | |
211 | - dfu->i_buf_start = dfu_buf; | |
212 | - dfu->i_buf_end = dfu_buf; | |
213 | - dfu->i_buf = dfu->i_buf_start; | |
214 | - | |
215 | - dfu->inited = 0; | |
216 | - | |
217 | - } | |
222 | + if (size == 0) | |
223 | + ret = dfu_flush(dfu, buf, size, blk_seq_num); | |
218 | 224 | |
219 | 225 | return ret = 0 ? size : ret; |
220 | 226 | } |
include/dfu.h
... | ... | @@ -138,6 +138,7 @@ |
138 | 138 | |
139 | 139 | int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
140 | 140 | int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); |
141 | +int dfu_flush(struct dfu_entity *de, void *buf, int size, int blk_seq_num); | |
141 | 142 | /* Device specific */ |
142 | 143 | #ifdef CONFIG_DFU_MMC |
143 | 144 | extern int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s); |