reiser.c 3.72 KB
Newer Older
1 2 3 4 5
/*
 * (C) Copyright 2003 - 2004
 * Sysgo Real-Time Solutions, AG <www.elinos.com>
 * Pavel Bartusek <pba@sysgo.com>
 *
6
 * SPDX-License-Identifier:	GPL-2.0+
7 8 9 10 11 12 13 14 15 16 17 18
 */

/*
 * Reiserfs support
 */
#include <common.h>
#include <config.h>
#include <command.h>
#include <image.h>
#include <linux/ctype.h>
#include <asm/byteorder.h>
#include <reiserfs.h>
19
#include <part.h>
20 21 22 23 24 25 26 27 28 29 30 31 32

#ifndef CONFIG_DOS_PARTITION
#error DOS partition support must be selected
#endif

/* #define	REISER_DEBUG */

#ifdef	REISER_DEBUG
#define	PRINTF(fmt,args...)	printf (fmt ,##args)
#else
#define PRINTF(fmt,args...)
#endif

33
int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
34 35
{
	char *filename = "/";
36
	int dev, part;
37
	struct blk_desc *dev_desc = NULL;
38
	disk_partition_t info;
39

40
	if (argc < 3)
41
		return CMD_RET_USAGE;
42

43
	part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
44
	if (part < 0)
45 46 47 48 49 50
		return 1;

	if (argc == 4) {
	    filename = argv[3];
	}

51
	dev = dev_desc->devnum;
52 53
	PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);

54
	reiserfs_set_blk_dev(dev_desc, &info);
55

56
	if (!reiserfs_mount(info.size)) {
57
		printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
58 59 60 61 62 63 64 65 66 67 68 69 70
		return 1;
	}

	if (reiserfs_ls (filename)) {
		printf ("** Error reiserfs_ls() **\n");
		return 1;
	};

	return 0;
}

U_BOOT_CMD(
	reiserls,	4,	1,	do_reiserls,
Peter Tyser's avatar
Peter Tyser committed
71
	"list files in a directory (default /)",
72
	"<interface> <dev[:part]> [directory]\n"
73
	"    - list files from 'dev' on 'interface' in a 'directory'"
74 75 76 77 78
);

/******************************************************************************
 * Reiserfs boot command intepreter. Derived from diskboot
 */
79
int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
80 81
{
	char *filename = NULL;
82 83
	int dev, part;
	ulong addr = 0, filelen;
84
	disk_partition_t info;
85
	struct blk_desc *dev_desc = NULL;
86 87 88 89 90 91 92 93 94
	unsigned long count;
	char *addr_str;

	switch (argc) {
	case 3:
		addr_str = getenv("loadaddr");
		if (addr_str != NULL) {
			addr = simple_strtoul (addr_str, NULL, 16);
		} else {
95
			addr = CONFIG_SYS_LOAD_ADDR;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
		}
		filename = getenv ("bootfile");
		count = 0;
		break;
	case 4:
		addr = simple_strtoul (argv[3], NULL, 16);
		filename = getenv ("bootfile");
		count = 0;
		break;
	case 5:
		addr = simple_strtoul (argv[3], NULL, 16);
		filename = argv[4];
		count = 0;
		break;
	case 6:
		addr = simple_strtoul (argv[3], NULL, 16);
		filename = argv[4];
		count = simple_strtoul (argv[5], NULL, 16);
		break;

	default:
117
		return CMD_RET_USAGE;
118 119 120 121 122 123 124
	}

	if (!filename) {
		puts ("\n** No boot file defined **\n");
		return 1;
	}

125
	part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
126
	if (part < 0)
127 128
		return 1;

129
	dev = dev_desc->devnum;
130

131 132 133
	printf("Loading file \"%s\" from %s device %d%c%c\n",
		filename, argv[1], dev,
		part ? ':' : ' ', part ? part + '0' : ' ');
134

135
	reiserfs_set_blk_dev(dev_desc, &info);
136

137
	if (!reiserfs_mount(info.size)) {
138
		printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
139 140 141 142 143
		return 1;
	}

	filelen = reiserfs_open(filename);
	if (filelen < 0) {
144
		printf("** File not found %s **\n", filename);
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
		return 1;
	}
	if ((count < filelen) && (count != 0)) {
	    filelen = count;
	}

	if (reiserfs_read((char *)addr, filelen) != filelen) {
		printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
		return 1;
	}

	/* Loading ok, update default load address */
	load_addr = addr;

	printf ("\n%ld bytes read\n", filelen);
160
	setenv_hex("filesize", filelen);
161 162 163 164 165 166

	return filelen;
}

U_BOOT_CMD(
	reiserload,	6,	0,	do_reiserload,
Peter Tyser's avatar
Peter Tyser committed
167
	"load binary file from a Reiser filesystem",
168 169
	"<interface> <dev[:part]> [addr] [filename] [bytes]\n"
	"    - load binary file 'filename' from 'dev' on 'interface'\n"
170
	"      to address 'addr' from dos filesystem"
171
);