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 | |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 6 | #define LOG_CATEGORY LOGC_CORE |
| 7 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | 4e4bf94 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 10 | #include <display_options.h> |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 11 | #include <errno.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 12 | #include <common.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 14 | #include <lmb.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 16 | #include <mapmem.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 17 | #include <part.h> |
| 18 | #include <ext4fs.h> |
| 19 | #include <fat.h> |
| 20 | #include <fs.h> |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 21 | #include <sandboxfs.h> |
Sean Anderson | f676b45 | 2022-03-22 16:59:20 -0400 | [diff] [blame] | 22 | #include <semihostingfs.h> |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 23 | #include <ubifs_uboot.h> |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 24 | #include <btrfs.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 25 | #include <asm/global_data.h> |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 26 | #include <asm/io.h> |
Tom Rini | 9e374e7 | 2014-11-24 11:50:46 -0500 | [diff] [blame] | 27 | #include <div64.h> |
| 28 | #include <linux/math64.h> |
Mian Yousaf Kaukab | ee88eac | 2019-06-18 15:03:44 +0200 | [diff] [blame] | 29 | #include <efi_loader.h> |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 30 | #include <squashfs.h> |
Huang Jianan | 830613f | 2022-02-26 15:05:47 +0800 | [diff] [blame] | 31 | #include <erofs.h> |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 32 | |
Stephen Warren | a1b231c | 2012-10-30 07:50:47 +0000 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 35 | static struct blk_desc *fs_dev_desc; |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 36 | static int fs_dev_part; |
Simon Glass | 0528979 | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 37 | static struct disk_partition fs_partition; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 38 | static int fs_type = FS_TYPE_ANY; |
| 39 | |
Simon Glass | c24e58f | 2022-04-24 23:31:04 -0600 | [diff] [blame] | 40 | void fs_set_type(int type) |
| 41 | { |
| 42 | fs_type = type; |
| 43 | } |
| 44 | |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 45 | static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc, |
Simon Glass | 0528979 | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 46 | struct disk_partition *fs_partition) |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 47 | { |
Heinrich Schuchardt | 3bd0e2c | 2021-09-20 14:15:03 +0200 | [diff] [blame] | 48 | log_debug("Unrecognized filesystem type\n"); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 49 | return -1; |
| 50 | } |
| 51 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 52 | static inline int fs_ls_unsupported(const char *dirname) |
| 53 | { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 54 | return -1; |
| 55 | } |
| 56 | |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 57 | /* generic implementation of ls in terms of opendir/readdir/closedir */ |
| 58 | __maybe_unused |
| 59 | static int fs_ls_generic(const char *dirname) |
| 60 | { |
| 61 | struct fs_dir_stream *dirs; |
| 62 | struct fs_dirent *dent; |
| 63 | int nfiles = 0, ndirs = 0; |
| 64 | |
| 65 | dirs = fs_opendir(dirname); |
| 66 | if (!dirs) |
| 67 | return -errno; |
| 68 | |
| 69 | while ((dent = fs_readdir(dirs))) { |
| 70 | if (dent->type == FS_DT_DIR) { |
| 71 | printf(" %s/\n", dent->name); |
| 72 | ndirs++; |
Joao Marcos Costa | 02c366b | 2020-07-30 15:33:51 +0200 | [diff] [blame] | 73 | } else if (dent->type == FS_DT_LNK) { |
| 74 | printf(" <SYM> %s\n", dent->name); |
| 75 | nfiles++; |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 76 | } else { |
| 77 | printf(" %8lld %s\n", dent->size, dent->name); |
| 78 | nfiles++; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | fs_closedir(dirs); |
| 83 | |
| 84 | printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 89 | static inline int fs_exists_unsupported(const char *filename) |
| 90 | { |
| 91 | return 0; |
| 92 | } |
| 93 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 94 | static inline int fs_size_unsupported(const char *filename, loff_t *size) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 95 | { |
| 96 | return -1; |
| 97 | } |
| 98 | |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 99 | static inline int fs_read_unsupported(const char *filename, void *buf, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 100 | loff_t offset, loff_t len, |
| 101 | loff_t *actread) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 102 | { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 103 | return -1; |
| 104 | } |
| 105 | |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 106 | static inline int fs_write_unsupported(const char *filename, void *buf, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 107 | loff_t offset, loff_t len, |
| 108 | loff_t *actwrite) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 109 | { |
| 110 | return -1; |
| 111 | } |
| 112 | |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 113 | static inline int fs_ln_unsupported(const char *filename, const char *target) |
| 114 | { |
| 115 | return -1; |
| 116 | } |
| 117 | |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 118 | static inline void fs_close_unsupported(void) |
| 119 | { |
| 120 | } |
| 121 | |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 122 | static inline int fs_uuid_unsupported(char *uuid_str) |
| 123 | { |
| 124 | return -1; |
| 125 | } |
| 126 | |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 127 | static inline int fs_opendir_unsupported(const char *filename, |
| 128 | struct fs_dir_stream **dirs) |
| 129 | { |
| 130 | return -EACCES; |
| 131 | } |
| 132 | |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 133 | static inline int fs_unlink_unsupported(const char *filename) |
| 134 | { |
| 135 | return -1; |
| 136 | } |
| 137 | |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 138 | static inline int fs_mkdir_unsupported(const char *dirname) |
| 139 | { |
| 140 | return -1; |
| 141 | } |
| 142 | |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 143 | struct fstype_info { |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 144 | int fstype; |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 145 | char *name; |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 146 | /* |
| 147 | * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This |
| 148 | * should be false in most cases. For "virtual" filesystems which |
| 149 | * 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] | 150 | * 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] | 151 | * of fstypes[], since that is essentially a "virtual" (non-existent) |
| 152 | * filesystem. |
| 153 | */ |
| 154 | bool null_dev_desc_ok; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 155 | int (*probe)(struct blk_desc *fs_dev_desc, |
Simon Glass | 0528979 | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 156 | struct disk_partition *fs_partition); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 157 | int (*ls)(const char *dirname); |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 158 | int (*exists)(const char *filename); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 159 | int (*size)(const char *filename, loff_t *size); |
| 160 | int (*read)(const char *filename, void *buf, loff_t offset, |
| 161 | loff_t len, loff_t *actread); |
| 162 | int (*write)(const char *filename, void *buf, loff_t offset, |
| 163 | loff_t len, loff_t *actwrite); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 164 | void (*close)(void); |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 165 | int (*uuid)(char *uuid_str); |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 166 | /* |
| 167 | * Open a directory stream. On success return 0 and directory |
| 168 | * stream pointer via 'dirsp'. On error, return -errno. See |
| 169 | * fs_opendir(). |
| 170 | */ |
| 171 | int (*opendir)(const char *filename, struct fs_dir_stream **dirsp); |
| 172 | /* |
| 173 | * Read next entry from directory stream. On success return 0 |
| 174 | * and directory entry pointer via 'dentp'. On error return |
| 175 | * -errno. See fs_readdir(). |
| 176 | */ |
| 177 | int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp); |
| 178 | /* see fs_closedir() */ |
| 179 | void (*closedir)(struct fs_dir_stream *dirs); |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 180 | int (*unlink)(const char *filename); |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 181 | int (*mkdir)(const char *dirname); |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 182 | int (*ln)(const char *filename, const char *target); |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | static struct fstype_info fstypes[] = { |
Pali RohĂĄr | 5bbaba6 | 2022-04-05 15:48:32 +0200 | [diff] [blame] | 186 | #if CONFIG_IS_ENABLED(FS_FAT) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 187 | { |
| 188 | .fstype = FS_TYPE_FAT, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 189 | .name = "fat", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 190 | .null_dev_desc_ok = false, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 191 | .probe = fat_set_blk_dev, |
| 192 | .close = fat_close, |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 193 | .ls = fs_ls_generic, |
Stephen Warren | b7b5f31 | 2014-02-03 13:21:10 -0700 | [diff] [blame] | 194 | .exists = fat_exists, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 195 | .size = fat_size, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 196 | .read = fat_read_file, |
Tien Fong Chee | d8c3ea9 | 2019-01-23 14:20:04 +0800 | [diff] [blame] | 197 | #if CONFIG_IS_ENABLED(FAT_WRITE) |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 198 | .write = file_fat_write, |
AKASHI Takahiro | f8240ce | 2018-09-11 15:59:14 +0900 | [diff] [blame] | 199 | .unlink = fat_unlink, |
AKASHI Takahiro | 31a18d5 | 2018-09-11 15:59:10 +0900 | [diff] [blame] | 200 | .mkdir = fat_mkdir, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 201 | #else |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 202 | .write = fs_write_unsupported, |
AKASHI Takahiro | f8240ce | 2018-09-11 15:59:14 +0900 | [diff] [blame] | 203 | .unlink = fs_unlink_unsupported, |
AKASHI Takahiro | 31a18d5 | 2018-09-11 15:59:10 +0900 | [diff] [blame] | 204 | .mkdir = fs_mkdir_unsupported, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 205 | #endif |
Heinrich Schuchardt | c0029e4 | 2020-12-31 00:38:13 +0100 | [diff] [blame] | 206 | .uuid = fat_uuid, |
Rob Clark | 89191d6 | 2017-09-09 13:15:58 -0400 | [diff] [blame] | 207 | .opendir = fat_opendir, |
| 208 | .readdir = fat_readdir, |
| 209 | .closedir = fat_closedir, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 210 | .ln = fs_ln_unsupported, |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 211 | }, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 212 | #endif |
Tien Fong Chee | cafc429 | 2019-01-23 14:20:06 +0800 | [diff] [blame] | 213 | |
| 214 | #if CONFIG_IS_ENABLED(FS_EXT4) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 215 | { |
| 216 | .fstype = FS_TYPE_EXT, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 217 | .name = "ext4", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 218 | .null_dev_desc_ok = false, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 219 | .probe = ext4fs_probe, |
| 220 | .close = ext4fs_close, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 221 | .ls = ext4fs_ls, |
Stephen Warren | 55af5c9 | 2014-02-03 13:21:09 -0700 | [diff] [blame] | 222 | .exists = ext4fs_exists, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 223 | .size = ext4fs_size, |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 224 | .read = ext4_read_file, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 225 | #ifdef CONFIG_CMD_EXT4_WRITE |
| 226 | .write = ext4_write_file, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 227 | .ln = ext4fs_create_link, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 228 | #else |
Stephen Warren | bd6fb31 | 2014-02-03 13:20:59 -0700 | [diff] [blame] | 229 | .write = fs_write_unsupported, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 230 | .ln = fs_ln_unsupported, |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 231 | #endif |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 232 | .uuid = ext4fs_uuid, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 233 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 234 | .unlink = fs_unlink_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 235 | .mkdir = fs_mkdir_unsupported, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 236 | }, |
| 237 | #endif |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 238 | #ifdef CONFIG_SANDBOX |
| 239 | { |
| 240 | .fstype = FS_TYPE_SANDBOX, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 241 | .name = "sandbox", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 242 | .null_dev_desc_ok = true, |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 243 | .probe = sandbox_fs_set_blk_dev, |
| 244 | .close = sandbox_fs_close, |
| 245 | .ls = sandbox_fs_ls, |
Stephen Warren | 0a30aa1 | 2014-02-03 13:21:07 -0700 | [diff] [blame] | 246 | .exists = sandbox_fs_exists, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 247 | .size = sandbox_fs_size, |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 248 | .read = fs_read_sandbox, |
Simon Glass | 7eb2c8d | 2013-04-20 08:42:51 +0000 | [diff] [blame] | 249 | .write = fs_write_sandbox, |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 250 | .uuid = fs_uuid_unsupported, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 251 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 252 | .unlink = fs_unlink_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 253 | .mkdir = fs_mkdir_unsupported, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 254 | .ln = fs_ln_unsupported, |
Simon Glass | 92ccc96 | 2012-12-26 09:53:35 +0000 | [diff] [blame] | 255 | }, |
| 256 | #endif |
Sean Anderson | f676b45 | 2022-03-22 16:59:20 -0400 | [diff] [blame] | 257 | #ifdef CONFIG_SEMIHOSTING |
| 258 | { |
| 259 | .fstype = FS_TYPE_SEMIHOSTING, |
| 260 | .name = "semihosting", |
| 261 | .null_dev_desc_ok = true, |
| 262 | .probe = smh_fs_set_blk_dev, |
| 263 | .close = fs_close_unsupported, |
| 264 | .ls = fs_ls_unsupported, |
| 265 | .exists = fs_exists_unsupported, |
| 266 | .size = smh_fs_size, |
| 267 | .read = smh_fs_read, |
| 268 | .write = smh_fs_write, |
| 269 | .uuid = fs_uuid_unsupported, |
| 270 | .opendir = fs_opendir_unsupported, |
| 271 | .unlink = fs_unlink_unsupported, |
| 272 | .mkdir = fs_mkdir_unsupported, |
| 273 | .ln = fs_ln_unsupported, |
| 274 | }, |
| 275 | #endif |
Pali RohĂĄr | b8617df | 2022-04-05 15:49:24 +0200 | [diff] [blame] | 276 | #ifndef CONFIG_SPL_BUILD |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 277 | #ifdef CONFIG_CMD_UBIFS |
| 278 | { |
| 279 | .fstype = FS_TYPE_UBIFS, |
| 280 | .name = "ubifs", |
| 281 | .null_dev_desc_ok = true, |
| 282 | .probe = ubifs_set_blk_dev, |
| 283 | .close = ubifs_close, |
| 284 | .ls = ubifs_ls, |
| 285 | .exists = ubifs_exists, |
| 286 | .size = ubifs_size, |
| 287 | .read = ubifs_read, |
| 288 | .write = fs_write_unsupported, |
| 289 | .uuid = fs_uuid_unsupported, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 290 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 291 | .unlink = fs_unlink_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 292 | .mkdir = fs_mkdir_unsupported, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 293 | .ln = fs_ln_unsupported, |
Hans de Goede | 251cee0 | 2015-09-17 18:46:58 -0400 | [diff] [blame] | 294 | }, |
| 295 | #endif |
Pali RohĂĄr | b8617df | 2022-04-05 15:49:24 +0200 | [diff] [blame] | 296 | #endif |
Pali RohĂĄr | b8a7916 | 2022-04-07 14:53:25 +0200 | [diff] [blame] | 297 | #ifndef CONFIG_SPL_BUILD |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 298 | #ifdef CONFIG_FS_BTRFS |
| 299 | { |
| 300 | .fstype = FS_TYPE_BTRFS, |
| 301 | .name = "btrfs", |
| 302 | .null_dev_desc_ok = false, |
| 303 | .probe = btrfs_probe, |
| 304 | .close = btrfs_close, |
| 305 | .ls = btrfs_ls, |
| 306 | .exists = btrfs_exists, |
| 307 | .size = btrfs_size, |
| 308 | .read = btrfs_read, |
| 309 | .write = fs_write_unsupported, |
| 310 | .uuid = btrfs_uuid, |
Marek BehĂșn | 38fc683 | 2017-10-06 16:56:07 +0200 | [diff] [blame] | 311 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 312 | .unlink = fs_unlink_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 313 | .mkdir = fs_mkdir_unsupported, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 314 | .ln = fs_ln_unsupported, |
Marek BehĂșn | 0c936ee | 2017-09-03 17:00:29 +0200 | [diff] [blame] | 315 | }, |
| 316 | #endif |
Pali RohĂĄr | b8a7916 | 2022-04-07 14:53:25 +0200 | [diff] [blame] | 317 | #endif |
Pali RohĂĄr | f362dea | 2022-04-06 23:34:00 +0200 | [diff] [blame] | 318 | #if CONFIG_IS_ENABLED(FS_SQUASHFS) |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 319 | { |
| 320 | .fstype = FS_TYPE_SQUASHFS, |
| 321 | .name = "squashfs", |
Richard Genoud | 1b1e0c0 | 2020-11-03 12:10:59 +0100 | [diff] [blame] | 322 | .null_dev_desc_ok = false, |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 323 | .probe = sqfs_probe, |
| 324 | .opendir = sqfs_opendir, |
| 325 | .readdir = sqfs_readdir, |
| 326 | .ls = fs_ls_generic, |
| 327 | .read = sqfs_read, |
| 328 | .size = sqfs_size, |
| 329 | .close = sqfs_close, |
| 330 | .closedir = sqfs_closedir, |
Richard Genoud | dd4866b | 2020-11-03 12:11:26 +0100 | [diff] [blame] | 331 | .exists = sqfs_exists, |
Richard Genoud | 1b1e0c0 | 2020-11-03 12:10:59 +0100 | [diff] [blame] | 332 | .uuid = fs_uuid_unsupported, |
| 333 | .write = fs_write_unsupported, |
| 334 | .ln = fs_ln_unsupported, |
| 335 | .unlink = fs_unlink_unsupported, |
| 336 | .mkdir = fs_mkdir_unsupported, |
Joao Marcos Costa | c510061 | 2020-07-30 15:33:47 +0200 | [diff] [blame] | 337 | }, |
| 338 | #endif |
Huang Jianan | 830613f | 2022-02-26 15:05:47 +0800 | [diff] [blame] | 339 | #if IS_ENABLED(CONFIG_FS_EROFS) |
| 340 | { |
| 341 | .fstype = FS_TYPE_EROFS, |
| 342 | .name = "erofs", |
| 343 | .null_dev_desc_ok = false, |
| 344 | .probe = erofs_probe, |
| 345 | .opendir = erofs_opendir, |
| 346 | .readdir = erofs_readdir, |
| 347 | .ls = fs_ls_generic, |
| 348 | .read = erofs_read, |
| 349 | .size = erofs_size, |
| 350 | .close = erofs_close, |
| 351 | .closedir = erofs_closedir, |
| 352 | .exists = erofs_exists, |
| 353 | .uuid = fs_uuid_unsupported, |
| 354 | .write = fs_write_unsupported, |
| 355 | .ln = fs_ln_unsupported, |
| 356 | .unlink = fs_unlink_unsupported, |
| 357 | .mkdir = fs_mkdir_unsupported, |
| 358 | }, |
| 359 | #endif |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 360 | { |
| 361 | .fstype = FS_TYPE_ANY, |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 362 | .name = "unsupported", |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 363 | .null_dev_desc_ok = true, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 364 | .probe = fs_probe_unsupported, |
| 365 | .close = fs_close_unsupported, |
| 366 | .ls = fs_ls_unsupported, |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 367 | .exists = fs_exists_unsupported, |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 368 | .size = fs_size_unsupported, |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 369 | .read = fs_read_unsupported, |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 370 | .write = fs_write_unsupported, |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 371 | .uuid = fs_uuid_unsupported, |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 372 | .opendir = fs_opendir_unsupported, |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 373 | .unlink = fs_unlink_unsupported, |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 374 | .mkdir = fs_mkdir_unsupported, |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 375 | .ln = fs_ln_unsupported, |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 376 | }, |
| 377 | }; |
| 378 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 379 | static struct fstype_info *fs_get_info(int fstype) |
| 380 | { |
| 381 | struct fstype_info *info; |
| 382 | int i; |
| 383 | |
| 384 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) { |
| 385 | if (fstype == info->fstype) |
| 386 | return info; |
| 387 | } |
| 388 | |
| 389 | /* Return the 'unsupported' sentinel */ |
| 390 | return info; |
| 391 | } |
| 392 | |
Alex Kiernan | 0d488e8 | 2018-05-29 15:30:50 +0000 | [diff] [blame] | 393 | /** |
AKASHI Takahiro | b7cd956 | 2019-10-07 14:59:37 +0900 | [diff] [blame] | 394 | * fs_get_type() - Get type of current filesystem |
| 395 | * |
| 396 | * Return: filesystem type |
| 397 | * |
| 398 | * Returns filesystem type representing the current filesystem, or |
| 399 | * FS_TYPE_ANY for any unrecognised filesystem. |
| 400 | */ |
| 401 | int fs_get_type(void) |
| 402 | { |
| 403 | return fs_type; |
| 404 | } |
| 405 | |
| 406 | /** |
Alex Kiernan | 0d488e8 | 2018-05-29 15:30:50 +0000 | [diff] [blame] | 407 | * fs_get_type_name() - Get type of current filesystem |
| 408 | * |
| 409 | * Return: Pointer to filesystem name |
| 410 | * |
| 411 | * Returns a string describing the current filesystem, or the sentinel |
| 412 | * "unsupported" for any unrecognised filesystem. |
| 413 | */ |
| 414 | const char *fs_get_type_name(void) |
| 415 | { |
| 416 | return fs_get_info(fs_type)->name; |
| 417 | } |
| 418 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 419 | int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) |
| 420 | { |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 421 | struct fstype_info *info; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 422 | int part, i; |
Stephen Warren | a1b231c | 2012-10-30 07:50:47 +0000 | [diff] [blame] | 423 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 424 | static int relocated; |
| 425 | |
| 426 | if (!relocated) { |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 427 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); |
| 428 | i++, info++) { |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 429 | info->name += gd->reloc_off; |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 430 | info->probe += gd->reloc_off; |
| 431 | info->close += gd->reloc_off; |
| 432 | info->ls += gd->reloc_off; |
| 433 | info->read += gd->reloc_off; |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 434 | info->write += gd->reloc_off; |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 435 | } |
Stephen Warren | a1b231c | 2012-10-30 07:50:47 +0000 | [diff] [blame] | 436 | relocated = 1; |
| 437 | } |
| 438 | #endif |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 439 | |
Sean Anderson | 7194527 | 2021-04-12 18:53:05 -0400 | [diff] [blame] | 440 | part = part_get_info_by_dev_and_name_or_num(ifname, dev_part_str, &fs_dev_desc, |
| 441 | &fs_partition, 1); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 442 | if (part < 0) |
| 443 | return -1; |
| 444 | |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 445 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { |
| 446 | if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY && |
| 447 | fstype != info->fstype) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 448 | continue; |
| 449 | |
Stephen Warren | 377202b | 2014-02-03 13:21:01 -0700 | [diff] [blame] | 450 | if (!fs_dev_desc && !info->null_dev_desc_ok) |
| 451 | continue; |
| 452 | |
Simon Glass | 2ded0d4 | 2012-12-26 09:53:31 +0000 | [diff] [blame] | 453 | if (!info->probe(fs_dev_desc, &fs_partition)) { |
Simon Glass | 436e2b7 | 2012-12-26 09:53:29 +0000 | [diff] [blame] | 454 | fs_type = info->fstype; |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 455 | fs_dev_part = part; |
| 456 | return 0; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | return -1; |
| 461 | } |
| 462 | |
| 463 | /* set current blk device w/ blk_desc + partition # */ |
| 464 | int fs_set_blk_dev_with_part(struct blk_desc *desc, int part) |
| 465 | { |
| 466 | struct fstype_info *info; |
| 467 | int ret, i; |
| 468 | |
| 469 | if (part >= 1) |
| 470 | ret = part_get_info(desc, part, &fs_partition); |
| 471 | else |
| 472 | ret = part_get_info_whole_disk(desc, &fs_partition); |
| 473 | if (ret) |
| 474 | return ret; |
| 475 | fs_dev_desc = desc; |
| 476 | |
| 477 | for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { |
| 478 | if (!info->probe(fs_dev_desc, &fs_partition)) { |
| 479 | fs_type = info->fstype; |
AKASHI Takahiro | b0c78d8 | 2018-10-17 16:32:02 +0900 | [diff] [blame] | 480 | fs_dev_part = part; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | } |
| 484 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 485 | return -1; |
| 486 | } |
| 487 | |
AKASHI Takahiro | 64f49eb | 2019-10-07 14:59:35 +0900 | [diff] [blame] | 488 | void fs_close(void) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 489 | { |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 490 | struct fstype_info *info = fs_get_info(fs_type); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 491 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 492 | info->close(); |
Simon Glass | e6d5241 | 2012-12-26 09:53:33 +0000 | [diff] [blame] | 493 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 494 | fs_type = FS_TYPE_ANY; |
| 495 | } |
| 496 | |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 497 | int fs_uuid(char *uuid_str) |
| 498 | { |
| 499 | struct fstype_info *info = fs_get_info(fs_type); |
| 500 | |
| 501 | return info->uuid(uuid_str); |
| 502 | } |
| 503 | |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 504 | int fs_ls(const char *dirname) |
| 505 | { |
| 506 | int ret; |
| 507 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 508 | struct fstype_info *info = fs_get_info(fs_type); |
| 509 | |
| 510 | ret = info->ls(dirname); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 511 | |
| 512 | fs_close(); |
| 513 | |
| 514 | return ret; |
| 515 | } |
| 516 | |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 517 | int fs_exists(const char *filename) |
| 518 | { |
| 519 | int ret; |
| 520 | |
| 521 | struct fstype_info *info = fs_get_info(fs_type); |
| 522 | |
| 523 | ret = info->exists(filename); |
| 524 | |
| 525 | fs_close(); |
| 526 | |
| 527 | return ret; |
| 528 | } |
| 529 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 530 | int fs_size(const char *filename, loff_t *size) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 531 | { |
| 532 | int ret; |
| 533 | |
| 534 | struct fstype_info *info = fs_get_info(fs_type); |
| 535 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 536 | ret = info->size(filename, size); |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 537 | |
| 538 | fs_close(); |
| 539 | |
| 540 | return ret; |
| 541 | } |
| 542 | |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 543 | #ifdef CONFIG_LMB |
| 544 | /* Check if a file may be read to the given address */ |
| 545 | static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset, |
| 546 | loff_t len, struct fstype_info *info) |
| 547 | { |
| 548 | struct lmb lmb; |
| 549 | int ret; |
| 550 | loff_t size; |
| 551 | loff_t read_len; |
| 552 | |
| 553 | /* get the actual size of the file */ |
| 554 | ret = info->size(filename, &size); |
| 555 | if (ret) |
| 556 | return ret; |
| 557 | if (offset >= size) { |
| 558 | /* offset >= EOF, no bytes will be written */ |
| 559 | return 0; |
| 560 | } |
| 561 | read_len = size - offset; |
| 562 | |
| 563 | /* limit to 'len' if it is smaller */ |
| 564 | if (len && len < read_len) |
| 565 | read_len = len; |
| 566 | |
Simon Goldschmidt | 9cc2323 | 2019-01-26 22:13:04 +0100 | [diff] [blame] | 567 | lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 568 | lmb_dump_all(&lmb); |
| 569 | |
| 570 | if (lmb_alloc_addr(&lmb, addr, read_len) == addr) |
| 571 | return 0; |
| 572 | |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 573 | log_err("** Reading file would overwrite reserved memory **\n"); |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 574 | return -ENOSPC; |
| 575 | } |
| 576 | #endif |
| 577 | |
| 578 | static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 579 | int do_lmb_check, loff_t *actread) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 580 | { |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 581 | struct fstype_info *info = fs_get_info(fs_type); |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 582 | void *buf; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 583 | int ret; |
| 584 | |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 585 | #ifdef CONFIG_LMB |
| 586 | if (do_lmb_check) { |
| 587 | ret = fs_read_lmb_check(filename, addr, offset, len, info); |
| 588 | if (ret) |
| 589 | return ret; |
| 590 | } |
| 591 | #endif |
| 592 | |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 593 | /* |
| 594 | * We don't actually know how many bytes are being read, since len==0 |
| 595 | * means read the whole file. |
| 596 | */ |
| 597 | buf = map_sysmem(addr, len); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 598 | ret = info->read(filename, buf, offset, len, actread); |
Simon Glass | 117e050 | 2012-12-26 09:53:32 +0000 | [diff] [blame] | 599 | unmap_sysmem(buf); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 600 | |
Simon Glass | c6f548d | 2012-12-26 09:53:30 +0000 | [diff] [blame] | 601 | /* If we requested a specific number of bytes, check we got it */ |
Max Krummenacher | 7a3e70c | 2015-08-05 17:16:58 +0200 | [diff] [blame] | 602 | if (ret == 0 && len && *actread != len) |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 603 | log_debug("** %s shorter than offset + len **\n", filename); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 604 | fs_close(); |
| 605 | |
| 606 | return ret; |
| 607 | } |
| 608 | |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 609 | int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 610 | loff_t *actread) |
| 611 | { |
| 612 | return _fs_read(filename, addr, offset, len, 0, actread); |
| 613 | } |
| 614 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 615 | int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len, |
| 616 | loff_t *actwrite) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 617 | { |
| 618 | struct fstype_info *info = fs_get_info(fs_type); |
| 619 | void *buf; |
| 620 | int ret; |
| 621 | |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 622 | buf = map_sysmem(addr, len); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 623 | ret = info->write(filename, buf, offset, len, actwrite); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 624 | unmap_sysmem(buf); |
| 625 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 626 | if (ret < 0 && len != *actwrite) { |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 627 | log_err("** Unable to write file %s **\n", filename); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 628 | ret = -1; |
| 629 | } |
| 630 | fs_close(); |
| 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 635 | struct fs_dir_stream *fs_opendir(const char *filename) |
| 636 | { |
| 637 | struct fstype_info *info = fs_get_info(fs_type); |
| 638 | struct fs_dir_stream *dirs = NULL; |
| 639 | int ret; |
| 640 | |
| 641 | ret = info->opendir(filename, &dirs); |
| 642 | fs_close(); |
| 643 | if (ret) { |
| 644 | errno = -ret; |
| 645 | return NULL; |
| 646 | } |
| 647 | |
| 648 | dirs->desc = fs_dev_desc; |
| 649 | dirs->part = fs_dev_part; |
| 650 | |
| 651 | return dirs; |
| 652 | } |
| 653 | |
| 654 | struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs) |
| 655 | { |
| 656 | struct fstype_info *info; |
| 657 | struct fs_dirent *dirent; |
| 658 | int ret; |
| 659 | |
| 660 | fs_set_blk_dev_with_part(dirs->desc, dirs->part); |
| 661 | info = fs_get_info(fs_type); |
| 662 | |
| 663 | ret = info->readdir(dirs, &dirent); |
| 664 | fs_close(); |
| 665 | if (ret) { |
| 666 | errno = -ret; |
| 667 | return NULL; |
| 668 | } |
| 669 | |
| 670 | return dirent; |
| 671 | } |
| 672 | |
| 673 | void fs_closedir(struct fs_dir_stream *dirs) |
| 674 | { |
| 675 | struct fstype_info *info; |
| 676 | |
| 677 | if (!dirs) |
| 678 | return; |
| 679 | |
| 680 | fs_set_blk_dev_with_part(dirs->desc, dirs->part); |
| 681 | info = fs_get_info(fs_type); |
| 682 | |
| 683 | info->closedir(dirs); |
| 684 | fs_close(); |
| 685 | } |
| 686 | |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 687 | int fs_unlink(const char *filename) |
| 688 | { |
| 689 | int ret; |
| 690 | |
| 691 | struct fstype_info *info = fs_get_info(fs_type); |
| 692 | |
| 693 | ret = info->unlink(filename); |
| 694 | |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 695 | fs_close(); |
| 696 | |
| 697 | return ret; |
| 698 | } |
Rob Clark | 4bbcc96 | 2017-09-09 13:15:55 -0400 | [diff] [blame] | 699 | |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 700 | int fs_mkdir(const char *dirname) |
| 701 | { |
| 702 | int ret; |
| 703 | |
| 704 | struct fstype_info *info = fs_get_info(fs_type); |
| 705 | |
| 706 | ret = info->mkdir(dirname); |
| 707 | |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 708 | fs_close(); |
| 709 | |
| 710 | return ret; |
| 711 | } |
| 712 | |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 713 | int fs_ln(const char *fname, const char *target) |
| 714 | { |
| 715 | struct fstype_info *info = fs_get_info(fs_type); |
| 716 | int ret; |
| 717 | |
| 718 | ret = info->ln(fname, target); |
| 719 | |
| 720 | if (ret < 0) { |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 721 | log_err("** Unable to create link %s -> %s **\n", fname, target); |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 722 | ret = -1; |
| 723 | } |
| 724 | fs_close(); |
| 725 | |
| 726 | return ret; |
| 727 | } |
| 728 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 729 | int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 730 | int fstype) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 731 | { |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 732 | loff_t size; |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 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 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 740 | if (fs_size(argv[3], &size) < 0) |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 741 | return CMD_RET_FAILURE; |
| 742 | |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 743 | env_set_hex("filesize", size); |
Stephen Warren | cf65981 | 2014-06-11 12:47:26 -0600 | [diff] [blame] | 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 748 | int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 749 | int fstype) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 750 | { |
| 751 | unsigned long addr; |
| 752 | const char *addr_str; |
| 753 | const char *filename; |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 754 | loff_t bytes; |
| 755 | loff_t pos; |
| 756 | loff_t len_read; |
| 757 | int ret; |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 758 | unsigned long time; |
Pavel Machek | 949bbd7 | 2014-07-09 22:42:57 +0200 | [diff] [blame] | 759 | char *ep; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 760 | |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 761 | if (argc < 2) |
| 762 | return CMD_RET_USAGE; |
| 763 | if (argc > 7) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 764 | return CMD_RET_USAGE; |
| 765 | |
Heinrich Schuchardt | ec9d19b | 2021-01-27 21:26:43 +0100 | [diff] [blame] | 766 | if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) { |
| 767 | log_err("Can't set block device\n"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 768 | return 1; |
Heinrich Schuchardt | ec9d19b | 2021-01-27 21:26:43 +0100 | [diff] [blame] | 769 | } |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 770 | |
| 771 | if (argc >= 4) { |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 772 | addr = hextoul(argv[3], &ep); |
Pavel Machek | 949bbd7 | 2014-07-09 22:42:57 +0200 | [diff] [blame] | 773 | if (ep == argv[3] || *ep != '\0') |
| 774 | return CMD_RET_USAGE; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 775 | } else { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 776 | addr_str = env_get("loadaddr"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 777 | if (addr_str != NULL) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 778 | addr = hextoul(addr_str, NULL); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 779 | else |
| 780 | addr = CONFIG_SYS_LOAD_ADDR; |
| 781 | } |
| 782 | if (argc >= 5) { |
| 783 | filename = argv[4]; |
| 784 | } else { |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 785 | filename = env_get("bootfile"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 786 | if (!filename) { |
| 787 | puts("** No boot file defined **\n"); |
| 788 | return 1; |
| 789 | } |
| 790 | } |
| 791 | if (argc >= 6) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 792 | bytes = hextoul(argv[5], NULL); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 793 | else |
| 794 | bytes = 0; |
| 795 | if (argc >= 7) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 796 | pos = hextoul(argv[6], NULL); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 797 | else |
| 798 | pos = 0; |
| 799 | |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 800 | time = get_timer(0); |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 801 | ret = _fs_read(filename, addr, pos, bytes, 1, &len_read); |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 802 | time = get_timer(time); |
Heinrich Schuchardt | 1244f36 | 2020-06-29 20:08:49 +0200 | [diff] [blame] | 803 | if (ret < 0) { |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 804 | log_err("Failed to load '%s'\n", filename); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 805 | return 1; |
Heinrich Schuchardt | 1244f36 | 2020-06-29 20:08:49 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | if (IS_ENABLED(CONFIG_CMD_BOOTEFI)) |
| 809 | efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "", |
Heinrich Schuchardt | 5f59518 | 2021-01-12 12:46:24 +0100 | [diff] [blame] | 810 | (argc > 4) ? argv[4] : "", map_sysmem(addr, 0), |
| 811 | len_read); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 812 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 813 | printf("%llu bytes read in %lu ms", len_read, time); |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 814 | if (time > 0) { |
| 815 | puts(" ("); |
Tom Rini | 9e374e7 | 2014-11-24 11:50:46 -0500 | [diff] [blame] | 816 | print_size(div_u64(len_read, time) * 1000, "/s"); |
Andreas BieĂmann | da1fd96 | 2012-11-14 13:32:37 +0100 | [diff] [blame] | 817 | puts(")"); |
| 818 | } |
| 819 | puts("\n"); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 820 | |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 821 | env_set_hex("fileaddr", addr); |
| 822 | env_set_hex("filesize", len_read); |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 827 | int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 828 | int fstype) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 829 | { |
| 830 | if (argc < 2) |
| 831 | return CMD_RET_USAGE; |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 832 | if (argc > 4) |
| 833 | return CMD_RET_USAGE; |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 834 | |
| 835 | if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) |
| 836 | return 1; |
| 837 | |
Stephen Warren | e9b0f99 | 2012-10-30 12:04:17 +0000 | [diff] [blame] | 838 | if (fs_ls(argc >= 4 ? argv[3] : "/")) |
Stephen Warren | 045fa1e | 2012-10-22 06:43:51 +0000 | [diff] [blame] | 839 | return 1; |
| 840 | |
| 841 | return 0; |
| 842 | } |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 843 | |
Stephen Warren | 6152916 | 2014-02-03 13:21:00 -0700 | [diff] [blame] | 844 | int file_exists(const char *dev_type, const char *dev_part, const char *file, |
| 845 | int fstype) |
| 846 | { |
| 847 | if (fs_set_blk_dev(dev_type, dev_part, fstype)) |
| 848 | return 0; |
| 849 | |
| 850 | return fs_exists(file); |
| 851 | } |
| 852 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 853 | int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 854 | int fstype) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 855 | { |
| 856 | unsigned long addr; |
| 857 | const char *filename; |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 858 | loff_t bytes; |
| 859 | loff_t pos; |
| 860 | loff_t len; |
| 861 | int ret; |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 862 | unsigned long time; |
| 863 | |
| 864 | if (argc < 6 || argc > 7) |
| 865 | return CMD_RET_USAGE; |
| 866 | |
| 867 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 868 | return 1; |
| 869 | |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 870 | addr = hextoul(argv[3], NULL); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 871 | filename = argv[4]; |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 872 | bytes = hextoul(argv[5], NULL); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 873 | if (argc >= 7) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 874 | pos = hextoul(argv[6], NULL); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 875 | else |
| 876 | pos = 0; |
| 877 | |
| 878 | time = get_timer(0); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 879 | ret = fs_write(filename, addr, pos, bytes, &len); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 880 | time = get_timer(time); |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 881 | if (ret < 0) |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 882 | return 1; |
| 883 | |
Suriyan Ramasami | d455d87 | 2014-11-17 14:39:38 -0800 | [diff] [blame] | 884 | printf("%llu bytes written in %lu ms", len, time); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 885 | if (time > 0) { |
| 886 | puts(" ("); |
Tom Rini | 9e374e7 | 2014-11-24 11:50:46 -0500 | [diff] [blame] | 887 | print_size(div_u64(len, time) * 1000, "/s"); |
Simon Glass | a8f6ab5 | 2013-04-20 08:42:50 +0000 | [diff] [blame] | 888 | puts(")"); |
| 889 | } |
| 890 | puts("\n"); |
| 891 | |
| 892 | return 0; |
| 893 | } |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 894 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 895 | int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
| 896 | int fstype) |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 897 | { |
| 898 | int ret; |
| 899 | char uuid[37]; |
| 900 | memset(uuid, 0, sizeof(uuid)); |
| 901 | |
| 902 | if (argc < 3 || argc > 4) |
| 903 | return CMD_RET_USAGE; |
| 904 | |
| 905 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 906 | return 1; |
| 907 | |
| 908 | ret = fs_uuid(uuid); |
| 909 | if (ret) |
| 910 | return CMD_RET_FAILURE; |
| 911 | |
| 912 | if (argc == 4) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 913 | env_set(argv[3], uuid); |
Christian Gmeiner | 59e890e | 2014-11-12 14:35:04 +0100 | [diff] [blame] | 914 | else |
| 915 | printf("%s\n", uuid); |
| 916 | |
| 917 | return CMD_RET_SUCCESS; |
| 918 | } |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 919 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 920 | int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 921 | { |
| 922 | struct fstype_info *info; |
| 923 | |
| 924 | if (argc < 3 || argc > 4) |
| 925 | return CMD_RET_USAGE; |
| 926 | |
| 927 | if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY)) |
| 928 | return 1; |
| 929 | |
| 930 | info = fs_get_info(fs_type); |
| 931 | |
| 932 | if (argc == 4) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 933 | env_set(argv[3], info->name); |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 934 | else |
| 935 | printf("%s\n", info->name); |
| 936 | |
Marek Vasut | e531c67 | 2019-02-06 13:19:29 +0100 | [diff] [blame] | 937 | fs_close(); |
| 938 | |
Sjoerd Simons | 1a1ad8e | 2015-01-05 18:13:36 +0100 | [diff] [blame] | 939 | return CMD_RET_SUCCESS; |
| 940 | } |
| 941 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 942 | int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
AKASHI Takahiro | e2519da | 2018-09-11 15:59:13 +0900 | [diff] [blame] | 943 | int fstype) |
| 944 | { |
| 945 | if (argc != 4) |
| 946 | return CMD_RET_USAGE; |
| 947 | |
| 948 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 949 | return 1; |
| 950 | |
| 951 | if (fs_unlink(argv[3])) |
| 952 | return 1; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 957 | int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 958 | int fstype) |
| 959 | { |
| 960 | int ret; |
| 961 | |
| 962 | if (argc != 4) |
| 963 | return CMD_RET_USAGE; |
| 964 | |
| 965 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 966 | return 1; |
| 967 | |
| 968 | ret = fs_mkdir(argv[3]); |
| 969 | if (ret) { |
Heinrich Schuchardt | 0d32d8c | 2020-08-25 17:49:16 +0000 | [diff] [blame] | 970 | log_err("** Unable to create a directory \"%s\" **\n", argv[3]); |
AKASHI Takahiro | e7074cf | 2018-09-11 15:59:08 +0900 | [diff] [blame] | 971 | return 1; |
| 972 | } |
| 973 | |
| 974 | return 0; |
| 975 | } |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 976 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 977 | int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], |
Jean-Jacques Hiblot | aaa1215 | 2019-02-13 12:15:26 +0100 | [diff] [blame] | 978 | int fstype) |
| 979 | { |
| 980 | if (argc != 5) |
| 981 | return CMD_RET_USAGE; |
| 982 | |
| 983 | if (fs_set_blk_dev(argv[1], argv[2], fstype)) |
| 984 | return 1; |
| 985 | |
| 986 | if (fs_ln(argv[3], argv[4])) |
| 987 | return 1; |
| 988 | |
| 989 | return 0; |
| 990 | } |
Niel Fourie | 2280fa5 | 2020-03-24 16:17:04 +0100 | [diff] [blame] | 991 | |
| 992 | int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) |
| 993 | { |
| 994 | struct fstype_info *drv = fstypes; |
| 995 | const int n_ents = ARRAY_SIZE(fstypes); |
| 996 | struct fstype_info *entry; |
| 997 | int i = 0; |
| 998 | |
| 999 | puts("Supported filesystems"); |
| 1000 | for (entry = drv; entry != drv + n_ents; entry++) { |
| 1001 | if (entry->fstype != FS_TYPE_ANY) { |
| 1002 | printf("%c %s", i ? ',' : ':', entry->name); |
| 1003 | i++; |
| 1004 | } |
| 1005 | } |
| 1006 | if (!i) |
| 1007 | puts(": <none>"); |
| 1008 | puts("\n"); |
| 1009 | return CMD_RET_SUCCESS; |
| 1010 | } |