blob: e52c02be10758f3f78b04226998f22b52987d74f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski34106b22012-08-06 14:41:08 +02002/*
3 * dfu.c -- DFU back-end routines
4 *
5 * Copyright (C) 2012 Samsung Electronics
6 * author: Lukasz Majewski <l.majewski@samsung.com>
Lukasz Majewski34106b22012-08-06 14:41:08 +02007 */
8
9#include <common.h>
10#include <malloc.h>
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +000011#include <errno.h>
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000012#include <div64.h>
Lukasz Majewski34106b22012-08-06 14:41:08 +020013#include <dfu.h>
Stephen Warren020e6f32014-06-11 12:47:27 -060014#include <ext4fs.h>
15#include <fat.h>
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010016#include <mmc.h>
Lukasz Majewski34106b22012-08-06 14:41:08 +020017
Przemyslaw Marczak9d6d51a2015-03-04 14:01:23 +010018static unsigned char *dfu_file_buf;
Patrick Delaunayf4e934f2017-07-19 16:39:23 +020019static u64 dfu_file_buf_len;
Stephen Warren7ae42bd2015-09-04 22:03:47 -060020static long dfu_file_buf_filled;
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000021
Afzal Mohammedb9a4a6b2013-09-18 01:14:50 +053022static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000023 u64 offset, void *buf, long *len)
Lukasz Majewski34106b22012-08-06 14:41:08 +020024{
Przemyslaw Marczak95a29472014-12-15 10:34:09 +010025 struct mmc *mmc;
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010026 u32 blk_start, blk_count, n = 0;
Lukasz Majewski4da65ea2014-05-09 16:58:15 +020027 int ret, part_num_bkp = 0;
Lukasz Majewski34106b22012-08-06 14:41:08 +020028
Przemyslaw Marczak95a29472014-12-15 10:34:09 +010029 mmc = find_mmc_device(dfu->data.mmc.dev_num);
30 if (!mmc) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090031 pr_err("Device MMC %d - not found!", dfu->data.mmc.dev_num);
Przemyslaw Marczak95a29472014-12-15 10:34:09 +010032 return -ENODEV;
33 }
34
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000035 /*
36 * We must ensure that we work in lba_blk_size chunks, so ALIGN
37 * this value.
38 */
39 *len = ALIGN(*len, dfu->data.mmc.lba_blk_size);
Lukasz Majewski34106b22012-08-06 14:41:08 +020040
Pantelis Antonioua6e788d2013-03-14 05:32:48 +000041 blk_start = dfu->data.mmc.lba_start +
42 (u32)lldiv(offset, dfu->data.mmc.lba_blk_size);
43 blk_count = *len / dfu->data.mmc.lba_blk_size;
44 if (blk_start + blk_count >
45 dfu->data.mmc.lba_start + dfu->data.mmc.lba_size) {
46 puts("Request would exceed designated area!\n");
47 return -EINVAL;
48 }
49
Lukasz Majewski4da65ea2014-05-09 16:58:15 +020050 if (dfu->data.mmc.hw_partition >= 0) {
Simon Glassaa7620b2016-06-12 23:30:33 -060051 part_num_bkp = mmc_get_blk_desc(mmc)->hwpart;
Simon Glass11f2bb62016-05-01 13:52:29 -060052 ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
53 dfu->data.mmc.dev_num,
54 dfu->data.mmc.hw_partition);
Lukasz Majewski4da65ea2014-05-09 16:58:15 +020055 if (ret)
56 return ret;
57 }
58
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010059 debug("%s: %s dev: %d start: %d cnt: %d buf: 0x%p\n", __func__,
Stephen Warren4afe50f2014-06-11 16:03:33 -060060 op == DFU_OP_READ ? "MMC READ" : "MMC WRITE",
61 dfu->data.mmc.dev_num, blk_start, blk_count, buf);
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010062 switch (op) {
63 case DFU_OP_READ:
Simon Glassaa7620b2016-06-12 23:30:33 -060064 n = blk_dread(mmc_get_blk_desc(mmc), blk_start, blk_count, buf);
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010065 break;
66 case DFU_OP_WRITE:
Simon Glassaa7620b2016-06-12 23:30:33 -060067 n = blk_dwrite(mmc_get_blk_desc(mmc), blk_start, blk_count,
68 buf);
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010069 break;
70 default:
Masahiro Yamada81e10422017-09-16 14:10:41 +090071 pr_err("Operation not supported\n");
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010072 }
73
74 if (n != blk_count) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090075 pr_err("MMC operation failed");
Lukasz Majewski4da65ea2014-05-09 16:58:15 +020076 if (dfu->data.mmc.hw_partition >= 0)
Simon Glass11f2bb62016-05-01 13:52:29 -060077 blk_select_hwpart_devnum(IF_TYPE_MMC,
78 dfu->data.mmc.dev_num,
79 part_num_bkp);
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010080 return -EIO;
81 }
Lukasz Majewski34106b22012-08-06 14:41:08 +020082
Lukasz Majewski4da65ea2014-05-09 16:58:15 +020083 if (dfu->data.mmc.hw_partition >= 0) {
Simon Glass11f2bb62016-05-01 13:52:29 -060084 ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
85 dfu->data.mmc.dev_num,
86 part_num_bkp);
Lukasz Majewski4da65ea2014-05-09 16:58:15 +020087 if (ret)
88 return ret;
89 }
90
Łukasz Majewskicf6d7db2014-02-21 08:23:00 +010091 return 0;
Lukasz Majewski34106b22012-08-06 14:41:08 +020092}
93
Afzal Mohammedb9a4a6b2013-09-18 01:14:50 +053094static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu,
Marek Szyprowski46901132019-12-02 12:11:15 +010095 u64 offset, void *buf, u64 *len)
Lukasz Majewski34106b22012-08-06 14:41:08 +020096{
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +010097 char dev_part_str[8];
Lukasz Majewski34106b22012-08-06 14:41:08 +020098 int ret;
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +010099 int fstype;
100 loff_t size = 0;
Lukasz Majewski34106b22012-08-06 14:41:08 +0200101
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000102 switch (dfu->layout) {
103 case DFU_FS_FAT:
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +0100104 fstype = FS_TYPE_FAT;
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000105 break;
106 case DFU_FS_EXT4:
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +0100107 fstype = FS_TYPE_EXT;
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000108 break;
109 default:
110 printf("%s: Layout (%s) not (yet) supported!\n", __func__,
111 dfu_get_layout(dfu->layout));
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000112 return -1;
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000113 }
Lukasz Majewski34106b22012-08-06 14:41:08 +0200114
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +0100115 snprintf(dev_part_str, sizeof(dev_part_str), "%d:%d",
116 dfu->data.mmc.dev, dfu->data.mmc.part);
117
118 ret = fs_set_blk_dev("mmc", dev_part_str, fstype);
119 if (ret) {
120 puts("dfu: fs_set_blk_dev error!\n");
121 return ret;
122 }
123
Stephen Warren020e6f32014-06-11 12:47:27 -0600124 switch (op) {
125 case DFU_OP_READ:
Marek Szyprowski46901132019-12-02 12:11:15 +0100126 ret = fs_read(dfu->name, (size_t)buf, offset, 0, &size);
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +0100127 if (ret) {
128 puts("dfu: fs_read error!\n");
129 return ret;
130 }
131 *len = size;
Stephen Warren020e6f32014-06-11 12:47:27 -0600132 break;
133 case DFU_OP_WRITE:
Marek Szyprowski46901132019-12-02 12:11:15 +0100134 ret = fs_write(dfu->name, (size_t)buf, offset, *len, &size);
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +0100135 if (ret) {
136 puts("dfu: fs_write error!\n");
137 return ret;
138 }
Stephen Warren020e6f32014-06-11 12:47:27 -0600139 break;
140 case DFU_OP_SIZE:
Simon Goldschmidt59fdf2e2019-01-25 19:58:01 +0100141 ret = fs_size(dfu->name, &size);
142 if (ret) {
143 puts("dfu: fs_size error!\n");
144 return ret;
145 }
146 *len = size;
Stephen Warren020e6f32014-06-11 12:47:27 -0600147 break;
148 default:
149 return -1;
150 }
151
Marek Szyprowski46901132019-12-02 12:11:15 +0100152 return ret;
153}
154
155static int mmc_file_buf_write(struct dfu_entity *dfu, u64 offset, void *buf, long *len)
156{
157 if (dfu_file_buf_len + *len > CONFIG_SYS_DFU_MAX_FILE_SIZE) {
158 dfu_file_buf_len = 0;
159 return -EINVAL;
160 }
161
162 /* Add to the current buffer. */
163 memcpy(dfu_file_buf + dfu_file_buf_len, buf, *len);
164 dfu_file_buf_len += *len;
165
166 return 0;
167}
168
169static int mmc_file_buf_write_finish(struct dfu_entity *dfu)
170{
171 int ret = mmc_file_op(DFU_OP_WRITE, dfu, 0, dfu_file_buf,
172 &dfu_file_buf_len);
173
174 /* Now that we're done */
175 dfu_file_buf_len = 0;
Lukasz Majewski34106b22012-08-06 14:41:08 +0200176 return ret;
177}
178
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000179int dfu_write_medium_mmc(struct dfu_entity *dfu,
180 u64 offset, void *buf, long *len)
Lukasz Majewski34106b22012-08-06 14:41:08 +0200181{
182 int ret = -1;
183
184 switch (dfu->layout) {
185 case DFU_RAW_ADDR:
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000186 ret = mmc_block_op(DFU_OP_WRITE, dfu, offset, buf, len);
Lukasz Majewski34106b22012-08-06 14:41:08 +0200187 break;
188 case DFU_FS_FAT:
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000189 case DFU_FS_EXT4:
Marek Szyprowski46901132019-12-02 12:11:15 +0100190 ret = mmc_file_buf_write(dfu, offset, buf, len);
Lukasz Majewski34106b22012-08-06 14:41:08 +0200191 break;
192 default:
193 printf("%s: Layout (%s) not (yet) supported!\n", __func__,
194 dfu_get_layout(dfu->layout));
195 }
196
197 return ret;
198}
199
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000200int dfu_flush_medium_mmc(struct dfu_entity *dfu)
201{
202 int ret = 0;
203
204 if (dfu->layout != DFU_RAW_ADDR) {
205 /* Do stuff here. */
Marek Szyprowski46901132019-12-02 12:11:15 +0100206 ret = mmc_file_buf_write_finish(dfu);
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000207 }
208
209 return ret;
210}
211
Patrick Delaunayf4e934f2017-07-19 16:39:23 +0200212int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size)
Stephen Warren020e6f32014-06-11 12:47:27 -0600213{
214 int ret;
Stephen Warren020e6f32014-06-11 12:47:27 -0600215
216 switch (dfu->layout) {
217 case DFU_RAW_ADDR:
Patrick Delaunay5ea9b892017-07-19 16:39:22 +0200218 *size = dfu->data.mmc.lba_size * dfu->data.mmc.lba_blk_size;
219 return 0;
Stephen Warren020e6f32014-06-11 12:47:27 -0600220 case DFU_FS_FAT:
221 case DFU_FS_EXT4:
Stephen Warren7ae42bd2015-09-04 22:03:47 -0600222 dfu_file_buf_filled = -1;
Marek Szyprowski46901132019-12-02 12:11:15 +0100223 ret = mmc_file_op(DFU_OP_SIZE, dfu, 0, NULL, size);
Stephen Warren020e6f32014-06-11 12:47:27 -0600224 if (ret < 0)
225 return ret;
Patrick Delaunay5ea9b892017-07-19 16:39:22 +0200226 if (*size > CONFIG_SYS_DFU_MAX_FILE_SIZE)
Stephen Warren7ae42bd2015-09-04 22:03:47 -0600227 return -1;
Patrick Delaunay5ea9b892017-07-19 16:39:22 +0200228 return 0;
Stephen Warren020e6f32014-06-11 12:47:27 -0600229 default:
230 printf("%s: Layout (%s) not (yet) supported!\n", __func__,
231 dfu_get_layout(dfu->layout));
232 return -1;
233 }
Stephen Warren7ae42bd2015-09-04 22:03:47 -0600234}
235
Marek Szyprowski46901132019-12-02 12:11:15 +0100236
237static int mmc_file_buf_read(struct dfu_entity *dfu, u64 offset, void *buf,
Stephen Warren7ae42bd2015-09-04 22:03:47 -0600238 long *len)
239{
240 int ret;
Patrick Delaunayf4e934f2017-07-19 16:39:23 +0200241 u64 file_len;
Stephen Warren7ae42bd2015-09-04 22:03:47 -0600242
243 if (dfu_file_buf_filled == -1) {
Marek Szyprowski46901132019-12-02 12:11:15 +0100244 ret = mmc_file_op(DFU_OP_READ, dfu, 0, dfu_file_buf, &file_len);
Stephen Warren7ae42bd2015-09-04 22:03:47 -0600245 if (ret < 0)
246 return ret;
247 dfu_file_buf_filled = file_len;
248 }
249 if (offset + *len > dfu_file_buf_filled)
250 return -EINVAL;
251
252 /* Add to the current buffer. */
253 memcpy(buf, dfu_file_buf + offset, *len);
254
255 return 0;
Stephen Warren020e6f32014-06-11 12:47:27 -0600256}
257
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000258int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf,
259 long *len)
Lukasz Majewski34106b22012-08-06 14:41:08 +0200260{
261 int ret = -1;
262
263 switch (dfu->layout) {
264 case DFU_RAW_ADDR:
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000265 ret = mmc_block_op(DFU_OP_READ, dfu, offset, buf, len);
Lukasz Majewski34106b22012-08-06 14:41:08 +0200266 break;
267 case DFU_FS_FAT:
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000268 case DFU_FS_EXT4:
Marek Szyprowski46901132019-12-02 12:11:15 +0100269 ret = mmc_file_buf_read(dfu, offset, buf, len);
Lukasz Majewski34106b22012-08-06 14:41:08 +0200270 break;
271 default:
272 printf("%s: Layout (%s) not (yet) supported!\n", __func__,
273 dfu_get_layout(dfu->layout));
274 }
275
276 return ret;
277}
278
Przemyslaw Marczak9d6d51a2015-03-04 14:01:23 +0100279void dfu_free_entity_mmc(struct dfu_entity *dfu)
280{
281 if (dfu_file_buf) {
282 free(dfu_file_buf);
283 dfu_file_buf = NULL;
284 }
285}
286
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200287/*
288 * @param s Parameter string containing space-separated arguments:
289 * 1st:
290 * raw (raw read/write)
291 * fat (files)
292 * ext4 (^)
293 * part (partition image)
294 * 2nd and 3rd:
295 * lba_start and lba_size, for raw write
296 * mmc_dev and mmc_part, for filesystems and part
Lukasz Majewski4da65ea2014-05-09 16:58:15 +0200297 * 4th (optional):
298 * mmcpart <num> (access to HW eMMC partitions)
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200299 */
Stephen Warren4afe50f2014-06-11 16:03:33 -0600300int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
Lukasz Majewski34106b22012-08-06 14:41:08 +0200301{
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200302 const char *entity_type;
303 size_t second_arg;
304 size_t third_arg;
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000305
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200306 struct mmc *mmc;
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000307
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200308 const char *argv[3];
309 const char **parg = argv;
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000310
Stephen Warren4afe50f2014-06-11 16:03:33 -0600311 dfu->data.mmc.dev_num = simple_strtoul(devstr, NULL, 10);
312
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200313 for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) {
314 *parg = strsep(&s, " ");
315 if (*parg == NULL) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900316 pr_err("Invalid number of arguments.\n");
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000317 return -ENODEV;
318 }
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200319 }
320
321 entity_type = argv[0];
Mateusz Zalega0ab80bf2014-04-28 21:13:25 +0200322 /*
323 * Base 0 means we'll accept (prefixed with 0x or 0) base 16, 8,
324 * with default 10.
325 */
326 second_arg = simple_strtoul(argv[1], NULL, 0);
327 third_arg = simple_strtoul(argv[2], NULL, 0);
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200328
Stephen Warren4afe50f2014-06-11 16:03:33 -0600329 mmc = find_mmc_device(dfu->data.mmc.dev_num);
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200330 if (mmc == NULL) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900331 pr_err("Couldn't find MMC device no. %d.\n",
Stephen Warren4afe50f2014-06-11 16:03:33 -0600332 dfu->data.mmc.dev_num);
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200333 return -ENODEV;
334 }
335
336 if (mmc_init(mmc)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900337 pr_err("Couldn't init MMC device.\n");
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200338 return -ENODEV;
339 }
340
Lukasz Majewski4da65ea2014-05-09 16:58:15 +0200341 dfu->data.mmc.hw_partition = -EINVAL;
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200342 if (!strcmp(entity_type, "raw")) {
343 dfu->layout = DFU_RAW_ADDR;
344 dfu->data.mmc.lba_start = second_arg;
345 dfu->data.mmc.lba_size = third_arg;
346 dfu->data.mmc.lba_blk_size = mmc->read_bl_len;
Lukasz Majewski4da65ea2014-05-09 16:58:15 +0200347
348 /*
349 * Check for an extra entry at dfu_alt_info env variable
350 * specifying the mmc HW defined partition number
351 */
352 if (s)
353 if (!strcmp(strsep(&s, " "), "mmcpart"))
354 dfu->data.mmc.hw_partition =
355 simple_strtoul(s, NULL, 0);
356
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200357 } else if (!strcmp(entity_type, "part")) {
358 disk_partition_t partinfo;
Simon Glassaa7620b2016-06-12 23:30:33 -0600359 struct blk_desc *blk_dev = mmc_get_blk_desc(mmc);
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200360 int mmcdev = second_arg;
361 int mmcpart = third_arg;
Marek Szyprowskif9378242019-10-02 12:34:37 +0200362 int offset = 0;
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000363
Simon Glassb89a8442016-02-29 15:25:48 -0700364 if (part_get_info(blk_dev, mmcpart, &partinfo) != 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900365 pr_err("Couldn't find part #%d on mmc device #%d\n",
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200366 mmcpart, mmcdev);
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000367 return -ENODEV;
368 }
369
Marek Szyprowskif9378242019-10-02 12:34:37 +0200370 /*
371 * Check for an extra entry at dfu_alt_info env variable
372 * specifying the mmc HW defined partition number
373 */
374 if (s)
375 if (!strcmp(strsep(&s, " "), "offset"))
376 offset = simple_strtoul(s, NULL, 0);
377
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200378 dfu->layout = DFU_RAW_ADDR;
Marek Szyprowskif9378242019-10-02 12:34:37 +0200379 dfu->data.mmc.lba_start = partinfo.start + offset;
380 dfu->data.mmc.lba_size = partinfo.size-offset;
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200381 dfu->data.mmc.lba_blk_size = partinfo.blksz;
382 } else if (!strcmp(entity_type, "fat")) {
383 dfu->layout = DFU_FS_FAT;
384 } else if (!strcmp(entity_type, "ext4")) {
385 dfu->layout = DFU_FS_EXT4;
Lukasz Majewski34106b22012-08-06 14:41:08 +0200386 } else {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900387 pr_err("Memory layout (%s) not supported!\n", entity_type);
Pantelis Antoniou620e9dd2012-11-30 08:01:11 +0000388 return -ENODEV;
Lukasz Majewski34106b22012-08-06 14:41:08 +0200389 }
390
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200391 /* if it's NOT a raw write */
392 if (strcmp(entity_type, "raw")) {
393 dfu->data.mmc.dev = second_arg;
394 dfu->data.mmc.part = third_arg;
Łukasz Majewski71c88eb2012-08-23 23:33:55 +0000395 }
396
Mateusz Zalegadcb6ea62014-04-28 21:13:24 +0200397 dfu->dev_type = DFU_DEV_MMC;
Stephen Warren020e6f32014-06-11 12:47:27 -0600398 dfu->get_medium_size = dfu_get_medium_size_mmc;
Lukasz Majewski34106b22012-08-06 14:41:08 +0200399 dfu->read_medium = dfu_read_medium_mmc;
400 dfu->write_medium = dfu_write_medium_mmc;
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000401 dfu->flush_medium = dfu_flush_medium_mmc;
Pantelis Antonioua6e788d2013-03-14 05:32:48 +0000402 dfu->inited = 0;
Przemyslaw Marczak9d6d51a2015-03-04 14:01:23 +0100403 dfu->free_entity = dfu_free_entity_mmc;
404
405 /* Check if file buffer is ready */
406 if (!dfu_file_buf) {
407 dfu_file_buf = memalign(CONFIG_SYS_CACHELINE_SIZE,
408 CONFIG_SYS_DFU_MAX_FILE_SIZE);
409 if (!dfu_file_buf) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900410 pr_err("Could not memalign 0x%x bytes",
Przemyslaw Marczak9d6d51a2015-03-04 14:01:23 +0100411 CONFIG_SYS_DFU_MAX_FILE_SIZE);
412 return -ENOMEM;
413 }
414 }
Lukasz Majewski34106b22012-08-06 14:41:08 +0200415
416 return 0;
417}