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