summaryrefslogtreecommitdiff
path: root/cmd/ubi.c
diff options
context:
space:
mode:
authorPhilippe Reynes <philippe.reynes@softathome.com>2020-03-23 19:20:47 +0100
committerHeiko Schocher <hs@denx.de>2020-04-20 06:34:56 +0200
commit83f7078b688528f1f5c117e404c056e048970012 (patch)
treeed5d6e05bc24e14bad7300fcc2389ab5ea4c7969 /cmd/ubi.c
parent8d5d3bcf3c53d798bd7f3fe7092e994593bcc41c (diff)
cmd: ubi: add a command to rename volume
This commit adds the command ubi rename to rename an ubi volume. The format of the command is: ubi rename <oldname> <newname>. To enable this command, the option CMD_UBI_RENAME must be selected. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd/ubi.c')
-rw-r--r--cmd/ubi.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/cmd/ubi.c b/cmd/ubi.c
index cecf251fdb..54d128dbc5 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -251,6 +251,39 @@ out_err:
return err;
}
+static int ubi_rename_vol(char *oldname, char *newname)
+{
+ struct ubi_volume *vol;
+ struct ubi_rename_entry rename;
+ struct ubi_volume_desc desc;
+ struct list_head list;
+
+ vol = ubi_find_volume(oldname);
+ if (!vol) {
+ printf("%s: volume %s doesn't exist\n", __func__, oldname);
+ return ENODEV;
+ }
+
+ printf("Rename UBI volume %s to %s\n", oldname, newname);
+
+ if (ubi->ro_mode) {
+ printf("%s: ubi device is in read-only mode\n", __func__);
+ return EROFS;
+ }
+
+ rename.new_name_len = strlen(newname);
+ strcpy(rename.new_name, newname);
+ rename.remove = 0;
+ desc.vol = vol;
+ desc.mode = 0;
+ rename.desc = &desc;
+ INIT_LIST_HEAD(&rename.list);
+ INIT_LIST_HEAD(&list);
+ list_add(&rename.list, &list);
+
+ return ubi_rename_volumes(ubi, &list);
+}
+
static int ubi_volume_continue_write(char *volume, void *buf, size_t size)
{
int err = 1;
@@ -604,6 +637,9 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
return ubi_remove_vol(argv[2]);
}
+ if (IS_ENABLED(CONFIG_CMD_UBI_RENAME) && !strncmp(argv[1], "rename", 6))
+ return ubi_rename_vol(argv[2], argv[3]);
+
if (strncmp(argv[1], "skipcheck", 9) == 0) {
/* E.g., change skip_check flag */
if (argc == 4) {
@@ -692,6 +728,9 @@ U_BOOT_CMD(
" - Read volume to address with size\n"
"ubi remove[vol] volume"
" - Remove volume\n"
+#if IS_ENABLED(CONFIG_CMD_UBI_RENAME)
+ "ubi rename oldname newname\n"
+#endif
"ubi skipcheck volume on/off - Set or clear skip_check flag in volume header\n"
"[Legends]\n"
" volume: character name\n"