]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
71f95118 WD |
2 | /* |
3 | * (C) Copyright 2002 | |
4 | * Richard Jones, [email protected] | |
71f95118 WD |
5 | */ |
6 | ||
7 | /* | |
8 | * Boot support | |
9 | */ | |
10 | #include <common.h> | |
09140113 | 11 | #include <command.h> |
0eb25b61 | 12 | #include <mapmem.h> |
71f95118 | 13 | #include <fat.h> |
045fa1e1 | 14 | #include <fs.h> |
e6f6f9e6 | 15 | #include <part.h> |
90526e9f | 16 | #include <asm/cache.h> |
7205e407 | 17 | |
09140113 | 18 | int do_fat_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
cf659819 SW |
19 | { |
20 | return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT); | |
21 | } | |
22 | ||
23 | U_BOOT_CMD( | |
24 | fatsize, 4, 0, do_fat_size, | |
25 | "determine a file's size", | |
26 | "<interface> <dev[:part]> <filename>\n" | |
27 | " - Find file 'filename' from 'dev' on 'interface'\n" | |
28 | " and determine its size." | |
29 | ); | |
30 | ||
09140113 | 31 | int do_fat_fsload(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
71f95118 | 32 | { |
b770e88a | 33 | return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT); |
71f95118 WD |
34 | } |
35 | ||
7205e407 | 36 | |
0d498393 | 37 | U_BOOT_CMD( |
1170e634 | 38 | fatload, 7, 0, do_fat_fsload, |
2fb2604d | 39 | "load binary file from a dos filesystem", |
6b367467 | 40 | "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n" |
1170e634 BT |
41 | " - Load binary file 'filename' from 'dev' on 'interface'\n" |
42 | " to address 'addr' from dos filesystem.\n" | |
43 | " 'pos' gives the file position to start loading from.\n" | |
44 | " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n" | |
45 | " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n" | |
3f83c87e | 46 | " the load stops on end of file.\n" |
01fac041 TR |
47 | " If either 'pos' or 'bytes' are not aligned to\n" |
48 | " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n" | |
b770e88a | 49 | " be printed and performance will suffer for the load." |
b0fce99b WD |
50 | ); |
51 | ||
09140113 SG |
52 | static int do_fat_ls(struct cmd_tbl *cmdtp, int flag, int argc, |
53 | char *const argv[]) | |
71f95118 | 54 | { |
045fa1e1 | 55 | return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT); |
71f95118 WD |
56 | } |
57 | ||
0d498393 | 58 | U_BOOT_CMD( |
7205e407 | 59 | fatls, 4, 1, do_fat_ls, |
2fb2604d | 60 | "list files in a directory (default /)", |
cfda5aea | 61 | "<interface> [<dev[:part]>] [directory]\n" |
a89c33db | 62 | " - list files from 'dev' on 'interface' in a 'directory'" |
b0fce99b WD |
63 | ); |
64 | ||
09140113 SG |
65 | static int do_fat_fsinfo(struct cmd_tbl *cmdtp, int flag, int argc, |
66 | char *const argv[]) | |
71f95118 | 67 | { |
cfda5aea | 68 | int dev, part; |
4101f687 | 69 | struct blk_desc *dev_desc; |
0528979f | 70 | struct disk_partition info; |
71f95118 | 71 | |
7205e407 | 72 | if (argc < 2) { |
cfda5aea | 73 | printf("usage: fatinfo <interface> [<dev[:part]>]\n"); |
7385c28e | 74 | return 0; |
7205e407 | 75 | } |
cfda5aea | 76 | |
e35929e4 | 77 | part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); |
cfda5aea | 78 | if (part < 0) |
7205e407 | 79 | return 1; |
cfda5aea | 80 | |
bcce53d0 | 81 | dev = dev_desc->devnum; |
5e8f9831 | 82 | if (fat_set_blk_dev(dev_desc, &info) != 0) { |
7385c28e WD |
83 | printf("\n** Unable to use %s %d:%d for fatinfo **\n", |
84 | argv[1], dev, part); | |
7205e407 WD |
85 | return 1; |
86 | } | |
7385c28e | 87 | return file_fat_detectfs(); |
71f95118 WD |
88 | } |
89 | ||
0d498393 | 90 | U_BOOT_CMD( |
7205e407 | 91 | fatinfo, 3, 1, do_fat_fsinfo, |
2fb2604d | 92 | "print information about filesystem", |
cfda5aea | 93 | "<interface> [<dev[:part]>]\n" |
a89c33db | 94 | " - print information about filesystem from 'dev' on 'interface'" |
b0fce99b | 95 | ); |
656f4c65 DK |
96 | |
97 | #ifdef CONFIG_FAT_WRITE | |
09140113 SG |
98 | static int do_fat_fswrite(struct cmd_tbl *cmdtp, int flag, int argc, |
99 | char *const argv[]) | |
656f4c65 | 100 | { |
1ad0b98a SR |
101 | loff_t size; |
102 | int ret; | |
656f4c65 DK |
103 | unsigned long addr; |
104 | unsigned long count; | |
cda40b2a | 105 | long offset; |
4101f687 | 106 | struct blk_desc *dev_desc = NULL; |
0528979f | 107 | struct disk_partition info; |
656f4c65 DK |
108 | int dev = 0; |
109 | int part = 1; | |
31e997f9 | 110 | void *buf; |
656f4c65 DK |
111 | |
112 | if (argc < 5) | |
113 | return cmd_usage(cmdtp); | |
114 | ||
e35929e4 | 115 | part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); |
cfda5aea | 116 | if (part < 0) |
656f4c65 | 117 | return 1; |
cfda5aea | 118 | |
bcce53d0 | 119 | dev = dev_desc->devnum; |
cfda5aea | 120 | |
5e8f9831 | 121 | if (fat_set_blk_dev(dev_desc, &info) != 0) { |
656f4c65 DK |
122 | printf("\n** Unable to use %s %d:%d for fatwrite **\n", |
123 | argv[1], dev, part); | |
124 | return 1; | |
125 | } | |
126 | addr = simple_strtoul(argv[3], NULL, 16); | |
454e3d90 | 127 | count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16); |
cda40b2a AT |
128 | /* offset should be a hex, but "-1" is allowed */ |
129 | offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16); | |
656f4c65 | 130 | |
31e997f9 | 131 | buf = map_sysmem(addr, count); |
cda40b2a | 132 | ret = file_fat_write(argv[4], buf, offset, count, &size); |
31e997f9 | 133 | unmap_sysmem(buf); |
1ad0b98a | 134 | if (ret < 0) { |
656f4c65 DK |
135 | printf("\n** Unable to write \"%s\" from %s %d:%d **\n", |
136 | argv[4], argv[1], dev, part); | |
137 | return 1; | |
138 | } | |
139 | ||
1ad0b98a | 140 | printf("%llu bytes written\n", size); |
656f4c65 DK |
141 | |
142 | return 0; | |
143 | } | |
144 | ||
145 | U_BOOT_CMD( | |
cda40b2a | 146 | fatwrite, 7, 0, do_fat_fswrite, |
656f4c65 | 147 | "write file into a dos filesystem", |
cda40b2a | 148 | "<interface> <dev[:part]> <addr> <filename> [<bytes> [<offset>]]\n" |
656f4c65 DK |
149 | " - write file 'filename' from the address 'addr' in RAM\n" |
150 | " to 'dev' on 'interface'" | |
151 | ); | |
0349da51 | 152 | |
09140113 SG |
153 | static int do_fat_rm(struct cmd_tbl *cmdtp, int flag, int argc, |
154 | char *const argv[]) | |
d4b751e9 AT |
155 | { |
156 | return do_rm(cmdtp, flag, argc, argv, FS_TYPE_FAT); | |
157 | } | |
158 | ||
159 | U_BOOT_CMD( | |
160 | fatrm, 4, 1, do_fat_rm, | |
161 | "delete a file", | |
162 | "<interface> [<dev[:part]>] <filename>\n" | |
163 | " - delete a file from 'dev' on 'interface'" | |
164 | ); | |
165 | ||
09140113 SG |
166 | static int do_fat_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, |
167 | char *const argv[]) | |
0349da51 AT |
168 | { |
169 | return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_FAT); | |
170 | } | |
171 | ||
172 | U_BOOT_CMD( | |
173 | fatmkdir, 4, 1, do_fat_mkdir, | |
174 | "create a directory", | |
175 | "<interface> [<dev[:part]>] <directory>\n" | |
176 | " - create a directory in 'dev' on 'interface'" | |
177 | ); | |
656f4c65 | 178 | #endif |