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