blob: fbb9484d0ae54e424d302e7876c9d70420ad987f [file] [log] [blame]
wdenk518e2e12004-03-25 14:59:05 +00001/*
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>
wdenk518e2e12004-03-25 14:59:05 +000030#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 Likely735dd972007-02-20 09:04:34 +010036#include <part.h>
wdenk518e2e12004-03-25 14:59:05 +000037
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 Denk54841ab2010-06-28 22:00:46 +020050int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +000051{
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 Denk47e26b12010-07-17 01:06:04 +020059 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +000060 return CMD_RET_USAGE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +020061
wdenk518e2e12004-03-25 14:59:05 +000062 dev = (int)simple_strtoul (argv[2], &ep, 16);
Grant Likely735dd972007-02-20 09:04:34 +010063 dev_desc = get_dev(argv[1],dev);
wdenk518e2e12004-03-25 14:59:05 +000064
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 Schocher566a4942007-06-22 19:11:54 +020090 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +000091 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
102U_BOOT_CMD(
103 reiserls, 4, 1, do_reiserls,
Peter Tyser2fb26042009-01-27 18:03:12 -0600104 "list files in a directory (default /)",
wdenk518e2e12004-03-25 14:59:05 +0000105 "<interface> <dev[:part]> [directory]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200106 " - list files from 'dev' on 'interface' in a 'directory'"
wdenk518e2e12004-03-25 14:59:05 +0000107);
108
109/******************************************************************************
110 * Reiserfs boot command intepreter. Derived from diskboot
111 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200112int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +0000113{
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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200130 addr = CONFIG_SYS_LOAD_ADDR;
wdenk518e2e12004-03-25 14:59:05 +0000131 }
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:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000152 return CMD_RET_USAGE;
wdenk518e2e12004-03-25 14:59:05 +0000153 }
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 Likely735dd972007-02-20 09:04:34 +0100161 dev_desc = get_dev(argv[1],dev);
wdenk518e2e12004-03-25 14:59:05 +0000162 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) {
wdenkb05dcb52005-03-04 11:27:31 +0000177 if (get_partition_info (dev_desc, part, &info)) {
wdenk518e2e12004-03-25 14:59:05 +0000178 printf ("** Bad partition %d **\n", part);
179 return 1;
180 }
181
Heiko Schocher566a4942007-06-22 19:11:54 +0200182 if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
wdenk518e2e12004-03-25 14:59:05 +0000183 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 Schocher566a4942007-06-22 19:11:54 +0200203 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +0000204 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
231U_BOOT_CMD(
232 reiserload, 6, 0, do_reiserload,
Peter Tyser2fb26042009-01-27 18:03:12 -0600233 "load binary file from a Reiser filesystem",
wdenk518e2e12004-03-25 14:59:05 +0000234 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
235 " - load binary file 'filename' from 'dev' on 'interface'\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200236 " to address 'addr' from dos filesystem"
wdenk518e2e12004-03-25 14:59:05 +0000237);