blob: 7f51b927a47548c074390cbab4939e98a9f5d498 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk4d01d9e2004-03-25 14:59:05 +00002/*
3 * (C) Copyright 2003 - 2004
4 * Sysgo Real-Time Solutions, AG <www.elinos.com>
5 * Pavel Bartusek <pba@sysgo.com>
wdenk4d01d9e2004-03-25 14:59:05 +00006 */
7
8/*
9 * Reiserfs support
10 */
11#include <common.h>
wdenk4d01d9e2004-03-25 14:59:05 +000012#include <config.h>
13#include <command.h>
Simon Glass313112a2019-08-01 09:46:46 -060014#include <env.h>
wdenk4d01d9e2004-03-25 14:59:05 +000015#include <image.h>
16#include <linux/ctype.h>
17#include <asm/byteorder.h>
18#include <reiserfs.h>
Grant Likelyffc2dd72007-02-20 09:04:34 +010019#include <part.h>
wdenk4d01d9e2004-03-25 14:59:05 +000020
Patrick Delaunayf7e07722017-01-27 11:00:37 +010021#if !CONFIG_IS_ENABLED(DOS_PARTITION)
wdenk4d01d9e2004-03-25 14:59:05 +000022#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
Wolfgang Denk6262d0212010-06-28 22:00:46 +020033int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk4d01d9e2004-03-25 14:59:05 +000034{
35 char *filename = "/";
Rob Herring8d6ba052012-08-23 11:31:50 +000036 int dev, part;
Simon Glasse3394752016-02-29 15:25:34 -070037 struct blk_desc *dev_desc = NULL;
Rob Herring8d6ba052012-08-23 11:31:50 +000038 disk_partition_t info;
wdenk4d01d9e2004-03-25 14:59:05 +000039
Wolfgang Denk3b683112010-07-17 01:06:04 +020040 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +000041 return CMD_RET_USAGE;
Wolfgang Denk3b683112010-07-17 01:06:04 +020042
Simon Glasse76ee972016-02-29 15:25:44 -070043 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring8d6ba052012-08-23 11:31:50 +000044 if (part < 0)
wdenk4d01d9e2004-03-25 14:59:05 +000045 return 1;
wdenk4d01d9e2004-03-25 14:59:05 +000046
47 if (argc == 4) {
48 filename = argv[3];
49 }
50
Simon Glass2f26fff2016-02-29 15:25:51 -070051 dev = dev_desc->devnum;
wdenk4d01d9e2004-03-25 14:59:05 +000052 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
53
Rob Herring8d6ba052012-08-23 11:31:50 +000054 reiserfs_set_blk_dev(dev_desc, &info);
wdenk4d01d9e2004-03-25 14:59:05 +000055
Rob Herring8d6ba052012-08-23 11:31:50 +000056 if (!reiserfs_mount(info.size)) {
Heiko Schocher633e03a2007-06-22 19:11:54 +020057 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk4d01d9e2004-03-25 14:59:05 +000058 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
69U_BOOT_CMD(
70 reiserls, 4, 1, do_reiserls,
Peter Tyserdfb72b82009-01-27 18:03:12 -060071 "list files in a directory (default /)",
wdenk4d01d9e2004-03-25 14:59:05 +000072 "<interface> <dev[:part]> [directory]\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +020073 " - list files from 'dev' on 'interface' in a 'directory'"
wdenk4d01d9e2004-03-25 14:59:05 +000074);
75
76/******************************************************************************
77 * Reiserfs boot command intepreter. Derived from diskboot
78 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020079int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk4d01d9e2004-03-25 14:59:05 +000080{
81 char *filename = NULL;
Rob Herring8d6ba052012-08-23 11:31:50 +000082 int dev, part;
83 ulong addr = 0, filelen;
wdenk4d01d9e2004-03-25 14:59:05 +000084 disk_partition_t info;
Simon Glasse3394752016-02-29 15:25:34 -070085 struct blk_desc *dev_desc = NULL;
wdenk4d01d9e2004-03-25 14:59:05 +000086 unsigned long count;
87 char *addr_str;
88
89 switch (argc) {
90 case 3:
Simon Glass64b723f2017-08-03 12:22:12 -060091 addr_str = env_get("loadaddr");
wdenk4d01d9e2004-03-25 14:59:05 +000092 if (addr_str != NULL) {
93 addr = simple_strtoul (addr_str, NULL, 16);
94 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095 addr = CONFIG_SYS_LOAD_ADDR;
wdenk4d01d9e2004-03-25 14:59:05 +000096 }
Simon Glass64b723f2017-08-03 12:22:12 -060097 filename = env_get("bootfile");
wdenk4d01d9e2004-03-25 14:59:05 +000098 count = 0;
99 break;
100 case 4:
101 addr = simple_strtoul (argv[3], NULL, 16);
Simon Glass64b723f2017-08-03 12:22:12 -0600102 filename = env_get("bootfile");
wdenk4d01d9e2004-03-25 14:59:05 +0000103 count = 0;
104 break;
105 case 5:
106 addr = simple_strtoul (argv[3], NULL, 16);
107 filename = argv[4];
108 count = 0;
109 break;
110 case 6:
111 addr = simple_strtoul (argv[3], NULL, 16);
112 filename = argv[4];
113 count = simple_strtoul (argv[5], NULL, 16);
114 break;
115
116 default:
Simon Glassa06dfc72011-12-10 08:44:01 +0000117 return CMD_RET_USAGE;
wdenk4d01d9e2004-03-25 14:59:05 +0000118 }
119
120 if (!filename) {
121 puts ("\n** No boot file defined **\n");
122 return 1;
123 }
124
Simon Glasse76ee972016-02-29 15:25:44 -0700125 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring8d6ba052012-08-23 11:31:50 +0000126 if (part < 0)
wdenk4d01d9e2004-03-25 14:59:05 +0000127 return 1;
wdenk4d01d9e2004-03-25 14:59:05 +0000128
Simon Glass2f26fff2016-02-29 15:25:51 -0700129 dev = dev_desc->devnum;
wdenk4d01d9e2004-03-25 14:59:05 +0000130
Rob Herring8d6ba052012-08-23 11:31:50 +0000131 printf("Loading file \"%s\" from %s device %d%c%c\n",
132 filename, argv[1], dev,
133 part ? ':' : ' ', part ? part + '0' : ' ');
wdenk4d01d9e2004-03-25 14:59:05 +0000134
Rob Herring8d6ba052012-08-23 11:31:50 +0000135 reiserfs_set_blk_dev(dev_desc, &info);
wdenk4d01d9e2004-03-25 14:59:05 +0000136
Rob Herring8d6ba052012-08-23 11:31:50 +0000137 if (!reiserfs_mount(info.size)) {
Heiko Schocher633e03a2007-06-22 19:11:54 +0200138 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk4d01d9e2004-03-25 14:59:05 +0000139 return 1;
140 }
141
142 filelen = reiserfs_open(filename);
143 if (filelen < 0) {
Luka Perkov94a4a1f2013-10-10 01:32:27 +0200144 printf("** File not found %s **\n", filename);
wdenk4d01d9e2004-03-25 14:59:05 +0000145 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 */
157 load_addr = addr;
158
159 printf ("\n%ld bytes read\n", filelen);
Simon Glass4d949a22017-08-03 12:22:10 -0600160 env_set_hex("filesize", filelen);
wdenk4d01d9e2004-03-25 14:59:05 +0000161
162 return filelen;
163}
164
165U_BOOT_CMD(
166 reiserload, 6, 0, do_reiserload,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600167 "load binary file from a Reiser filesystem",
wdenk4d01d9e2004-03-25 14:59:05 +0000168 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
169 " - load binary file 'filename' from 'dev' on 'interface'\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200170 " to address 'addr' from dos filesystem"
wdenk4d01d9e2004-03-25 14:59:05 +0000171);