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