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