Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2003 - 2004 |
| 4 | * Sysgo Real-Time Solutions, AG <www.elinos.com> |
| 5 | * Pavel Bartusek <pba@sysgo.com> |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Reiserfs support |
| 10 | */ |
| 11 | #include <common.h> |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 12 | #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 Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 18 | #include <part.h> |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 19 | |
Patrick Delaunay | f7e0772 | 2017-01-27 11:00:37 +0100 | [diff] [blame] | 20 | #if !CONFIG_IS_ENABLED(DOS_PARTITION) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 21 | #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 Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 32 | int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 33 | { |
| 34 | char *filename = "/"; |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 35 | int dev, part; |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 36 | struct blk_desc *dev_desc = NULL; |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 37 | disk_partition_t info; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 38 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 39 | if (argc < 3) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 40 | return CMD_RET_USAGE; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 41 | |
Simon Glass | e76ee97 | 2016-02-29 15:25:44 -0700 | [diff] [blame] | 42 | part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 43 | if (part < 0) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 44 | return 1; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 45 | |
| 46 | if (argc == 4) { |
| 47 | filename = argv[3]; |
| 48 | } |
| 49 | |
Simon Glass | 2f26fff | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 50 | dev = dev_desc->devnum; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 51 | PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); |
| 52 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 53 | reiserfs_set_blk_dev(dev_desc, &info); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 54 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 55 | if (!reiserfs_mount(info.size)) { |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 56 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 57 | 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 | |
| 68 | U_BOOT_CMD( |
| 69 | reiserls, 4, 1, do_reiserls, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 70 | "list files in a directory (default /)", |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 71 | "<interface> <dev[:part]> [directory]\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 72 | " - list files from 'dev' on 'interface' in a 'directory'" |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 73 | ); |
| 74 | |
| 75 | /****************************************************************************** |
| 76 | * Reiserfs boot command intepreter. Derived from diskboot |
| 77 | */ |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 78 | int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 79 | { |
| 80 | char *filename = NULL; |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 81 | int dev, part; |
| 82 | ulong addr = 0, filelen; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 83 | disk_partition_t info; |
Simon Glass | e339475 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 84 | struct blk_desc *dev_desc = NULL; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 85 | unsigned long count; |
| 86 | char *addr_str; |
| 87 | |
| 88 | switch (argc) { |
| 89 | case 3: |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 90 | addr_str = env_get("loadaddr"); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 91 | if (addr_str != NULL) { |
| 92 | addr = simple_strtoul (addr_str, NULL, 16); |
| 93 | } else { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | addr = CONFIG_SYS_LOAD_ADDR; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 95 | } |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 96 | filename = env_get("bootfile"); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 97 | count = 0; |
| 98 | break; |
| 99 | case 4: |
| 100 | addr = simple_strtoul (argv[3], NULL, 16); |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 101 | filename = env_get("bootfile"); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 102 | 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 Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 116 | return CMD_RET_USAGE; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | if (!filename) { |
| 120 | puts ("\n** No boot file defined **\n"); |
| 121 | return 1; |
| 122 | } |
| 123 | |
Simon Glass | e76ee97 | 2016-02-29 15:25:44 -0700 | [diff] [blame] | 124 | part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 125 | if (part < 0) |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 126 | return 1; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 127 | |
Simon Glass | 2f26fff | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 128 | dev = dev_desc->devnum; |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 129 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 130 | printf("Loading file \"%s\" from %s device %d%c%c\n", |
| 131 | filename, argv[1], dev, |
| 132 | part ? ':' : ' ', part ? part + '0' : ' '); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 133 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 134 | reiserfs_set_blk_dev(dev_desc, &info); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 135 | |
Rob Herring | 8d6ba05 | 2012-08-23 11:31:50 +0000 | [diff] [blame] | 136 | if (!reiserfs_mount(info.size)) { |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 137 | printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | filelen = reiserfs_open(filename); |
| 142 | if (filelen < 0) { |
Luka Perkov | 94a4a1f | 2013-10-10 01:32:27 +0200 | [diff] [blame] | 143 | printf("** File not found %s **\n", filename); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 144 | 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 Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 159 | env_set_hex("filesize", filelen); |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 160 | |
| 161 | return filelen; |
| 162 | } |
| 163 | |
| 164 | U_BOOT_CMD( |
| 165 | reiserload, 6, 0, do_reiserload, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 166 | "load binary file from a Reiser filesystem", |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 167 | "<interface> <dev[:part]> [addr] [filename] [bytes]\n" |
| 168 | " - load binary file 'filename' from 'dev' on 'interface'\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 169 | " to address 'addr' from dos filesystem" |
wdenk | 4d01d9e | 2004-03-25 14:59:05 +0000 | [diff] [blame] | 170 | ); |