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 | |
| 36 | static int ubifs_initialized; |
| 37 | static int ubifs_mounted; |
| 38 | |
| 39 | /* Prototypes */ |
| 40 | int ubifs_init(void); |
| 41 | int ubifs_mount(char *vol_name); |
| 42 | int ubifs_ls(char *dir_name); |
| 43 | int ubifs_load(char *filename, u32 addr, u32 size); |
| 44 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame^] | 45 | 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] | 46 | { |
| 47 | char *vol_name; |
| 48 | int ret; |
| 49 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 50 | if (argc != 2) { |
| 51 | cmd_usage(cmdtp); |
| 52 | return 1; |
| 53 | } |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 54 | vol_name = argv[1]; |
| 55 | debug("Using volume %s\n", vol_name); |
| 56 | |
| 57 | if (ubifs_initialized == 0) { |
| 58 | ubifs_init(); |
| 59 | ubifs_initialized = 1; |
| 60 | } |
| 61 | |
| 62 | ret = ubifs_mount(vol_name); |
| 63 | if (ret) |
| 64 | return -1; |
| 65 | |
| 66 | ubifs_mounted = 1; |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame^] | 71 | 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] | 72 | { |
| 73 | char *filename = "/"; |
| 74 | int ret; |
| 75 | |
| 76 | if (!ubifs_mounted) { |
| 77 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | if (argc == 2) |
| 82 | filename = argv[1]; |
| 83 | debug("Using filename %s\n", filename); |
| 84 | |
| 85 | ret = ubifs_ls(filename); |
| 86 | if (ret) |
| 87 | printf("%s not found!\n", filename); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame^] | 92 | 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] | 93 | { |
| 94 | char *filename; |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 95 | char *endp; |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 96 | int ret; |
| 97 | u32 addr; |
| 98 | u32 size = 0; |
| 99 | |
| 100 | if (!ubifs_mounted) { |
| 101 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | if (argc < 3) { |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 106 | cmd_usage(cmdtp); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 107 | return -1; |
| 108 | } |
| 109 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 110 | addr = simple_strtoul(argv[1], &endp, 16); |
| 111 | if (endp == argv[1]) { |
| 112 | cmd_usage(cmdtp); |
| 113 | return 1; |
| 114 | } |
| 115 | |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 116 | filename = argv[2]; |
| 117 | |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 118 | if (argc == 4) { |
| 119 | size = simple_strtoul(argv[3], &endp, 16); |
| 120 | if (endp == argv[3]) { |
| 121 | cmd_usage(cmdtp); |
| 122 | return 1; |
| 123 | } |
| 124 | } |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 125 | debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size); |
| 126 | |
| 127 | ret = ubifs_load(filename, addr, size); |
| 128 | if (ret) |
| 129 | printf("%s not found!\n", filename); |
| 130 | |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | U_BOOT_CMD( |
| 135 | ubifsmount, 2, 0, do_ubifs_mount, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame] | 136 | "mount UBIFS volume", |
Simon Kagstrom | 9dae38a | 2009-07-07 16:01:02 +0200 | [diff] [blame] | 137 | "<volume-name>\n" |
| 138 | " - mount 'volume-name' volume" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 139 | ); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 140 | |
| 141 | U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 142 | "list files in a directory", |
| 143 | "[directory]\n" |
| 144 | " - list files in a 'directory' (default '/')" |
| 145 | ); |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 146 | |
| 147 | U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load, |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 148 | "load file from an UBIFS filesystem", |
| 149 | "<addr> <filename> [bytes]\n" |
| 150 | " - load file 'filename' to address 'addr'" |
| 151 | ); |