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