From patchwork Thu Sep 9 11:52:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayoub Zaki X-Patchwork-Id: 1526175 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=embexus.com header.i=@embexus.com header.a=rsa-sha256 header.s=20191106 header.b=UDYNZxie; dkim=pass (2048-bit key; unprotected) header.d=embexus.com header.i=@embexus.com header.a=rsa-sha256 header.s=rsa1 header.b=EX/eF4bu; dkim=pass header.d=embexus.com header.i=@embexus.com header.a=ed25519-sha256 header.s=ed1 header.b=8lkJBHl5; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H4y7g0h3Xz9sXV for ; Thu, 9 Sep 2021 21:53:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E99C1832DC; Thu, 9 Sep 2021 13:53:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=embexus.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=embexus.com header.i=@embexus.com header.b="UDYNZxie"; dkim=pass (2048-bit key; unprotected) header.d=embexus.com header.i=@embexus.com header.b="EX/eF4bu"; dkim=permerror (0-bit key) header.d=embexus.com header.i=@embexus.com header.b="8lkJBHl5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66EA882952; Thu, 9 Sep 2021 13:53:06 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mailrelay1-3.pub.mailoutpod1-cph3.one.com (mailrelay1-3.pub.mailoutpod1-cph3.one.com [46.30.212.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 15172832FD for ; Thu, 9 Sep 2021 13:53:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=embexus.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=ayoub.zaki@embexus.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embexus.com; s=20191106; h=message-id:date:subject:cc:to:from:from; bh=bS7GjtM7wNz17pywtErDnC7/Jt5ERzVDpdZE6Z2RZgY=; b=UDYNZxieZWaMeMAlb40oMEg+dEd/xNGFXv3t3qYe+6QNF+wGKU7boN4iDe1Xi2AKf+34TmcAjulti du1E3NACSVI0az+1+DAKiIg1FZ/XAMK9xQOU65ruqDRcm7f+uBWXpiinchhE/xkejsyheQTkt7wnbV 8YwiwmlLG3SNZIuuuiFg8ZoWIzU+5CDS3sZwxOtdp3XfQswPuigsGhZ0M+g8/hibpnlciIu54tMWKr fGLwTZMsVIAGOSEj2CW03YN/hcHedcWsrRTn7rNGRohbLpObjpkhv/Y+faIi7wrCSMt+SLLqyhCZsJ COUFsz7ZZIsELEq/a9LT0jjEXGipieQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embexus.com; s=rsa1; h=message-id:date:subject:cc:to:from:from; bh=bS7GjtM7wNz17pywtErDnC7/Jt5ERzVDpdZE6Z2RZgY=; b=EX/eF4bumwp+ZKteforwgFpw2zn+rWCXeiVGYZo//eLpF3O+5vDU95Lkwy6EKW/dUJCx9LQ4CmIxW 2yxeNOLatzI0iBOl9HChZvoO9/9JpM63p29qhuhZc6CoiUoa2dAA10OQLNgdP/gM6/GI4mumzKXqWR J4pWr91r0pVKeGvJ4M6LSth89kMRER3U682I0J+HZnFPAmXq6omv66UIKA9a3sbZ4EZtVbZkH9RHjD qEpWPfegWdrroxNF4/frhDLiJ4vrFwYbM5FAFqdJMiDLDM0/1yMKdCzFgdb9tXlznHYowtjOuDuA18 99ucyHxNTf84qesGY6hq1TfJwzJwY1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=embexus.com; s=ed1; h=message-id:date:subject:cc:to:from:from; bh=bS7GjtM7wNz17pywtErDnC7/Jt5ERzVDpdZE6Z2RZgY=; b=8lkJBHl5m/WdSyazQ9K2iquO4DG/aPwPwopZSxeFGgwJaxL8O1M8+JZVaGdf5tc97ZzLoojvZ9xTc sjD6YmDDw== X-HalOne-Cookie: c60129f8e24bd605e604a2308541f5d758e98ada X-HalOne-ID: 7a8ce8de-1164-11ec-b7cf-d0431ea8a283 Received: from xps.home (unknown [2a02:121e:74fa:0:1813:4393:4449:2137]) by mailrelay1.pub.mailoutpod1-cph3.one.com (Halon) with ESMTPSA id 7a8ce8de-1164-11ec-b7cf-d0431ea8a283; Thu, 09 Sep 2021 11:53:00 +0000 (UTC) From: Ayoub Zaki To: u-boot@lists.denx.de Cc: hs@denx.de, Ayoub Zaki Subject: [PATCH v2] cmd: ubi: add a command to swap volumes Date: Thu, 9 Sep 2021 13:52:57 +0200 Message-Id: <20210909115257.14147-1-ayoub.zaki@embexus.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This commit adds the command ubi swap to swap an ubi volumes. The format of the command is: ubi swap . To enable this command, the option CMD_UBI_SWAPVOL must be selected. --- cmd/Kconfig | 8 ++++++++ cmd/ubi.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index ffef3cc76c..ae0edc9cb1 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2381,6 +2381,14 @@ config CMD_UBI_RENAME Enable a "ubi" command to rename ubi volume: ubi rename +config CMD_UBI_SWAPVOL + bool "Enable swap volumes" + depends on CMD_UBI + default n + help + Enable a "ubi" command to swap ubi volumes: + ubi swap + config CMD_UBIFS tristate "Enable UBIFS - Unsorted block images filesystem commands" depends on CMD_UBI diff --git a/cmd/ubi.c b/cmd/ubi.c index fe8ac58bac..43cb3c26a2 100644 --- a/cmd/ubi.c +++ b/cmd/ubi.c @@ -289,6 +289,54 @@ static int ubi_rename_vol(char *oldname, char *newname) return ubi_rename_volumes(ubi, &list); } +static int ubi_swap_vol(char *volume_a, char *volume_b) +{ + struct ubi_volume *vol_a, *vol_b; + struct ubi_rename_entry a, b; + struct ubi_volume_desc desc_a, desc_b; + struct list_head list; + + vol_a = ubi_find_volume(volume_a); + if (!vol_a) { + printf("%s: volume %s doesn't exist\n", __func__, volume_a); + return ENODEV; + } + + vol_b = ubi_find_volume(volume_b); + if (!vol_b) { + printf("%s: volume %s doesn't exist\n", __func__, volume_a); + return ENODEV; + } + + printf("Swap UBI volumes: %s - %s\n", volume_a, volume_b); + + if (ubi->ro_mode) { + printf("%s: ubi device is in read-only mode\n", __func__); + return EROFS; + } + + a.new_name_len = strlen(volume_a); + strcpy(a.new_name, volume_a); + a.remove = 0; + desc_a.vol = vol_b; + desc_a.mode = 0; + a.desc = &desc_a; + + b.new_name_len = strlen(volume_b); + strcpy(b.new_name, volume_b); + b.remove = 0; + desc_b.vol = vol_a; + desc_b.mode = 0; + b.desc = &desc_b; + + INIT_LIST_HEAD(&a.list); + INIT_LIST_HEAD(&b.list); + INIT_LIST_HEAD(&list); + list_add(&a.list, &list); + list_add(&b.list, &list); + return ubi_rename_volumes(ubi, &list); +} + static int ubi_volume_continue_write(char *volume, void *buf, size_t size) { int err = 1; @@ -645,6 +693,9 @@ static int do_ubi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (IS_ENABLED(CONFIG_CMD_UBI_RENAME) && !strncmp(argv[1], "rename", 6)) return ubi_rename_vol(argv[2], argv[3]); + if (IS_ENABLED(CONFIG_CMD_UBI_SWAPVOL) && !strncmp(argv[1], "swap", 4)) + return ubi_swap_vol(argv[2], argv[3]); + if (strncmp(argv[1], "skipcheck", 9) == 0) { /* E.g., change skip_check flag */ if (argc == 4) { @@ -735,6 +786,9 @@ U_BOOT_CMD( " - Remove volume\n" #if IS_ENABLED(CONFIG_CMD_UBI_RENAME) "ubi rename oldname newname\n" +#endif +#if IS_ENABLED(CONFIG_CMD_UBI_SWAPVOL) + "ubi swap volume_a volume_b\n" #endif "ubi skipcheck volume on/off - Set or clear skip_check flag in volume header\n" "[Legends]\n"