blob: a2f22866b656994a15390f03e3131a86d29848ca [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
wdenk518e2e12004-03-25 14:59:05 +000050int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
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
59 if (argc < 3) {
Peter Tyser62c3ae72009-01-27 18:03:10 -060060 cmd_usage(cmdtp);
wdenk518e2e12004-03-25 14:59:05 +000061 return 1;
62 }
63 dev = (int)simple_strtoul (argv[2], &ep, 16);
Grant Likely735dd972007-02-20 09:04:34 +010064 dev_desc = get_dev(argv[1],dev);
wdenk518e2e12004-03-25 14:59:05 +000065
66 if (dev_desc == NULL) {
67 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
68 return 1;
69 }
70
71 if (*ep) {
72 if (*ep != ':') {
73 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
74 return 1;
75 }
76 part = (int)simple_strtoul(++ep, NULL, 16);
77 }
78
79 if (argc == 4) {
80 filename = argv[3];
81 }
82
83 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
84
85 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
86 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
87 return 1;
88 }
89
90 if (!reiserfs_mount(part_length)) {
Heiko Schocher566a4942007-06-22 19:11:54 +020091 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +000092 return 1;
93 }
94
95 if (reiserfs_ls (filename)) {
96 printf ("** Error reiserfs_ls() **\n");
97 return 1;
98 };
99
100 return 0;
101}
102
103U_BOOT_CMD(
104 reiserls, 4, 1, do_reiserls,
105 "reiserls- list files in a directory (default /)\n",
106 "<interface> <dev[:part]> [directory]\n"
107 " - list files from 'dev' on 'interface' in a 'directory'\n"
108);
109
110/******************************************************************************
111 * Reiserfs boot command intepreter. Derived from diskboot
112 */
113int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
114{
115 char *filename = NULL;
116 char *ep;
117 int dev, part = 0;
118 ulong addr = 0, part_length, filelen;
119 disk_partition_t info;
120 block_dev_desc_t *dev_desc = NULL;
121 char buf [12];
122 unsigned long count;
123 char *addr_str;
124
125 switch (argc) {
126 case 3:
127 addr_str = getenv("loadaddr");
128 if (addr_str != NULL) {
129 addr = simple_strtoul (addr_str, NULL, 16);
130 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200131 addr = CONFIG_SYS_LOAD_ADDR;
wdenk518e2e12004-03-25 14:59:05 +0000132 }
133 filename = getenv ("bootfile");
134 count = 0;
135 break;
136 case 4:
137 addr = simple_strtoul (argv[3], NULL, 16);
138 filename = getenv ("bootfile");
139 count = 0;
140 break;
141 case 5:
142 addr = simple_strtoul (argv[3], NULL, 16);
143 filename = argv[4];
144 count = 0;
145 break;
146 case 6:
147 addr = simple_strtoul (argv[3], NULL, 16);
148 filename = argv[4];
149 count = simple_strtoul (argv[5], NULL, 16);
150 break;
151
152 default:
Peter Tyser62c3ae72009-01-27 18:03:10 -0600153 cmd_usage(cmdtp);
wdenk518e2e12004-03-25 14:59:05 +0000154 return 1;
155 }
156
157 if (!filename) {
158 puts ("\n** No boot file defined **\n");
159 return 1;
160 }
161
162 dev = (int)simple_strtoul (argv[2], &ep, 16);
Grant Likely735dd972007-02-20 09:04:34 +0100163 dev_desc = get_dev(argv[1],dev);
wdenk518e2e12004-03-25 14:59:05 +0000164 if (dev_desc==NULL) {
165 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
166 return 1;
167 }
168 if (*ep) {
169 if (*ep != ':') {
170 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
171 return 1;
172 }
173 part = (int)simple_strtoul(++ep, NULL, 16);
174 }
175
176 PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
177
178 if (part != 0) {
wdenkb05dcb52005-03-04 11:27:31 +0000179 if (get_partition_info (dev_desc, part, &info)) {
wdenk518e2e12004-03-25 14:59:05 +0000180 printf ("** Bad partition %d **\n", part);
181 return 1;
182 }
183
Heiko Schocher566a4942007-06-22 19:11:54 +0200184 if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
wdenk518e2e12004-03-25 14:59:05 +0000185 printf ("\n** Invalid partition type \"%.32s\""
186 " (expect \"" BOOT_PART_TYPE "\")\n",
187 info.type);
188 return 1;
189 }
190 PRINTF ("\nLoading from block device %s device %d, partition %d: "
191 "Name: %.32s Type: %.32s File:%s\n",
192 argv[1], dev, part, info.name, info.type, filename);
193 } else {
194 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
195 argv[1], dev, filename);
196 }
197
198
199 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
200 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
201 return 1;
202 }
203
204 if (!reiserfs_mount(part_length)) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200205 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +0000206 return 1;
207 }
208
209 filelen = reiserfs_open(filename);
210 if (filelen < 0) {
211 printf("** File not found %s\n", filename);
212 return 1;
213 }
214 if ((count < filelen) && (count != 0)) {
215 filelen = count;
216 }
217
218 if (reiserfs_read((char *)addr, filelen) != filelen) {
219 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
220 return 1;
221 }
222
223 /* Loading ok, update default load address */
224 load_addr = addr;
225
226 printf ("\n%ld bytes read\n", filelen);
227 sprintf(buf, "%lX", filelen);
228 setenv("filesize", buf);
229
230 return filelen;
231}
232
233U_BOOT_CMD(
234 reiserload, 6, 0, do_reiserload,
235 "reiserload- load binary file from a Reiser filesystem\n",
236 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
237 " - load binary file 'filename' from 'dev' on 'interface'\n"
238 " to address 'addr' from dos filesystem\n"
239);