blob: 717c7f657b241fc8012585850fe8260f00096c23 [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 = "/";
Rob Herring650f3662012-08-23 11:31:50 +000053 int dev, part;
wdenk518e2e12004-03-25 14:59:05 +000054 block_dev_desc_t *dev_desc=NULL;
Rob Herring650f3662012-08-23 11:31:50 +000055 disk_partition_t info;
wdenk518e2e12004-03-25 14:59:05 +000056
Wolfgang Denk47e26b12010-07-17 01:06:04 +020057 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +000058 return CMD_RET_USAGE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +020059
Stephen Warren10a37fd2012-09-21 09:50:57 +000060 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring650f3662012-08-23 11:31:50 +000061 if (part < 0)
wdenk518e2e12004-03-25 14:59:05 +000062 return 1;
wdenk518e2e12004-03-25 14:59:05 +000063
64 if (argc == 4) {
65 filename = argv[3];
66 }
67
Rob Herring650f3662012-08-23 11:31:50 +000068 dev = dev_desc->dev;
wdenk518e2e12004-03-25 14:59:05 +000069 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
70
Rob Herring650f3662012-08-23 11:31:50 +000071 reiserfs_set_blk_dev(dev_desc, &info);
wdenk518e2e12004-03-25 14:59:05 +000072
Rob Herring650f3662012-08-23 11:31:50 +000073 if (!reiserfs_mount(info.size)) {
Heiko Schocher566a4942007-06-22 19:11:54 +020074 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +000075 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
86U_BOOT_CMD(
87 reiserls, 4, 1, do_reiserls,
Peter Tyser2fb26042009-01-27 18:03:12 -060088 "list files in a directory (default /)",
wdenk518e2e12004-03-25 14:59:05 +000089 "<interface> <dev[:part]> [directory]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020090 " - list files from 'dev' on 'interface' in a 'directory'"
wdenk518e2e12004-03-25 14:59:05 +000091);
92
93/******************************************************************************
94 * Reiserfs boot command intepreter. Derived from diskboot
95 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020096int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +000097{
98 char *filename = NULL;
Rob Herring650f3662012-08-23 11:31:50 +000099 int dev, part;
100 ulong addr = 0, filelen;
wdenk518e2e12004-03-25 14:59:05 +0000101 disk_partition_t info;
102 block_dev_desc_t *dev_desc = NULL;
wdenk518e2e12004-03-25 14:59:05 +0000103 unsigned long count;
104 char *addr_str;
105
106 switch (argc) {
107 case 3:
108 addr_str = getenv("loadaddr");
109 if (addr_str != NULL) {
110 addr = simple_strtoul (addr_str, NULL, 16);
111 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200112 addr = CONFIG_SYS_LOAD_ADDR;
wdenk518e2e12004-03-25 14:59:05 +0000113 }
114 filename = getenv ("bootfile");
115 count = 0;
116 break;
117 case 4:
118 addr = simple_strtoul (argv[3], NULL, 16);
119 filename = getenv ("bootfile");
120 count = 0;
121 break;
122 case 5:
123 addr = simple_strtoul (argv[3], NULL, 16);
124 filename = argv[4];
125 count = 0;
126 break;
127 case 6:
128 addr = simple_strtoul (argv[3], NULL, 16);
129 filename = argv[4];
130 count = simple_strtoul (argv[5], NULL, 16);
131 break;
132
133 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000134 return CMD_RET_USAGE;
wdenk518e2e12004-03-25 14:59:05 +0000135 }
136
137 if (!filename) {
138 puts ("\n** No boot file defined **\n");
139 return 1;
140 }
141
Stephen Warren10a37fd2012-09-21 09:50:57 +0000142 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring650f3662012-08-23 11:31:50 +0000143 if (part < 0)
wdenk518e2e12004-03-25 14:59:05 +0000144 return 1;
wdenk518e2e12004-03-25 14:59:05 +0000145
Rob Herring650f3662012-08-23 11:31:50 +0000146 dev = dev_desc->dev;
wdenk518e2e12004-03-25 14:59:05 +0000147
Rob Herring650f3662012-08-23 11:31:50 +0000148 printf("Loading file \"%s\" from %s device %d%c%c\n",
149 filename, argv[1], dev,
150 part ? ':' : ' ', part ? part + '0' : ' ');
wdenk518e2e12004-03-25 14:59:05 +0000151
Rob Herring650f3662012-08-23 11:31:50 +0000152 reiserfs_set_blk_dev(dev_desc, &info);
wdenk518e2e12004-03-25 14:59:05 +0000153
Rob Herring650f3662012-08-23 11:31:50 +0000154 if (!reiserfs_mount(info.size)) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200155 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +0000156 return 1;
157 }
158
159 filelen = reiserfs_open(filename);
160 if (filelen < 0) {
161 printf("** File not found %s\n", filename);
162 return 1;
163 }
164 if ((count < filelen) && (count != 0)) {
165 filelen = count;
166 }
167
168 if (reiserfs_read((char *)addr, filelen) != filelen) {
169 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
170 return 1;
171 }
172
173 /* Loading ok, update default load address */
174 load_addr = addr;
175
176 printf ("\n%ld bytes read\n", filelen);
Simon Glass41ef3722013-02-24 17:33:22 +0000177 setenv_hex("filesize", filelen);
wdenk518e2e12004-03-25 14:59:05 +0000178
179 return filelen;
180}
181
182U_BOOT_CMD(
183 reiserload, 6, 0, do_reiserload,
Peter Tyser2fb26042009-01-27 18:03:12 -0600184 "load binary file from a Reiser filesystem",
wdenk518e2e12004-03-25 14:59:05 +0000185 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
186 " - load binary file 'filename' from 'dev' on 'interface'\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200187 " to address 'addr' from dos filesystem"
wdenk518e2e12004-03-25 14:59:05 +0000188);