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