blob: 2c0bca1c54f9637cb6bd6bf722bcb6fe272ef56d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk518e2e12004-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>
wdenk518e2e12004-03-25 14:59:05 +00006 */
7
8/*
9 * Reiserfs support
10 */
11#include <common.h>
wdenk518e2e12004-03-25 14:59:05 +000012#include <config.h>
13#include <command.h>
14#include <image.h>
15#include <linux/ctype.h>
16#include <asm/byteorder.h>
17#include <reiserfs.h>
Grant Likely735dd972007-02-20 09:04:34 +010018#include <part.h>
wdenk518e2e12004-03-25 14:59:05 +000019
Patrick Delaunayb0cf7332017-01-27 11:00:37 +010020#if !CONFIG_IS_ENABLED(DOS_PARTITION)
wdenk518e2e12004-03-25 14:59:05 +000021#error DOS partition support must be selected
22#endif
23
24/* #define REISER_DEBUG */
25
26#ifdef REISER_DEBUG
27#define PRINTF(fmt,args...) printf (fmt ,##args)
28#else
29#define PRINTF(fmt,args...)
30#endif
31
Wolfgang Denk54841ab2010-06-28 22:00:46 +020032int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +000033{
34 char *filename = "/";
Rob Herring650f3662012-08-23 11:31:50 +000035 int dev, part;
Simon Glass4101f682016-02-29 15:25:34 -070036 struct blk_desc *dev_desc = NULL;
Rob Herring650f3662012-08-23 11:31:50 +000037 disk_partition_t info;
wdenk518e2e12004-03-25 14:59:05 +000038
Wolfgang Denk47e26b12010-07-17 01:06:04 +020039 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +000040 return CMD_RET_USAGE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +020041
Simon Glasse35929e2016-02-29 15:25:44 -070042 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring650f3662012-08-23 11:31:50 +000043 if (part < 0)
wdenk518e2e12004-03-25 14:59:05 +000044 return 1;
wdenk518e2e12004-03-25 14:59:05 +000045
46 if (argc == 4) {
47 filename = argv[3];
48 }
49
Simon Glassbcce53d2016-02-29 15:25:51 -070050 dev = dev_desc->devnum;
wdenk518e2e12004-03-25 14:59:05 +000051 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
52
Rob Herring650f3662012-08-23 11:31:50 +000053 reiserfs_set_blk_dev(dev_desc, &info);
wdenk518e2e12004-03-25 14:59:05 +000054
Rob Herring650f3662012-08-23 11:31:50 +000055 if (!reiserfs_mount(info.size)) {
Heiko Schocher566a4942007-06-22 19:11:54 +020056 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +000057 return 1;
58 }
59
60 if (reiserfs_ls (filename)) {
61 printf ("** Error reiserfs_ls() **\n");
62 return 1;
63 };
64
65 return 0;
66}
67
68U_BOOT_CMD(
69 reiserls, 4, 1, do_reiserls,
Peter Tyser2fb26042009-01-27 18:03:12 -060070 "list files in a directory (default /)",
wdenk518e2e12004-03-25 14:59:05 +000071 "<interface> <dev[:part]> [directory]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020072 " - list files from 'dev' on 'interface' in a 'directory'"
wdenk518e2e12004-03-25 14:59:05 +000073);
74
75/******************************************************************************
76 * Reiserfs boot command intepreter. Derived from diskboot
77 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020078int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +000079{
80 char *filename = NULL;
Rob Herring650f3662012-08-23 11:31:50 +000081 int dev, part;
82 ulong addr = 0, filelen;
wdenk518e2e12004-03-25 14:59:05 +000083 disk_partition_t info;
Simon Glass4101f682016-02-29 15:25:34 -070084 struct blk_desc *dev_desc = NULL;
wdenk518e2e12004-03-25 14:59:05 +000085 unsigned long count;
86 char *addr_str;
87
88 switch (argc) {
89 case 3:
Simon Glass00caae62017-08-03 12:22:12 -060090 addr_str = env_get("loadaddr");
wdenk518e2e12004-03-25 14:59:05 +000091 if (addr_str != NULL) {
92 addr = simple_strtoul (addr_str, NULL, 16);
93 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020094 addr = CONFIG_SYS_LOAD_ADDR;
wdenk518e2e12004-03-25 14:59:05 +000095 }
Simon Glass00caae62017-08-03 12:22:12 -060096 filename = env_get("bootfile");
wdenk518e2e12004-03-25 14:59:05 +000097 count = 0;
98 break;
99 case 4:
100 addr = simple_strtoul (argv[3], NULL, 16);
Simon Glass00caae62017-08-03 12:22:12 -0600101 filename = env_get("bootfile");
wdenk518e2e12004-03-25 14:59:05 +0000102 count = 0;
103 break;
104 case 5:
105 addr = simple_strtoul (argv[3], NULL, 16);
106 filename = argv[4];
107 count = 0;
108 break;
109 case 6:
110 addr = simple_strtoul (argv[3], NULL, 16);
111 filename = argv[4];
112 count = simple_strtoul (argv[5], NULL, 16);
113 break;
114
115 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000116 return CMD_RET_USAGE;
wdenk518e2e12004-03-25 14:59:05 +0000117 }
118
119 if (!filename) {
120 puts ("\n** No boot file defined **\n");
121 return 1;
122 }
123
Simon Glasse35929e2016-02-29 15:25:44 -0700124 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring650f3662012-08-23 11:31:50 +0000125 if (part < 0)
wdenk518e2e12004-03-25 14:59:05 +0000126 return 1;
wdenk518e2e12004-03-25 14:59:05 +0000127
Simon Glassbcce53d2016-02-29 15:25:51 -0700128 dev = dev_desc->devnum;
wdenk518e2e12004-03-25 14:59:05 +0000129
Rob Herring650f3662012-08-23 11:31:50 +0000130 printf("Loading file \"%s\" from %s device %d%c%c\n",
131 filename, argv[1], dev,
132 part ? ':' : ' ', part ? part + '0' : ' ');
wdenk518e2e12004-03-25 14:59:05 +0000133
Rob Herring650f3662012-08-23 11:31:50 +0000134 reiserfs_set_blk_dev(dev_desc, &info);
wdenk518e2e12004-03-25 14:59:05 +0000135
Rob Herring650f3662012-08-23 11:31:50 +0000136 if (!reiserfs_mount(info.size)) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200137 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +0000138 return 1;
139 }
140
141 filelen = reiserfs_open(filename);
142 if (filelen < 0) {
Luka Perkov2e18cb22013-10-10 01:32:27 +0200143 printf("** File not found %s **\n", filename);
wdenk518e2e12004-03-25 14:59:05 +0000144 return 1;
145 }
146 if ((count < filelen) && (count != 0)) {
147 filelen = count;
148 }
149
150 if (reiserfs_read((char *)addr, filelen) != filelen) {
151 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
152 return 1;
153 }
154
155 /* Loading ok, update default load address */
156 load_addr = addr;
157
158 printf ("\n%ld bytes read\n", filelen);
Simon Glass018f5302017-08-03 12:22:10 -0600159 env_set_hex("filesize", filelen);
wdenk518e2e12004-03-25 14:59:05 +0000160
161 return filelen;
162}
163
164U_BOOT_CMD(
165 reiserload, 6, 0, do_reiserload,
Peter Tyser2fb26042009-01-27 18:03:12 -0600166 "load binary file from a Reiser filesystem",
wdenk518e2e12004-03-25 14:59:05 +0000167 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
168 " - load binary file 'filename' from 'dev' on 'interface'\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200169 " to address 'addr' from dos filesystem"
wdenk518e2e12004-03-25 14:59:05 +0000170);