Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | |
| 9 | /* |
| 10 | * UBIFS command support |
| 11 | */ |
| 12 | |
| 13 | #undef DEBUG |
| 14 | |
| 15 | #include <common.h> |
| 16 | #include <config.h> |
| 17 | #include <command.h> |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 18 | #include <ubifs_uboot.h> |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 19 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 20 | static int ubifs_initialized; |
| 21 | static int ubifs_mounted; |
| 22 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 23 | static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, |
| 24 | char * const argv[]) |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 25 | { |
| 26 | char *vol_name; |
| 27 | int ret; |
| 28 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 29 | if (argc != 2) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 30 | return CMD_RET_USAGE; |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 31 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 32 | vol_name = argv[1]; |
| 33 | debug("Using volume %s\n", vol_name); |
| 34 | |
| 35 | if (ubifs_initialized == 0) { |
| 36 | ubifs_init(); |
| 37 | ubifs_initialized = 1; |
| 38 | } |
| 39 | |
Heiko Schocher | f5895d1 | 2014-06-24 10:10:04 +0200 | [diff] [blame] | 40 | ret = uboot_ubifs_mount(vol_name); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 41 | if (ret) |
| 42 | return -1; |
| 43 | |
| 44 | ubifs_mounted = 1; |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Stefan Roese | 408c6c4 | 2010-11-01 17:28:22 +0100 | [diff] [blame] | 49 | int ubifs_is_mounted(void) |
| 50 | { |
| 51 | return ubifs_mounted; |
| 52 | } |
| 53 | |
| 54 | void cmd_ubifs_umount(void) |
| 55 | { |
Hans de Goede | a164477 | 2015-09-17 18:46:56 -0400 | [diff] [blame] | 56 | uboot_ubifs_umount(); |
Stefan Roese | 408c6c4 | 2010-11-01 17:28:22 +0100 | [diff] [blame] | 57 | ubifs_mounted = 0; |
| 58 | ubifs_initialized = 0; |
| 59 | } |
| 60 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 61 | static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, |
| 62 | char * const argv[]) |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 63 | { |
| 64 | if (argc != 1) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 65 | return CMD_RET_USAGE; |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 66 | |
| 67 | if (ubifs_initialized == 0) { |
| 68 | printf("No UBIFS volume mounted!\n"); |
| 69 | return -1; |
| 70 | } |
| 71 | |
Stefan Roese | 408c6c4 | 2010-11-01 17:28:22 +0100 | [diff] [blame] | 72 | cmd_ubifs_umount(); |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 77 | static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, |
| 78 | char * const argv[]) |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 79 | { |
| 80 | char *filename = "/"; |
| 81 | int ret; |
| 82 | |
| 83 | if (!ubifs_mounted) { |
Stefan Roese | 67a0f52 | 2010-10-28 14:09:29 +0200 | [diff] [blame] | 84 | printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 85 | return -1; |
| 86 | } |
| 87 | |
| 88 | if (argc == 2) |
| 89 | filename = argv[1]; |
| 90 | debug("Using filename %s\n", filename); |
| 91 | |
| 92 | ret = ubifs_ls(filename); |
Tim Harvey | 8d66edc | 2013-10-10 01:32:26 +0200 | [diff] [blame] | 93 | if (ret) { |
| 94 | printf("** File not found %s **\n", filename); |
| 95 | ret = CMD_RET_FAILURE; |
| 96 | } |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 101 | static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, |
| 102 | char * const argv[]) |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 103 | { |
| 104 | char *filename; |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 105 | char *endp; |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 106 | int ret; |
| 107 | u32 addr; |
| 108 | u32 size = 0; |
| 109 | |
| 110 | if (!ubifs_mounted) { |
| 111 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); |
| 112 | return -1; |
| 113 | } |
| 114 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 115 | if (argc < 3) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 116 | return CMD_RET_USAGE; |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 117 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 118 | addr = simple_strtoul(argv[1], &endp, 16); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 119 | if (endp == argv[1]) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 120 | return CMD_RET_USAGE; |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 121 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 122 | filename = argv[2]; |
| 123 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 124 | if (argc == 4) { |
| 125 | size = simple_strtoul(argv[3], &endp, 16); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 126 | if (endp == argv[3]) |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 127 | return CMD_RET_USAGE; |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 128 | } |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 129 | debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size); |
| 130 | |
| 131 | ret = ubifs_load(filename, addr, size); |
Tim Harvey | 8d66edc | 2013-10-10 01:32:26 +0200 | [diff] [blame] | 132 | if (ret) { |
| 133 | printf("** File not found %s **\n", filename); |
| 134 | ret = CMD_RET_FAILURE; |
| 135 | } |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 136 | |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | U_BOOT_CMD( |
| 141 | ubifsmount, 2, 0, do_ubifs_mount, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 142 | "mount UBIFS volume", |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 143 | "<volume-name>\n" |
| 144 | " - mount 'volume-name' volume" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 145 | ); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 146 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 147 | U_BOOT_CMD( |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 148 | ubifsumount, 1, 0, do_ubifs_umount, |
| 149 | "unmount UBIFS volume", |
| 150 | " - unmount current volume" |
| 151 | ); |
| 152 | |
| 153 | U_BOOT_CMD( |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 154 | ubifsls, 2, 0, do_ubifs_ls, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 155 | "list files in a directory", |
| 156 | "[directory]\n" |
| 157 | " - list files in a 'directory' (default '/')" |
| 158 | ); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 159 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 160 | U_BOOT_CMD( |
| 161 | ubifsload, 4, 0, do_ubifs_load, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 162 | "load file from an UBIFS filesystem", |
| 163 | "<addr> <filename> [bytes]\n" |
| 164 | " - load file 'filename' to address 'addr'" |
| 165 | ); |