mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/1] commands/ubi.c: Add support for VID header offset in ubiattach
@ 2013-02-08 20:01 Xavier Douville
  2013-02-11  9:19 ` Sascha Hauer
  0 siblings, 1 reply; 12+ messages in thread
From: Xavier Douville @ 2013-02-08 20:01 UTC (permalink / raw)
  To: barebox

Hi

On my board I needed to pass a custom VID header offset to ubiattach.
This patch adds the required option to the barebox command.

I also fixed a bug in the error handling of the return value of 
ubi_attach_mtd_dev().
This function doesn't always return 0 on success, it returns the UBI number.
So without this patch, an error message is printed when attaching many 
UBI devices.

thanks for your work

Xavier Douville


  commands/ubi.c |   25 +++++++++++++++++--------
  1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/commands/ubi.c b/commands/ubi.c
index 1653eaa..a10ea1c 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -60,9 +60,14 @@ static int do_ubiattach(int argc, char *argv[])
  {
      struct mtd_info_user user;
      int fd, ret;
+    int vid_hdr_offset = 0;

-    if (argc != 2)
-        return COMMAND_ERROR_USAGE;
+    if (argc != 2) {
+        if (argc == 3)
+            vid_hdr_offset = simple_strtol(argv[2], NULL, 0);
+        else
+            return COMMAND_ERROR_USAGE;
+    }

      fd = open(argv[1], O_RDWR);
      if (fd < 0) {
@@ -71,19 +76,23 @@ static int do_ubiattach(int argc, char *argv[])
      }

      ret = ioctl(fd, MEMGETINFO, &user);
-    if (!ret)
-        ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+    if (!ret) {
+        ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 
vid_hdr_offset);
+        if (ret >= 0) {
+            close(fd);
+            return 0;
+        }
+    }

-    if (ret)
-        printf("failed to attach: %s\n", strerror(-ret));
+    printf("failed to attach: %s\n", strerror(ret));

      close(fd);

-    return ret ? 1 : 0;
+    return 1;
  }

  static const __maybe_unused char cmd_ubiattach_help[] =
-"Usage: ubiattach <mtddev>\n"
+"Usage: ubiattach <mtddev> [vid_hdr_offset]\n"
  "Attach <mtddev> to ubi\n";

  BAREBOX_CMD_START(ubiattach)


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

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

end of thread, other threads:[~2013-02-15 16:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-08 20:01 [PATCH 1/1] commands/ubi.c: Add support for VID header offset in ubiattach Xavier Douville
2013-02-11  9:19 ` Sascha Hauer
2013-02-11 15:14   ` Xavier Douville
2013-02-11 15:21     ` Sascha Hauer
2013-02-14 16:23       ` Jan Lübbe
2013-02-15 15:54         ` Xavier Douville
2013-02-15 16:06           ` Jan Lübbe
2013-02-15 16:58             ` Xavier Douville
2013-02-12 22:49     ` Marc Kleine-Budde
2013-02-12 22:52       ` Jean-Christophe PLAGNIOL-VILLARD
2013-02-13  9:00         ` Marc Kleine-Budde
2013-02-12 15:31   ` [PATCH] Do not print error message when successfully attaching more than one UBI device Xavier Douville

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox