blob: 5a5698b056cf013784e21421906a31f05725aa19 [file] [log] [blame]
wdenk7a428cc2003-06-15 22:40:42 +00001/*
2 * (C) Copyright 2002
3 * Richard Jones, rjones@nexus-tech.net
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Boot support
26 */
27#include <common.h>
28#include <command.h>
wdenk7a428cc2003-06-15 22:40:42 +000029#include <s_record.h>
30#include <net.h>
31#include <ata.h>
Grant Likelyffc2dd72007-02-20 09:04:34 +010032#include <part.h>
wdenk7a428cc2003-06-15 22:40:42 +000033#include <fat.h>
34
wdenk2c9b05d2003-09-10 22:30:53 +000035
Wolfgang Denk6262d0212010-06-28 22:00:46 +020036int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk7a428cc2003-06-15 22:40:42 +000037{
38 long size;
39 unsigned long offset;
Benoît Thébaudeau5295aa82012-09-18 08:14:56 +000040 unsigned long count = 0;
41 unsigned long pos = 0;
wdenk7182b0f2003-10-06 21:55:32 +000042 char buf [12];
wdenk2c9b05d2003-09-10 22:30:53 +000043 block_dev_desc_t *dev_desc=NULL;
Rob Herring5fc26df2012-08-23 11:31:47 +000044 disk_partition_t info;
45 int part, dev;
wdenk7a428cc2003-06-15 22:40:42 +000046
wdenk2c9b05d2003-09-10 22:30:53 +000047 if (argc < 5) {
Rob Herring5fc26df2012-08-23 11:31:47 +000048 printf("usage: fatload <interface> [<dev[:part]>] "
Benoît Thébaudeau5295aa82012-09-18 08:14:56 +000049 "<addr> <filename> [bytes [pos]]\n");
wdenk79cf7572004-08-28 21:09:14 +000050 return 1;
wdenk7a428cc2003-06-15 22:40:42 +000051 }
Wolfgang Denk927b8ce2010-07-19 11:37:00 +020052
Stephen Warrenc87ff222012-09-21 09:50:57 +000053 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring5fc26df2012-08-23 11:31:47 +000054 if (part < 0)
wdenk2c9b05d2003-09-10 22:30:53 +000055 return 1;
Rob Herring5fc26df2012-08-23 11:31:47 +000056
57 dev = dev_desc->dev;
wdenk2c9b05d2003-09-10 22:30:53 +000058 if (fat_register_device(dev_desc,part)!=0) {
Wolfgang Denk927b8ce2010-07-19 11:37:00 +020059 printf("\n** Unable to use %s %d:%d for fatload **\n",
60 argv[1], dev, part);
wdenk2c9b05d2003-09-10 22:30:53 +000061 return 1;
62 }
Wolfgang Denk927b8ce2010-07-19 11:37:00 +020063 offset = simple_strtoul(argv[3], NULL, 16);
Benoît Thébaudeau5295aa82012-09-18 08:14:56 +000064 if (argc >= 6)
Wolfgang Denk927b8ce2010-07-19 11:37:00 +020065 count = simple_strtoul(argv[5], NULL, 16);
Benoît Thébaudeau5295aa82012-09-18 08:14:56 +000066 if (argc >= 7)
67 pos = simple_strtoul(argv[6], NULL, 16);
68 size = file_fat_read_at(argv[4], pos, (unsigned char *)offset, count);
wdenk7a428cc2003-06-15 22:40:42 +000069
wdenk7182b0f2003-10-06 21:55:32 +000070 if(size==-1) {
Wolfgang Denk927b8ce2010-07-19 11:37:00 +020071 printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
72 argv[4], argv[1], dev, part);
wdenk79cf7572004-08-28 21:09:14 +000073 return 1;
wdenk7182b0f2003-10-06 21:55:32 +000074 }
75
Wolfgang Denk927b8ce2010-07-19 11:37:00 +020076 printf("\n%ld bytes read\n", size);
wdenk79cf7572004-08-28 21:09:14 +000077
78 sprintf(buf, "%lX", size);
79 setenv("filesize", buf);
80
81 return 0;
wdenk7a428cc2003-06-15 22:40:42 +000082}
83
wdenk2c9b05d2003-09-10 22:30:53 +000084
wdenkf287a242003-07-01 21:06:45 +000085U_BOOT_CMD(
Benoît Thébaudeau5295aa82012-09-18 08:14:56 +000086 fatload, 7, 0, do_fat_fsload,
Peter Tyserdfb72b82009-01-27 18:03:12 -060087 "load binary file from a dos filesystem",
Benoît Thébaudeau5295aa82012-09-18 08:14:56 +000088 "<interface> [<dev[:part]>] <addr> <filename> [bytes [pos]]\n"
89 " - Load binary file 'filename' from 'dev' on 'interface'\n"
90 " to address 'addr' from dos filesystem.\n"
91 " 'pos' gives the file position to start loading from.\n"
92 " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
93 " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
94 " the load stops on end of file."
wdenkf12e3962003-06-29 21:03:46 +000095);
96
Wolfgang Denk6262d0212010-06-28 22:00:46 +020097int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk7a428cc2003-06-15 22:40:42 +000098{
99 char *filename = "/";
Rob Herring5fc26df2012-08-23 11:31:47 +0000100 int ret, dev, part;
wdenk2c9b05d2003-09-10 22:30:53 +0000101 block_dev_desc_t *dev_desc=NULL;
Rob Herring5fc26df2012-08-23 11:31:47 +0000102 disk_partition_t info;
wdenk7a428cc2003-06-15 22:40:42 +0000103
Rob Herring5fc26df2012-08-23 11:31:47 +0000104 if (argc < 2) {
105 printf("usage: fatls <interface> [<dev[:part]>] [directory]\n");
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200106 return 0;
wdenk2c9b05d2003-09-10 22:30:53 +0000107 }
Rob Herring5fc26df2012-08-23 11:31:47 +0000108
Stephen Warrenc87ff222012-09-21 09:50:57 +0000109 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring5fc26df2012-08-23 11:31:47 +0000110 if (part < 0)
wdenk2c9b05d2003-09-10 22:30:53 +0000111 return 1;
Rob Herring5fc26df2012-08-23 11:31:47 +0000112
113 dev = dev_desc->dev;
wdenk2c9b05d2003-09-10 22:30:53 +0000114 if (fat_register_device(dev_desc,part)!=0) {
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200115 printf("\n** Unable to use %s %d:%d for fatls **\n",
116 argv[1], dev, part);
wdenk2c9b05d2003-09-10 22:30:53 +0000117 return 1;
118 }
119 if (argc == 4)
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200120 ret = file_fat_ls(argv[3]);
wdenk7a428cc2003-06-15 22:40:42 +0000121 else
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200122 ret = file_fat_ls(filename);
wdenk7a428cc2003-06-15 22:40:42 +0000123
wdenk2c9b05d2003-09-10 22:30:53 +0000124 if(ret!=0)
125 printf("No Fat FS detected\n");
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200126 return ret;
wdenk7a428cc2003-06-15 22:40:42 +0000127}
128
wdenkf287a242003-07-01 21:06:45 +0000129U_BOOT_CMD(
wdenk2c9b05d2003-09-10 22:30:53 +0000130 fatls, 4, 1, do_fat_ls,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600131 "list files in a directory (default /)",
Rob Herring5fc26df2012-08-23 11:31:47 +0000132 "<interface> [<dev[:part]>] [directory]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200133 " - list files from 'dev' on 'interface' in a 'directory'"
wdenkf12e3962003-06-29 21:03:46 +0000134);
135
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200136int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk7a428cc2003-06-15 22:40:42 +0000137{
Rob Herring5fc26df2012-08-23 11:31:47 +0000138 int dev, part;
139 block_dev_desc_t *dev_desc;
140 disk_partition_t info;
wdenk7a428cc2003-06-15 22:40:42 +0000141
wdenk2c9b05d2003-09-10 22:30:53 +0000142 if (argc < 2) {
Rob Herring5fc26df2012-08-23 11:31:47 +0000143 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200144 return 0;
wdenk2c9b05d2003-09-10 22:30:53 +0000145 }
Rob Herring5fc26df2012-08-23 11:31:47 +0000146
Stephen Warrenc87ff222012-09-21 09:50:57 +0000147 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring5fc26df2012-08-23 11:31:47 +0000148 if (part < 0)
wdenk2c9b05d2003-09-10 22:30:53 +0000149 return 1;
Rob Herring5fc26df2012-08-23 11:31:47 +0000150
151 dev = dev_desc->dev;
wdenk2c9b05d2003-09-10 22:30:53 +0000152 if (fat_register_device(dev_desc,part)!=0) {
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200153 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
154 argv[1], dev, part);
wdenk2c9b05d2003-09-10 22:30:53 +0000155 return 1;
156 }
Wolfgang Denk927b8ce2010-07-19 11:37:00 +0200157 return file_fat_detectfs();
wdenk7a428cc2003-06-15 22:40:42 +0000158}
159
wdenkf287a242003-07-01 21:06:45 +0000160U_BOOT_CMD(
wdenk2c9b05d2003-09-10 22:30:53 +0000161 fatinfo, 3, 1, do_fat_fsinfo,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600162 "print information about filesystem",
Rob Herring5fc26df2012-08-23 11:31:47 +0000163 "<interface> [<dev[:part]>]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200164 " - print information about filesystem from 'dev' on 'interface'"
wdenkf12e3962003-06-29 21:03:46 +0000165);
Donggeun Kimb44c8ab2012-03-22 04:38:56 +0000166
167#ifdef CONFIG_FAT_WRITE
168static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
169 int argc, char * const argv[])
170{
171 long size;
172 unsigned long addr;
173 unsigned long count;
174 block_dev_desc_t *dev_desc = NULL;
Rob Herring5fc26df2012-08-23 11:31:47 +0000175 disk_partition_t info;
Donggeun Kimb44c8ab2012-03-22 04:38:56 +0000176 int dev = 0;
177 int part = 1;
Donggeun Kimb44c8ab2012-03-22 04:38:56 +0000178
179 if (argc < 5)
180 return cmd_usage(cmdtp);
181
Stephen Warrenc87ff222012-09-21 09:50:57 +0000182 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring5fc26df2012-08-23 11:31:47 +0000183 if (part < 0)
Donggeun Kimb44c8ab2012-03-22 04:38:56 +0000184 return 1;
Rob Herring5fc26df2012-08-23 11:31:47 +0000185
186 dev = dev_desc->dev;
187
Donggeun Kimb44c8ab2012-03-22 04:38:56 +0000188 if (fat_register_device(dev_desc, part) != 0) {
189 printf("\n** Unable to use %s %d:%d for fatwrite **\n",
190 argv[1], dev, part);
191 return 1;
192 }
193 addr = simple_strtoul(argv[3], NULL, 16);
194 count = simple_strtoul(argv[5], NULL, 16);
195
196 size = file_fat_write(argv[4], (void *)addr, count);
197 if (size == -1) {
198 printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
199 argv[4], argv[1], dev, part);
200 return 1;
201 }
202
203 printf("%ld bytes written\n", size);
204
205 return 0;
206}
207
208U_BOOT_CMD(
209 fatwrite, 6, 0, do_fat_fswrite,
210 "write file into a dos filesystem",
211 "<interface> <dev[:part]> <addr> <filename> <bytes>\n"
212 " - write file 'filename' from the address 'addr' in RAM\n"
213 " to 'dev' on 'interface'"
214);
215#endif