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