blob: 022049434343dc04cf6acea10ab8c1e821cc875e [file] [log] [blame]
wdenk71f95112003-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>
wdenk71f95112003-06-15 22:40:42 +000029#include <s_record.h>
30#include <net.h>
31#include <ata.h>
Grant Likely735dd972007-02-20 09:04:34 +010032#include <part.h>
wdenk71f95112003-06-15 22:40:42 +000033#include <fat.h>
34
wdenk7205e402003-09-10 22:30:53 +000035
Wolfgang Denk54841ab2010-06-28 22:00:46 +020036int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk71f95112003-06-15 22:40:42 +000037{
38 long size;
39 unsigned long offset;
40 unsigned long count;
wdenkfbe4b5c2003-10-06 21:55:32 +000041 char buf [12];
wdenk7205e402003-09-10 22:30:53 +000042 block_dev_desc_t *dev_desc=NULL;
43 int dev=0;
44 int part=1;
45 char *ep;
wdenk71f95112003-06-15 22:40:42 +000046
wdenk7205e402003-09-10 22:30:53 +000047 if (argc < 5) {
Wolfgang Denk7385c282010-07-19 11:37:00 +020048 printf( "usage: fatload <interface> <dev[:part]> "
49 "<addr> <filename> [bytes]\n");
wdenk31a64922004-08-28 21:09:14 +000050 return 1;
wdenk71f95112003-06-15 22:40:42 +000051 }
Wolfgang Denk7385c282010-07-19 11:37:00 +020052
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");
wdenk7205e402003-09-10 22:30:53 +000057 return 1;
58 }
59 if (*ep) {
60 if (*ep != ':') {
Wolfgang Denk7385c282010-07-19 11:37:00 +020061 puts("\n** Invalid boot device, use `dev[:part]' **\n");
wdenk7205e402003-09-10 22:30:53 +000062 return 1;
63 }
64 part = (int)simple_strtoul(++ep, NULL, 16);
65 }
66 if (fat_register_device(dev_desc,part)!=0) {
Wolfgang Denk7385c282010-07-19 11:37:00 +020067 printf("\n** Unable to use %s %d:%d for fatload **\n",
68 argv[1], dev, part);
wdenk7205e402003-09-10 22:30:53 +000069 return 1;
70 }
Wolfgang Denk7385c282010-07-19 11:37:00 +020071 offset = simple_strtoul(argv[3], NULL, 16);
wdenk7205e402003-09-10 22:30:53 +000072 if (argc == 6)
Wolfgang Denk7385c282010-07-19 11:37:00 +020073 count = simple_strtoul(argv[5], NULL, 16);
wdenk71f95112003-06-15 22:40:42 +000074 else
75 count = 0;
Wolfgang Denk7385c282010-07-19 11:37:00 +020076 size = file_fat_read(argv[4], (unsigned char *)offset, count);
wdenk71f95112003-06-15 22:40:42 +000077
wdenkfbe4b5c2003-10-06 21:55:32 +000078 if(size==-1) {
Wolfgang Denk7385c282010-07-19 11:37:00 +020079 printf("\n** Unable to read \"%s\" from %s %d:%d **\n",
80 argv[4], argv[1], dev, part);
wdenk31a64922004-08-28 21:09:14 +000081 return 1;
wdenkfbe4b5c2003-10-06 21:55:32 +000082 }
83
Wolfgang Denk7385c282010-07-19 11:37:00 +020084 printf("\n%ld bytes read\n", size);
wdenk31a64922004-08-28 21:09:14 +000085
86 sprintf(buf, "%lX", size);
87 setenv("filesize", buf);
88
89 return 0;
wdenk71f95112003-06-15 22:40:42 +000090}
91
wdenk7205e402003-09-10 22:30:53 +000092
wdenk0d498392003-07-01 21:06:45 +000093U_BOOT_CMD(
wdenk7205e402003-09-10 22:30:53 +000094 fatload, 6, 0, do_fat_fsload,
Peter Tyser2fb26042009-01-27 18:03:12 -060095 "load binary file from a dos filesystem",
wdenk7205e402003-09-10 22:30:53 +000096 "<interface> <dev[:part]> <addr> <filename> [bytes]\n"
97 " - load binary file 'filename' from 'dev' on 'interface'\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020098 " to address 'addr' from dos filesystem"
wdenkb0fce992003-06-29 21:03:46 +000099);
100
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200101int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk71f95112003-06-15 22:40:42 +0000102{
103 char *filename = "/";
104 int ret;
wdenk7205e402003-09-10 22:30:53 +0000105 int dev=0;
106 int part=1;
107 char *ep;
108 block_dev_desc_t *dev_desc=NULL;
wdenk71f95112003-06-15 22:40:42 +0000109
wdenk7205e402003-09-10 22:30:53 +0000110 if (argc < 3) {
Wolfgang Denk7385c282010-07-19 11:37:00 +0200111 printf("usage: fatls <interface> <dev[:part]> [directory]\n");
112 return 0;
wdenk7205e402003-09-10 22:30:53 +0000113 }
Wolfgang Denk7385c282010-07-19 11:37:00 +0200114 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");
wdenk7205e402003-09-10 22:30:53 +0000118 return 1;
119 }
120 if (*ep) {
121 if (*ep != ':') {
Wolfgang Denk7385c282010-07-19 11:37:00 +0200122 puts("\n** Invalid boot device, use `dev[:part]' **\n");
wdenk7205e402003-09-10 22:30:53 +0000123 return 1;
124 }
125 part = (int)simple_strtoul(++ep, NULL, 16);
126 }
127 if (fat_register_device(dev_desc,part)!=0) {
Wolfgang Denk7385c282010-07-19 11:37:00 +0200128 printf("\n** Unable to use %s %d:%d for fatls **\n",
129 argv[1], dev, part);
wdenk7205e402003-09-10 22:30:53 +0000130 return 1;
131 }
132 if (argc == 4)
Wolfgang Denk7385c282010-07-19 11:37:00 +0200133 ret = file_fat_ls(argv[3]);
wdenk71f95112003-06-15 22:40:42 +0000134 else
Wolfgang Denk7385c282010-07-19 11:37:00 +0200135 ret = file_fat_ls(filename);
wdenk71f95112003-06-15 22:40:42 +0000136
wdenk7205e402003-09-10 22:30:53 +0000137 if(ret!=0)
138 printf("No Fat FS detected\n");
Wolfgang Denk7385c282010-07-19 11:37:00 +0200139 return ret;
wdenk71f95112003-06-15 22:40:42 +0000140}
141
wdenk0d498392003-07-01 21:06:45 +0000142U_BOOT_CMD(
wdenk7205e402003-09-10 22:30:53 +0000143 fatls, 4, 1, do_fat_ls,
Peter Tyser2fb26042009-01-27 18:03:12 -0600144 "list files in a directory (default /)",
wdenk7205e402003-09-10 22:30:53 +0000145 "<interface> <dev[:part]> [directory]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200146 " - list files from 'dev' on 'interface' in a 'directory'"
wdenkb0fce992003-06-29 21:03:46 +0000147);
148
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200149int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk71f95112003-06-15 22:40:42 +0000150{
wdenk7205e402003-09-10 22:30:53 +0000151 int dev=0;
152 int part=1;
153 char *ep;
154 block_dev_desc_t *dev_desc=NULL;
wdenk71f95112003-06-15 22:40:42 +0000155
wdenk7205e402003-09-10 22:30:53 +0000156 if (argc < 2) {
Wolfgang Denk7385c282010-07-19 11:37:00 +0200157 printf("usage: fatinfo <interface> <dev[:part]>\n");
158 return 0;
wdenk7205e402003-09-10 22:30:53 +0000159 }
Wolfgang Denk7385c282010-07-19 11:37:00 +0200160 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");
wdenk7205e402003-09-10 22:30:53 +0000164 return 1;
165 }
166 if (*ep) {
167 if (*ep != ':') {
Wolfgang Denk7385c282010-07-19 11:37:00 +0200168 puts("\n** Invalid boot device, use `dev[:part]' **\n");
wdenk7205e402003-09-10 22:30:53 +0000169 return 1;
170 }
171 part = (int)simple_strtoul(++ep, NULL, 16);
172 }
173 if (fat_register_device(dev_desc,part)!=0) {
Wolfgang Denk7385c282010-07-19 11:37:00 +0200174 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
175 argv[1], dev, part);
wdenk7205e402003-09-10 22:30:53 +0000176 return 1;
177 }
Wolfgang Denk7385c282010-07-19 11:37:00 +0200178 return file_fat_detectfs();
wdenk71f95112003-06-15 22:40:42 +0000179}
180
wdenk0d498392003-07-01 21:06:45 +0000181U_BOOT_CMD(
wdenk7205e402003-09-10 22:30:53 +0000182 fatinfo, 3, 1, do_fat_fsinfo,
Peter Tyser2fb26042009-01-27 18:03:12 -0600183 "print information about filesystem",
wdenk7205e402003-09-10 22:30:53 +0000184 "<interface> <dev[:part]>\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200185 " - print information about filesystem from 'dev' on 'interface'"
wdenkb0fce992003-06-29 21:03:46 +0000186);