All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Tools for controling ubiblk
@ 2011-08-24 16:43 ` David Wagner
  0 siblings, 0 replies; 6+ messages in thread
From: David Wagner @ 2011-08-24 16:43 UTC (permalink / raw)
  To: David Wagner, linux-mtd; +Cc: David Wagner, linux-embedded, Artem Bityutskiy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6881 bytes --]

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 <david.wagner@free-electrons.com>
---

	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 <linux sources>/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 <linux/types.h>
+
+/**
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <mtd/ubiblk-user.h>
+
+#define PROGRAM_NAME "ubiblk_ctrl"
+#include <common.h>
+
+#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
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] Tools for controling ubiblk
@ 2011-08-24 16:43 ` David Wagner
  0 siblings, 0 replies; 6+ messages in thread
From: David Wagner @ 2011-08-24 16:43 UTC (permalink / raw)
  To: David Wagner, linux-mtd; +Cc: Artem Bityutskiy, linux-embedded, David Wagner

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 <david.wagner@free-electrons.com>
---

	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 <linux sources>/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 <linux/types.h>
+
+/**
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <mtd/ubiblk-user.h>
+
+#define PROGRAM_NAME "ubiblk_ctrl"
+#include <common.h>
+
+#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
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Tools for controling ubiblk
  2011-08-17 14:20   ` David Wagner
@ 2011-08-22  8:17     ` Artem Bityutskiy
  -1 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2011-08-22  8:17 UTC (permalink / raw)
  To: David Wagner; +Cc: David Woodhouse, linux-mtd, Tim Bird, linux-embedded

I do not think LKML is interested in mtd-utils user-space project
patches, please, do not add lkml to spam it less.

On Wed, 2011-08-17 at 16:20 +0200, David Wagner wrote:
> +#ifndef __UBIBLK_USER_H__
> +#define __UBIBLK_USER_H__
> +
> +#include <linux/types.h>
> +
> +/* Structure to be passed to UBIBLK_IOCADD or IOCDEL ioctl */
> +struct ubiblk_ctrl_req {
> +	__s32 ubi_num;
> +	__s32 vol_id;
> +};
> +
> +/* 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

Please, do not copy kernel headers verbatim, copy the result of "make
headers_install" invoked in the kernel tree.

-- 
Best Regards,
Artem Bityutskiy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Tools for controling ubiblk
@ 2011-08-22  8:17     ` Artem Bityutskiy
  0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2011-08-22  8:17 UTC (permalink / raw)
  To: David Wagner; +Cc: linux-mtd, linux-embedded, Tim Bird, David Woodhouse

I do not think LKML is interested in mtd-utils user-space project
patches, please, do not add lkml to spam it less.

On Wed, 2011-08-17 at 16:20 +0200, David Wagner wrote:
> +#ifndef __UBIBLK_USER_H__
> +#define __UBIBLK_USER_H__
> +
> +#include <linux/types.h>
> +
> +/* Structure to be passed to UBIBLK_IOCADD or IOCDEL ioctl */
> +struct ubiblk_ctrl_req {
> +	__s32 ubi_num;
> +	__s32 vol_id;
> +};
> +
> +/* 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

Please, do not copy kernel headers verbatim, copy the result of "make
headers_install" invoked in the kernel tree.

-- 
Best Regards,
Artem Bityutskiy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Tools for controling ubiblk
  2011-08-17 13:17 [PATCHv3] UBI: new module ubiblk: block layer on top of UBI david.wagner
@ 2011-08-17 14:20   ` David Wagner
  0 siblings, 0 replies; 6+ messages in thread
From: David Wagner @ 2011-08-17 14:20 UTC (permalink / raw)
  To: linux-mtd
  Cc: Artem Bityutskiy, linux-embedded, lkml, Tim Bird,
	David Woodhouse, David Wagner

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5958 bytes --]

ubiblk_ctrl sends an appropriate ioctl to ubiblk control node.

ubiblkadd and ubiblkdel are wrappers 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 <david.wagner@free-electrons.com>
---

This is a preliminary version: it has the control device node hardcoded which is
probably not nice.

 Makefile                  |    6 ++-
 include/mtd/ubiblk-user.h |   43 ++++++++++++++++++++
 ubi-utils/ubiblk_ctrl.c   |   95 +++++++++++++++++++++++++++++++++++++++++++++
 ubi-utils/ubiblkadd       |    2 +
 ubi-utils/ubiblkdel       |    2 +
 5 files changed, 147 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 67e42ce..2859a8c 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..fa0d007
--- /dev/null
+++ b/include/mtd/ubiblk-user.h
@@ -0,0 +1,43 @@
+/*
+ * 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 <linux/types.h>
+
+/* Structure to be passed to UBIBLK_IOCADD or IOCDEL ioctl */
+struct ubiblk_ctrl_req {
+	__s32 ubi_num;
+	__s32 vol_id;
+};
+
+/* 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..1132f35
--- /dev/null
+++ b/ubi-utils/ubiblk_ctrl.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <mtd/ubiblk-user.h>
+
+#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 = -2, vol_id = -1;
+	int fd;
+	struct ubiblk_ctrl_req req;
+	int ret;
+	int command;
+
+	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 = atoi(optarg);
+			break;
+		case 'v':
+			vol_id = atoi(optarg);
+			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..fd8fbdd
--- /dev/null
+++ b/ubi-utils/ubiblkadd
@@ -0,0 +1,2 @@
+#! /bin/sh
+ubiblk_ctrl -a -u $0 -v $1
diff --git a/ubi-utils/ubiblkdel b/ubi-utils/ubiblkdel
new file mode 100755
index 0000000..40a1fd1
--- /dev/null
+++ b/ubi-utils/ubiblkdel
@@ -0,0 +1,2 @@
+#! /bin/sh
+ubiblk_ctrl -d -u $0 -v $1
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] Tools for controling ubiblk
@ 2011-08-17 14:20   ` David Wagner
  0 siblings, 0 replies; 6+ messages in thread
From: David Wagner @ 2011-08-17 14:20 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-embedded, Artem Bityutskiy, David Wagner, lkml, Tim Bird,
	David Woodhouse

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5957 bytes --]

ubiblk_ctrl sends an appropriate ioctl to ubiblk control node.

ubiblkadd and ubiblkdel are wrappers 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 <david.wagner@free-electrons.com>
---

This is a preliminary version: it has the control device node hardcoded which is
probably not nice.

 Makefile                  |    6 ++-
 include/mtd/ubiblk-user.h |   43 ++++++++++++++++++++
 ubi-utils/ubiblk_ctrl.c   |   95 +++++++++++++++++++++++++++++++++++++++++++++
 ubi-utils/ubiblkadd       |    2 +
 ubi-utils/ubiblkdel       |    2 +
 5 files changed, 147 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 67e42ce..2859a8c 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..fa0d007
--- /dev/null
+++ b/include/mtd/ubiblk-user.h
@@ -0,0 +1,43 @@
+/*
+ * 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 <linux/types.h>
+
+/* Structure to be passed to UBIBLK_IOCADD or IOCDEL ioctl */
+struct ubiblk_ctrl_req {
+	__s32 ubi_num;
+	__s32 vol_id;
+};
+
+/* 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..1132f35
--- /dev/null
+++ b/ubi-utils/ubiblk_ctrl.c
@@ -0,0 +1,95 @@
+/*
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <mtd/ubiblk-user.h>
+
+#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 = -2, vol_id = -1;
+	int fd;
+	struct ubiblk_ctrl_req req;
+	int ret;
+	int command;
+
+	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 = atoi(optarg);
+			break;
+		case 'v':
+			vol_id = atoi(optarg);
+			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..fd8fbdd
--- /dev/null
+++ b/ubi-utils/ubiblkadd
@@ -0,0 +1,2 @@
+#! /bin/sh
+ubiblk_ctrl -a -u $0 -v $1
diff --git a/ubi-utils/ubiblkdel b/ubi-utils/ubiblkdel
new file mode 100755
index 0000000..40a1fd1
--- /dev/null
+++ b/ubi-utils/ubiblkdel
@@ -0,0 +1,2 @@
+#! /bin/sh
+ubiblk_ctrl -d -u $0 -v $1
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-08-24 16:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-24 16:43 [PATCH] Tools for controling ubiblk David Wagner
2011-08-24 16:43 ` David Wagner
  -- strict thread matches above, loose matches on Subject: below --
2011-08-17 13:17 [PATCHv3] UBI: new module ubiblk: block layer on top of UBI david.wagner
2011-08-17 14:20 ` [PATCH] Tools for controling ubiblk David Wagner
2011-08-17 14:20   ` David Wagner
2011-08-22  8:17   ` Artem Bityutskiy
2011-08-22  8:17     ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.