Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <config.h> |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 7 | #include <errno.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 8 | #include <common.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 9 | #include <mapmem.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 10 | #include <part.h> |
| 11 | #include <ext4fs.h> |
| 12 | #include <fat.h> |
| 13 | #include <fs.h> |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 14 | #include <sandboxfs.h> |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 15 | #include <ubifs_uboot.h> |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 16 | #include <btrfs.h> |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 17 | #include <asm/io.h> |
Tom Rini | 9e374e7 | 2014-11-24 11:50:46 -0500 | [diff] [blame] | 18 | #include <div64.h> |
| 19 | #include <linux/math64.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 20 | |
Stephen Warren | a1b231c | 2012-10-30 07:50:47 +0000 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 23 | static struct blk_desc *fs_dev_desc; |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 24 | static int fs_dev_part; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 25 | static disk_partition_t fs_partition; |
| 26 | static int fs_type = FS_TYPE_ANY; |
| 27 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 28 | static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc, |
Simon Glass | 2ded0d4 | 2012-12-26 09:53:31 +0000 | [diff] [blame] | 29 | disk_partition_t *fs_partition) |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 30 | { |
| 31 | printf("** Unrecognized filesystem type **\n"); |
| 32 | return -1; |
| 33 | } |
| 34 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 35 | static inline int fs_ls_unsupported(const char *dirname) |
| 36 | { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 37 | return -1; |
| 38 | } |
| 39 | |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 40 | /* generic implementation of ls in terms of opendir/readdir/closedir */ |
| 41 | __maybe_unused |
| 42 | static int fs_ls_generic(const char *dirname) |
| 43 | { |
| 44 | struct fs_dir_stream *dirs; |
| 45 | struct fs_dirent *dent; |
| 46 | int nfiles = 0, ndirs = 0; |
| 47 | |
| 48 | dirs = fs_opendir(dirname); |
| 49 | if (!dirs) |
| 50 | return -errno; |
| 51 | |
| 52 | while ((dent = fs_readdir(dirs))) { |
| 53 | if (dent->type == FS_DT_DIR) { |
| 54 | printf(" %s/\n", dent->name); |
| 55 | ndirs++; |
| 56 | } else { |
| 57 | printf(" %8lld %s\n", dent->size, dent->name); |
| 58 | nfiles++; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | fs_closedir(dirs); |
| 63 | |
| 64 | printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 69 | static inline int fs_exists_unsupported(const char *filename) |
| 70 | { |
| 71 | return 0; |
| 72 | } |
| 73 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 74 | static inline int fs_size_unsupported(const char *filename, loff_t *size) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 75 | { |
| 76 | return -1; |
| 77 | } |
| 78 | |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 79 | static inline int fs_read_unsupported(const char *filename, void *buf, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 80 | loff_t offset, loff_t len, |
| 81 | loff_t *actread) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 82 | { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 86 | static inline int fs_write_unsupported(const char *filename, void *buf, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 87 | loff_t offset, loff_t len, |
| 88 | loff_t *actwrite) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 89 | { |
| 90 | return -1; |
| 91 | } |
| 92 | |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 93 | static inline void fs_close_unsupported(void) |
| 94 | { |
| 95 | } |
| 96 | |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 97 | static inline int fs_uuid_unsupported(char *uuid_str) |
| 98 | { |
| 99 | return -1; |
| 100 | } |
| 101 | |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 102 | static inline int fs_opendir_unsupported(const char *filename, |
| 103 | struct fs_dir_stream **dirs) |
| 104 | { |
| 105 | return -EACCES; |
| 106 | } |
| 107 | |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 108 | static inline int fs_mkdir_unsupported(const char *dirname) |
| 109 | { |
| 110 | return -1; |
| 111 | } |
| 112 | |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 113 | struct fstype_info { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 114 | int fstype; |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 115 | char *name; |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 116 | /* |
| 117 | * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This |
| 118 | * should be false in most cases. For "virtual" filesystems which |
| 119 | * aren't based on a U-Boot block device (e.g. sandbox), this can be |
Heinrich Schuchardt | ca230b0 | 2018-08-11 15:52:14 +0200 | [diff] [blame] | 120 | * set to true. This should also be true for the dummy entry at the end |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 121 | * of fstypes[], since that is essentially a "virtual" (non-existent) |
| 122 | * filesystem. |
| 123 | */ |
| 124 | bool null_dev_desc_ok; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 125 | int (*probe)(struct blk_desc *fs_dev_desc, |
Simon Glass | 2ded0d4 | 2012-12-26 09:53:31 +0000 | [diff] [blame] | 126 | disk_partition_t *fs_partition); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 127 | int (*ls)(const char *dirname); |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 128 | int (*exists)(const char *filename); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 129 | int (*size)(const char *filename, loff_t *size); |
| 130 | int (*read)(const char *filename, void *buf, loff_t offset, |
| 131 | loff_t len, loff_t *actread); |
| 132 | int (*write)(const char *filename, void *buf, loff_t offset, |
| 133 | loff_t len, loff_t *actwrite); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 134 | void (*close)(void); |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 135 | int (*uuid)(char *uuid_str); |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 136 | /* |
| 137 | * Open a directory stream. On success return 0 and directory |
| 138 | * stream pointer via 'dirsp'. On error, return -errno. See |
| 139 | * fs_opendir(). |
| 140 | */ |
| 141 | int (*opendir)(const char *filename, struct fs_dir_stream **dirsp); |
| 142 | /* |
| 143 | * Read next entry from directory stream. On success return 0 |
| 144 | * and directory entry pointer via 'dentp'. On error return |
| 145 | * -errno. See fs_readdir(). |
| 146 | */ |
| 147 | int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp); |
| 148 | /* see fs_closedir() */ |
| 149 | void (*closedir)(struct fs_dir_stream *dirs); |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 150 | int (*mkdir)(const char *dirname); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | static struct fstype_info fstypes[] = { |
| 154 | #ifdef CONFIG_FS_FAT |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 155 | { |
| 156 | .fstype = FS_TYPE_FAT, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 157 | .name = "fat", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 158 | .null_dev_desc_ok = false, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 159 | .probe = fat_set_blk_dev, |
| 160 | .close = fat_close, |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 161 | .ls = fs_ls_generic, |
Stephen Warren | b7b5f31 | 2014-02-03 13:21:10 -0700 | [diff] [blame] | 162 | .exists = fat_exists, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 163 | .size = fat_size, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 164 | .read = fat_read_file, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 165 | #ifdef CONFIG_FAT_WRITE |
| 166 | .write = file_fat_write, |
| 167 | #else |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 168 | .write = fs_write_unsupported, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 169 | #endif |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 170 | .uuid = fs_uuid_unsupported, |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 171 | .opendir = fat_opendir, |
| 172 | .readdir = fat_readdir, |
| 173 | .closedir = fat_closedir, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 174 | .mkdir = fs_mkdir_unsupported, |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 175 | }, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 176 | #endif |
| 177 | #ifdef CONFIG_FS_EXT4 |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 178 | { |
| 179 | .fstype = FS_TYPE_EXT, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 180 | .name = "ext4", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 181 | .null_dev_desc_ok = false, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 182 | .probe = ext4fs_probe, |
| 183 | .close = ext4fs_close, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 184 | .ls = ext4fs_ls, |
Stephen Warren | 55af5c9 | 2014-02-03 13:21:09 -0700 | [diff] [blame] | 185 | .exists = ext4fs_exists, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 186 | .size = ext4fs_size, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 187 | .read = ext4_read_file, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 188 | #ifdef CONFIG_CMD_EXT4_WRITE |
| 189 | .write = ext4_write_file, |
| 190 | #else |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 191 | .write = fs_write_unsupported, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 192 | #endif |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 193 | .uuid = ext4fs_uuid, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 194 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 195 | .mkdir = fs_mkdir_unsupported, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 196 | }, |
| 197 | #endif |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 198 | #ifdef CONFIG_SANDBOX |
| 199 | { |
| 200 | .fstype = FS_TYPE_SANDBOX, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 201 | .name = "sandbox", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 202 | .null_dev_desc_ok = true, |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 203 | .probe = sandbox_fs_set_blk_dev, |
| 204 | .close = sandbox_fs_close, |
| 205 | .ls = sandbox_fs_ls, |
Stephen Warren | 0a30aa1 | 2014-02-03 13:21:07 -0700 | [diff] [blame] | 206 | .exists = sandbox_fs_exists, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 207 | .size = sandbox_fs_size, |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 208 | .read = fs_read_sandbox, |
Simon Glass | 7eb2c8d | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 209 | .write = fs_write_sandbox, |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 210 | .uuid = fs_uuid_unsupported, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 211 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 212 | .mkdir = fs_mkdir_unsupported, |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 213 | }, |
| 214 | #endif |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 215 | #ifdef CONFIG_CMD_UBIFS |
| 216 | { |
| 217 | .fstype = FS_TYPE_UBIFS, |
| 218 | .name = "ubifs", |
| 219 | .null_dev_desc_ok = true, |
| 220 | .probe = ubifs_set_blk_dev, |
| 221 | .close = ubifs_close, |
| 222 | .ls = ubifs_ls, |
| 223 | .exists = ubifs_exists, |
| 224 | .size = ubifs_size, |
| 225 | .read = ubifs_read, |
| 226 | .write = fs_write_unsupported, |
| 227 | .uuid = fs_uuid_unsupported, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 228 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 229 | .mkdir = fs_mkdir_unsupported, |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 230 | }, |
| 231 | #endif |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 232 | #ifdef CONFIG_FS_BTRFS |
| 233 | { |
| 234 | .fstype = FS_TYPE_BTRFS, |
| 235 | .name = "btrfs", |
| 236 | .null_dev_desc_ok = false, |
| 237 | .probe = btrfs_probe, |
| 238 | .close = btrfs_close, |
| 239 | .ls = btrfs_ls, |
| 240 | .exists = btrfs_exists, |
| 241 | .size = btrfs_size, |
| 242 | .read = btrfs_read, |
| 243 | .write = fs_write_unsupported, |
| 244 | .uuid = btrfs_uuid, |
Marek BehĂșn | 38fc683 | 2017-10-06 16:56:07 +0200 | [diff] [blame] | 245 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 246 | .mkdir = fs_mkdir_unsupported, |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 247 | }, |
| 248 | #endif |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 249 | { |
| 250 | .fstype = FS_TYPE_ANY, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 251 | .name = "unsupported", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 252 | .null_dev_desc_ok = true, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 253 | .probe = fs_probe_unsupported, |
| 254 | .close = fs_close_unsupported, |
| 255 | .ls = fs_ls_unsupported, |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 256 | .exists = fs_exists_unsupported, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 257 | .size = fs_size_unsupported, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 258 | .read = fs_read_unsupported, |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 259 | .write = fs_write_unsupported, |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 260 | .uuid = fs_uuid_unsupported, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 261 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 262 | .mkdir = fs_mkdir_unsupported, |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 263 | }, |
| 264 | }; |
| 265 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 266 | static struct fstype_info *fs_get_info(int fstype) |
| 267 | { |
| 268 | struct fstype_info *info; |
| 269 | int i; |
| 270 | |
| 271 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) { |
| 272 | if (fstype == info->fstype) |
| 273 | return info; |
| 274 | } |
| 275 | |
| 276 | /* Return the 'unsupported' sentinel */ |
| 277 | return info; |
| 278 | } |
| 279 | |
Alex Kiernan | 0d488e8 | 2018-05-29 15:30:50 +0000 | [diff] [blame] | 280 | /** |
| 281 | * fs_get_type_name() - Get type of current filesystem |
| 282 | * |
| 283 | * Return: Pointer to filesystem name |
| 284 | * |
| 285 | * Returns a string describing the current filesystem, or the sentinel |
| 286 | * "unsupported" for any unrecognised filesystem. |
| 287 | */ |
| 288 | const char *fs_get_type_name(void) |
| 289 | { |
| 290 | return fs_get_info(fs_type)->name; |
| 291 | } |
| 292 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 293 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) |
| 294 | { |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 295 | struct fstype_info *info; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 296 | int part, i; |
Stephen Warren | a1b231c | 2012-10-30 07:50:47 +0000 | [diff] [blame] | 297 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 298 | static int relocated; |
| 299 | |
| 300 | if (!relocated) { |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 301 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); |
| 302 | i++, info++) { |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 303 | info->name += gd->reloc_off; |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 304 | info->probe += gd->reloc_off; |
| 305 | info->close += gd->reloc_off; |
| 306 | info->ls += gd->reloc_off; |
| 307 | info->read += gd->reloc_off; |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 308 | info->write += gd->reloc_off; |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 309 | } |
Stephen Warren | a1b231c | 2012-10-30 07:50:47 +0000 | [diff] [blame] | 310 | relocated = 1; |
| 311 | } |
| 312 | #endif |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 313 | |
Simon Glass | e35929e | 2016-02-29 15:25:44 -0700 | [diff] [blame] | 314 | part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc, |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 315 | &fs_partition, 1); |
| 316 | if (part < 0) |
| 317 | return -1; |
| 318 | |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 319 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { |
| 320 | if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY && |
| 321 | fstype != info->fstype) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 322 | continue; |
| 323 | |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 324 | if (!fs_dev_desc && !info->null_dev_desc_ok) |
| 325 | continue; |
| 326 | |
Simon Glass | 2ded0d4 | 2012-12-26 09:53:31 +0000 | [diff] [blame] | 327 | if (!info->probe(fs_dev_desc, &fs_partition)) { |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 328 | fs_type = info->fstype; |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 329 | fs_dev_part = part; |
| 330 | return 0; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | return -1; |
| 335 | } |
| 336 | |
| 337 | /* set current blk device w/ blk_desc + partition # */ |
| 338 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part) |
| 339 | { |
| 340 | struct fstype_info *info; |
| 341 | int ret, i; |
| 342 | |
| 343 | if (part >= 1) |
| 344 | ret = part_get_info(desc, part, &fs_partition); |
| 345 | else |
| 346 | ret = part_get_info_whole_disk(desc, &fs_partition); |
| 347 | if (ret) |
| 348 | return ret; |
| 349 | fs_dev_desc = desc; |
| 350 | |
| 351 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { |
| 352 | if (!info->probe(fs_dev_desc, &fs_partition)) { |
| 353 | fs_type = info->fstype; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | } |
| 357 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 358 | return -1; |
| 359 | } |
| 360 | |
| 361 | static void fs_close(void) |
| 362 | { |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 363 | struct fstype_info *info = fs_get_info(fs_type); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 364 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 365 | info->close(); |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 366 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 367 | fs_type = FS_TYPE_ANY; |
| 368 | } |
| 369 | |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 370 | int fs_uuid(char *uuid_str) |
| 371 | { |
| 372 | struct fstype_info *info = fs_get_info(fs_type); |
| 373 | |
| 374 | return info->uuid(uuid_str); |
| 375 | } |
| 376 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 377 | int fs_ls(const char *dirname) |
| 378 | { |
| 379 | int ret; |
| 380 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 381 | struct fstype_info *info = fs_get_info(fs_type); |
| 382 | |
| 383 | ret = info->ls(dirname); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 384 | |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 385 | fs_type = FS_TYPE_ANY; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 386 | fs_close(); |
| 387 | |
| 388 | return ret; |
| 389 | } |
| 390 | |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 391 | int fs_exists(const char *filename) |
| 392 | { |
| 393 | int ret; |
| 394 | |
| 395 | struct fstype_info *info = fs_get_info(fs_type); |
| 396 | |
| 397 | ret = info->exists(filename); |
| 398 | |
| 399 | fs_close(); |
| 400 | |
| 401 | return ret; |
| 402 | } |
| 403 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 404 | int fs_size(const char *filename, loff_t *size) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 405 | { |
| 406 | int ret; |
| 407 | |
| 408 | struct fstype_info *info = fs_get_info(fs_type); |
| 409 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 410 | ret = info->size(filename, size); |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 411 | |
| 412 | fs_close(); |
| 413 | |
| 414 | return ret; |
| 415 | } |
| 416 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 417 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 418 | loff_t *actread) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 419 | { |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 420 | struct fstype_info *info = fs_get_info(fs_type); |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 421 | void *buf; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 422 | int ret; |
| 423 | |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 424 | /* |
| 425 | * We don't actually know how many bytes are being read, since len==0 |
| 426 | * means read the whole file. |
| 427 | */ |
| 428 | buf = map_sysmem(addr, len); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 429 | ret = info->read(filename, buf, offset, len, actread); |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 430 | unmap_sysmem(buf); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 431 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 432 | /* If we requested a specific number of bytes, check we got it */ |
Max Krummenacher | 7a3e70c | 2015-08-05 17:16:58 +0200 | [diff] [blame] | 433 | if (ret == 0 && len && *actread != len) |
Heinrich Schuchardt | a327bde | 2018-01-01 21:15:37 +0100 | [diff] [blame] | 434 | debug("** %s shorter than offset + len **\n", filename); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 435 | fs_close(); |
| 436 | |
| 437 | return ret; |
| 438 | } |
| 439 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 440 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 441 | loff_t *actwrite) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 442 | { |
| 443 | struct fstype_info *info = fs_get_info(fs_type); |
| 444 | void *buf; |
| 445 | int ret; |
| 446 | |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 447 | buf = map_sysmem(addr, len); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 448 | ret = info->write(filename, buf, offset, len, actwrite); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 449 | unmap_sysmem(buf); |
| 450 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 451 | if (ret < 0 && len != *actwrite) { |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 452 | printf("** Unable to write file %s **\n", filename); |
| 453 | ret = -1; |
| 454 | } |
| 455 | fs_close(); |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 460 | struct fs_dir_stream *fs_opendir(const char *filename) |
| 461 | { |
| 462 | struct fstype_info *info = fs_get_info(fs_type); |
| 463 | struct fs_dir_stream *dirs = NULL; |
| 464 | int ret; |
| 465 | |
| 466 | ret = info->opendir(filename, &dirs); |
| 467 | fs_close(); |
| 468 | if (ret) { |
| 469 | errno = -ret; |
| 470 | return NULL; |
| 471 | } |
| 472 | |
| 473 | dirs->desc = fs_dev_desc; |
| 474 | dirs->part = fs_dev_part; |
| 475 | |
| 476 | return dirs; |
| 477 | } |
| 478 | |
| 479 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs) |
| 480 | { |
| 481 | struct fstype_info *info; |
| 482 | struct fs_dirent *dirent; |
| 483 | int ret; |
| 484 | |
| 485 | fs_set_blk_dev_with_part(dirs->desc, dirs->part); |
| 486 | info = fs_get_info(fs_type); |
| 487 | |
| 488 | ret = info->readdir(dirs, &dirent); |
| 489 | fs_close(); |
| 490 | if (ret) { |
| 491 | errno = -ret; |
| 492 | return NULL; |
| 493 | } |
| 494 | |
| 495 | return dirent; |
| 496 | } |
| 497 | |
| 498 | void fs_closedir(struct fs_dir_stream *dirs) |
| 499 | { |
| 500 | struct fstype_info *info; |
| 501 | |
| 502 | if (!dirs) |
| 503 | return; |
| 504 | |
| 505 | fs_set_blk_dev_with_part(dirs->desc, dirs->part); |
| 506 | info = fs_get_info(fs_type); |
| 507 | |
| 508 | info->closedir(dirs); |
| 509 | fs_close(); |
| 510 | } |
| 511 | |
| 512 | |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 513 | int fs_mkdir(const char *dirname) |
| 514 | { |
| 515 | int ret; |
| 516 | |
| 517 | struct fstype_info *info = fs_get_info(fs_type); |
| 518 | |
| 519 | ret = info->mkdir(dirname); |
| 520 | |
| 521 | fs_type = FS_TYPE_ANY; |
| 522 | fs_close(); |
| 523 | |
| 524 | return ret; |
| 525 | } |
| 526 | |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 527 | int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 528 | int fstype) |
| 529 | { |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 530 | loff_t size; |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 531 | |
| 532 | if (argc != 4) |
| 533 | return CMD_RET_USAGE; |
| 534 | |
| 535 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 536 | return 1; |
| 537 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 538 | if (fs_size(argv[3], &size) < 0) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 539 | return CMD_RET_FAILURE; |
| 540 | |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 541 | env_set_hex("filesize", size); |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
Stephen Warren | f9b55e2 | 2012-10-31 11:05:07 +0000 | [diff] [blame] | 546 | int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 547 | int fstype) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 548 | { |
| 549 | unsigned long addr; |
| 550 | const char *addr_str; |
| 551 | const char *filename; |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 552 | loff_t bytes; |
| 553 | loff_t pos; |
| 554 | loff_t len_read; |
| 555 | int ret; |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 556 | unsigned long time; |
Pavel Machek | 949bbd7 | 2014-07-09 22:42:57 +0200 | [diff] [blame] | 557 | char *ep; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 558 | |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 559 | if (argc < 2) |
| 560 | return CMD_RET_USAGE; |
| 561 | if (argc > 7) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 562 | return CMD_RET_USAGE; |
| 563 | |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 564 | if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 565 | return 1; |
| 566 | |
| 567 | if (argc >= 4) { |
Pavel Machek | 949bbd7 | 2014-07-09 22:42:57 +0200 | [diff] [blame] | 568 | addr = simple_strtoul(argv[3], &ep, 16); |
| 569 | if (ep == argv[3] || *ep != '\0') |
| 570 | return CMD_RET_USAGE; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 571 | } else { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 572 | addr_str = env_get("loadaddr"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 573 | if (addr_str != NULL) |
| 574 | addr = simple_strtoul(addr_str, NULL, 16); |
| 575 | else |
| 576 | addr = CONFIG_SYS_LOAD_ADDR; |
| 577 | } |
| 578 | if (argc >= 5) { |
| 579 | filename = argv[4]; |
| 580 | } else { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 581 | filename = env_get("bootfile"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 582 | if (!filename) { |
| 583 | puts("** No boot file defined **\n"); |
| 584 | return 1; |
| 585 | } |
| 586 | } |
| 587 | if (argc >= 6) |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 588 | bytes = simple_strtoul(argv[5], NULL, 16); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 589 | else |
| 590 | bytes = 0; |
| 591 | if (argc >= 7) |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 592 | pos = simple_strtoul(argv[6], NULL, 16); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 593 | else |
| 594 | pos = 0; |
| 595 | |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 596 | time = get_timer(0); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 597 | ret = fs_read(filename, addr, pos, bytes, &len_read); |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 598 | time = get_timer(time); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 599 | if (ret < 0) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 600 | return 1; |
| 601 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 602 | printf("%llu bytes read in %lu ms", len_read, time); |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 603 | if (time > 0) { |
| 604 | puts(" ("); |
Tom Rini | 9e374e7 | 2014-11-24 11:50:46 -0500 | [diff] [blame] | 605 | print_size(div_u64(len_read, time) * 1000, "/s"); |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 606 | puts(")"); |
| 607 | } |
| 608 | puts("\n"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 609 | |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 610 | env_set_hex("fileaddr", addr); |
| 611 | env_set_hex("filesize", len_read); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 617 | int fstype) |
| 618 | { |
| 619 | if (argc < 2) |
| 620 | return CMD_RET_USAGE; |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 621 | if (argc > 4) |
| 622 | return CMD_RET_USAGE; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 623 | |
| 624 | if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) |
| 625 | return 1; |
| 626 | |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 627 | if (fs_ls(argc >= 4 ? argv[3] : "/")) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 628 | return 1; |
| 629 | |
| 630 | return 0; |
| 631 | } |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 632 | |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 633 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
| 634 | int fstype) |
| 635 | { |
| 636 | if (fs_set_blk_dev(dev_type, dev_part, fstype)) |
| 637 | return 0; |
| 638 | |
| 639 | return fs_exists(file); |
| 640 | } |
| 641 | |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 642 | int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 643 | int fstype) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 644 | { |
| 645 | unsigned long addr; |
| 646 | const char *filename; |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 647 | loff_t bytes; |
| 648 | loff_t pos; |
| 649 | loff_t len; |
| 650 | int ret; |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 651 | unsigned long time; |
| 652 | |
| 653 | if (argc < 6 || argc > 7) |
| 654 | return CMD_RET_USAGE; |
| 655 | |
| 656 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 657 | return 1; |
| 658 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 659 | addr = simple_strtoul(argv[3], NULL, 16); |
| 660 | filename = argv[4]; |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 661 | bytes = simple_strtoul(argv[5], NULL, 16); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 662 | if (argc >= 7) |
Wolfgang Denk | b770e88 | 2013-10-05 21:07:25 +0200 | [diff] [blame] | 663 | pos = simple_strtoul(argv[6], NULL, 16); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 664 | else |
| 665 | pos = 0; |
| 666 | |
| 667 | time = get_timer(0); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 668 | ret = fs_write(filename, addr, pos, bytes, &len); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 669 | time = get_timer(time); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 670 | if (ret < 0) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 671 | return 1; |
| 672 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 673 | printf("%llu bytes written in %lu ms", len, time); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 674 | if (time > 0) { |
| 675 | puts(" ("); |
Tom Rini | 9e374e7 | 2014-11-24 11:50:46 -0500 | [diff] [blame] | 676 | print_size(div_u64(len, time) * 1000, "/s"); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 677 | puts(")"); |
| 678 | } |
| 679 | puts("\n"); |
| 680 | |
| 681 | return 0; |
| 682 | } |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 683 | |
| 684 | int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 685 | int fstype) |
| 686 | { |
| 687 | int ret; |
| 688 | char uuid[37]; |
| 689 | memset(uuid, 0, sizeof(uuid)); |
| 690 | |
| 691 | if (argc < 3 || argc > 4) |
| 692 | return CMD_RET_USAGE; |
| 693 | |
| 694 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 695 | return 1; |
| 696 | |
| 697 | ret = fs_uuid(uuid); |
| 698 | if (ret) |
| 699 | return CMD_RET_FAILURE; |
| 700 | |
| 701 | if (argc == 4) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 702 | env_set(argv[3], uuid); |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 703 | else |
| 704 | printf("%s\n", uuid); |
| 705 | |
| 706 | return CMD_RET_SUCCESS; |
| 707 | } |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 708 | |
| 709 | int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 710 | { |
| 711 | struct fstype_info *info; |
| 712 | |
| 713 | if (argc < 3 || argc > 4) |
| 714 | return CMD_RET_USAGE; |
| 715 | |
| 716 | if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY)) |
| 717 | return 1; |
| 718 | |
| 719 | info = fs_get_info(fs_type); |
| 720 | |
| 721 | if (argc == 4) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 722 | env_set(argv[3], info->name); |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 723 | else |
| 724 | printf("%s\n", info->name); |
| 725 | |
| 726 | return CMD_RET_SUCCESS; |
| 727 | } |
| 728 | |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame^] | 729 | int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], |
| 730 | int fstype) |
| 731 | { |
| 732 | int ret; |
| 733 | |
| 734 | if (argc != 4) |
| 735 | return CMD_RET_USAGE; |
| 736 | |
| 737 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 738 | return 1; |
| 739 | |
| 740 | ret = fs_mkdir(argv[3]); |
| 741 | if (ret) { |
| 742 | printf("** Unable to create a directory \"%s\" **\n", argv[3]); |
| 743 | return 1; |
| 744 | } |
| 745 | |
| 746 | return 0; |
| 747 | } |