Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi 2014-11-04 19:41 GMT+01:00 Simon Glass : > Hi Christian, > > On 3 November 2014 02:47, Christian Gmeiner > wrote: >> Hi Simon, > > [snip] > + + if (argc == 4) + setenv(argv[3], uuid); + else + printf("%s\n", uuid); + + return 0; +} diff --git a/include/ext4fs.h b/include/ext4fs.h index 6c419f3..19816de 100644 --- a/include/ext4fs.h +++ b/include/ext4fs.h @@ -137,6 +137,7 @@ void ext4fs_reinit_global(void); int ext4fs_ls(const char *dirname); int ext4fs_exists(const char *filename); int ext4fs_size(const char *filename); +int ext4fs_uuid(char *uuid_str); void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf); void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); diff --git a/include/fs.h b/include/fs.h index 06a45f2..41082b3 100644 --- a/include/fs.h +++ b/include/fs.h @@ -92,5 +92,7 @@ int file_exists(const char *dev_type, const char *dev_part, const char *file, int fstype); int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype); +int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype); >>> >>> Can you please add a function comment for this? >> >> Yes I will add one - directly here in the .h file? > > Yes I think so - this is where the API is > Great! Cheers -- Christian Gmeiner, MSc https://soundcloud.com/christian-gmeiner ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi 2014-11-04 7:31 GMT+01:00 Simon Glass : > Hi Christian, > > On 31 October 2014 09:08, 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. >> >> Hit any key to stop autoboot: 0 >> => fsuuid >> fsuuid - Look up a filesystem UUID >> >> Usage: >> fsuuid : >> - print filesystem UUID >> fsuuid : >> - 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 >> --- >> README | 1 + >> common/Makefile | 1 + >> fs/ext4/ext4fs.c | 15 +++ >> fs/fs.c | 39 +++ >> include/ext4fs.h | 1 + >> include/fs.h | 2 ++ >> 6 files changed, 59 insertions(+) >> >> 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/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c >> index cbdc220..61b6dc2 100644 >> --- a/fs/ext4/ext4fs.c >> +++ b/fs/ext4/ext4fs.c >> @@ -187,6 +187,21 @@ int ext4fs_size(const char *filename) >> return ext4fs_open(filename); >> } >> >> +int ext4fs_uuid(char *uuid_str) >> +{ >> + if (ext4fs_root == NULL) >> + return -1; > > One other tiny note - should that be -ENOENT or some other error perhaps? > I used the other functions as inspiration. I think that needs to be in a follow up commit as it affects more functions. greets -- Christian Gmeiner, MSc https://soundcloud.com/christian-gmeiner ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi 2014-11-03 22:00 GMT+01:00 Stephen Warren : > On 10/31/2014 09:08 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. >> >> Hit any key to stop autoboot: 0 >> => fsuuid >> fsuuid - Look up a filesystem UUID >> >> Usage: >> fsuuid : >> - print filesystem UUID >> fsuuid : >> - 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 >> => > > > Acked-by: Stephen Warren > > It'd be nice if you could implement fat_uuid() too, and plumb that in. That > could be a separate commit though I suppose. > > IIRC, the kernel accepts the format -MM where is the 32-bit > FAT disk ID (I don't recall the exact correct term) in 0-filled hex and MM > is the partition number in 0-filled decimal. > Lets see if I can find the motivation to look into fat :) >> diff --git a/fs/fs.c b/fs/fs.c > > >> +int fs_uuid(char *uuid_str) >> +{ >> + struct fstype_info *info = fs_get_info(fs_type); >> + int ret = -ENOSYS; >> + >> + if (info->uuid) >> + ret = info->uuid(uuid_str); >> + >> + return ret; >> +} > > > Actually, that might be better as: > > return info->uuid(uuid_str); > > To make that work, you'd need to implement a fs_uuid_unsuported() function > and fill it in for all the fs types in fstypes[]. That would be more > consistent with the way other optional functionality works in this file. I will do it that way - looks more consistent. greets -- Christian Gmeiner, MSc https://soundcloud.com/christian-gmeiner ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi Christian, On 3 November 2014 02:47, Christian Gmeiner wrote: > Hi Simon, [snip] >>> + >>> + if (argc == 4) >>> + setenv(argv[3], uuid); >>> + else >>> + printf("%s\n", uuid); >>> + >>> + return 0; >>> +} >>> diff --git a/include/ext4fs.h b/include/ext4fs.h >>> index 6c419f3..19816de 100644 >>> --- a/include/ext4fs.h >>> +++ b/include/ext4fs.h >>> @@ -137,6 +137,7 @@ void ext4fs_reinit_global(void); >>> int ext4fs_ls(const char *dirname); >>> int ext4fs_exists(const char *filename); >>> int ext4fs_size(const char *filename); >>> +int ext4fs_uuid(char *uuid_str); >>> void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node >>> *currroot); >>> int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char >>> *buf); >>> void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); >>> diff --git a/include/fs.h b/include/fs.h >>> index 06a45f2..41082b3 100644 >>> --- a/include/fs.h >>> +++ b/include/fs.h >>> @@ -92,5 +92,7 @@ int file_exists(const char *dev_type, const char >>> *dev_part, const char *file, >>> int fstype); >>> int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], >>> int fstype); >>> +int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], >>> + int fstype); >> >> Can you please add a function comment for this? > > Yes I will add one - directly here in the .h file? Yes I think so - this is where the API is Regards, Simon ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi Christian, On 31 October 2014 09:08, 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. > > Hit any key to stop autoboot: 0 > => fsuuid > fsuuid - Look up a filesystem UUID > > Usage: > fsuuid : > - print filesystem UUID > fsuuid : > - 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 > --- > README | 1 + > common/Makefile | 1 + > fs/ext4/ext4fs.c | 15 +++ > fs/fs.c | 39 +++ > include/ext4fs.h | 1 + > include/fs.h | 2 ++ > 6 files changed, 59 insertions(+) > > 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/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c > index cbdc220..61b6dc2 100644 > --- a/fs/ext4/ext4fs.c > +++ b/fs/ext4/ext4fs.c > @@ -187,6 +187,21 @@ int ext4fs_size(const char *filename) > return ext4fs_open(filename); > } > > +int ext4fs_uuid(char *uuid_str) > +{ > + if (ext4fs_root == NULL) > + return -1; One other tiny note - should that be -ENOENT or some other error perhaps? Anyway otherwise (with my other comments) this looks good to me. Regards, Simon ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
On 10/31/2014 09:08 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. Hit any key to stop autoboot: 0 => fsuuid fsuuid - Look up a filesystem UUID Usage: fsuuid : - print filesystem UUID fsuuid : - 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 => Acked-by: Stephen Warren It'd be nice if you could implement fat_uuid() too, and plumb that in. That could be a separate commit though I suppose. IIRC, the kernel accepts the format -MM where is the 32-bit FAT disk ID (I don't recall the exact correct term) in 0-filled hex and MM is the partition number in 0-filled decimal. diff --git a/fs/fs.c b/fs/fs.c +int fs_uuid(char *uuid_str) +{ + struct fstype_info *info = fs_get_info(fs_type); + int ret = -ENOSYS; + + if (info->uuid) + ret = info->uuid(uuid_str); + + return ret; +} Actually, that might be better as: return info->uuid(uuid_str); To make that work, you'd need to implement a fs_uuid_unsuported() function and fill it in for all the fs types in fstypes[]. That would be more consistent with the way other optional functionality works in this file. ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi Simon, 2014-11-01 16:13 GMT+01:00 Simon Glass : > Hi Christian, > > On 31 October 2014 09:08, 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. >> >> Hit any key to stop autoboot: 0 >> => fsuuid >> fsuuid - Look up a filesystem UUID >> >> Usage: >> fsuuid : >> - print filesystem UUID >> fsuuid : >> - 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 > > If this is version 2 you should have a change list. You can use patman > (tools/patman/patman) to automate this. Yes.. the first version was the RFC. I really need to look into patman. Normally I do these things per hand. > >> --- >> README | 1 + >> common/Makefile | 1 + >> fs/ext4/ext4fs.c | 15 +++ >> fs/fs.c | 39 +++ >> include/ext4fs.h | 1 + >> include/fs.h | 2 ++ >> 6 files changed, 59 insertions(+) >> >> 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/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c >> index cbdc220..61b6dc2 100644 >> --- a/fs/ext4/ext4fs.c >> +++ b/fs/ext4/ext4fs.c >> @@ -187,6 +187,21 @@ int ext4fs_size(const char *filename) >> return ext4fs_open(filename); >> } >> >> +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; >> +} >> + >> int ext4fs_read(char *buf, unsigned len) >> { >> if (ext4fs_root == NULL || ext4fs_file == NULL) >> diff --git a/fs/fs.c b/fs/fs.c >> index dd680f3..492d8b1 100644 >> --- a/fs/fs.c >> +++ b/fs/fs.c >> @@ -15,6 +15,7 @@ >> */ >> >> #include >> +#include >> #include >> #include >> #include >> @@ -86,6 +87,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[] = { >> @@ -113,6 +115,7 @@ static struct fstype_info fstypes[] = { >> .size = ext4fs_size, >> .read = ext4_read_file, >> .write = fs_write_unsupported, >> + .uuid = ext4fs_uuid, >> }, >> #endif >> #ifdef CONFIG_SANDBOX >> @@ -206,6 +209,17 @@ 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); >> + int ret = -ENOSYS; >> + >> + if (info->uuid) >> + ret = info->uuid(uuid_str); >> + >> + return ret; >> +} >> + >> int fs_ls(const char *dirname) >> { >> int ret; >> @@ -443,3 +457,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 ret; > > H
Re: [U-Boot] [PATCH] fs: make it possible to read the filesystem UUID
Hi Christian, On 31 October 2014 09:08, 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. > > Hit any key to stop autoboot: 0 > => fsuuid > fsuuid - Look up a filesystem UUID > > Usage: > fsuuid : > - print filesystem UUID > fsuuid : > - 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 If this is version 2 you should have a change list. You can use patman (tools/patman/patman) to automate this. > --- > README | 1 + > common/Makefile | 1 + > fs/ext4/ext4fs.c | 15 +++ > fs/fs.c | 39 +++ > include/ext4fs.h | 1 + > include/fs.h | 2 ++ > 6 files changed, 59 insertions(+) > > 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/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c > index cbdc220..61b6dc2 100644 > --- a/fs/ext4/ext4fs.c > +++ b/fs/ext4/ext4fs.c > @@ -187,6 +187,21 @@ int ext4fs_size(const char *filename) > return ext4fs_open(filename); > } > > +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; > +} > + > int ext4fs_read(char *buf, unsigned len) > { > if (ext4fs_root == NULL || ext4fs_file == NULL) > diff --git a/fs/fs.c b/fs/fs.c > index dd680f3..492d8b1 100644 > --- a/fs/fs.c > +++ b/fs/fs.c > @@ -15,6 +15,7 @@ > */ > > #include > +#include > #include > #include > #include > @@ -86,6 +87,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[] = { > @@ -113,6 +115,7 @@ static struct fstype_info fstypes[] = { > .size = ext4fs_size, > .read = ext4_read_file, > .write = fs_write_unsupported, > + .uuid = ext4fs_uuid, > }, > #endif > #ifdef CONFIG_SANDBOX > @@ -206,6 +209,17 @@ 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); > + int ret = -ENOSYS; > + > + if (info->uuid) > + ret = info->uuid(uuid_str); > + > + return ret; > +} > + > int fs_ls(const char *dirname) > { > int ret; > @@ -443,3 +457,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 ret; Here you should return CMD_RET_SUCCESS or CMD_RET_FAILURE. You should not return raw errors since they are not the same thing. > + > + if (argc == 4) > + setenv(argv[3], uuid); > + else > + printf("%s\n", uuid); > + > + return 0; > +} > diff --git a/include/ext4fs.h b/include/ext4fs.h >
[U-Boot] [PATCH] 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. Hit any key to stop autoboot: 0 => fsuuid fsuuid - Look up a filesystem UUID Usage: fsuuid : - print filesystem UUID fsuuid : - 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 --- README | 1 + common/Makefile | 1 + fs/ext4/ext4fs.c | 15 +++ fs/fs.c | 39 +++ include/ext4fs.h | 1 + include/fs.h | 2 ++ 6 files changed, 59 insertions(+) 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/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index cbdc220..61b6dc2 100644 --- a/fs/ext4/ext4fs.c +++ b/fs/ext4/ext4fs.c @@ -187,6 +187,21 @@ int ext4fs_size(const char *filename) return ext4fs_open(filename); } +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; +} + int ext4fs_read(char *buf, unsigned len) { if (ext4fs_root == NULL || ext4fs_file == NULL) diff --git a/fs/fs.c b/fs/fs.c index dd680f3..492d8b1 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -86,6 +87,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[] = { @@ -113,6 +115,7 @@ static struct fstype_info fstypes[] = { .size = ext4fs_size, .read = ext4_read_file, .write = fs_write_unsupported, + .uuid = ext4fs_uuid, }, #endif #ifdef CONFIG_SANDBOX @@ -206,6 +209,17 @@ 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); + int ret = -ENOSYS; + + if (info->uuid) + ret = info->uuid(uuid_str); + + return ret; +} + int fs_ls(const char *dirname) { int ret; @@ -443,3 +457,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 ret; + + if (argc == 4) + setenv(argv[3], uuid); + else + printf("%s\n", uuid); + + return 0; +} diff --git a/include/ext4fs.h b/include/ext4fs.h index 6c419f3..19816de 100644 --- a/include/ext4fs.h +++ b/include/ext4fs.h @@ -137,6 +137,7 @@ void ext4fs_reinit_global(void); int ext4fs_ls(const char *dirname); int ext4fs_exists(const char *filename); int ext4fs_size(const char *filename); +int ext4fs_uuid(char *uuid_str); void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot); int ext4fs_devread(lbaint_t sector, int byte_offset, int byte_len, char *buf); void ext4fs_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info); diff --git a/include/fs.h b/include/fs.h index 06a45f2..41082b3 100644 --- a/include/fs.h +++ b/include/