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 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | /* |
| 27 | * UBIFS command support |
| 28 | */ |
| 29 | |
| 30 | #undef DEBUG |
| 31 | |
| 32 | #include <common.h> |
| 33 | #include <config.h> |
| 34 | #include <command.h> |
| 35 | |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 36 | #include "../fs/ubifs/ubifs.h" |
| 37 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 38 | static int ubifs_initialized; |
| 39 | static int ubifs_mounted; |
| 40 | |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 41 | extern struct super_block *ubifs_sb; |
| 42 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 43 | /* Prototypes */ |
| 44 | int ubifs_init(void); |
| 45 | int ubifs_mount(char *vol_name); |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 46 | void ubifs_umount(struct ubifs_info *c); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 47 | int ubifs_ls(char *dir_name); |
| 48 | int ubifs_load(char *filename, u32 addr, u32 size); |
| 49 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 50 | int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 51 | { |
| 52 | char *vol_name; |
| 53 | int ret; |
| 54 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 55 | if (argc != 2) |
| 56 | return cmd_usage(cmdtp); |
| 57 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 58 | vol_name = argv[1]; |
| 59 | debug("Using volume %s\n", vol_name); |
| 60 | |
| 61 | if (ubifs_initialized == 0) { |
| 62 | ubifs_init(); |
| 63 | ubifs_initialized = 1; |
| 64 | } |
| 65 | |
| 66 | ret = ubifs_mount(vol_name); |
| 67 | if (ret) |
| 68 | return -1; |
| 69 | |
| 70 | ubifs_mounted = 1; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 75 | int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 76 | { |
| 77 | if (argc != 1) |
| 78 | return cmd_usage(cmdtp); |
| 79 | |
| 80 | if (ubifs_initialized == 0) { |
| 81 | printf("No UBIFS volume mounted!\n"); |
| 82 | return -1; |
| 83 | } |
| 84 | |
| 85 | if (ubifs_sb) |
| 86 | ubifs_umount(ubifs_sb->s_fs_info); |
| 87 | |
| 88 | ubifs_sb = NULL; |
| 89 | ubifs_mounted = 0; |
| 90 | ubifs_initialized = 0; |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 95 | int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 96 | { |
| 97 | char *filename = "/"; |
| 98 | int ret; |
| 99 | |
| 100 | if (!ubifs_mounted) { |
Stefan Roese | 67a0f52 | 2010-10-28 14:09:29 +0200 | [diff] [blame^] | 101 | printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | if (argc == 2) |
| 106 | filename = argv[1]; |
| 107 | debug("Using filename %s\n", filename); |
| 108 | |
| 109 | ret = ubifs_ls(filename); |
| 110 | if (ret) |
| 111 | printf("%s not found!\n", filename); |
| 112 | |
| 113 | return ret; |
| 114 | } |
| 115 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 116 | int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 117 | { |
| 118 | char *filename; |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 119 | char *endp; |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 120 | int ret; |
| 121 | u32 addr; |
| 122 | u32 size = 0; |
| 123 | |
| 124 | if (!ubifs_mounted) { |
| 125 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); |
| 126 | return -1; |
| 127 | } |
| 128 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 129 | if (argc < 3) |
| 130 | return cmd_usage(cmdtp); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 131 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 132 | addr = simple_strtoul(argv[1], &endp, 16); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 133 | if (endp == argv[1]) |
| 134 | return cmd_usage(cmdtp); |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 135 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 136 | filename = argv[2]; |
| 137 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 138 | if (argc == 4) { |
| 139 | size = simple_strtoul(argv[3], &endp, 16); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 140 | if (endp == argv[3]) |
| 141 | return cmd_usage(cmdtp); |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 142 | } |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 143 | debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size); |
| 144 | |
| 145 | ret = ubifs_load(filename, addr, size); |
| 146 | if (ret) |
| 147 | printf("%s not found!\n", filename); |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | U_BOOT_CMD( |
| 153 | ubifsmount, 2, 0, do_ubifs_mount, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 154 | "mount UBIFS volume", |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 155 | "<volume-name>\n" |
| 156 | " - mount 'volume-name' volume" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 157 | ); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 158 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 159 | U_BOOT_CMD( |
Stefan Roese | ff98053 | 2010-10-28 14:09:22 +0200 | [diff] [blame] | 160 | ubifsumount, 1, 0, do_ubifs_umount, |
| 161 | "unmount UBIFS volume", |
| 162 | " - unmount current volume" |
| 163 | ); |
| 164 | |
| 165 | U_BOOT_CMD( |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 166 | ubifsls, 2, 0, do_ubifs_ls, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 167 | "list files in a directory", |
| 168 | "[directory]\n" |
| 169 | " - list files in a 'directory' (default '/')" |
| 170 | ); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 171 | |
Frans Meulenbroeks | 7675a09 | 2010-07-31 15:01:53 +0200 | [diff] [blame] | 172 | U_BOOT_CMD( |
| 173 | ubifsload, 4, 0, do_ubifs_load, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 174 | "load file from an UBIFS filesystem", |
| 175 | "<addr> <filename> [bytes]\n" |
| 176 | " - load file 'filename' to address 'addr'" |
| 177 | ); |