blob: 9c3e9e9e582be7e19d1dcc8106397867fce6ae66 [file] [log] [blame]
wdenk518e2e12004-03-25 14:59:05 +00001/*
2 * (C) Copyright 2003 - 2004
3 * Sysgo Real-Time Solutions, AG <www.elinos.com>
4 * Pavel Bartusek <pba@sysgo.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenk518e2e12004-03-25 14:59:05 +00007 */
8
9/*
10 * Reiserfs support
11 */
12#include <common.h>
wdenk518e2e12004-03-25 14:59:05 +000013#include <config.h>
14#include <command.h>
15#include <image.h>
16#include <linux/ctype.h>
17#include <asm/byteorder.h>
18#include <reiserfs.h>
Grant Likely735dd972007-02-20 09:04:34 +010019#include <part.h>
wdenk518e2e12004-03-25 14:59:05 +000020
Patrick Delaunayb0cf7332017-01-27 11:00:37 +010021#if !CONFIG_IS_ENABLED(DOS_PARTITION)
wdenk518e2e12004-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 Denk54841ab2010-06-28 22:00:46 +020033int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +000034{
35 char *filename = "/";
Rob Herring650f3662012-08-23 11:31:50 +000036 int dev, part;
Simon Glass4101f682016-02-29 15:25:34 -070037 struct blk_desc *dev_desc = NULL;
Rob Herring650f3662012-08-23 11:31:50 +000038 disk_partition_t info;
wdenk518e2e12004-03-25 14:59:05 +000039
Wolfgang Denk47e26b12010-07-17 01:06:04 +020040 if (argc < 3)
Simon Glass4c12eeb2011-12-10 08:44:01 +000041 return CMD_RET_USAGE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +020042
Simon Glasse35929e2016-02-29 15:25:44 -070043 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring650f3662012-08-23 11:31:50 +000044 if (part < 0)
wdenk518e2e12004-03-25 14:59:05 +000045 return 1;
wdenk518e2e12004-03-25 14:59:05 +000046
47 if (argc == 4) {
48 filename = argv[3];
49 }
50
Simon Glassbcce53d2016-02-29 15:25:51 -070051 dev = dev_desc->devnum;
wdenk518e2e12004-03-25 14:59:05 +000052 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
53
Rob Herring650f3662012-08-23 11:31:50 +000054 reiserfs_set_blk_dev(dev_desc, &info);
wdenk518e2e12004-03-25 14:59:05 +000055
Rob Herring650f3662012-08-23 11:31:50 +000056 if (!reiserfs_mount(info.size)) {
Heiko Schocher566a4942007-06-22 19:11:54 +020057 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-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 Tyser2fb26042009-01-27 18:03:12 -060071 "list files in a directory (default /)",
wdenk518e2e12004-03-25 14:59:05 +000072 "<interface> <dev[:part]> [directory]\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +020073 " - list files from 'dev' on 'interface' in a 'directory'"
wdenk518e2e12004-03-25 14:59:05 +000074);
75
76/******************************************************************************
77 * Reiserfs boot command intepreter. Derived from diskboot
78 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020079int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk518e2e12004-03-25 14:59:05 +000080{
81 char *filename = NULL;
Rob Herring650f3662012-08-23 11:31:50 +000082 int dev, part;
83 ulong addr = 0, filelen;
wdenk518e2e12004-03-25 14:59:05 +000084 disk_partition_t info;
Simon Glass4101f682016-02-29 15:25:34 -070085 struct blk_desc *dev_desc = NULL;
wdenk518e2e12004-03-25 14:59:05 +000086 unsigned long count;
87 char *addr_str;
88
89 switch (argc) {
90 case 3:
91 addr_str = getenv("loadaddr");
92 if (addr_str != NULL) {
93 addr = simple_strtoul (addr_str, NULL, 16);
94 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 addr = CONFIG_SYS_LOAD_ADDR;
wdenk518e2e12004-03-25 14:59:05 +000096 }
97 filename = getenv ("bootfile");
98 count = 0;
99 break;
100 case 4:
101 addr = simple_strtoul (argv[3], NULL, 16);
102 filename = getenv ("bootfile");
103 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 Glass4c12eeb2011-12-10 08:44:01 +0000117 return CMD_RET_USAGE;
wdenk518e2e12004-03-25 14:59:05 +0000118 }
119
120 if (!filename) {
121 puts ("\n** No boot file defined **\n");
122 return 1;
123 }
124
Simon Glasse35929e2016-02-29 15:25:44 -0700125 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
Rob Herring650f3662012-08-23 11:31:50 +0000126 if (part < 0)
wdenk518e2e12004-03-25 14:59:05 +0000127 return 1;
wdenk518e2e12004-03-25 14:59:05 +0000128
Simon Glassbcce53d2016-02-29 15:25:51 -0700129 dev = dev_desc->devnum;
wdenk518e2e12004-03-25 14:59:05 +0000130
Rob Herring650f3662012-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' : ' ');
wdenk518e2e12004-03-25 14:59:05 +0000134
Rob Herring650f3662012-08-23 11:31:50 +0000135 reiserfs_set_blk_dev(dev_desc, &info);
wdenk518e2e12004-03-25 14:59:05 +0000136
Rob Herring650f3662012-08-23 11:31:50 +0000137 if (!reiserfs_mount(info.size)) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200138 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
wdenk518e2e12004-03-25 14:59:05 +0000139 return 1;
140 }
141
142 filelen = reiserfs_open(filename);
143 if (filelen < 0) {
Luka Perkov2e18cb22013-10-10 01:32:27 +0200144 printf("** File not found %s **\n", filename);
wdenk518e2e12004-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 Glass41ef3722013-02-24 17:33:22 +0000160 setenv_hex("filesize", filelen);
wdenk518e2e12004-03-25 14:59:05 +0000161
162 return filelen;
163}
164
165U_BOOT_CMD(
166 reiserload, 6, 0, do_reiserload,
Peter Tyser2fb26042009-01-27 18:03:12 -0600167 "load binary file from a Reiser filesystem",
wdenk518e2e12004-03-25 14:59:05 +0000168 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
169 " - load binary file 'filename' from 'dev' on 'interface'\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200170 " to address 'addr' from dos filesystem"
wdenk518e2e12004-03-25 14:59:05 +0000171);