Commit e7e75c70c5d5d3365606c4a76adb7ff4822d2f75
Committed by
Marek Vasut
1 parent
e6bf18dba2
Exists in
master
and in
53 other branches
dfu: make data buffer size configurable
Dfu transfer uses a buffer before writing data to the raw storage device. Make the size (in bytes) of this buffer configurable through environment variable "dfu_bufsiz". Defaut value is configurable through CONFIG_SYS_DFU_DATA_BUF_SIZE Signed-off-by: Heiko Schocher <hs@denx.de> Cc: Pantelis Antoniou <panto@antoniou-consulting.com> Cc: Tom Rini <trini@ti.com> Cc: Lukasz Majewski <l.majewski@samsung.com> Cc: Kyungmin Park <kyungmin.park@samsung.com> Cc: Marek Vasut <marex@denx.de> Cc: Wolfgang Denk <wd@denx.de> Acked-by: Tom Rini <trini@ti.com>
Showing 3 changed files with 50 additions and 9 deletions Side-by-side Diff
README
... | ... | @@ -1392,6 +1392,12 @@ |
1392 | 1392 | CONFIG_DFU_NAND |
1393 | 1393 | This enables support for exposing NAND devices via DFU. |
1394 | 1394 | |
1395 | + CONFIG_SYS_DFU_DATA_BUF_SIZE | |
1396 | + Dfu transfer uses a buffer before writing data to the | |
1397 | + raw storage device. Make the size (in bytes) of this buffer | |
1398 | + configurable. The size of this buffer is also configurable | |
1399 | + through the "dfu_bufsiz" environment variable. | |
1400 | + | |
1395 | 1401 | CONFIG_SYS_DFU_MAX_FILE_SIZE |
1396 | 1402 | When updating files rather than the raw storage device, |
1397 | 1403 | we use a static buffer to copy the file into and then write |
drivers/dfu/dfu.c
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 | */ |
21 | 21 | |
22 | 22 | #include <common.h> |
23 | +#include <errno.h> | |
23 | 24 | #include <malloc.h> |
24 | 25 | #include <mmc.h> |
25 | 26 | #include <fat.h> |
26 | 27 | |
... | ... | @@ -41,9 +42,35 @@ |
41 | 42 | return ++i; |
42 | 43 | } |
43 | 44 | |
44 | -static unsigned char __aligned(CONFIG_SYS_CACHELINE_SIZE) | |
45 | - dfu_buf[DFU_DATA_BUF_SIZE]; | |
45 | +static unsigned char *dfu_buf; | |
46 | +static unsigned long dfu_buf_size = CONFIG_SYS_DFU_DATA_BUF_SIZE; | |
46 | 47 | |
48 | +static unsigned char *dfu_free_buf(void) | |
49 | +{ | |
50 | + free(dfu_buf); | |
51 | + dfu_buf = NULL; | |
52 | + return dfu_buf; | |
53 | +} | |
54 | + | |
55 | +static unsigned char *dfu_get_buf(void) | |
56 | +{ | |
57 | + char *s; | |
58 | + | |
59 | + if (dfu_buf != NULL) | |
60 | + return dfu_buf; | |
61 | + | |
62 | + s = getenv("dfu_bufsiz"); | |
63 | + dfu_buf_size = s ? (unsigned long)simple_strtol(s, NULL, 16) : | |
64 | + CONFIG_SYS_DFU_DATA_BUF_SIZE; | |
65 | + | |
66 | + dfu_buf = memalign(CONFIG_SYS_CACHELINE_SIZE, dfu_buf_size); | |
67 | + if (dfu_buf == NULL) | |
68 | + printf("%s: Could not memalign 0x%lx bytes\n", | |
69 | + __func__, dfu_buf_size); | |
70 | + | |
71 | + return dfu_buf; | |
72 | +} | |
73 | + | |
47 | 74 | static int dfu_write_buffer_drain(struct dfu_entity *dfu) |
48 | 75 | { |
49 | 76 | long w_size; |
... | ... | @@ -87,8 +114,10 @@ |
87 | 114 | dfu->offset = 0; |
88 | 115 | dfu->bad_skip = 0; |
89 | 116 | dfu->i_blk_seq_num = 0; |
90 | - dfu->i_buf_start = dfu_buf; | |
91 | - dfu->i_buf_end = dfu_buf + sizeof(dfu_buf); | |
117 | + dfu->i_buf_start = dfu_get_buf(); | |
118 | + if (dfu->i_buf_start == NULL) | |
119 | + return -ENOMEM; | |
120 | + dfu->i_buf_end = dfu_get_buf() + dfu_buf_size; | |
92 | 121 | dfu->i_buf = dfu->i_buf_start; |
93 | 122 | |
94 | 123 | dfu->inited = 1; |
95 | 124 | |
... | ... | @@ -148,11 +177,12 @@ |
148 | 177 | printf("\nDFU complete CRC32: 0x%08x\n", dfu->crc); |
149 | 178 | |
150 | 179 | /* clear everything */ |
180 | + dfu_free_buf(); | |
151 | 181 | dfu->crc = 0; |
152 | 182 | dfu->offset = 0; |
153 | 183 | dfu->i_blk_seq_num = 0; |
154 | 184 | dfu->i_buf_start = dfu_buf; |
155 | - dfu->i_buf_end = dfu_buf + sizeof(dfu_buf); | |
185 | + dfu->i_buf_end = dfu_buf; | |
156 | 186 | dfu->i_buf = dfu->i_buf_start; |
157 | 187 | |
158 | 188 | dfu->inited = 0; |
... | ... | @@ -229,8 +259,10 @@ |
229 | 259 | dfu->i_blk_seq_num = 0; |
230 | 260 | dfu->crc = 0; |
231 | 261 | dfu->offset = 0; |
232 | - dfu->i_buf_start = dfu_buf; | |
233 | - dfu->i_buf_end = dfu_buf + sizeof(dfu_buf); | |
262 | + dfu->i_buf_start = dfu_get_buf(); | |
263 | + if (dfu->i_buf_start == NULL) | |
264 | + return -ENOMEM; | |
265 | + dfu->i_buf_end = dfu_get_buf() + dfu_buf_size; | |
234 | 266 | dfu->i_buf = dfu->i_buf_start; |
235 | 267 | dfu->b_left = 0; |
236 | 268 | |
237 | 269 | |
... | ... | @@ -257,11 +289,12 @@ |
257 | 289 | debug("%s: %s CRC32: 0x%x\n", __func__, dfu->name, dfu->crc); |
258 | 290 | puts("\nUPLOAD ... done\nCtrl+C to exit ...\n"); |
259 | 291 | |
292 | + dfu_free_buf(); | |
260 | 293 | dfu->i_blk_seq_num = 0; |
261 | 294 | dfu->crc = 0; |
262 | 295 | dfu->offset = 0; |
263 | 296 | dfu->i_buf_start = dfu_buf; |
264 | - dfu->i_buf_end = dfu_buf + sizeof(dfu_buf); | |
297 | + dfu->i_buf_end = dfu_buf; | |
265 | 298 | dfu->i_buf = dfu->i_buf_start; |
266 | 299 | dfu->b_left = 0; |
267 | 300 |
include/dfu.h
... | ... | @@ -68,7 +68,9 @@ |
68 | 68 | |
69 | 69 | #define DFU_NAME_SIZE 32 |
70 | 70 | #define DFU_CMD_BUF_SIZE 128 |
71 | -#define DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ | |
71 | +#ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE | |
72 | +#define CONFIG_SYS_DFU_DATA_BUF_SIZE (1024*1024*8) /* 8 MiB */ | |
73 | +#endif | |
72 | 74 | #ifndef CONFIG_SYS_DFU_MAX_FILE_SIZE |
73 | 75 | #define CONFIG_SYS_DFU_MAX_FILE_SIZE (4 << 20) /* 4 MiB */ |
74 | 76 | #endif |