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