blob: 707167fcd59b55ee9699be01b473056d7cf85d36 [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>
Simon Glassc7694dd2019-08-01 09:46:46 -060014#include <env.h>
wdenk518e2e12004-03-25 14:59:05 +000015#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
Simon Glass09140112020-05-10 11:40:03 -060033int do_reiserls(struct cmd_tbl *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;
Simon Glass05289792020-05-10 11:39:57 -060038 struct disk_partition 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 */
Simon Glass09140112020-05-10 11:40:03 -060079int do_reiserload(struct cmd_tbl *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;
Simon Glass05289792020-05-10 11:39:57 -060084 struct disk_partition 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:
Simon Glass00caae62017-08-03 12:22:12 -060091 addr_str = env_get("loadaddr");
wdenk518e2e12004-03-25 14:59:05 +000092 if (addr_str != NULL) {
Simon Glass7e5f4602021-07-24 09:03:29 -060093 addr = hextoul(addr_str, NULL);
wdenk518e2e12004-03-25 14:59:05 +000094 } else {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 addr = CONFIG_SYS_LOAD_ADDR;
wdenk518e2e12004-03-25 14:59:05 +000096 }
Simon Glass00caae62017-08-03 12:22:12 -060097 filename = env_get("bootfile");
wdenk518e2e12004-03-25 14:59:05 +000098 count = 0;
99 break;
100 case 4:
Simon Glass7e5f4602021-07-24 09:03:29 -0600101 addr = hextoul(argv[3], NULL);
Simon Glass00caae62017-08-03 12:22:12 -0600102 filename = env_get("bootfile");
wdenk518e2e12004-03-25 14:59:05 +0000103 count = 0;
104 break;
105 case 5:
Simon Glass7e5f4602021-07-24 09:03:29 -0600106 addr = hextoul(argv[3], NULL);
wdenk518e2e12004-03-25 14:59:05 +0000107 filename = argv[4];
108 count = 0;
109 break;
110 case 6:
Simon Glass7e5f4602021-07-24 09:03:29 -0600111 addr = hextoul(argv[3], NULL);
wdenk518e2e12004-03-25 14:59:05 +0000112 filename = argv[4];
Simon Glass7e5f4602021-07-24 09:03:29 -0600113 count = hextoul(argv[5], NULL);
wdenk518e2e12004-03-25 14:59:05 +0000114 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 */
Simon Glassbb872dd2019-12-28 10:45:02 -0700157 image_load_addr = addr;
wdenk518e2e12004-03-25 14:59:05 +0000158
159 printf ("\n%ld bytes read\n", filelen);
Simon Glass018f5302017-08-03 12:22:10 -0600160 env_set_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);