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, part;
54 block_dev_desc_t *dev_desc=NULL;
55 disk_partition_t info;
56
57 if (argc < 3)
58 return CMD_RET_USAGE;
59
60 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
61 if (part < 0)
62 return 1;
63
64 if (argc == 4) {
65 filename = argv[3];
66 }
67
68 dev = dev_desc->dev;
69 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
70
71 reiserfs_set_blk_dev(dev_desc, &info);
72
73 if (!reiserfs_mount(info.size)) {
74 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
75 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,
88 "list files in a directory (default /)",
89 "<interface> <dev[:part]> [directory]\n"
90 " - list files from 'dev' on 'interface' in a 'directory'"
91);
92
93
94
95
96int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
97{
98 char *filename = NULL;
99 int dev, part;
100 ulong addr = 0, filelen;
101 disk_partition_t info;
102 block_dev_desc_t *dev_desc = NULL;
103 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 {
112 addr = CONFIG_SYS_LOAD_ADDR;
113 }
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:
134 return CMD_RET_USAGE;
135 }
136
137 if (!filename) {
138 puts ("\n** No boot file defined **\n");
139 return 1;
140 }
141
142 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
143 if (part < 0)
144 return 1;
145
146 dev = dev_desc->dev;
147
148 printf("Loading file \"%s\" from %s device %d%c%c\n",
149 filename, argv[1], dev,
150 part ? ':' : ' ', part ? part + '0' : ' ');
151
152 reiserfs_set_blk_dev(dev_desc, &info);
153
154 if (!reiserfs_mount(info.size)) {
155 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
156 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
174 load_addr = addr;
175
176 printf ("\n%ld bytes read\n", filelen);
177 setenv_hex("filesize", filelen);
178
179 return filelen;
180}
181
182U_BOOT_CMD(
183 reiserload, 6, 0, do_reiserload,
184 "load binary file from a Reiser filesystem",
185 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
186 " - load binary file 'filename' from 'dev' on 'interface'\n"
187 " to address 'addr' from dos filesystem"
188);
189