summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorTeresa Remmet <t.remmet@phytec.de>2016-06-27 13:42:19 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-06-28 07:34:27 +0200
commitf5205bd0922c579959353a56e8e522d40377f74d (patch)
tree13d4183f4d13d9ba3b514645298f1ca5c1d88cd8 /commands
parentc087e0804f0290e9886899e8a3cccb07c4ce088b (diff)
downloadbarebox-f5205bd0922c579959353a56e8e522d40377f74d.tar.gz
barebox-f5205bd0922c579959353a56e8e522d40377f74d.tar.xz
commands: ubi: Add ubiupdatevol command
Add ubiupdatevol command. This is to update static and dynamic volumes. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/ubi.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/commands/ubi.c b/commands/ubi.c
index dc2b4b502d..65d2d256a8 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -7,10 +7,97 @@
#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;
+
+ if (size == FILESIZE_MAX) {
+ printf("%s has unknown filesize, this is not supported\n",
+ argv[optind + 1]);
+ return 1;
+ }
+
+ 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;