[U-Boot] [PATCH v2] fs: make it possible to read the filesystem UUID

2014-11-12 Thread Christian Gmeiner
Some filesystems have a UUID stored in its superblock. To
allow using root=UUID=... for the kernel command line we
need a way to read-out the filesystem UUID.

changes rfc - v1:
 - make the environment variable an option parameter. If not
   given, the UUID is printed out. If given, it is stored in the env
   variable.
 - corrected typos
 - return error codes

changes v1 - v2:
 - fix return code of do_fs_uuid(..)
 - document do_fs_uuid(..)
 - implement fs_uuid_unsuported(..) be more consistent with the
   way other optional functionality works

Hit any key to stop autoboot:  0
= fsuuid
fsuuid - Look up a filesystem UUID

Usage:
fsuuid interface dev:part
- print filesystem UUID
fsuuid interface dev:part varname
- set environment variable to filesystem UUID

= fsuuid mmc 0:1
d9f9fc05-45ae-4a36-a616-fccce0e4f887
= fsuuid mmc 0:2
eb3db83c-7b28-499f-95ce-9e0bb21cda81
= fsuuid mmc 0:1 uuid1
= fsuuid mmc 0:2 uuid2
= printenv uuid1
uuid1=d9f9fc05-45ae-4a36-a616-fccce0e4f887
= printenv uuid2
uuid2=eb3db83c-7b28-499f-95ce-9e0bb21cda81
=

Signed-off-by: Christian Gmeiner christian.gmei...@gmail.com
---
 README   |  1 +
 common/Makefile  |  1 +
 common/cmd_fs_uuid.c | 26 ++
 fs/ext4/ext4fs.c | 15 +++
 fs/fs.c  | 43 +++
 include/ext4fs.h |  1 +
 include/fs.h |  7 +++
 7 files changed, 94 insertions(+)
 create mode 100644 common/cmd_fs_uuid.c

diff --git a/README b/README
index 7b5538e..53b84a6 100644
--- a/README
+++ b/README
@@ -989,6 +989,7 @@ The following options need to be configured:
CONFIG_CMD_EXT4 * ext4 command support
CONFIG_CMD_FS_GENERIC   * filesystem commands (e.g. load, ls)
  that work for multiple fs types
+   CONFIG_CMD_FS_UUID  * Look up a filesystem UUID
CONFIG_CMD_SAVEENVsaveenv
CONFIG_CMD_FDC  * Floppy Disk Support
CONFIG_CMD_FAT  * FAT command support
diff --git a/common/Makefile b/common/Makefile
index 6cc4de8..508a0b2 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -188,6 +188,7 @@ obj-y += usb.o usb_hub.o
 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
 endif
 obj-$(CONFIG_CMD_FASTBOOT) += cmd_fastboot.o
+obj-$(CONFIG_CMD_FS_UUID) += cmd_fs_uuid.o
 
 obj-$(CONFIG_CMD_USB_MASS_STORAGE) += cmd_usb_mass_storage.o
 obj-$(CONFIG_CMD_THOR_DOWNLOAD) += cmd_thordown.o
diff --git a/common/cmd_fs_uuid.c b/common/cmd_fs_uuid.c
new file mode 100644
index 000..613f3a4
--- /dev/null
+++ b/common/cmd_fs_uuid.c
@@ -0,0 +1,26 @@
+/*
+ * cmd_fs_uuid.c -- fsuuid command
+ *
+ * Copyright (C) 2014, Bachmann electronic GmbH
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include common.h
+#include command.h
+#include fs.h
+
+static int do_fs_uuid_wrapper(cmd_tbl_t *cmdtp, int flag,
+   int argc, char * const argv[])
+{
+   return do_fs_uuid(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+   fsuuid, 4, 1, do_fs_uuid_wrapper,
+   Look up a filesystem UUID,
+   interface dev:part\n
+   - print filesystem UUID\n
+   fsuuid interface dev:part varname\n
+   - set environment variable to filesystem UUID\n
+);
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index cbdc220..19757d2 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -231,3 +231,18 @@ int ext4_read_file(const char *filename, void *buf, int 
offset, int len)
 
return len_read;
 }
+
+int ext4fs_uuid(char *uuid_str)
+{
+   if (ext4fs_root == NULL)
+   return -1;
+
+#ifdef CONFIG_LIB_UUID
+   uuid_bin_to_str((unsigned char *)ext4fs_root-sblock.unique_id,
+   uuid_str, UUID_STR_FORMAT_STD);
+
+   return 0;
+#endif
+
+   return -ENOSYS;
+}
diff --git a/fs/fs.c b/fs/fs.c
index dd680f3..e4ad6bc 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -15,6 +15,7 @@
  */
 
 #include config.h
+#include errno.h
 #include common.h
 #include part.h
 #include ext4fs.h
@@ -67,6 +68,11 @@ static inline void fs_close_unsupported(void)
 {
 }
 
+static inline int fs_uuid_unsupported(char *uuid_str)
+{
+   return -1;
+}
+
 struct fstype_info {
int fstype;
/*
@@ -86,6 +92,7 @@ struct fstype_info {
int (*read)(const char *filename, void *buf, int offset, int len);
int (*write)(const char *filename, void *buf, int offset, int len);
void (*close)(void);
+   int (*uuid)(char *uuid_str);
 };
 
 static struct fstype_info fstypes[] = {
@@ -100,6 +107,7 @@ static struct fstype_info fstypes[] = {
.size = fat_size,
.read = fat_read_file,
.write = fs_write_unsupported,
+   .uuid = fs_uuid_unsupported,
},
 #endif
 #ifdef CONFIG_FS_EXT4
@@ -113,6 +121,7 @@ static struct fstype_info fstypes[] = {
.size = ext4fs_size,
.read = ext4_read_file,
   

Re: [U-Boot] [PATCH v2] fs: make it possible to read the filesystem UUID

2014-11-12 Thread Simon Glass
On 12 November 2014 06:35, Christian Gmeiner
christian.gmei...@gmail.com wrote:
 Some filesystems have a UUID stored in its superblock. To
 allow using root=UUID=... for the kernel command line we
 need a way to read-out the filesystem UUID.

 changes rfc - v1:
  - make the environment variable an option parameter. If not
given, the UUID is printed out. If given, it is stored in the env
variable.
  - corrected typos
  - return error codes

 changes v1 - v2:
  - fix return code of do_fs_uuid(..)
  - document do_fs_uuid(..)
  - implement fs_uuid_unsuported(..) be more consistent with the
way other optional functionality works

 Hit any key to stop autoboot:  0
 = fsuuid
 fsuuid - Look up a filesystem UUID

 Usage:
 fsuuid interface dev:part
 - print filesystem UUID
 fsuuid interface dev:part varname
 - set environment variable to filesystem UUID

 = fsuuid mmc 0:1
 d9f9fc05-45ae-4a36-a616-fccce0e4f887
 = fsuuid mmc 0:2
 eb3db83c-7b28-499f-95ce-9e0bb21cda81
 = fsuuid mmc 0:1 uuid1
 = fsuuid mmc 0:2 uuid2
 = printenv uuid1
 uuid1=d9f9fc05-45ae-4a36-a616-fccce0e4f887
 = printenv uuid2
 uuid2=eb3db83c-7b28-499f-95ce-9e0bb21cda81
 =

 Signed-off-by: Christian Gmeiner christian.gmei...@gmail.com

Acked-by: Simon Glass s...@chromium.org

Tested on Pi with eMMC:
Tested-by: Simon Glass s...@chromium.org
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2] fs: make it possible to read the filesystem UUID

2014-11-11 Thread Christian Gmeiner
Some filesystems have a UUID stored in its superblock. To
allow using root=UUID=... for the kernel command line we
need a way to read-out the filesystem UUID.

changes rfc - v1:
 - make the environment variable an option parameter. If not
   given, the UUID is printed out. If given, it is stored in the env
   variable.
 - corrected typos
 - return error codes

changes v1 - v2:
 - fix return code of do_fs_uuid(..)
 - document do_fs_uuid(..)
 - implement fs_uuid_unsuported(..) be more consistent with the
   way other optional functionality works

Hit any key to stop autoboot:  0
= fsuuid
fsuuid - Look up a filesystem UUID

Usage:
fsuuid interface dev:part
- print filesystem UUID
fsuuid interface dev:part varname
- set environment variable to filesystem UUID

= fsuuid mmc 0:1
d9f9fc05-45ae-4a36-a616-fccce0e4f887
= fsuuid mmc 0:2
eb3db83c-7b28-499f-95ce-9e0bb21cda81
= fsuuid mmc 0:1 uuid1
= fsuuid mmc 0:2 uuid2
= printenv uuid1
uuid1=d9f9fc05-45ae-4a36-a616-fccce0e4f887
= printenv uuid2
uuid2=eb3db83c-7b28-499f-95ce-9e0bb21cda81
=

Signed-off-by: Christian Gmeiner christian.gmei...@gmail.com
---
 README   |  1 +
 common/Makefile  |  1 +
 common/cmd_fs_uuid.c | 26 ++
 fs/ext4/ext4fs.c | 15 +++
 fs/fs.c  | 43 +++
 include/ext4fs.h |  1 +
 include/fs.h |  7 +++
 7 files changed, 94 insertions(+)
 create mode 100644 common/cmd_fs_uuid.c

diff --git a/README b/README
index 7b5538e..53b84a6 100644
--- a/README
+++ b/README
@@ -989,6 +989,7 @@ The following options need to be configured:
CONFIG_CMD_EXT4 * ext4 command support
CONFIG_CMD_FS_GENERIC   * filesystem commands (e.g. load, ls)
  that work for multiple fs types
+   CONFIG_CMD_FS_UUID  * Look up a filesystem UUID
CONFIG_CMD_SAVEENVsaveenv
CONFIG_CMD_FDC  * Floppy Disk Support
CONFIG_CMD_FAT  * FAT command support
diff --git a/common/Makefile b/common/Makefile
index 6cc4de8..508a0b2 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -188,6 +188,7 @@ obj-y += usb.o usb_hub.o
 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
 endif
 obj-$(CONFIG_CMD_FASTBOOT) += cmd_fastboot.o
+obj-$(CONFIG_CMD_FS_UUID) += cmd_fs_uuid.o
 
 obj-$(CONFIG_CMD_USB_MASS_STORAGE) += cmd_usb_mass_storage.o
 obj-$(CONFIG_CMD_THOR_DOWNLOAD) += cmd_thordown.o
diff --git a/common/cmd_fs_uuid.c b/common/cmd_fs_uuid.c
new file mode 100644
index 000..613f3a4
--- /dev/null
+++ b/common/cmd_fs_uuid.c
@@ -0,0 +1,26 @@
+/*
+ * cmd_fs_uuid.c -- fsuuid command
+ *
+ * Copyright (C) 2014, Bachmann electronic GmbH
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include common.h
+#include command.h
+#include fs.h
+
+static int do_fs_uuid_wrapper(cmd_tbl_t *cmdtp, int flag,
+   int argc, char * const argv[])
+{
+   return do_fs_uuid(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+   fsuuid, 4, 1, do_fs_uuid_wrapper,
+   Look up a filesystem UUID,
+   interface dev:part\n
+   - print filesystem UUID\n
+   fsuuid interface dev:part varname\n
+   - set environment variable to filesystem UUID\n
+);
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index cbdc220..19757d2 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -231,3 +231,18 @@ int ext4_read_file(const char *filename, void *buf, int 
offset, int len)
 
return len_read;
 }
+
+int ext4fs_uuid(char *uuid_str)
+{
+   if (ext4fs_root == NULL)
+   return -1;
+
+#ifdef CONFIG_LIB_UUID
+   uuid_bin_to_str((unsigned char *)ext4fs_root-sblock.unique_id,
+   uuid_str, UUID_STR_FORMAT_STD);
+
+   return 0;
+#endif
+
+   return -ENOSYS;
+}
diff --git a/fs/fs.c b/fs/fs.c
index dd680f3..e4ad6bc 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -15,6 +15,7 @@
  */
 
 #include config.h
+#include errno.h
 #include common.h
 #include part.h
 #include ext4fs.h
@@ -67,6 +68,11 @@ static inline void fs_close_unsupported(void)
 {
 }
 
+static inline int fs_uuid_unsupported(char *uuid_str)
+{
+   return -1;
+}
+
 struct fstype_info {
int fstype;
/*
@@ -86,6 +92,7 @@ struct fstype_info {
int (*read)(const char *filename, void *buf, int offset, int len);
int (*write)(const char *filename, void *buf, int offset, int len);
void (*close)(void);
+   int (*uuid)(char *uuid_str);
 };
 
 static struct fstype_info fstypes[] = {
@@ -100,6 +107,7 @@ static struct fstype_info fstypes[] = {
.size = fat_size,
.read = fat_read_file,
.write = fs_write_unsupported,
+   .uuid = fs_uuid_unsupported,
},
 #endif
 #ifdef CONFIG_FS_EXT4
@@ -113,6 +121,7 @@ static struct fstype_info fstypes[] = {
.size = ext4fs_size,
.read = ext4_read_file,
   

Re: [U-Boot] [PATCH v2] fs: make it possible to read the filesystem UUID

2014-11-11 Thread Stephen Warren

On 11/11/2014 05:55 AM, Christian Gmeiner wrote:

Some filesystems have a UUID stored in its superblock. To
allow using root=UUID=... for the kernel command line we
need a way to read-out the filesystem UUID.


Just one more nit below, otherwise,

Acked-by: Stephen Warren swar...@nvidia.com

(feel free to add that the patch description for any repost)


diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c



+int ext4fs_uuid(char *uuid_str)
+{
+   if (ext4fs_root == NULL)
+   return -1;
+
+#ifdef CONFIG_LIB_UUID
+   uuid_bin_to_str((unsigned char *)ext4fs_root-sblock.unique_id,
+   uuid_str, UUID_STR_FORMAT_STD);
+
+   return 0;
+#endif
+
+   return -ENOSYS;
+}


If CONFIG_LIB_UUID is defined, doesn't that generate an unreachable code 
warning for the second return statement? I think you want a #if ... 
#else ... #endif to avoid that.

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot