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 = "/"; |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 53 | int dev, part; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 54 | block_dev_desc_t *dev_desc=NULL; |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 55 | disk_partition_t info; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 56 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 57 | if (argc < 3) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 58 | return CMD_RET_USAGE; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 59 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 60 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 61 | if (part < 0) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 62 | return 1; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 63 | |
| 64 | if (argc == 4) { |
| 65 | filename = argv[3]; |
| 66 | } |
| 67 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 68 | dev = dev_desc->dev; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 69 | PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); |
| 70 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 71 | reiserfs_set_blk_dev(dev_desc, &info); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 72 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 73 | if (!reiserfs_mount(info.size)) { |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 74 | 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] | 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | if (reiserfs_ls (filename)) { |
| 79 | printf ("** Error reiserfs_ls() **\n"); |
| 80 | return 1; |
| 81 | }; |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | U_BOOT_CMD( |
| 87 | reiserls, 4, 1, do_reiserls, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 88 | "list files in a directory (default /)", |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 89 | "<interface> <dev[:part]> [directory]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 90 | " - list files from 'dev' on 'interface' in a 'directory'" |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 91 | ); |
| 92 | |
| 93 | /****************************************************************************** |
| 94 | * Reiserfs boot command intepreter. Derived from diskboot |
| 95 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 96 | 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] | 97 | { |
| 98 | char *filename = NULL; |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 99 | int dev, part; |
| 100 | ulong addr = 0, filelen; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 101 | disk_partition_t info; |
| 102 | block_dev_desc_t *dev_desc = NULL; |
| 103 | char buf [12]; |
| 104 | unsigned long count; |
| 105 | char *addr_str; |
| 106 | |
| 107 | switch (argc) { |
| 108 | case 3: |
| 109 | addr_str = getenv("loadaddr"); |
| 110 | if (addr_str != NULL) { |
| 111 | addr = simple_strtoul (addr_str, NULL, 16); |
| 112 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | addr = CONFIG_SYS_LOAD_ADDR; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 114 | } |
| 115 | filename = getenv ("bootfile"); |
| 116 | count = 0; |
| 117 | break; |
| 118 | case 4: |
| 119 | addr = simple_strtoul (argv[3], NULL, 16); |
| 120 | filename = getenv ("bootfile"); |
| 121 | count = 0; |
| 122 | break; |
| 123 | case 5: |
| 124 | addr = simple_strtoul (argv[3], NULL, 16); |
| 125 | filename = argv[4]; |
| 126 | count = 0; |
| 127 | break; |
| 128 | case 6: |
| 129 | addr = simple_strtoul (argv[3], NULL, 16); |
| 130 | filename = argv[4]; |
| 131 | count = simple_strtoul (argv[5], NULL, 16); |
| 132 | break; |
| 133 | |
| 134 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 135 | return CMD_RET_USAGE; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (!filename) { |
| 139 | puts ("\n** No boot file defined **\n"); |
| 140 | return 1; |
| 141 | } |
| 142 | |
Stephen Warren | c87ff22 | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 143 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 144 | if (part < 0) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 145 | return 1; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 146 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 147 | dev = dev_desc->dev; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 148 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 149 | printf("Loading file \"%s\" from %s device %d%c%c\n", |
| 150 | filename, argv[1], dev, |
| 151 | part ? ':' : ' ', part ? part + '0' : ' '); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 152 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 153 | reiserfs_set_blk_dev(dev_desc, &info); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 154 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 155 | if (!reiserfs_mount(info.size)) { |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 156 | 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] | 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | filelen = reiserfs_open(filename); |
| 161 | if (filelen < 0) { |
| 162 | printf("** File not found %s\n", filename); |
| 163 | return 1; |
| 164 | } |
| 165 | if ((count < filelen) && (count != 0)) { |
| 166 | filelen = count; |
| 167 | } |
| 168 | |
| 169 | if (reiserfs_read((char *)addr, filelen) != filelen) { |
| 170 | printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); |
| 171 | return 1; |
| 172 | } |
| 173 | |
| 174 | /* Loading ok, update default load address */ |
| 175 | load_addr = addr; |
| 176 | |
| 177 | printf ("\n%ld bytes read\n", filelen); |
| 178 | sprintf(buf, "%lX", filelen); |
| 179 | setenv("filesize", buf); |
| 180 | |
| 181 | return filelen; |
| 182 | } |
| 183 | |
| 184 | U_BOOT_CMD( |
| 185 | reiserload, 6, 0, do_reiserload, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 186 | "load binary file from a Reiser filesystem", |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 187 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" |
| 188 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 189 | " to address 'addr' from dos filesystem" |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 190 | ); |