]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
518e2e1a WD |
2 | /* |
3 | * (C) Copyright 2003 - 2004 | |
4 | * Sysgo Real-Time Solutions, AG <www.elinos.com> | |
5 | * Pavel Bartusek <[email protected]> | |
518e2e1a WD |
6 | */ |
7 | ||
8 | /* | |
9 | * Reiserfs support | |
10 | */ | |
11 | #include <common.h> | |
518e2e1a WD |
12 | #include <config.h> |
13 | #include <command.h> | |
c7694dd4 | 14 | #include <env.h> |
518e2e1a WD |
15 | #include <image.h> |
16 | #include <linux/ctype.h> | |
17 | #include <asm/byteorder.h> | |
18 | #include <reiserfs.h> | |
735dd97b | 19 | #include <part.h> |
518e2e1a | 20 | |
b0cf7339 | 21 | #if !CONFIG_IS_ENABLED(DOS_PARTITION) |
518e2e1a WD |
22 | #error DOS partition support must be selected |
23 | #endif | |
24 | ||
25 | /* #define REISER_DEBUG */ | |
26 | ||
27 | #ifdef REISER_DEBUG | |
28 | #define PRINTF(fmt,args...) printf (fmt ,##args) | |
29 | #else | |
30 | #define PRINTF(fmt,args...) | |
31 | #endif | |
32 | ||
09140113 | 33 | int do_reiserls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
518e2e1a WD |
34 | { |
35 | char *filename = "/"; | |
650f3664 | 36 | int dev, part; |
4101f687 | 37 | struct blk_desc *dev_desc = NULL; |
0528979f | 38 | struct disk_partition info; |
518e2e1a | 39 | |
47e26b1b | 40 | if (argc < 3) |
4c12eeb8 | 41 | return CMD_RET_USAGE; |
47e26b1b | 42 | |
e35929e4 | 43 | part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); |
650f3664 | 44 | if (part < 0) |
518e2e1a | 45 | return 1; |
518e2e1a WD |
46 | |
47 | if (argc == 4) { | |
48 | filename = argv[3]; | |
49 | } | |
50 | ||
bcce53d0 | 51 | dev = dev_desc->devnum; |
518e2e1a WD |
52 | PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); |
53 | ||
650f3664 | 54 | reiserfs_set_blk_dev(dev_desc, &info); |
518e2e1a | 55 | |
650f3664 | 56 | if (!reiserfs_mount(info.size)) { |
566a494f | 57 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
518e2e1a WD |
58 | return 1; |
59 | } | |
60 | ||
61 | if (reiserfs_ls (filename)) { | |
62 | printf ("** Error reiserfs_ls() **\n"); | |
63 | return 1; | |
64 | }; | |
65 | ||
66 | return 0; | |
67 | } | |
68 | ||
69 | U_BOOT_CMD( | |
70 | reiserls, 4, 1, do_reiserls, | |
2fb2604d | 71 | "list files in a directory (default /)", |
518e2e1a | 72 | "<interface> <dev[:part]> [directory]\n" |
a89c33db | 73 | " - list files from 'dev' on 'interface' in a 'directory'" |
518e2e1a WD |
74 | ); |
75 | ||
76 | /****************************************************************************** | |
77 | * Reiserfs boot command intepreter. Derived from diskboot | |
78 | */ | |
09140113 | 79 | int do_reiserload(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
518e2e1a WD |
80 | { |
81 | char *filename = NULL; | |
650f3664 RH |
82 | int dev, part; |
83 | ulong addr = 0, filelen; | |
0528979f | 84 | struct disk_partition info; |
4101f687 | 85 | struct blk_desc *dev_desc = NULL; |
518e2e1a WD |
86 | unsigned long count; |
87 | char *addr_str; | |
88 | ||
89 | switch (argc) { | |
90 | case 3: | |
00caae6d | 91 | addr_str = env_get("loadaddr"); |
518e2e1a | 92 | if (addr_str != NULL) { |
7e5f460e | 93 | addr = hextoul(addr_str, NULL); |
518e2e1a | 94 | } else { |
6d0f6bcf | 95 | addr = CONFIG_SYS_LOAD_ADDR; |
518e2e1a | 96 | } |
00caae6d | 97 | filename = env_get("bootfile"); |
518e2e1a WD |
98 | count = 0; |
99 | break; | |
100 | case 4: | |
7e5f460e | 101 | addr = hextoul(argv[3], NULL); |
00caae6d | 102 | filename = env_get("bootfile"); |
518e2e1a WD |
103 | count = 0; |
104 | break; | |
105 | case 5: | |
7e5f460e | 106 | addr = hextoul(argv[3], NULL); |
518e2e1a WD |
107 | filename = argv[4]; |
108 | count = 0; | |
109 | break; | |
110 | case 6: | |
7e5f460e | 111 | addr = hextoul(argv[3], NULL); |
518e2e1a | 112 | filename = argv[4]; |
7e5f460e | 113 | count = hextoul(argv[5], NULL); |
518e2e1a WD |
114 | break; |
115 | ||
116 | default: | |
4c12eeb8 | 117 | return CMD_RET_USAGE; |
518e2e1a WD |
118 | } |
119 | ||
120 | if (!filename) { | |
121 | puts ("\n** No boot file defined **\n"); | |
122 | return 1; | |
123 | } | |
124 | ||
e35929e4 | 125 | part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); |
650f3664 | 126 | if (part < 0) |
518e2e1a | 127 | return 1; |
518e2e1a | 128 | |
bcce53d0 | 129 | dev = dev_desc->devnum; |
518e2e1a | 130 | |
650f3664 RH |
131 | printf("Loading file \"%s\" from %s device %d%c%c\n", |
132 | filename, argv[1], dev, | |
133 | part ? ':' : ' ', part ? part + '0' : ' '); | |
518e2e1a | 134 | |
650f3664 | 135 | reiserfs_set_blk_dev(dev_desc, &info); |
518e2e1a | 136 | |
650f3664 | 137 | if (!reiserfs_mount(info.size)) { |
566a494f | 138 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
518e2e1a WD |
139 | return 1; |
140 | } | |
141 | ||
142 | filelen = reiserfs_open(filename); | |
143 | if (filelen < 0) { | |
2e18cb26 | 144 | printf("** File not found %s **\n", filename); |
518e2e1a WD |
145 | return 1; |
146 | } | |
147 | if ((count < filelen) && (count != 0)) { | |
148 | filelen = count; | |
149 | } | |
150 | ||
151 | if (reiserfs_read((char *)addr, filelen) != filelen) { | |
152 | printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); | |
153 | return 1; | |
154 | } | |
155 | ||
156 | /* Loading ok, update default load address */ | |
bb872dd9 | 157 | image_load_addr = addr; |
518e2e1a WD |
158 | |
159 | printf ("\n%ld bytes read\n", filelen); | |
018f5303 | 160 | env_set_hex("filesize", filelen); |
518e2e1a WD |
161 | |
162 | return filelen; | |
163 | } | |
164 | ||
165 | U_BOOT_CMD( | |
166 | reiserload, 6, 0, do_reiserload, | |
2fb2604d | 167 | "load binary file from a Reiser filesystem", |
518e2e1a WD |
168 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" |
169 | " - load binary file 'filename' from 'dev' on 'interface'\n" | |
a89c33db | 170 | " to address 'addr' from dos filesystem" |
518e2e1a | 171 | ); |