wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 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> |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 29 | #include <s_record.h> |
| 30 | #include <net.h> |
| 31 | #include <ata.h> |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 32 | #include <part.h> |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 33 | #include <fat.h> |
| 34 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 35 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 36 | int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 37 | { |
| 38 | long size; |
| 39 | unsigned long offset; |
| 40 | unsigned long count; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 41 | char buf [12]; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 42 | block_dev_desc_t *dev_desc=NULL; |
| 43 | int dev=0; |
| 44 | int part=1; |
| 45 | char *ep; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 46 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 47 | if (argc < 5) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 48 | printf( "usage: fatload <interface> <dev[:part]> " |
| 49 | "<addr> <filename> [bytes]\n"); |
wdenk | 31a6492 | 2004-08-28 21:09:14 +0000 | [diff] [blame] | 50 | return 1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 51 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 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"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 57 | return 1; |
| 58 | } |
| 59 | if (*ep) { |
| 60 | if (*ep != ':') { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 61 | puts("\n** Invalid boot device, use `dev[:part]' **\n"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 62 | return 1; |
| 63 | } |
| 64 | part = (int)simple_strtoul(++ep, NULL, 16); |
| 65 | } |
| 66 | if (fat_register_device(dev_desc,part)!=0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 67 | printf("\n** Unable to use %s %d:%d for fatload **\n", |
| 68 | argv[1], dev, part); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 69 | return 1; |
| 70 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 71 | offset = simple_strtoul(argv[3], NULL, 16); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 72 | if (argc == 6) |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 73 | count = simple_strtoul(argv[5], NULL, 16); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 74 | else |
| 75 | count = 0; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 76 | size = file_fat_read(argv[4], (unsigned char *)offset, count); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 77 | |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 78 | if(size==-1) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 79 | printf("\n** Unable to read \"%s\" from %s %d:%d **\n", |
| 80 | argv[4], argv[1], dev, part); |
wdenk | 31a6492 | 2004-08-28 21:09:14 +0000 | [diff] [blame] | 81 | return 1; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 84 | printf("\n%ld bytes read\n", size); |
wdenk | 31a6492 | 2004-08-28 21:09:14 +0000 | [diff] [blame] | 85 | |
| 86 | sprintf(buf, "%lX", size); |
| 87 | setenv("filesize", buf); |
| 88 | |
| 89 | return 0; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 90 | } |
| 91 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 92 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 93 | U_BOOT_CMD( |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 94 | fatload, 6, 0, do_fat_fsload, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 95 | "load binary file from a dos filesystem", |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 96 | "<interface> <dev[:part]> <addr> <filename> [bytes]\n" |
| 97 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 98 | " to address 'addr' from dos filesystem" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 99 | ); |
| 100 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 101 | int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 102 | { |
| 103 | char *filename = "/"; |
| 104 | int ret; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 105 | int dev=0; |
| 106 | int part=1; |
| 107 | char *ep; |
| 108 | block_dev_desc_t *dev_desc=NULL; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 109 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 110 | if (argc < 3) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 111 | printf("usage: fatls <interface> <dev[:part]> [directory]\n"); |
| 112 | return 0; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 113 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 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"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 118 | return 1; |
| 119 | } |
| 120 | if (*ep) { |
| 121 | if (*ep != ':') { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 122 | puts("\n** Invalid boot device, use `dev[:part]' **\n"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 123 | return 1; |
| 124 | } |
| 125 | part = (int)simple_strtoul(++ep, NULL, 16); |
| 126 | } |
| 127 | if (fat_register_device(dev_desc,part)!=0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 128 | printf("\n** Unable to use %s %d:%d for fatls **\n", |
| 129 | argv[1], dev, part); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 130 | return 1; |
| 131 | } |
| 132 | if (argc == 4) |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 133 | ret = file_fat_ls(argv[3]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 134 | else |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 135 | ret = file_fat_ls(filename); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 136 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 137 | if(ret!=0) |
| 138 | printf("No Fat FS detected\n"); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 139 | return ret; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 140 | } |
| 141 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 142 | U_BOOT_CMD( |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 143 | fatls, 4, 1, do_fat_ls, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 144 | "list files in a directory (default /)", |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 145 | "<interface> <dev[:part]> [directory]\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 146 | " - list files from 'dev' on 'interface' in a 'directory'" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 147 | ); |
| 148 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 149 | int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 150 | { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 151 | int dev=0; |
| 152 | int part=1; |
| 153 | char *ep; |
| 154 | block_dev_desc_t *dev_desc=NULL; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 155 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 156 | if (argc < 2) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 157 | printf("usage: fatinfo <interface> <dev[:part]>\n"); |
| 158 | return 0; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 159 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 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"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 164 | return 1; |
| 165 | } |
| 166 | if (*ep) { |
| 167 | if (*ep != ':') { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 168 | puts("\n** Invalid boot device, use `dev[:part]' **\n"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 169 | return 1; |
| 170 | } |
| 171 | part = (int)simple_strtoul(++ep, NULL, 16); |
| 172 | } |
| 173 | if (fat_register_device(dev_desc,part)!=0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 174 | printf("\n** Unable to use %s %d:%d for fatinfo **\n", |
| 175 | argv[1], dev, part); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 176 | return 1; |
| 177 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 178 | return file_fat_detectfs(); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 179 | } |
| 180 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 181 | U_BOOT_CMD( |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 182 | fatinfo, 3, 1, do_fat_fsinfo, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 183 | "print information about filesystem", |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 184 | "<interface> <dev[:part]>\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 185 | " - print information about filesystem from 'dev' on 'interface'" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 186 | ); |