]> git.ipfire.org Git - people/ms/u-boot.git/blame - cmd/ubifs.c
ARM: uniphier: disable CONFIG_ARCH_FIXUP_FDT_MEMORY
[people/ms/u-boot.git] / cmd / ubifs.c
CommitLineData
ce6d0c8d
SR
1/*
2 * (C) Copyright 2008
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
ce6d0c8d
SR
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>
ad15749b 18#include <ubifs_uboot.h>
cb9c09d4 19
ce6d0c8d
SR
20static int ubifs_initialized;
21static int ubifs_mounted;
22
0e350f81
JH
23static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
24 char * const argv[])
ce6d0c8d
SR
25{
26 char *vol_name;
27 int ret;
28
47e26b1b 29 if (argc != 2)
4c12eeb8 30 return CMD_RET_USAGE;
47e26b1b 31
ce6d0c8d
SR
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
ff94bc40 40 ret = uboot_ubifs_mount(vol_name);
ce6d0c8d
SR
41 if (ret)
42 return -1;
43
44 ubifs_mounted = 1;
45
46 return 0;
47}
48
2f15cfd1
SR
49int ubifs_is_mounted(void)
50{
51 return ubifs_mounted;
52}
53
54void cmd_ubifs_umount(void)
55{
ad15749b 56 uboot_ubifs_umount();
2f15cfd1
SR
57 ubifs_mounted = 0;
58 ubifs_initialized = 0;
59}
60
0e350f81
JH
61static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
62 char * const argv[])
cb9c09d4
SR
63{
64 if (argc != 1)
4c12eeb8 65 return CMD_RET_USAGE;
cb9c09d4
SR
66
67 if (ubifs_initialized == 0) {
68 printf("No UBIFS volume mounted!\n");
69 return -1;
70 }
71
2f15cfd1 72 cmd_ubifs_umount();
cb9c09d4
SR
73
74 return 0;
75}
76
0e350f81
JH
77static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
78 char * const argv[])
ce6d0c8d
SR
79{
80 char *filename = "/";
81 int ret;
82
83 if (!ubifs_mounted) {
9a2ea578 84 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
ce6d0c8d
SR
85 return -1;
86 }
87
88 if (argc == 2)
89 filename = argv[1];
90 debug("Using filename %s\n", filename);
91
92 ret = ubifs_ls(filename);
7cdebc32
TH
93 if (ret) {
94 printf("** File not found %s **\n", filename);
95 ret = CMD_RET_FAILURE;
96 }
ce6d0c8d
SR
97
98 return ret;
99}
100
0e350f81
JH
101static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
102 char * const argv[])
ce6d0c8d
SR
103{
104 char *filename;
2896b585 105 char *endp;
ce6d0c8d
SR
106 int ret;
107 u32 addr;
108 u32 size = 0;
109
110 if (!ubifs_mounted) {
111 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
112 return -1;
113 }
114
47e26b1b 115 if (argc < 3)
4c12eeb8 116 return CMD_RET_USAGE;
ce6d0c8d 117
2896b585 118 addr = simple_strtoul(argv[1], &endp, 16);
47e26b1b 119 if (endp == argv[1])
4c12eeb8 120 return CMD_RET_USAGE;
2896b585 121
ce6d0c8d
SR
122 filename = argv[2];
123
2896b585
SK
124 if (argc == 4) {
125 size = simple_strtoul(argv[3], &endp, 16);
47e26b1b 126 if (endp == argv[3])
4c12eeb8 127 return CMD_RET_USAGE;
2896b585 128 }
ce6d0c8d
SR
129 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
130
131 ret = ubifs_load(filename, addr, size);
7cdebc32
TH
132 if (ret) {
133 printf("** File not found %s **\n", filename);
134 ret = CMD_RET_FAILURE;
135 }
ce6d0c8d
SR
136
137 return ret;
138}
139
140U_BOOT_CMD(
141 ubifsmount, 2, 0, do_ubifs_mount,
852dbfdd 142 "mount UBIFS volume",
2896b585
SK
143 "<volume-name>\n"
144 " - mount 'volume-name' volume"
a89c33db 145);
ce6d0c8d 146
cb9c09d4
SR
147U_BOOT_CMD(
148 ubifsumount, 1, 0, do_ubifs_umount,
149 "unmount UBIFS volume",
150 " - unmount current volume"
151);
152
388a29d0
FM
153U_BOOT_CMD(
154 ubifsls, 2, 0, do_ubifs_ls,
a89c33db
WD
155 "list files in a directory",
156 "[directory]\n"
157 " - list files in a 'directory' (default '/')"
158);
ce6d0c8d 159
388a29d0
FM
160U_BOOT_CMD(
161 ubifsload, 4, 0, do_ubifs_load,
a89c33db
WD
162 "load file from an UBIFS filesystem",
163 "<addr> <filename> [bytes]\n"
164 " - load file 'filename' to address 'addr'"
165);