From patchwork Wed Aug 24 16:43:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Wagner X-Patchwork-Id: 111385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1EF65B6F57 for ; Thu, 25 Aug 2011 02:41:14 +1000 (EST) Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QwGVX-00088F-JJ; Wed, 24 Aug 2011 16:40:51 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QwGVX-0003V2-3W; Wed, 24 Aug 2011 16:40:51 +0000 Received: from mail.free-electrons.com ([88.190.12.23]) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QwGVU-0003Uj-BK for linux-mtd@lists.infradead.org; Wed, 24 Aug 2011 16:40:49 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 3DE8F1DD; Wed, 24 Aug 2011 18:40:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.1 Received: from localhost.localdomain (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id C33D1138; Wed, 24 Aug 2011 18:40:39 +0200 (CEST) From: David Wagner To: David Wagner , linux-mtd Subject: [PATCH] Tools for controling ubiblk Date: Wed, 24 Aug 2011 18:43:59 +0200 Message-Id: <1314204239-7782-1-git-send-email-david.wagner@free-electrons.com> X-Mailer: git-send-email 1.7.0.4 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110824_124048_653958_89341FC2 X-CRM114-Status: GOOD ( 22.46 ) X-Spam-Score: -0.5 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: David Wagner , linux-embedded , Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org ubiblk_ctrl sends an appropriate ioctl to ubiblk control node. ubiblkadd and ubiblkdel are wrapper around ubiblk_ctrl. The syntax is: ubiblk{add,del} x y where x is the UBI device number and y the volume ID. Signed-off-by: David Wagner --- Hi This tool is intended to add and remove ubiblk devices on top of specified UBI volumes. ubiblk is a new module proposal (WIP) ; full description can be found at https://lkml.org/lkml/2011/8/24/244 changes since v1: ~~~~~~~~~~~~~~~~~ - update ubiblk-user.h from the latest version of ubiblk (PATCHv4) and copy it from /usr/include/mtd/ubi/ - more foolproof and correct stupid mistakes Regards, David. PS: I had troubles integrating it in buildroot: they use the 1.4.6 version or mtd-utils (latest to date of writing) but 1.4.6 doesn't contain the build system rework. However, the fix is trivial and when the next mtd-utils version gets released, that won't be a problem anymore. Makefile | 6 ++- include/mtd/ubiblk-user.h | 46 +++++++++++++++++++ ubi-utils/ubiblk_ctrl.c | 106 +++++++++++++++++++++++++++++++++++++++++++++ ubi-utils/ubiblkadd | 2 + ubi-utils/ubiblkdel | 2 + 5 files changed, 161 insertions(+), 1 deletions(-) create mode 100644 include/mtd/ubiblk-user.h create mode 100644 ubi-utils/ubiblk_ctrl.c create mode 100755 ubi-utils/ubiblkadd create mode 100755 ubi-utils/ubiblkdel diff --git a/Makefile b/Makefile index 5a0044b..e7856d2 100644 --- a/Makefile +++ b/Makefile @@ -27,12 +27,16 @@ MTD_BINS = \ sumtool #jffs2reader UBI_BINS = \ ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \ - ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol + ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol \ + ubiblk_ctrl +UBI_SCRIPTS = \ + ubiblkadd ubiblkdel BINS = $(MTD_BINS) BINS += mkfs.ubifs/mkfs.ubifs BINS += $(addprefix ubi-utils/,$(UBI_BINS)) SCRIPTS = flash_eraseall +SCRIPTS += $(addprefix ubi-utils/,$(UBI_SCRIPTS)) TARGETS = $(BINS) TARGETS += lib/libmtd.a diff --git a/include/mtd/ubiblk-user.h b/include/mtd/ubiblk-user.h new file mode 100644 index 0000000..229d2da --- /dev/null +++ b/include/mtd/ubiblk-user.h @@ -0,0 +1,46 @@ +/* + * Copyright © Free Electrons, 2011 + * Copyright © International Business Machines Corp., 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: David Wagner + * Some code taken from ubi-user.h + */ + +#ifndef __UBIBLK_USER_H__ +#define __UBIBLK_USER_H__ + +#include + +/** + * ubiblk_ctrl_req - additional ioctl data structure + * @ubi_num: UBI device number + * @vol_id: UBI volume identifier + */ +struct ubiblk_ctrl_req { + __s32 ubi_num; + __s32 vol_id; +} __packed; + +/* ioctl commands of the UBI control character device */ +#define UBIBLK_CTRL_IOC_MAGIC 'O' + +/* Create a ubiblk device from a UBI volume */ +#define UBIBLK_IOCADD _IOW(UBIBLK_CTRL_IOC_MAGIC, 0x10, struct ubiblk_ctrl_req) +/* Delete a ubiblk device */ +#define UBIBLK_IOCDEL _IOW(UBIBLK_CTRL_IOC_MAGIC, 0x11, struct ubiblk_ctrl_req) + +#endif diff --git a/ubi-utils/ubiblk_ctrl.c b/ubi-utils/ubiblk_ctrl.c new file mode 100644 index 0000000..7b309aa --- /dev/null +++ b/ubi-utils/ubiblk_ctrl.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) Free Electrons, 2011 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: David Wagner + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PROGRAM_NAME "ubiblk_ctrl" +#include + +#define CONTROL_NODE "/dev/ubiblk_ctrl" + +void usage(char *exec_path) +{ + fprintf(stderr, "%s <-a|-d> <-u UBI_DEVICE_NUMBER> <-v VOLUME_ID>\n", + basename(exec_path)); +} + +int main(int argc, char *argv[]) +{ + int ubi_num = -1, vol_id = -1; + int fd; + struct ubiblk_ctrl_req req; + int ret, err = 0; + int command = 0; + + int option; + + while ((option = getopt(argc, argv, "adu:v:")) != -1) { + switch (option) { + case 'a': + command = UBIBLK_IOCADD; + break; + case 'd': + command = UBIBLK_IOCDEL; + break; + case 'u': + ubi_num = simple_strtol(optarg, &err); + if (err) { + usage(argv[0]); + return EXIT_FAILURE; + } + break; + case 'v': + vol_id = simple_strtol(optarg, &err); + if (err) { + usage(argv[0]); + return EXIT_FAILURE; + } + break; + } + } + + if (command != UBIBLK_IOCDEL && command != UBIBLK_IOCADD) { + usage(argv[0]); + return EXIT_FAILURE; + } + if (vol_id == -1 || vol_id == -1) { + usage(argv[0]); + return EXIT_FAILURE; + } + + req.ubi_num = ubi_num; + req.vol_id = vol_id; + + fd = open(CONTROL_NODE, O_RDONLY); + if (fd == -1) { + fprintf(stderr, "Error while opening the control node: %s\n", + strerror(errno)); + return EXIT_FAILURE; + } + + ret = ioctl(fd, command, &req); + if (ret == -1) { + fprintf(stderr, "Error while ioctl: %s\n", strerror(errno)); + close(fd); + return EXIT_FAILURE; + } + close(fd); + return EXIT_SUCCESS; +} diff --git a/ubi-utils/ubiblkadd b/ubi-utils/ubiblkadd new file mode 100755 index 0000000..92f9992 --- /dev/null +++ b/ubi-utils/ubiblkadd @@ -0,0 +1,2 @@ +#! /bin/sh +ubiblk_ctrl -a -u $1 -v $2 diff --git a/ubi-utils/ubiblkdel b/ubi-utils/ubiblkdel new file mode 100755 index 0000000..4c7660d --- /dev/null +++ b/ubi-utils/ubiblkdel @@ -0,0 +1,2 @@ +#! /bin/sh +ubiblk_ctrl -d -u $1 -v $2