blob: ddd751c9cccc1d4c30ed6d29bf1d55581e208ab7 [file] [log] [blame]
Stephen Warreneefbc3f2012-10-22 06:43:51 +00001/*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <config.h>
Christian Gmeiner9f9eec32014-11-12 14:35:04 +010018#include <errno.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +000019#include <common.h>
20#include <part.h>
21#include <ext4fs.h>
22#include <fat.h>
23#include <fs.h>
Simon Glass11842872012-12-26 09:53:35 +000024#include <sandboxfs.h>
Simon Glasscbe5d5d2012-12-26 09:53:32 +000025#include <asm/io.h>
Tom Rinia17b7bc2014-11-24 11:50:46 -050026#include <div64.h>
27#include <linux/math64.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +000028
Stephen Warren44161af2012-10-30 07:50:47 +000029DECLARE_GLOBAL_DATA_PTR;
30
Stephen Warreneefbc3f2012-10-22 06:43:51 +000031static block_dev_desc_t *fs_dev_desc;
32static disk_partition_t fs_partition;
33static int fs_type = FS_TYPE_ANY;
34
Simon Glass6a46e2f2012-12-26 09:53:31 +000035static inline int fs_probe_unsupported(block_dev_desc_t *fs_dev_desc,
36 disk_partition_t *fs_partition)
Simon Glass1aede482012-12-26 09:53:29 +000037{
38 printf("** Unrecognized filesystem type **\n");
39 return -1;
40}
41
Stephen Warreneefbc3f2012-10-22 06:43:51 +000042static inline int fs_ls_unsupported(const char *dirname)
43{
Stephen Warreneefbc3f2012-10-22 06:43:51 +000044 return -1;
45}
46
Stephen Warrend008fbb2014-02-03 13:21:00 -070047static inline int fs_exists_unsupported(const char *filename)
48{
49 return 0;
50}
51
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080052static inline int fs_size_unsupported(const char *filename, loff_t *size)
Stephen Warren3eb58f52014-06-11 12:47:26 -060053{
54 return -1;
55}
56
Simon Glasscbe5d5d2012-12-26 09:53:32 +000057static inline int fs_read_unsupported(const char *filename, void *buf,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080058 loff_t offset, loff_t len,
59 loff_t *actread)
Stephen Warreneefbc3f2012-10-22 06:43:51 +000060{
Stephen Warreneefbc3f2012-10-22 06:43:51 +000061 return -1;
62}
63
Simon Glasseda14ea2013-04-20 08:42:50 +000064static inline int fs_write_unsupported(const char *filename, void *buf,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080065 loff_t offset, loff_t len,
66 loff_t *actwrite)
Simon Glasseda14ea2013-04-20 08:42:50 +000067{
68 return -1;
69}
70
Simon Glass1aede482012-12-26 09:53:29 +000071static inline void fs_close_unsupported(void)
72{
73}
74
Christian Gmeiner9f9eec32014-11-12 14:35:04 +010075static inline int fs_uuid_unsupported(char *uuid_str)
76{
77 return -1;
78}
79
Simon Glass1aede482012-12-26 09:53:29 +000080struct fstype_info {
Stephen Warreneefbc3f2012-10-22 06:43:51 +000081 int fstype;
Stephen Warrenec63d4a2014-02-03 13:21:01 -070082 /*
83 * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
84 * should be false in most cases. For "virtual" filesystems which
85 * aren't based on a U-Boot block device (e.g. sandbox), this can be
86 * set to true. This should also be true for the dumm entry at the end
87 * of fstypes[], since that is essentially a "virtual" (non-existent)
88 * filesystem.
89 */
90 bool null_dev_desc_ok;
Simon Glass6a46e2f2012-12-26 09:53:31 +000091 int (*probe)(block_dev_desc_t *fs_dev_desc,
92 disk_partition_t *fs_partition);
Simon Glass1aede482012-12-26 09:53:29 +000093 int (*ls)(const char *dirname);
Stephen Warrend008fbb2014-02-03 13:21:00 -070094 int (*exists)(const char *filename);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080095 int (*size)(const char *filename, loff_t *size);
96 int (*read)(const char *filename, void *buf, loff_t offset,
97 loff_t len, loff_t *actread);
98 int (*write)(const char *filename, void *buf, loff_t offset,
99 loff_t len, loff_t *actwrite);
Simon Glass1aede482012-12-26 09:53:29 +0000100 void (*close)(void);
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100101 int (*uuid)(char *uuid_str);
Simon Glass1aede482012-12-26 09:53:29 +0000102};
103
104static struct fstype_info fstypes[] = {
105#ifdef CONFIG_FS_FAT
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000106 {
107 .fstype = FS_TYPE_FAT,
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700108 .null_dev_desc_ok = false,
Simon Glass19e38582012-12-26 09:53:33 +0000109 .probe = fat_set_blk_dev,
110 .close = fat_close,
Simon Glass1aede482012-12-26 09:53:29 +0000111 .ls = file_fat_ls,
Stephen Warren1d2f9a02014-02-03 13:21:10 -0700112 .exists = fat_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600113 .size = fat_size,
Simon Glass19e38582012-12-26 09:53:33 +0000114 .read = fat_read_file,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800115#ifdef CONFIG_FAT_WRITE
116 .write = file_fat_write,
117#else
Stephen Warren9df25802014-02-03 13:20:59 -0700118 .write = fs_write_unsupported,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800119#endif
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100120 .uuid = fs_uuid_unsupported,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000121 },
Simon Glass1aede482012-12-26 09:53:29 +0000122#endif
123#ifdef CONFIG_FS_EXT4
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000124 {
125 .fstype = FS_TYPE_EXT,
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700126 .null_dev_desc_ok = false,
Simon Glass19e38582012-12-26 09:53:33 +0000127 .probe = ext4fs_probe,
128 .close = ext4fs_close,
Simon Glass1aede482012-12-26 09:53:29 +0000129 .ls = ext4fs_ls,
Stephen Warren12d6d0c2014-02-03 13:21:09 -0700130 .exists = ext4fs_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600131 .size = ext4fs_size,
Simon Glass19e38582012-12-26 09:53:33 +0000132 .read = ext4_read_file,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800133#ifdef CONFIG_CMD_EXT4_WRITE
134 .write = ext4_write_file,
135#else
Stephen Warren9df25802014-02-03 13:20:59 -0700136 .write = fs_write_unsupported,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800137#endif
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100138 .uuid = ext4fs_uuid,
Simon Glass1aede482012-12-26 09:53:29 +0000139 },
140#endif
Simon Glass11842872012-12-26 09:53:35 +0000141#ifdef CONFIG_SANDBOX
142 {
143 .fstype = FS_TYPE_SANDBOX,
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700144 .null_dev_desc_ok = true,
Simon Glass11842872012-12-26 09:53:35 +0000145 .probe = sandbox_fs_set_blk_dev,
146 .close = sandbox_fs_close,
147 .ls = sandbox_fs_ls,
Stephen Warren97d66f22014-02-03 13:21:07 -0700148 .exists = sandbox_fs_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600149 .size = sandbox_fs_size,
Simon Glass11842872012-12-26 09:53:35 +0000150 .read = fs_read_sandbox,
Simon Glassea307e82013-04-20 08:42:51 +0000151 .write = fs_write_sandbox,
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100152 .uuid = fs_uuid_unsupported,
Simon Glass11842872012-12-26 09:53:35 +0000153 },
154#endif
Simon Glass1aede482012-12-26 09:53:29 +0000155 {
156 .fstype = FS_TYPE_ANY,
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700157 .null_dev_desc_ok = true,
Simon Glass1aede482012-12-26 09:53:29 +0000158 .probe = fs_probe_unsupported,
159 .close = fs_close_unsupported,
160 .ls = fs_ls_unsupported,
Stephen Warrend008fbb2014-02-03 13:21:00 -0700161 .exists = fs_exists_unsupported,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600162 .size = fs_size_unsupported,
Simon Glass1aede482012-12-26 09:53:29 +0000163 .read = fs_read_unsupported,
Simon Glasseda14ea2013-04-20 08:42:50 +0000164 .write = fs_write_unsupported,
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100165 .uuid = fs_uuid_unsupported,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000166 },
167};
168
Simon Glasse6aad852012-12-26 09:53:30 +0000169static struct fstype_info *fs_get_info(int fstype)
170{
171 struct fstype_info *info;
172 int i;
173
174 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
175 if (fstype == info->fstype)
176 return info;
177 }
178
179 /* Return the 'unsupported' sentinel */
180 return info;
181}
182
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000183int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
184{
Simon Glass1aede482012-12-26 09:53:29 +0000185 struct fstype_info *info;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000186 int part, i;
Stephen Warren44161af2012-10-30 07:50:47 +0000187#ifdef CONFIG_NEEDS_MANUAL_RELOC
188 static int relocated;
189
190 if (!relocated) {
Simon Glass1aede482012-12-26 09:53:29 +0000191 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
192 i++, info++) {
193 info->probe += gd->reloc_off;
194 info->close += gd->reloc_off;
195 info->ls += gd->reloc_off;
196 info->read += gd->reloc_off;
Simon Glasseda14ea2013-04-20 08:42:50 +0000197 info->write += gd->reloc_off;
Simon Glass1aede482012-12-26 09:53:29 +0000198 }
Stephen Warren44161af2012-10-30 07:50:47 +0000199 relocated = 1;
200 }
201#endif
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000202
203 part = get_device_and_partition(ifname, dev_part_str, &fs_dev_desc,
204 &fs_partition, 1);
205 if (part < 0)
206 return -1;
207
Simon Glass1aede482012-12-26 09:53:29 +0000208 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
209 if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
210 fstype != info->fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000211 continue;
212
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700213 if (!fs_dev_desc && !info->null_dev_desc_ok)
214 continue;
215
Simon Glass6a46e2f2012-12-26 09:53:31 +0000216 if (!info->probe(fs_dev_desc, &fs_partition)) {
Simon Glass1aede482012-12-26 09:53:29 +0000217 fs_type = info->fstype;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000218 return 0;
219 }
220 }
221
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000222 return -1;
223}
224
225static void fs_close(void)
226{
Simon Glasse6aad852012-12-26 09:53:30 +0000227 struct fstype_info *info = fs_get_info(fs_type);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000228
Simon Glasse6aad852012-12-26 09:53:30 +0000229 info->close();
Simon Glass19e38582012-12-26 09:53:33 +0000230
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000231 fs_type = FS_TYPE_ANY;
232}
233
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100234int fs_uuid(char *uuid_str)
235{
236 struct fstype_info *info = fs_get_info(fs_type);
237
238 return info->uuid(uuid_str);
239}
240
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000241int fs_ls(const char *dirname)
242{
243 int ret;
244
Simon Glasse6aad852012-12-26 09:53:30 +0000245 struct fstype_info *info = fs_get_info(fs_type);
246
247 ret = info->ls(dirname);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000248
Simon Glass19e38582012-12-26 09:53:33 +0000249 fs_type = FS_TYPE_ANY;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000250 fs_close();
251
252 return ret;
253}
254
Stephen Warrend008fbb2014-02-03 13:21:00 -0700255int fs_exists(const char *filename)
256{
257 int ret;
258
259 struct fstype_info *info = fs_get_info(fs_type);
260
261 ret = info->exists(filename);
262
263 fs_close();
264
265 return ret;
266}
267
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800268int fs_size(const char *filename, loff_t *size)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600269{
270 int ret;
271
272 struct fstype_info *info = fs_get_info(fs_type);
273
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800274 ret = info->size(filename, size);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600275
276 fs_close();
277
278 return ret;
279}
280
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800281int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
282 loff_t *actread)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000283{
Simon Glasse6aad852012-12-26 09:53:30 +0000284 struct fstype_info *info = fs_get_info(fs_type);
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000285 void *buf;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000286 int ret;
287
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000288 /*
289 * We don't actually know how many bytes are being read, since len==0
290 * means read the whole file.
291 */
292 buf = map_sysmem(addr, len);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800293 ret = info->read(filename, buf, offset, len, actread);
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000294 unmap_sysmem(buf);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000295
Simon Glasse6aad852012-12-26 09:53:30 +0000296 /* If we requested a specific number of bytes, check we got it */
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800297 if (ret == 0 && len && *actread != len) {
Simon Glasse6aad852012-12-26 09:53:30 +0000298 printf("** Unable to read file %s **\n", filename);
299 ret = -1;
300 }
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000301 fs_close();
302
303 return ret;
304}
305
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800306int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
307 loff_t *actwrite)
Simon Glasseda14ea2013-04-20 08:42:50 +0000308{
309 struct fstype_info *info = fs_get_info(fs_type);
310 void *buf;
311 int ret;
312
Simon Glasseda14ea2013-04-20 08:42:50 +0000313 buf = map_sysmem(addr, len);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800314 ret = info->write(filename, buf, offset, len, actwrite);
Simon Glasseda14ea2013-04-20 08:42:50 +0000315 unmap_sysmem(buf);
316
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800317 if (ret < 0 && len != *actwrite) {
Simon Glasseda14ea2013-04-20 08:42:50 +0000318 printf("** Unable to write file %s **\n", filename);
319 ret = -1;
320 }
321 fs_close();
322
323 return ret;
324}
325
Stephen Warren3eb58f52014-06-11 12:47:26 -0600326int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
327 int fstype)
328{
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800329 loff_t size;
Stephen Warren3eb58f52014-06-11 12:47:26 -0600330
331 if (argc != 4)
332 return CMD_RET_USAGE;
333
334 if (fs_set_blk_dev(argv[1], argv[2], fstype))
335 return 1;
336
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800337 if (fs_size(argv[3], &size) < 0)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600338 return CMD_RET_FAILURE;
339
340 setenv_hex("filesize", size);
341
342 return 0;
343}
344
Stephen Warren128d3d92012-10-31 11:05:07 +0000345int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200346 int fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000347{
348 unsigned long addr;
349 const char *addr_str;
350 const char *filename;
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800351 loff_t bytes;
352 loff_t pos;
353 loff_t len_read;
354 int ret;
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100355 unsigned long time;
Pavel Machek4c1a9c52014-07-09 22:42:57 +0200356 char *ep;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000357
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000358 if (argc < 2)
359 return CMD_RET_USAGE;
360 if (argc > 7)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000361 return CMD_RET_USAGE;
362
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000363 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000364 return 1;
365
366 if (argc >= 4) {
Pavel Machek4c1a9c52014-07-09 22:42:57 +0200367 addr = simple_strtoul(argv[3], &ep, 16);
368 if (ep == argv[3] || *ep != '\0')
369 return CMD_RET_USAGE;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000370 } else {
371 addr_str = getenv("loadaddr");
372 if (addr_str != NULL)
373 addr = simple_strtoul(addr_str, NULL, 16);
374 else
375 addr = CONFIG_SYS_LOAD_ADDR;
376 }
377 if (argc >= 5) {
378 filename = argv[4];
379 } else {
380 filename = getenv("bootfile");
381 if (!filename) {
382 puts("** No boot file defined **\n");
383 return 1;
384 }
385 }
386 if (argc >= 6)
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200387 bytes = simple_strtoul(argv[5], NULL, 16);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000388 else
389 bytes = 0;
390 if (argc >= 7)
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200391 pos = simple_strtoul(argv[6], NULL, 16);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000392 else
393 pos = 0;
394
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100395 time = get_timer(0);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800396 ret = fs_read(filename, addr, pos, bytes, &len_read);
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100397 time = get_timer(time);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800398 if (ret < 0)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000399 return 1;
400
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800401 printf("%llu bytes read in %lu ms", len_read, time);
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100402 if (time > 0) {
403 puts(" (");
Tom Rinia17b7bc2014-11-24 11:50:46 -0500404 print_size(div_u64(len_read, time) * 1000, "/s");
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100405 puts(")");
406 }
407 puts("\n");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000408
Simon Glassfff5c072013-02-24 17:33:23 +0000409 setenv_hex("filesize", len_read);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000410
411 return 0;
412}
413
414int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
415 int fstype)
416{
417 if (argc < 2)
418 return CMD_RET_USAGE;
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000419 if (argc > 4)
420 return CMD_RET_USAGE;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000421
422 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
423 return 1;
424
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000425 if (fs_ls(argc >= 4 ? argv[3] : "/"))
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000426 return 1;
427
428 return 0;
429}
Simon Glasseda14ea2013-04-20 08:42:50 +0000430
Stephen Warrend008fbb2014-02-03 13:21:00 -0700431int file_exists(const char *dev_type, const char *dev_part, const char *file,
432 int fstype)
433{
434 if (fs_set_blk_dev(dev_type, dev_part, fstype))
435 return 0;
436
437 return fs_exists(file);
438}
439
Simon Glasseda14ea2013-04-20 08:42:50 +0000440int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200441 int fstype)
Simon Glasseda14ea2013-04-20 08:42:50 +0000442{
443 unsigned long addr;
444 const char *filename;
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800445 loff_t bytes;
446 loff_t pos;
447 loff_t len;
448 int ret;
Simon Glasseda14ea2013-04-20 08:42:50 +0000449 unsigned long time;
450
451 if (argc < 6 || argc > 7)
452 return CMD_RET_USAGE;
453
454 if (fs_set_blk_dev(argv[1], argv[2], fstype))
455 return 1;
456
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800457 addr = simple_strtoul(argv[3], NULL, 16);
458 filename = argv[4];
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200459 bytes = simple_strtoul(argv[5], NULL, 16);
Simon Glasseda14ea2013-04-20 08:42:50 +0000460 if (argc >= 7)
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200461 pos = simple_strtoul(argv[6], NULL, 16);
Simon Glasseda14ea2013-04-20 08:42:50 +0000462 else
463 pos = 0;
464
465 time = get_timer(0);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800466 ret = fs_write(filename, addr, pos, bytes, &len);
Simon Glasseda14ea2013-04-20 08:42:50 +0000467 time = get_timer(time);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800468 if (ret < 0)
Simon Glasseda14ea2013-04-20 08:42:50 +0000469 return 1;
470
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800471 printf("%llu bytes written in %lu ms", len, time);
Simon Glasseda14ea2013-04-20 08:42:50 +0000472 if (time > 0) {
473 puts(" (");
Tom Rinia17b7bc2014-11-24 11:50:46 -0500474 print_size(div_u64(len, time) * 1000, "/s");
Simon Glasseda14ea2013-04-20 08:42:50 +0000475 puts(")");
476 }
477 puts("\n");
478
479 return 0;
480}
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100481
482int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
483 int fstype)
484{
485 int ret;
486 char uuid[37];
487 memset(uuid, 0, sizeof(uuid));
488
489 if (argc < 3 || argc > 4)
490 return CMD_RET_USAGE;
491
492 if (fs_set_blk_dev(argv[1], argv[2], fstype))
493 return 1;
494
495 ret = fs_uuid(uuid);
496 if (ret)
497 return CMD_RET_FAILURE;
498
499 if (argc == 4)
500 setenv(argv[3], uuid);
501 else
502 printf("%s\n", uuid);
503
504 return CMD_RET_SUCCESS;
505}