1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
22e192b24SSimon Glass /*
32e192b24SSimon Glass * (C) Copyright 2003 - 2004
42e192b24SSimon Glass * Sysgo Real-Time Solutions, AG <www.elinos.com>
52e192b24SSimon Glass * Pavel Bartusek <pba@sysgo.com>
62e192b24SSimon Glass */
72e192b24SSimon Glass
82e192b24SSimon Glass /*
92e192b24SSimon Glass * Reiserfs support
102e192b24SSimon Glass */
112e192b24SSimon Glass #include <common.h>
122e192b24SSimon Glass #include <config.h>
132e192b24SSimon Glass #include <command.h>
142e192b24SSimon Glass #include <image.h>
152e192b24SSimon Glass #include <linux/ctype.h>
162e192b24SSimon Glass #include <asm/byteorder.h>
172e192b24SSimon Glass #include <reiserfs.h>
182e192b24SSimon Glass #include <part.h>
192e192b24SSimon Glass
20b0cf7339SPatrick Delaunay #if !CONFIG_IS_ENABLED(DOS_PARTITION)
212e192b24SSimon Glass #error DOS partition support must be selected
222e192b24SSimon Glass #endif
232e192b24SSimon Glass
242e192b24SSimon Glass /* #define REISER_DEBUG */
252e192b24SSimon Glass
262e192b24SSimon Glass #ifdef REISER_DEBUG
272e192b24SSimon Glass #define PRINTF(fmt,args...) printf (fmt ,##args)
282e192b24SSimon Glass #else
292e192b24SSimon Glass #define PRINTF(fmt,args...)
302e192b24SSimon Glass #endif
312e192b24SSimon Glass
do_reiserls(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])322e192b24SSimon Glass int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
332e192b24SSimon Glass {
342e192b24SSimon Glass char *filename = "/";
352e192b24SSimon Glass int dev, part;
364101f687SSimon Glass struct blk_desc *dev_desc = NULL;
372e192b24SSimon Glass disk_partition_t info;
382e192b24SSimon Glass
392e192b24SSimon Glass if (argc < 3)
402e192b24SSimon Glass return CMD_RET_USAGE;
412e192b24SSimon Glass
42e35929e4SSimon Glass part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
432e192b24SSimon Glass if (part < 0)
442e192b24SSimon Glass return 1;
452e192b24SSimon Glass
462e192b24SSimon Glass if (argc == 4) {
472e192b24SSimon Glass filename = argv[3];
482e192b24SSimon Glass }
492e192b24SSimon Glass
50bcce53d0SSimon Glass dev = dev_desc->devnum;
512e192b24SSimon Glass PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
522e192b24SSimon Glass
532e192b24SSimon Glass reiserfs_set_blk_dev(dev_desc, &info);
542e192b24SSimon Glass
552e192b24SSimon Glass if (!reiserfs_mount(info.size)) {
562e192b24SSimon Glass printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
572e192b24SSimon Glass return 1;
582e192b24SSimon Glass }
592e192b24SSimon Glass
602e192b24SSimon Glass if (reiserfs_ls (filename)) {
612e192b24SSimon Glass printf ("** Error reiserfs_ls() **\n");
622e192b24SSimon Glass return 1;
632e192b24SSimon Glass };
642e192b24SSimon Glass
652e192b24SSimon Glass return 0;
662e192b24SSimon Glass }
672e192b24SSimon Glass
682e192b24SSimon Glass U_BOOT_CMD(
692e192b24SSimon Glass reiserls, 4, 1, do_reiserls,
702e192b24SSimon Glass "list files in a directory (default /)",
712e192b24SSimon Glass "<interface> <dev[:part]> [directory]\n"
722e192b24SSimon Glass " - list files from 'dev' on 'interface' in a 'directory'"
732e192b24SSimon Glass );
742e192b24SSimon Glass
752e192b24SSimon Glass /******************************************************************************
762e192b24SSimon Glass * Reiserfs boot command intepreter. Derived from diskboot
772e192b24SSimon Glass */
do_reiserload(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])782e192b24SSimon Glass int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
792e192b24SSimon Glass {
802e192b24SSimon Glass char *filename = NULL;
812e192b24SSimon Glass int dev, part;
822e192b24SSimon Glass ulong addr = 0, filelen;
832e192b24SSimon Glass disk_partition_t info;
844101f687SSimon Glass struct blk_desc *dev_desc = NULL;
852e192b24SSimon Glass unsigned long count;
862e192b24SSimon Glass char *addr_str;
872e192b24SSimon Glass
882e192b24SSimon Glass switch (argc) {
892e192b24SSimon Glass case 3:
9000caae6dSSimon Glass addr_str = env_get("loadaddr");
912e192b24SSimon Glass if (addr_str != NULL) {
922e192b24SSimon Glass addr = simple_strtoul (addr_str, NULL, 16);
932e192b24SSimon Glass } else {
942e192b24SSimon Glass addr = CONFIG_SYS_LOAD_ADDR;
952e192b24SSimon Glass }
9600caae6dSSimon Glass filename = env_get("bootfile");
972e192b24SSimon Glass count = 0;
982e192b24SSimon Glass break;
992e192b24SSimon Glass case 4:
1002e192b24SSimon Glass addr = simple_strtoul (argv[3], NULL, 16);
10100caae6dSSimon Glass filename = env_get("bootfile");
1022e192b24SSimon Glass count = 0;
1032e192b24SSimon Glass break;
1042e192b24SSimon Glass case 5:
1052e192b24SSimon Glass addr = simple_strtoul (argv[3], NULL, 16);
1062e192b24SSimon Glass filename = argv[4];
1072e192b24SSimon Glass count = 0;
1082e192b24SSimon Glass break;
1092e192b24SSimon Glass case 6:
1102e192b24SSimon Glass addr = simple_strtoul (argv[3], NULL, 16);
1112e192b24SSimon Glass filename = argv[4];
1122e192b24SSimon Glass count = simple_strtoul (argv[5], NULL, 16);
1132e192b24SSimon Glass break;
1142e192b24SSimon Glass
1152e192b24SSimon Glass default:
1162e192b24SSimon Glass return CMD_RET_USAGE;
1172e192b24SSimon Glass }
1182e192b24SSimon Glass
1192e192b24SSimon Glass if (!filename) {
1202e192b24SSimon Glass puts ("\n** No boot file defined **\n");
1212e192b24SSimon Glass return 1;
1222e192b24SSimon Glass }
1232e192b24SSimon Glass
124e35929e4SSimon Glass part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
1252e192b24SSimon Glass if (part < 0)
1262e192b24SSimon Glass return 1;
1272e192b24SSimon Glass
128bcce53d0SSimon Glass dev = dev_desc->devnum;
1292e192b24SSimon Glass
1302e192b24SSimon Glass printf("Loading file \"%s\" from %s device %d%c%c\n",
1312e192b24SSimon Glass filename, argv[1], dev,
1322e192b24SSimon Glass part ? ':' : ' ', part ? part + '0' : ' ');
1332e192b24SSimon Glass
1342e192b24SSimon Glass reiserfs_set_blk_dev(dev_desc, &info);
1352e192b24SSimon Glass
1362e192b24SSimon Glass if (!reiserfs_mount(info.size)) {
1372e192b24SSimon Glass printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
1382e192b24SSimon Glass return 1;
1392e192b24SSimon Glass }
1402e192b24SSimon Glass
1412e192b24SSimon Glass filelen = reiserfs_open(filename);
1422e192b24SSimon Glass if (filelen < 0) {
1432e192b24SSimon Glass printf("** File not found %s **\n", filename);
1442e192b24SSimon Glass return 1;
1452e192b24SSimon Glass }
1462e192b24SSimon Glass if ((count < filelen) && (count != 0)) {
1472e192b24SSimon Glass filelen = count;
1482e192b24SSimon Glass }
1492e192b24SSimon Glass
1502e192b24SSimon Glass if (reiserfs_read((char *)addr, filelen) != filelen) {
1512e192b24SSimon Glass printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
1522e192b24SSimon Glass return 1;
1532e192b24SSimon Glass }
1542e192b24SSimon Glass
1552e192b24SSimon Glass /* Loading ok, update default load address */
1562e192b24SSimon Glass load_addr = addr;
1572e192b24SSimon Glass
1582e192b24SSimon Glass printf ("\n%ld bytes read\n", filelen);
159018f5303SSimon Glass env_set_hex("filesize", filelen);
1602e192b24SSimon Glass
1612e192b24SSimon Glass return filelen;
1622e192b24SSimon Glass }
1632e192b24SSimon Glass
1642e192b24SSimon Glass U_BOOT_CMD(
1652e192b24SSimon Glass reiserload, 6, 0, do_reiserload,
1662e192b24SSimon Glass "load binary file from a Reiser filesystem",
1672e192b24SSimon Glass "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
1682e192b24SSimon Glass " - load binary file 'filename' from 'dev' on 'interface'\n"
1692e192b24SSimon Glass " to address 'addr' from dos filesystem"
1702e192b24SSimon Glass );
171