wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 - 2004 |
| 3 | * Sysgo Real-Time Solutions, AG <www.elinos.com> |
| 4 | * Pavel Bartusek <pba@sysgo.com> |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Reiserfs support |
| 11 | */ |
| 12 | #include <common.h> |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 13 | #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 Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 19 | #include <part.h> |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 20 | |
| 21 | #ifndef CONFIG_DOS_PARTITION |
| 22 | #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 Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 33 | int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 34 | { |
| 35 | char *filename = "/"; |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 36 | int dev, part; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 37 | block_dev_desc_t *dev_desc=NULL; |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 38 | disk_partition_t info; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 39 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 40 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 41 | return CMD_RET_USAGE; |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 42 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 43 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 44 | if (part < 0) |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 45 | return 1; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 46 | |
| 47 | if (argc == 4) { |
| 48 | filename = argv[3]; |
| 49 | } |
| 50 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 51 | dev = dev_desc->dev; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 52 | PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); |
| 53 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 54 | reiserfs_set_blk_dev(dev_desc, &info); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 55 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 56 | if (!reiserfs_mount(info.size)) { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 57 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 58 | 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 | |
| 69 | U_BOOT_CMD( |
| 70 | reiserls, 4, 1, do_reiserls, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 71 | "list files in a directory (default /)", |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 72 | "<interface> <dev[:part]> [directory]\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 73 | " - list files from 'dev' on 'interface' in a 'directory'" |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 74 | ); |
| 75 | |
| 76 | /****************************************************************************** |
| 77 | * Reiserfs boot command intepreter. Derived from diskboot |
| 78 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 79 | int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 80 | { |
| 81 | char *filename = NULL; |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 82 | int dev, part; |
| 83 | ulong addr = 0, filelen; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 84 | disk_partition_t info; |
| 85 | block_dev_desc_t *dev_desc = NULL; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 86 | 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | addr = CONFIG_SYS_LOAD_ADDR; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 96 | } |
| 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 Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 117 | return CMD_RET_USAGE; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | if (!filename) { |
| 121 | puts ("\n** No boot file defined **\n"); |
| 122 | return 1; |
| 123 | } |
| 124 | |
Stephen Warren | 10a37fd | 2012-09-21 09:50:57 +0000 | [diff] [blame] | 125 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 126 | if (part < 0) |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 127 | return 1; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 128 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 129 | dev = dev_desc->dev; |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 130 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 131 | printf("Loading file \"%s\" from %s device %d%c%c\n", |
| 132 | filename, argv[1], dev, |
| 133 | part ? ':' : ' ', part ? part + '0' : ' '); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 134 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 135 | reiserfs_set_blk_dev(dev_desc, &info); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 136 | |
Rob Herring | 650f366 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 137 | if (!reiserfs_mount(info.size)) { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 138 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | filelen = reiserfs_open(filename); |
| 143 | if (filelen < 0) { |
Luka Perkov | 2e18cb2 | 2013-10-10 01:32:27 +0200 | [diff] [blame^] | 144 | printf("** File not found %s **\n", filename); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 145 | 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 Glass | 41ef372 | 2013-02-24 17:33:22 +0000 | [diff] [blame] | 160 | setenv_hex("filesize", filelen); |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 161 | |
| 162 | return filelen; |
| 163 | } |
| 164 | |
| 165 | U_BOOT_CMD( |
| 166 | reiserload, 6, 0, do_reiserload, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 167 | "load binary file from a Reiser filesystem", |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 168 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" |
| 169 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 170 | " to address 'addr' from dos filesystem" |
wdenk | 518e2e1 | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 171 | ); |