wdenk | 7a428cc | 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 | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 29 | #include <s_record.h> |
| 30 | #include <net.h> |
| 31 | #include <ata.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 32 | #include <part.h> |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 33 | #include <fat.h> |
| 34 | |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 35 | |
Wolfgang Denk | 6262d021 | 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 | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 37 | { |
| 38 | long size; |
| 39 | unsigned long offset; |
Benoît Thébaudeau | 5295aa8 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 40 | unsigned long count = 0; |
| 41 | unsigned long pos = 0; |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 42 | char buf [12]; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 43 | block_dev_desc_t *dev_desc=NULL; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 44 | disk_partition_t info; |
| 45 | int part, dev; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 46 | |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 47 | if (argc < 5) { |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 48 | printf("usage: fatload <interface> [<dev[:part]>] " |
Benoît Thébaudeau | 5295aa8 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 49 | "<addr> <filename> [bytes [pos]]\n"); |
wdenk | 79cf757 | 2004-08-28 21:09:14 +0000 | [diff] [blame] | 50 | return 1; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 51 | } |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 52 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 53 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 54 | if (part < 0) |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 55 | return 1; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 56 | |
| 57 | dev = dev_desc->dev; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 58 | if (fat_register_device(dev_desc,part)!=0) { |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 59 | printf("\n** Unable to use %s %d:%d for fatload **\n", |
| 60 | argv[1], dev, part); |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 61 | return 1; |
| 62 | } |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 63 | offset = simple_strtoul(argv[3], NULL, 16); |
Benoît Thébaudeau | 5295aa8 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 64 | if (argc >= 6) |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 65 | count = simple_strtoul(argv[5], NULL, 16); |
Benoît Thébaudeau | 5295aa8 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 66 | if (argc >= 7) |
| 67 | pos = simple_strtoul(argv[6], NULL, 16); |
| 68 | size = file_fat_read_at(argv[4], pos, (unsigned char *)offset, count); |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 69 | |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 70 | if(size==-1) { |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 71 | printf("\n** Unable to read \"%s\" from %s %d:%d **\n", |
| 72 | argv[4], argv[1], dev, part); |
wdenk | 79cf757 | 2004-08-28 21:09:14 +0000 | [diff] [blame] | 73 | return 1; |
wdenk | 7182b0f | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 76 | printf("\n%ld bytes read\n", size); |
wdenk | 79cf757 | 2004-08-28 21:09:14 +0000 | [diff] [blame] | 77 | |
| 78 | sprintf(buf, "%lX", size); |
| 79 | setenv("filesize", buf); |
| 80 | |
| 81 | return 0; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 82 | } |
| 83 | |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 84 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 85 | U_BOOT_CMD( |
Benoît Thébaudeau | 5295aa8 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 86 | fatload, 7, 0, do_fat_fsload, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 87 | "load binary file from a dos filesystem", |
Benoît Thébaudeau | 5295aa8 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 88 | "<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." |
wdenk | f12e396 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 95 | ); |
| 96 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 97 | int do_fat_ls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 98 | { |
| 99 | char *filename = "/"; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 100 | int ret, dev, part; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 101 | block_dev_desc_t *dev_desc=NULL; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 102 | disk_partition_t info; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 103 | |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 104 | if (argc < 2) { |
| 105 | printf("usage: fatls <interface> [<dev[:part]>] [directory]\n"); |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 106 | return 0; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 107 | } |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 108 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 109 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 110 | if (part < 0) |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 111 | return 1; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 112 | |
| 113 | dev = dev_desc->dev; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 114 | if (fat_register_device(dev_desc,part)!=0) { |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 115 | printf("\n** Unable to use %s %d:%d for fatls **\n", |
| 116 | argv[1], dev, part); |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 117 | return 1; |
| 118 | } |
| 119 | if (argc == 4) |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 120 | ret = file_fat_ls(argv[3]); |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 121 | else |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 122 | ret = file_fat_ls(filename); |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 123 | |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 124 | if(ret!=0) |
| 125 | printf("No Fat FS detected\n"); |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 126 | return ret; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 127 | } |
| 128 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 129 | U_BOOT_CMD( |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 130 | fatls, 4, 1, do_fat_ls, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 131 | "list files in a directory (default /)", |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 132 | "<interface> [<dev[:part]>] [directory]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 133 | " - list files from 'dev' on 'interface' in a 'directory'" |
wdenk | f12e396 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 134 | ); |
| 135 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 136 | int do_fat_fsinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 137 | { |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 138 | int dev, part; |
| 139 | block_dev_desc_t *dev_desc; |
| 140 | disk_partition_t info; |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 141 | |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 142 | if (argc < 2) { |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 143 | printf("usage: fatinfo <interface> [<dev[:part]>]\n"); |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 144 | return 0; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 145 | } |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 146 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 147 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 148 | if (part < 0) |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 149 | return 1; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 150 | |
| 151 | dev = dev_desc->dev; |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 152 | if (fat_register_device(dev_desc,part)!=0) { |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 153 | printf("\n** Unable to use %s %d:%d for fatinfo **\n", |
| 154 | argv[1], dev, part); |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 155 | return 1; |
| 156 | } |
Wolfgang Denk | 927b8ce | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 157 | return file_fat_detectfs(); |
wdenk | 7a428cc | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 158 | } |
| 159 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 160 | U_BOOT_CMD( |
wdenk | 2c9b05d | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 161 | fatinfo, 3, 1, do_fat_fsinfo, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 162 | "print information about filesystem", |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 163 | "<interface> [<dev[:part]>]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 164 | " - print information about filesystem from 'dev' on 'interface'" |
wdenk | f12e396 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 165 | ); |
Donggeun Kim | b44c8ab | 2012-03-22 04:38:56 +0000 | [diff] [blame] | 166 | |
| 167 | #ifdef CONFIG_FAT_WRITE |
| 168 | static 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 Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 175 | disk_partition_t info; |
Donggeun Kim | b44c8ab | 2012-03-22 04:38:56 +0000 | [diff] [blame] | 176 | int dev = 0; |
| 177 | int part = 1; |
Donggeun Kim | b44c8ab | 2012-03-22 04:38:56 +0000 | [diff] [blame] | 178 | |
| 179 | if (argc < 5) |
| 180 | return cmd_usage(cmdtp); |
| 181 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 182 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 183 | if (part < 0) |
Donggeun Kim | b44c8ab | 2012-03-22 04:38:56 +0000 | [diff] [blame] | 184 | return 1; |
Rob Herring | 5fc26df | 2012-08-23 11:31:47 +0000 | [diff] [blame] | 185 | |
| 186 | dev = dev_desc->dev; |
| 187 | |
Donggeun Kim | b44c8ab | 2012-03-22 04:38:56 +0000 | [diff] [blame] | 188 | 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 | |
| 208 | U_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 |