diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2014-11-12 14:35:04 +0100 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-11-23 06:49:01 -0500 |
commit | 59e890ef7bf5b80d96802e115255f969491ef645 (patch) | |
tree | 570d6ef6e5a64a25e3a71eaf67273f8e0b8aa013 /fs | |
parent | 1b51d32c0f0ac7cdcab0ae04d531129a020cc903 (diff) | |
download | u-boot-imx-59e890ef7bf5b80d96802e115255f969491ef645.zip u-boot-imx-59e890ef7bf5b80d96802e115255f969491ef645.tar.gz u-boot-imx-59e890ef7bf5b80d96802e115255f969491ef645.tar.bz2 |
fs: make it possible to read the filesystem UUID
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
changes v2 -> v3:
- change ext4fs_uuid(..) to make use of #if .. #else .. #endif
construct to get rid of unreachable code
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.gmeiner@gmail.com>
Acked-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/ext4fs.c | 15 | ||||
-rw-r--r-- | fs/fs.c | 43 |
2 files changed, 58 insertions, 0 deletions
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index cbdc220..87d5128 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; +#else + return -ENOSYS; +#endif +} @@ -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, .write = fs_write_unsupported, + .uuid = ext4fs_uuid, }, #endif #ifdef CONFIG_SANDBOX @@ -126,6 +135,7 @@ static struct fstype_info fstypes[] = { .size = sandbox_fs_size, .read = fs_read_sandbox, .write = fs_write_sandbox, + .uuid = fs_uuid_unsupported, }, #endif { @@ -138,6 +148,7 @@ static struct fstype_info fstypes[] = { .size = fs_size_unsupported, .read = fs_read_unsupported, .write = fs_write_unsupported, + .uuid = fs_uuid_unsupported, }, }; @@ -206,6 +217,13 @@ static void fs_close(void) fs_type = FS_TYPE_ANY; } +int fs_uuid(char *uuid_str) +{ + struct fstype_info *info = fs_get_info(fs_type); + + return info->uuid(uuid_str); +} + int fs_ls(const char *dirname) { int ret; @@ -443,3 +461,28 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], return 0; } + +int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype) +{ + int ret; + char uuid[37]; + memset(uuid, 0, sizeof(uuid)); + + if (argc < 3 || argc > 4) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + ret = fs_uuid(uuid); + if (ret) + return CMD_RET_FAILURE; + + if (argc == 4) + setenv(argv[3], uuid); + else + printf("%s\n", uuid); + + return CMD_RET_SUCCESS; +} |