2 * (C) Copyright 2003 - 2004
3 * Sysgo Real-Time Solutions, AG <www.elinos.com>
4 * Pavel Bartusek <pba@sysgo.com>
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
31 #if (CONFIG_COMMANDS & CFG_CMD_REISER)
35 #include <linux/ctype.h>
36 #include <asm/byteorder.h>
39 #ifndef CONFIG_DOS_PARTITION
40 #error DOS partition support must be selected
43 /* #define REISER_DEBUG */
46 #define PRINTF(fmt,args...) printf (fmt ,##args)
48 #define PRINTF(fmt,args...)
51 static block_dev_desc_t *get_dev (char* ifname, int dev)
53 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
54 if (strncmp(ifname,"ide",3)==0) {
55 extern block_dev_desc_t * ide_get_dev(int dev);
56 return((dev >= CFG_IDE_MAXDEVICE) ? NULL : ide_get_dev(dev));
59 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
60 if (strncmp(ifname,"scsi",4)==0) {
61 extern block_dev_desc_t * scsi_get_dev(int dev);
62 return((dev >= CFG_SCSI_MAXDEVICE) ? NULL : scsi_get_dev(dev));
65 #if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
66 if (strncmp(ifname,"usb",3)==0) {
67 extern block_dev_desc_t * usb_stor_get_dev(int dev);
68 return((dev >= USB_MAX_STOR_DEV) ? NULL : usb_stor_get_dev(dev));
71 #if defined(CONFIG_MMC)
72 if (strncmp(ifname,"mmc",3)==0) {
73 extern block_dev_desc_t * mmc_get_dev(int dev);
74 return((dev >= 1) ? NULL : mmc_get_dev(dev));
77 #if defined(CONFIG_SYSTEMACE)
78 if (strcmp(ifname,"ace")==0) {
79 extern block_dev_desc_t * systemace_get_dev(int dev);
80 return((dev >= 1) ? NULL : systemace_get_dev(dev));
86 int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
92 block_dev_desc_t *dev_desc=NULL;
96 printf ("Usage:\n%s\n", cmdtp->usage);
99 dev = (int)simple_strtoul (argv[2], &ep, 16);
100 dev_desc=get_dev(argv[1],dev);
102 if (dev_desc == NULL) {
103 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
109 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
112 part = (int)simple_strtoul(++ep, NULL, 16);
119 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
121 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
122 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
126 if (!reiserfs_mount(part_length)) {
127 printf ("** Bad Reisefs partition or disk - %s %d:%d **\n", argv[1], dev, part);
131 if (reiserfs_ls (filename)) {
132 printf ("** Error reiserfs_ls() **\n");
140 reiserls, 4, 1, do_reiserls,
141 "reiserls- list files in a directory (default /)\n",
142 "<interface> <dev[:part]> [directory]\n"
143 " - list files from 'dev' on 'interface' in a 'directory'\n"
146 /******************************************************************************
147 * Reiserfs boot command intepreter. Derived from diskboot
149 int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
151 char *filename = NULL;
154 ulong addr = 0, part_length, filelen;
155 disk_partition_t info;
156 block_dev_desc_t *dev_desc = NULL;
163 addr_str = getenv("loadaddr");
164 if (addr_str != NULL) {
165 addr = simple_strtoul (addr_str, NULL, 16);
167 addr = CFG_LOAD_ADDR;
169 filename = getenv ("bootfile");
173 addr = simple_strtoul (argv[3], NULL, 16);
174 filename = getenv ("bootfile");
178 addr = simple_strtoul (argv[3], NULL, 16);
183 addr = simple_strtoul (argv[3], NULL, 16);
185 count = simple_strtoul (argv[5], NULL, 16);
189 printf ("Usage:\n%s\n", cmdtp->usage);
194 puts ("\n** No boot file defined **\n");
198 dev = (int)simple_strtoul (argv[2], &ep, 16);
199 dev_desc=get_dev(argv[1],dev);
200 if (dev_desc==NULL) {
201 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
206 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
209 part = (int)simple_strtoul(++ep, NULL, 16);
212 PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
215 if (get_partition_info (&dev_desc[dev], part, &info)) {
216 printf ("** Bad partition %d **\n", part);
220 if (strncmp(info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
221 printf ("\n** Invalid partition type \"%.32s\""
222 " (expect \"" BOOT_PART_TYPE "\")\n",
226 PRINTF ("\nLoading from block device %s device %d, partition %d: "
227 "Name: %.32s Type: %.32s File:%s\n",
228 argv[1], dev, part, info.name, info.type, filename);
230 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
231 argv[1], dev, filename);
235 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
236 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
240 if (!reiserfs_mount(part_length)) {
241 printf ("** Bad Reisefs partition or disk - %s %d:%d **\n", argv[1], dev, part);
245 filelen = reiserfs_open(filename);
247 printf("** File not found %s\n", filename);
250 if ((count < filelen) && (count != 0)) {
254 if (reiserfs_read((char *)addr, filelen) != filelen) {
255 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
259 /* Loading ok, update default load address */
262 printf ("\n%ld bytes read\n", filelen);
263 sprintf(buf, "%lX", filelen);
264 setenv("filesize", buf);
270 reiserload, 6, 0, do_reiserload,
271 "reiserload- load binary file from a Reiser filesystem\n",
272 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
273 " - load binary file 'filename' from 'dev' on 'interface'\n"
274 " to address 'addr' from dos filesystem\n"
277 #endif /* CONFIG_COMMANDS & CFG_CMD_REISER */