blob: d83c31ab3fe916ce39b32b1892550172eec83f67 [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>
30
31#if (CONFIG_COMMANDS & CFG_CMD_REISER)
32#include <config.h>
33#include <command.h>
34#include <image.h>
35#include <linux/ctype.h>
36#include <asm/byteorder.h>
37#include <reiserfs.h>
Grant Likely735dd972007-02-20 09:04:34 +010038#include <part.h>
wdenk518e2e12004-03-25 14:59:05 +000039
40#ifndef CONFIG_DOS_PARTITION
41#error DOS partition support must be selected
42#endif
43
44/* #define REISER_DEBUG */
45
46#ifdef REISER_DEBUG
47#define PRINTF(fmt,args...) printf (fmt ,##args)
48#else
49#define PRINTF(fmt,args...)
50#endif
51
wdenk518e2e12004-03-25 14:59:05 +000052int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
53{
54 char *filename = "/";
55 int dev=0;
56 int part=1;
57 char *ep;
58 block_dev_desc_t *dev_desc=NULL;
59 int part_length;
60
61 if (argc < 3) {
62 printf ("Usage:\n%s\n", cmdtp->usage);
63 return 1;
64 }
65 dev = (int)simple_strtoul (argv[2], &ep, 16);
Grant Likely735dd972007-02-20 09:04:34 +010066 dev_desc = get_dev(argv[1],dev);
wdenk518e2e12004-03-25 14:59:05 +000067
68 if (dev_desc == NULL) {
69 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
70 return 1;
71 }
72
73 if (*ep) {
74 if (*ep != ':') {
75 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
76 return 1;
77 }
78 part = (int)simple_strtoul(++ep, NULL, 16);
79 }
80
81 if (argc == 4) {
82 filename = argv[3];
83 }
84
85 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
86
87 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
88 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
89 return 1;
90 }
91
92 if (!reiserfs_mount(part_length)) {
Heiko Schocher566a4942007-06-22 19:11:54 +020093 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +000094 return 1;
95 }
96
97 if (reiserfs_ls (filename)) {
98 printf ("** Error reiserfs_ls() **\n");
99 return 1;
100 };
101
102 return 0;
103}
104
105U_BOOT_CMD(
106 reiserls, 4, 1, do_reiserls,
107 "reiserls- list files in a directory (default /)\n",
108 "<interface> <dev[:part]> [directory]\n"
109 " - list files from 'dev' on 'interface' in a 'directory'\n"
110);
111
112/******************************************************************************
113 * Reiserfs boot command intepreter. Derived from diskboot
114 */
115int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
116{
117 char *filename = NULL;
118 char *ep;
119 int dev, part = 0;
120 ulong addr = 0, part_length, filelen;
121 disk_partition_t info;
122 block_dev_desc_t *dev_desc = NULL;
123 char buf [12];
124 unsigned long count;
125 char *addr_str;
126
127 switch (argc) {
128 case 3:
129 addr_str = getenv("loadaddr");
130 if (addr_str != NULL) {
131 addr = simple_strtoul (addr_str, NULL, 16);
132 } else {
133 addr = CFG_LOAD_ADDR;
134 }
135 filename = getenv ("bootfile");
136 count = 0;
137 break;
138 case 4:
139 addr = simple_strtoul (argv[3], NULL, 16);
140 filename = getenv ("bootfile");
141 count = 0;
142 break;
143 case 5:
144 addr = simple_strtoul (argv[3], NULL, 16);
145 filename = argv[4];
146 count = 0;
147 break;
148 case 6:
149 addr = simple_strtoul (argv[3], NULL, 16);
150 filename = argv[4];
151 count = simple_strtoul (argv[5], NULL, 16);
152 break;
153
154 default:
155 printf ("Usage:\n%s\n", cmdtp->usage);
156 return 1;
157 }
158
159 if (!filename) {
160 puts ("\n** No boot file defined **\n");
161 return 1;
162 }
163
164 dev = (int)simple_strtoul (argv[2], &ep, 16);
Grant Likely735dd972007-02-20 09:04:34 +0100165 dev_desc = get_dev(argv[1],dev);
wdenk518e2e12004-03-25 14:59:05 +0000166 if (dev_desc==NULL) {
167 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
168 return 1;
169 }
170 if (*ep) {
171 if (*ep != ':') {
172 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
173 return 1;
174 }
175 part = (int)simple_strtoul(++ep, NULL, 16);
176 }
177
178 PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
179
180 if (part != 0) {
wdenkb05dcb52005-03-04 11:27:31 +0000181 if (get_partition_info (dev_desc, part, &info)) {
wdenk518e2e12004-03-25 14:59:05 +0000182 printf ("** Bad partition %d **\n", part);
183 return 1;
184 }
185
Heiko Schocher566a4942007-06-22 19:11:54 +0200186 if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
wdenk518e2e12004-03-25 14:59:05 +0000187 printf ("\n** Invalid partition type \"%.32s\""
188 " (expect \"" BOOT_PART_TYPE "\")\n",
189 info.type);
190 return 1;
191 }
192 PRINTF ("\nLoading from block device %s device %d, partition %d: "
193 "Name: %.32s Type: %.32s File:%s\n",
194 argv[1], dev, part, info.name, info.type, filename);
195 } else {
196 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
197 argv[1], dev, filename);
198 }
199
200
201 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
202 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
203 return 1;
204 }
205
206 if (!reiserfs_mount(part_length)) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200207 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +0000208 return 1;
209 }
210
211 filelen = reiserfs_open(filename);
212 if (filelen < 0) {
213 printf("** File not found %s\n", filename);
214 return 1;
215 }
216 if ((count < filelen) && (count != 0)) {
217 filelen = count;
218 }
219
220 if (reiserfs_read((char *)addr, filelen) != filelen) {
221 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
222 return 1;
223 }
224
225 /* Loading ok, update default load address */
226 load_addr = addr;
227
228 printf ("\n%ld bytes read\n", filelen);
229 sprintf(buf, "%lX", filelen);
230 setenv("filesize", buf);
231
232 return filelen;
233}
234
235U_BOOT_CMD(
236 reiserload, 6, 0, do_reiserload,
237 "reiserload- load binary file from a Reiser filesystem\n",
238 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
239 " - load binary file 'filename' from 'dev' on 'interface'\n"
240 " to address 'addr' from dos filesystem\n"
241);
242
243#endif /* CONFIG_COMMANDS & CFG_CMD_REISER */