mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Teresa Remmet <t.remmet@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 3/4] commands: ubi: Add ubiupdatevol command
Date: Mon, 27 Jun 2016 13:42:19 +0200	[thread overview]
Message-ID: <1467027740-24201-3-git-send-email-t.remmet@phytec.de> (raw)
In-Reply-To: <1467027740-24201-1-git-send-email-t.remmet@phytec.de>

Add ubiupdatevol command. This is to update static
and dynamic volumes.

Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
---
Changes in v2:
	- instead of using read_file, used a smaller
		buffer and read/write in a loop

 commands/ubi.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/commands/ubi.c b/commands/ubi.c
index dc2b4b5..b8b3f38 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -7,10 +7,91 @@
 #include <getopt.h>
 #include <linux/mtd/mtd.h>
 #include <linux/kernel.h>
+#include <linux/stat.h>
 #include <linux/mtd/mtd-abi.h>
 #include <mtd/ubi-user.h>
 #include <mtd/ubi-media.h>
 
+static int do_ubiupdatevol(int argc, char *argv[])
+{
+	int fd_img, fd_vol, ret = 0;
+	uint64_t size = 0;
+	struct stat st;
+	unsigned int count;
+	void *buf;
+
+	if (argc - optind < 2)
+		return COMMAND_ERROR_USAGE;
+
+	if (stat(argv[optind+1], &st)) {
+		perror("stat image");
+		return 1;
+	}
+
+	size = st.st_size;
+
+	fd_img  = open(argv[optind+1], O_RDONLY);
+	if (fd_img < 0) {
+		perror("open image");
+		return 1;
+	}
+
+	fd_vol = open(argv[optind], O_WRONLY);
+	if (fd_vol < 0) {
+		perror("open volume");
+		ret = 1;
+		goto error_img;
+	}
+
+	ret = ioctl(fd_vol, UBI_IOCVOLUP, &size);
+	if (ret) {
+		printf("failed to start update: %s\n", strerror(-ret));
+		goto error;
+	}
+
+	buf = xmalloc(RW_BUF_SIZE);
+
+	while (size) {
+
+		count = read(fd_img, buf, RW_BUF_SIZE);
+		if (count < 0) {
+			perror("read");
+			ret = 1;
+			break;
+		}
+
+		ret = write(fd_vol, buf, count);
+		if (ret < 0) {
+			perror("write");
+			break;
+		}
+
+		size -= count;
+	}
+
+	free(buf);
+
+error:
+	close(fd_vol);
+error_img:
+	close(fd_img);
+	return ret;
+}
+
+
+BAREBOX_CMD_HELP_START(ubiupdatevol)
+BAREBOX_CMD_HELP_TEXT("Update UBI volume with an image.")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ubiupdatevol)
+	.cmd		= do_ubiupdatevol,
+	BAREBOX_CMD_DESC("Update an UBI volume")
+	BAREBOX_CMD_OPTS("UBIVOL IMAGE")
+	BAREBOX_CMD_GROUP(CMD_GRP_PART)
+	BAREBOX_CMD_HELP(cmd_ubiupdatevol_help)
+BAREBOX_CMD_END
+
+
 static int do_ubimkvol(int argc, char *argv[])
 {
 	int opt;
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-06-27 11:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-27 11:42 [PATCH v2 1/4] commands: ubimkvol: Add option for static volumes Teresa Remmet
2016-06-27 11:42 ` [PATCH v2 2/4] mtd: UBI: Add support for updating " Teresa Remmet
2016-06-27 11:42 ` Teresa Remmet [this message]
2016-06-28  5:45   ` [PATCH v2 3/4] commands: ubi: Add ubiupdatevol command Sascha Hauer
2016-06-28 11:17     ` Teresa Remmet
2016-06-27 11:42 ` [PATCH v2 4/4] ARM: am335x_defconfig: Enable ubi fastmap and ubifs Teresa Remmet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467027740-24201-3-git-send-email-t.remmet@phytec.de \
    --to=t.remmet@phytec.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox