1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <common.h>
30#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>
36#include <part.h>
37
38#ifndef CONFIG_DOS_PARTITION
39#error DOS partition support must be selected
40#endif
41
42
43
44#ifdef REISER_DEBUG
45#define PRINTF(fmt,args...) printf (fmt ,##args)
46#else
47#define PRINTF(fmt,args...)
48#endif
49
50int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const 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)
60 return CMD_RET_USAGE;
61
62 dev = (int)simple_strtoul (argv[2], &ep, 16);
63 dev_desc = get_dev(argv[1],dev);
64
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)) {
90 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
91 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,
104 "list files in a directory (default /)",
105 "<interface> <dev[:part]> [directory]\n"
106 " - list files from 'dev' on 'interface' in a 'directory'"
107);
108
109
110
111
112int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
113{
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 {
130 addr = CONFIG_SYS_LOAD_ADDR;
131 }
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:
152 return CMD_RET_USAGE;
153 }
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);
161 dev_desc = get_dev(argv[1],dev);
162 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) {
177 if (get_partition_info (dev_desc, part, &info)) {
178 printf ("** Bad partition %d **\n", part);
179 return 1;
180 }
181
182 if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
183 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)) {
203 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
204 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
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,
233 "load binary file from a Reiser filesystem",
234 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
235 " - load binary file 'filename' from 'dev' on 'interface'\n"
236 " to address 'addr' from dos filesystem"
237);
238