wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 - 2004 |
| 3 | * Sysgo Real-Time Solutions, AG <www.elinos.com> |
| 4 | * Pavel Bartusek <pba@sysgo.com> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * Reiserfs support |
| 28 | */ |
| 29 | #include <common.h> |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 30 | #include <config.h> |
| 31 | #include <command.h> |
| 32 | #include <image.h> |
| 33 | #include <linux/ctype.h> |
| 34 | #include <asm/byteorder.h> |
| 35 | #include <reiserfs.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 36 | #include <part.h> |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 37 | |
| 38 | #ifndef CONFIG_DOS_PARTITION |
| 39 | #error DOS partition support must be selected |
| 40 | #endif |
| 41 | |
| 42 | /* #define REISER_DEBUG */ |
| 43 | |
| 44 | #ifdef REISER_DEBUG |
| 45 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 46 | #else |
| 47 | #define PRINTF(fmt,args...) |
| 48 | #endif |
| 49 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 50 | int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 51 | { |
| 52 | char *filename = "/"; |
| 53 | int dev=0; |
| 54 | int part=1; |
| 55 | char *ep; |
| 56 | block_dev_desc_t *dev_desc=NULL; |
| 57 | int part_length; |
| 58 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 59 | if (argc < 3) |
| 60 | return cmd_usage(cmdtp); |
| 61 | |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 62 | dev = (int)simple_strtoul (argv[2], &ep, 16); |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 63 | dev_desc = get_dev(argv[1],dev); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 64 | |
| 65 | if (dev_desc == NULL) { |
| 66 | printf ("\n** Block device %s %d not supported\n", argv[1], dev); |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | if (*ep) { |
| 71 | if (*ep != ':') { |
| 72 | puts ("\n** Invalid boot device, use `dev[:part]' **\n"); |
| 73 | return 1; |
| 74 | } |
| 75 | part = (int)simple_strtoul(++ep, NULL, 16); |
| 76 | } |
| 77 | |
| 78 | if (argc == 4) { |
| 79 | filename = argv[3]; |
| 80 | } |
| 81 | |
| 82 | PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); |
| 83 | |
| 84 | if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) { |
| 85 | printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part); |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | if (!reiserfs_mount(part_length)) { |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 90 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 91 | return 1; |
| 92 | } |
| 93 | |
| 94 | if (reiserfs_ls (filename)) { |
| 95 | printf ("** Error reiserfs_ls() **\n"); |
| 96 | return 1; |
| 97 | }; |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | U_BOOT_CMD( |
| 103 | reiserls, 4, 1, do_reiserls, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 104 | "list files in a directory (default /)", |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 105 | "<interface> <dev[:part]> [directory]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 106 | " - list files from 'dev' on 'interface' in a 'directory'" |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 107 | ); |
| 108 | |
| 109 | /****************************************************************************** |
| 110 | * Reiserfs boot command intepreter. Derived from diskboot |
| 111 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 112 | int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 113 | { |
| 114 | char *filename = NULL; |
| 115 | char *ep; |
| 116 | int dev, part = 0; |
| 117 | ulong addr = 0, part_length, filelen; |
| 118 | disk_partition_t info; |
| 119 | block_dev_desc_t *dev_desc = NULL; |
| 120 | char buf [12]; |
| 121 | unsigned long count; |
| 122 | char *addr_str; |
| 123 | |
| 124 | switch (argc) { |
| 125 | case 3: |
| 126 | addr_str = getenv("loadaddr"); |
| 127 | if (addr_str != NULL) { |
| 128 | addr = simple_strtoul (addr_str, NULL, 16); |
| 129 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 130 | addr = CONFIG_SYS_LOAD_ADDR; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 131 | } |
| 132 | filename = getenv ("bootfile"); |
| 133 | count = 0; |
| 134 | break; |
| 135 | case 4: |
| 136 | addr = simple_strtoul (argv[3], NULL, 16); |
| 137 | filename = getenv ("bootfile"); |
| 138 | count = 0; |
| 139 | break; |
| 140 | case 5: |
| 141 | addr = simple_strtoul (argv[3], NULL, 16); |
| 142 | filename = argv[4]; |
| 143 | count = 0; |
| 144 | break; |
| 145 | case 6: |
| 146 | addr = simple_strtoul (argv[3], NULL, 16); |
| 147 | filename = argv[4]; |
| 148 | count = simple_strtoul (argv[5], NULL, 16); |
| 149 | break; |
| 150 | |
| 151 | default: |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 152 | return cmd_usage(cmdtp); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | if (!filename) { |
| 156 | puts ("\n** No boot file defined **\n"); |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | dev = (int)simple_strtoul (argv[2], &ep, 16); |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 161 | dev_desc = get_dev(argv[1],dev); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 162 | if (dev_desc==NULL) { |
| 163 | printf ("\n** Block device %s %d not supported\n", argv[1], dev); |
| 164 | return 1; |
| 165 | } |
| 166 | if (*ep) { |
| 167 | if (*ep != ':') { |
| 168 | puts ("\n** Invalid boot device, use `dev[:part]' **\n"); |
| 169 | return 1; |
| 170 | } |
| 171 | part = (int)simple_strtoul(++ep, NULL, 16); |
| 172 | } |
| 173 | |
| 174 | PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part); |
| 175 | |
| 176 | if (part != 0) { |
wdenk | 286dca8 | 2005-03-04 11:27:31 +0000 | [diff] [blame] | 177 | if (get_partition_info (dev_desc, part, &info)) { |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 178 | printf ("** Bad partition %d **\n", part); |
| 179 | return 1; |
| 180 | } |
| 181 | |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 182 | if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) { |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 183 | printf ("\n** Invalid partition type \"%.32s\"" |
| 184 | " (expect \"" BOOT_PART_TYPE "\")\n", |
| 185 | info.type); |
| 186 | return 1; |
| 187 | } |
| 188 | PRINTF ("\nLoading from block device %s device %d, partition %d: " |
| 189 | "Name: %.32s Type: %.32s File:%s\n", |
| 190 | argv[1], dev, part, info.name, info.type, filename); |
| 191 | } else { |
| 192 | PRINTF ("\nLoading from block device %s device %d, File:%s\n", |
| 193 | argv[1], dev, filename); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) { |
| 198 | printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part); |
| 199 | return 1; |
| 200 | } |
| 201 | |
| 202 | if (!reiserfs_mount(part_length)) { |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 203 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 204 | return 1; |
| 205 | } |
| 206 | |
| 207 | filelen = reiserfs_open(filename); |
| 208 | if (filelen < 0) { |
| 209 | printf("** File not found %s\n", filename); |
| 210 | return 1; |
| 211 | } |
| 212 | if ((count < filelen) && (count != 0)) { |
| 213 | filelen = count; |
| 214 | } |
| 215 | |
| 216 | if (reiserfs_read((char *)addr, filelen) != filelen) { |
| 217 | printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); |
| 218 | return 1; |
| 219 | } |
| 220 | |
| 221 | /* Loading ok, update default load address */ |
| 222 | load_addr = addr; |
| 223 | |
| 224 | printf ("\n%ld bytes read\n", filelen); |
| 225 | sprintf(buf, "%lX", filelen); |
| 226 | setenv("filesize", buf); |
| 227 | |
| 228 | return filelen; |
| 229 | } |
| 230 | |
| 231 | U_BOOT_CMD( |
| 232 | reiserload, 6, 0, do_reiserload, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 233 | "load binary file from a Reiser filesystem", |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 234 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" |
| 235 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 236 | " to address 'addr' from dos filesystem" |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 237 | ); |