]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_fat.c
Merge branch 'master' of git://git.denx.de/u-boot-nand-flash
[people/ms/u-boot.git] / common / cmd_fat.c
CommitLineData
71f95118
WD
1/*
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>
71f95118
WD
29#include <s_record.h>
30#include <net.h>
31#include <ata.h>
735dd97b 32#include <part.h>
71f95118
WD
33#include <fat.h>
34
7205e407 35
54841ab5 36int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118
WD
37{
38 long size;
39 unsigned long offset;
40 unsigned long count;
fbe4b5cb 41 char buf [12];
7205e407
WD
42 block_dev_desc_t *dev_desc=NULL;
43 int dev=0;
44 int part=1;
45 char *ep;
71f95118 46
7205e407 47 if (argc < 5) {
7385c28e
WD
48 printf( "usage: fatload <interface> <dev[:part]> "
49 "<addr> <filename> [bytes]\n");
31a64923 50 return 1;
71f95118 51 }
7385c28e
WD
52
53 dev = (int)simple_strtoul(argv[2], &ep, 16);
54 dev_desc = get_dev(argv[1],dev);
55 if (dev_desc == NULL) {
56 puts("\n** Invalid boot device **\n");
7205e407
WD
57 return 1;
58 }
59 if (*ep) {
60 if (*ep != ':') {
7385c28e 61 puts("\n** Invalid boot device, use `dev[:part]' **\n");
7205e407
WD
62 return 1;
63 }
64 part = (int)simple_strtoul(++ep, NULL, 16);
65 }
66 if (fat_register_device(dev_desc,part)!=0) {
7385c28e
WD
67 printf("\n** Unable to use %s %d:%d for fatload **\n",
68 argv[1], dev, part);
7205e407
WD
69 return 1;
70 }
7385c28e 71 offset = simple_strtoul(argv[3], NULL, 16);
7205e407 72 if (argc == 6)
7385c28e 73 count = simple_strtoul(argv[5], NULL, 16);
71f95118
WD
74 else
75 count = 0;
7385c28e 76 size = file_fat_read(argv[4], (unsigned char *)offset, count);
71f95118 77
fbe4b5cb 78 if(size==-1) {
7385c28e
WD
79 printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
80 argv[4], argv[1], dev, part);
31a64923 81 return 1;
fbe4b5cb
WD
82 }
83
7385c28e 84 printf("\n%ld bytes read\n", size);
31a64923
WD
85
86 sprintf(buf, "%lX", size);
87 setenv("filesize", buf);
88
89 return 0;
71f95118
WD
90}
91
7205e407 92
0d498393 93U_BOOT_CMD(
7205e407 94 fatload, 6, 0, do_fat_fsload,
2fb2604d 95 "load binary file from a dos filesystem",
7205e407
WD
96 "<interface> <dev[:part]> <addr> <filename> [bytes]\n"
97 " - load binary file 'filename' from 'dev' on 'interface'\n"
a89c33db 98 " to address 'addr' from dos filesystem"
b0fce99b
WD
99);
100
54841ab5 101int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118
WD
102{
103 char *filename = "/";
104 int ret;
7205e407
WD
105 int dev=0;
106 int part=1;
107 char *ep;
108 block_dev_desc_t *dev_desc=NULL;
71f95118 109
7205e407 110 if (argc < 3) {
7385c28e
WD
111 printf("usage: fatls <interface> <dev[:part]> [directory]\n");
112 return 0;
7205e407 113 }
7385c28e
WD
114 dev = (int)simple_strtoul(argv[2], &ep, 16);
115 dev_desc = get_dev(argv[1],dev);
116 if (dev_desc == NULL) {
117 puts("\n** Invalid boot device **\n");
7205e407
WD
118 return 1;
119 }
120 if (*ep) {
121 if (*ep != ':') {
7385c28e 122 puts("\n** Invalid boot device, use `dev[:part]' **\n");
7205e407
WD
123 return 1;
124 }
125 part = (int)simple_strtoul(++ep, NULL, 16);
126 }
127 if (fat_register_device(dev_desc,part)!=0) {
7385c28e
WD
128 printf("\n** Unable to use %s %d:%d for fatls **\n",
129 argv[1], dev, part);
7205e407
WD
130 return 1;
131 }
132 if (argc == 4)
7385c28e 133 ret = file_fat_ls(argv[3]);
71f95118 134 else
7385c28e 135 ret = file_fat_ls(filename);
71f95118 136
7205e407
WD
137 if(ret!=0)
138 printf("No Fat FS detected\n");
7385c28e 139 return ret;
71f95118
WD
140}
141
0d498393 142U_BOOT_CMD(
7205e407 143 fatls, 4, 1, do_fat_ls,
2fb2604d 144 "list files in a directory (default /)",
7205e407 145 "<interface> <dev[:part]> [directory]\n"
a89c33db 146 " - list files from 'dev' on 'interface' in a 'directory'"
b0fce99b
WD
147);
148
54841ab5 149int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71f95118 150{
7205e407
WD
151 int dev=0;
152 int part=1;
153 char *ep;
154 block_dev_desc_t *dev_desc=NULL;
71f95118 155
7205e407 156 if (argc < 2) {
7385c28e
WD
157 printf("usage: fatinfo <interface> <dev[:part]>\n");
158 return 0;
7205e407 159 }
7385c28e
WD
160 dev = (int)simple_strtoul(argv[2], &ep, 16);
161 dev_desc = get_dev(argv[1],dev);
162 if (dev_desc == NULL) {
163 puts("\n** Invalid boot device **\n");
7205e407
WD
164 return 1;
165 }
166 if (*ep) {
167 if (*ep != ':') {
7385c28e 168 puts("\n** Invalid boot device, use `dev[:part]' **\n");
7205e407
WD
169 return 1;
170 }
171 part = (int)simple_strtoul(++ep, NULL, 16);
172 }
173 if (fat_register_device(dev_desc,part)!=0) {
7385c28e
WD
174 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
175 argv[1], dev, part);
7205e407
WD
176 return 1;
177 }
7385c28e 178 return file_fat_detectfs();
71f95118
WD
179}
180
0d498393 181U_BOOT_CMD(
7205e407 182 fatinfo, 3, 1, do_fat_fsinfo,
2fb2604d 183 "print information about filesystem",
7205e407 184 "<interface> <dev[:part]>\n"
a89c33db 185 " - print information about filesystem from 'dev' on 'interface'"
b0fce99b 186);