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 | |
| 45 | int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 46 | { |
| 47 | char *vol_name; |
| 48 | int ret; |
| 49 | |
| 50 | vol_name = argv[1]; |
| 51 | debug("Using volume %s\n", vol_name); |
| 52 | |
| 53 | if (ubifs_initialized == 0) { |
| 54 | ubifs_init(); |
| 55 | ubifs_initialized = 1; |
| 56 | } |
| 57 | |
| 58 | ret = ubifs_mount(vol_name); |
| 59 | if (ret) |
| 60 | return -1; |
| 61 | |
| 62 | ubifs_mounted = 1; |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 68 | { |
| 69 | char *filename = "/"; |
| 70 | int ret; |
| 71 | |
| 72 | if (!ubifs_mounted) { |
| 73 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); |
| 74 | return -1; |
| 75 | } |
| 76 | |
| 77 | if (argc == 2) |
| 78 | filename = argv[1]; |
| 79 | debug("Using filename %s\n", filename); |
| 80 | |
| 81 | ret = ubifs_ls(filename); |
| 82 | if (ret) |
| 83 | printf("%s not found!\n", filename); |
| 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 89 | { |
| 90 | char *filename; |
| 91 | int ret; |
| 92 | u32 addr; |
| 93 | u32 size = 0; |
| 94 | |
| 95 | if (!ubifs_mounted) { |
| 96 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); |
| 97 | return -1; |
| 98 | } |
| 99 | |
| 100 | if (argc < 3) { |
| 101 | printf("Usage:\n%s\n", cmdtp->usage); |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | addr = simple_strtoul(argv[1], NULL, 16); |
| 106 | filename = argv[2]; |
| 107 | |
| 108 | if (argc == 4) |
| 109 | size = simple_strtoul(argv[3], NULL, 16); |
| 110 | debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size); |
| 111 | |
| 112 | ret = ubifs_load(filename, addr, size); |
| 113 | if (ret) |
| 114 | printf("%s not found!\n", filename); |
| 115 | |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | U_BOOT_CMD( |
| 120 | ubifsmount, 2, 0, do_ubifs_mount, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame^] | 121 | "mount UBIFS volume", |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 122 | "\n"); |
| 123 | |
| 124 | U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame^] | 125 | "list files in a directory", |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 126 | "[directory]\n" |
| 127 | " - list files in a 'directory' (default '/')\n"); |
| 128 | |
| 129 | U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load, |
Mike Frysinger | 27e1e62 | 2009-03-23 22:27:34 -0400 | [diff] [blame^] | 130 | "load file from an UBIFS filesystem", |
Stefan Roese | 5c72127 | 2009-03-19 15:35:50 +0100 | [diff] [blame] | 131 | "<addr> <filename> [bytes]\n" |
| 132 | " - load file 'filename' to address 'addr'\n"); |