Blame view

cmd/ubifs.c 2.89 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
2
3
4
  /*
   * (C) Copyright 2008
   * Stefan Roese, DENX Software Engineering, sr@denx.de.
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
5
6
7
8
9
10
11
12
13
14
15
16
   */
  
  
  /*
   * UBIFS command support
   */
  
  #undef DEBUG
  
  #include <common.h>
  #include <config.h>
  #include <command.h>
ad15749b6   Hans de Goede   ubifs: Modify ubi...
17
  #include <ubifs_uboot.h>
cb9c09d48   Stefan Roese   UBIFS: Add ubifsu...
18

ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
19
20
  static int ubifs_initialized;
  static int ubifs_mounted;
14dfc6482   Tien Fong Chee   cmd: ubifs: Facto...
21
  int cmd_ubifs_mount(char *vol_name)
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
22
  {
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
23
  	int ret;
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
24
25
26
27
28
29
30
  	debug("Using volume %s
  ", vol_name);
  
  	if (ubifs_initialized == 0) {
  		ubifs_init();
  		ubifs_initialized = 1;
  	}
ff94bc40a   Heiko Schocher   mtd, ubi, ubifs: ...
31
  	ret = uboot_ubifs_mount(vol_name);
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
32
33
34
35
  	if (ret)
  		return -1;
  
  	ubifs_mounted = 1;
14dfc6482   Tien Fong Chee   cmd: ubifs: Facto...
36
37
38
39
40
41
42
43
44
45
46
47
48
  	return ret;
  }
  static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
  				char * const argv[])
  {
  	char *vol_name;
  
  	if (argc != 2)
  		return CMD_RET_USAGE;
  
  	vol_name = argv[1];
  
  	return cmd_ubifs_mount(vol_name);
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
49
  }
2f15cfd18   Stefan Roese   UBI/UBIFS: Automa...
50
51
52
53
  int ubifs_is_mounted(void)
  {
  	return ubifs_mounted;
  }
10c204406   Tien Fong Chee   cmd: ubifs: Move ...
54
  int cmd_ubifs_umount(void)
2f15cfd18   Stefan Roese   UBI/UBIFS: Automa...
55
  {
10c204406   Tien Fong Chee   cmd: ubifs: Move ...
56
57
58
59
60
  	if (ubifs_initialized == 0) {
  		printf("No UBIFS volume mounted!
  ");
  		return -1;
  	}
ad15749b6   Hans de Goede   ubifs: Modify ubi...
61
  	uboot_ubifs_umount();
2f15cfd18   Stefan Roese   UBI/UBIFS: Automa...
62
63
  	ubifs_mounted = 0;
  	ubifs_initialized = 0;
10c204406   Tien Fong Chee   cmd: ubifs: Move ...
64
65
  
  	return 0;
2f15cfd18   Stefan Roese   UBI/UBIFS: Automa...
66
  }
0e350f81e   Jeroen Hofstee   common: commands:...
67
68
  static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
  				char * const argv[])
cb9c09d48   Stefan Roese   UBIFS: Add ubifsu...
69
70
  {
  	if (argc != 1)
4c12eeb8b   Simon Glass   Convert cmd_usage...
71
  		return CMD_RET_USAGE;
cb9c09d48   Stefan Roese   UBIFS: Add ubifsu...
72

10c204406   Tien Fong Chee   cmd: ubifs: Move ...
73
  	return cmd_ubifs_umount();
cb9c09d48   Stefan Roese   UBIFS: Add ubifsu...
74
  }
0e350f81e   Jeroen Hofstee   common: commands:...
75
76
  static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
  			char * const argv[])
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
77
78
79
80
81
  {
  	char *filename = "/";
  	int ret;
  
  	if (!ubifs_mounted) {
9a2ea578b   Stefan Roese   UBIFS: Change "ub...
82
83
  		printf("UBIFS not mounted, use ubifsmount to mount volume first!
  ");
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
84
85
86
87
88
89
90
91
92
  		return -1;
  	}
  
  	if (argc == 2)
  		filename = argv[1];
  	debug("Using filename %s
  ", filename);
  
  	ret = ubifs_ls(filename);
7cdebc328   Tim Harvey   cmd_ubifs: normal...
93
94
95
96
97
  	if (ret) {
  		printf("** File not found %s **
  ", filename);
  		ret = CMD_RET_FAILURE;
  	}
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
98
99
100
  
  	return ret;
  }
0e350f81e   Jeroen Hofstee   common: commands:...
101
102
  static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
  				char * const argv[])
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
103
104
  {
  	char *filename;
2896b5851   Simon Kagstrom   Command improveme...
105
  	char *endp;
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
106
107
108
109
110
111
112
113
114
  	int ret;
  	u32 addr;
  	u32 size = 0;
  
  	if (!ubifs_mounted) {
  		printf("UBIFS not mounted, use ubifs mount to mount volume first!
  ");
  		return -1;
  	}
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
115
  	if (argc < 3)
4c12eeb8b   Simon Glass   Convert cmd_usage...
116
  		return CMD_RET_USAGE;
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
117

2896b5851   Simon Kagstrom   Command improveme...
118
  	addr = simple_strtoul(argv[1], &endp, 16);
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
119
  	if (endp == argv[1])
4c12eeb8b   Simon Glass   Convert cmd_usage...
120
  		return CMD_RET_USAGE;
2896b5851   Simon Kagstrom   Command improveme...
121

ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
122
  	filename = argv[2];
2896b5851   Simon Kagstrom   Command improveme...
123
124
  	if (argc == 4) {
  		size = simple_strtoul(argv[3], &endp, 16);
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
125
  		if (endp == argv[3])
4c12eeb8b   Simon Glass   Convert cmd_usage...
126
  			return CMD_RET_USAGE;
2896b5851   Simon Kagstrom   Command improveme...
127
  	}
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
128
129
130
131
  	debug("Loading file '%s' to address 0x%08x (size %d)
  ", filename, addr, size);
  
  	ret = ubifs_load(filename, addr, size);
7cdebc328   Tim Harvey   cmd_ubifs: normal...
132
133
134
135
136
  	if (ret) {
  		printf("** File not found %s **
  ", filename);
  		ret = CMD_RET_FAILURE;
  	}
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
137
138
139
140
141
142
  
  	return ret;
  }
  
  U_BOOT_CMD(
  	ubifsmount, 2, 0, do_ubifs_mount,
852dbfdd5   Mike Frysinger   more command usag...
143
  	"mount UBIFS volume",
2896b5851   Simon Kagstrom   Command improveme...
144
145
146
  	"<volume-name>
  "
  	"    - mount 'volume-name' volume"
a89c33db9   Wolfgang Denk   General help mess...
147
  );
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
148

388a29d02   Frans Meulenbroeks   various cmd_* fil...
149
  U_BOOT_CMD(
cb9c09d48   Stefan Roese   UBIFS: Add ubifsu...
150
151
152
153
154
155
  	ubifsumount, 1, 0, do_ubifs_umount,
  	"unmount UBIFS volume",
  	"    - unmount current volume"
  );
  
  U_BOOT_CMD(
388a29d02   Frans Meulenbroeks   various cmd_* fil...
156
  	ubifsls, 2, 0, do_ubifs_ls,
a89c33db9   Wolfgang Denk   General help mess...
157
158
159
160
161
  	"list files in a directory",
  	"[directory]
  "
  	"    - list files in a 'directory' (default '/')"
  );
ce6d0c8de   Stefan Roese   UBIFS: Add UBIFS ...
162

388a29d02   Frans Meulenbroeks   various cmd_* fil...
163
164
  U_BOOT_CMD(
  	ubifsload, 4, 0, do_ubifs_load,
a89c33db9   Wolfgang Denk   General help mess...
165
166
167
168
169
  	"load file from an UBIFS filesystem",
  	"<addr> <filename> [bytes]
  "
  	"    - load file 'filename' to address 'addr'"
  );