Re: [U-Boot] [PATCH v4 5/6] cmd:gpt: randomly generate each partition uuid if undefined
On 03/26/2014 07:36 PM, Stephen Warren wrote: On 03/26/2014 06:01 AM, Przemyslaw Marczak wrote: On 03/25/2014 08:51 PM, Stephen Warren wrote: On 03/19/2014 11:58 AM, Przemyslaw Marczak wrote: Changes: - randomly generate partition uuid if any is undefined and CONFIG_RAND_UUID is defined - print debug info about set/unset/generated uuid - update doc/README.gpt Update existing code to the new library functions. diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c -if ((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}')) { -s = strdup(str); -if (s == NULL) -return -1; -memset(s + strlen(s) - 1, '\0', 1); -memmove(s, s + 2, strlen(s) - 1); +if (!((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}'))) +return -1; Since you're inverting that test, you need to change to || too. No, because the invertion refers to the result of if - not one of conditions. !(cond1 cond2) is the same as: (!cond1 || !cond2) so this change is ok. Ah yes, right. diff --git a/doc/README.gpt b/doc/README.gpt index 5c133f3..51515c8 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -101,7 +101,7 @@ Offset SizeDescription 40 8 B First usable LBA for partitions (primary partition table last LBA + 1) 48 8 B Last usable LBA (secondary partition table first LBA - 1) -56 16 BDisk GUID (also referred as UUID on UNIXes) +56 16 BDisk GUID (also referred as UUID on UNIXes) in big endian According to your earlier comment, GUIDs have a mix of LE and BE fields, so I would simply drop this change and the similar change below. Let wikipedia or the comment you added near to top of lib/uuid.c specify the details. Actually I think that this is an important info here. The information about endianness is also placed in few places in lib/uuid.c Why isn't the endianness of all the fields in this structure defined in this comment then? Right notice, I will add there more info. Thanks -- Przemyslaw Marczak Samsung RD Institute Poland Samsung Electronics p.marc...@samsung.com ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v4 5/6] cmd:gpt: randomly generate each partition uuid if undefined
Hello Stephen, On 03/25/2014 08:51 PM, Stephen Warren wrote: On 03/19/2014 11:58 AM, Przemyslaw Marczak wrote: Changes: - randomly generate partition uuid if any is undefined and CONFIG_RAND_UUID is defined - print debug info about set/unset/generated uuid - update doc/README.gpt Update existing code to the new library functions. The changelog should be below the --- line, and a patch description should exist. This is the patch description:) and there is also change log below ---, but okay I can make some edits. Assuming the comments below are fixed, Acked-by: Stephen Warren swar...@nvidia.com diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c -static char extract_env(const char *str, char **env) +static int extract_env(const char *str, char **env) { + int ret = -1; char *e, *s; - +#ifdef CONFIG_RANDOM_UUID + char uuid_str[UUID_STR_LEN + 1]; +#endif if (!str || strlen(str) 4) The blank line needs to be after the #endif not before the #ifdef, so the variable declarations are separate from the code. Ok. return -1; - if ((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}')) { - s = strdup(str); - if (s == NULL) - return -1; - memset(s + strlen(s) - 1, '\0', 1); - memmove(s, s + 2, strlen(s) - 1); + if (!((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}'))) + return -1; Since you're inverting that test, you need to change to || too. No, because the invertion refers to the result of if - not one of conditions. !(cond1 cond2) is the same as: (!cond1 || !cond2) so this change is ok. diff --git a/doc/README.gpt b/doc/README.gpt index 5c133f3..51515c8 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -101,7 +101,7 @@ Offset SizeDescription 40 8 B First usable LBA for partitions (primary partition table last LBA + 1) 48 8 B Last usable LBA (secondary partition table first LBA - 1) -56 16 BDisk GUID (also referred as UUID on UNIXes) +56 16 BDisk GUID (also referred as UUID on UNIXes) in big endian According to your earlier comment, GUIDs have a mix of LE and BE fields, so I would simply drop this change and the similar change below. Let wikipedia or the comment you added near to top of lib/uuid.c specify the details. Actually I think that this is an important info here. The information about endianness is also placed in few places in lib/uuid.c @@ -160,6 +160,9 @@ To restore GUID partition table one needs to: Fields 'name', 'size' and 'uuid' are mandatory for every partition. The field 'start' is optional. + option: CONFIG_RANDOM_UUID + If any partition uuid no exists then it is randomly generated. s/uuid/UUID/ Ok. Thanks -- Przemyslaw Marczak Samsung RD Institute Poland Samsung Electronics p.marc...@samsung.com ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v4 5/6] cmd:gpt: randomly generate each partition uuid if undefined
On 03/26/2014 06:01 AM, Przemyslaw Marczak wrote: On 03/25/2014 08:51 PM, Stephen Warren wrote: On 03/19/2014 11:58 AM, Przemyslaw Marczak wrote: Changes: - randomly generate partition uuid if any is undefined and CONFIG_RAND_UUID is defined - print debug info about set/unset/generated uuid - update doc/README.gpt Update existing code to the new library functions. diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c -if ((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}')) { -s = strdup(str); -if (s == NULL) -return -1; -memset(s + strlen(s) - 1, '\0', 1); -memmove(s, s + 2, strlen(s) - 1); +if (!((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}'))) +return -1; Since you're inverting that test, you need to change to || too. No, because the invertion refers to the result of if - not one of conditions. !(cond1 cond2) is the same as: (!cond1 || !cond2) so this change is ok. Ah yes, right. diff --git a/doc/README.gpt b/doc/README.gpt index 5c133f3..51515c8 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -101,7 +101,7 @@ Offset SizeDescription 40 8 B First usable LBA for partitions (primary partition table last LBA + 1) 48 8 B Last usable LBA (secondary partition table first LBA - 1) -56 16 BDisk GUID (also referred as UUID on UNIXes) +56 16 BDisk GUID (also referred as UUID on UNIXes) in big endian According to your earlier comment, GUIDs have a mix of LE and BE fields, so I would simply drop this change and the similar change below. Let wikipedia or the comment you added near to top of lib/uuid.c specify the details. Actually I think that this is an important info here. The information about endianness is also placed in few places in lib/uuid.c Why isn't the endianness of all the fields in this structure defined in this comment then? ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v4 5/6] cmd:gpt: randomly generate each partition uuid if undefined
On 03/19/2014 11:58 AM, Przemyslaw Marczak wrote: Changes: - randomly generate partition uuid if any is undefined and CONFIG_RAND_UUID is defined - print debug info about set/unset/generated uuid - update doc/README.gpt Update existing code to the new library functions. The changelog should be below the --- line, and a patch description should exist. Assuming the comments below are fixed, Acked-by: Stephen Warren swar...@nvidia.com diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c -static char extract_env(const char *str, char **env) +static int extract_env(const char *str, char **env) { + int ret = -1; char *e, *s; - +#ifdef CONFIG_RANDOM_UUID + char uuid_str[UUID_STR_LEN + 1]; +#endif if (!str || strlen(str) 4) The blank line needs to be after the #endif not before the #ifdef, so the variable declarations are separate from the code. return -1; - if ((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}')) { - s = strdup(str); - if (s == NULL) - return -1; - memset(s + strlen(s) - 1, '\0', 1); - memmove(s, s + 2, strlen(s) - 1); + if (!((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}'))) + return -1; Since you're inverting that test, you need to change to || too. diff --git a/doc/README.gpt b/doc/README.gpt index 5c133f3..51515c8 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -101,7 +101,7 @@ Offset SizeDescription 40 8 B First usable LBA for partitions (primary partition table last LBA + 1) 48 8 B Last usable LBA (secondary partition table first LBA - 1) -56 16 BDisk GUID (also referred as UUID on UNIXes) +56 16 BDisk GUID (also referred as UUID on UNIXes) in big endian According to your earlier comment, GUIDs have a mix of LE and BE fields, so I would simply drop this change and the similar change below. Let wikipedia or the comment you added near to top of lib/uuid.c specify the details. @@ -160,6 +160,9 @@ To restore GUID partition table one needs to: Fields 'name', 'size' and 'uuid' are mandatory for every partition. The field 'start' is optional. + option: CONFIG_RANDOM_UUID + If any partition uuid no exists then it is randomly generated. s/uuid/UUID/ ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
[U-Boot] [PATCH v4 5/6] cmd:gpt: randomly generate each partition uuid if undefined
Changes: - randomly generate partition uuid if any is undefined and CONFIG_RAND_UUID is defined - print debug info about set/unset/generated uuid - update doc/README.gpt Signed-off-by: Przemyslaw Marczak p.marc...@samsung.com Acked-by: Lukasz Majewski l.majew...@samsung.com Cc: Piotr Wilczek p.wilc...@samsung.com Cc: Tom Rini tr...@ti.com Cc: Stephen Warren swar...@nvidia.com Cc: Lukasz Majewski l.majew...@samsung.com --- Changes v2: - cmd_gpt: extract_env: change return type from char to int - add tmp array to generate uuid string - store generated uuid in env and next get it from it - don't need to alloc and maintain allcoated memory outside extract_env() Changes v3: - print info if uuid_gpt_* env is get from env/set random - change some word in README.gpt to meaningful Changes v4: - change printf/puts to debug - reduce indentation level in extract_env() - generate rand uuid if CONFIG_RAND_UUID is defined --- common/cmd_gpt.c | 62 +--- doc/README.gpt | 24 -- lib/uuid.c | 4 ++-- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/common/cmd_gpt.c b/common/cmd_gpt.c index 1f12e6d..4048b77 100644 --- a/common/cmd_gpt.c +++ b/common/cmd_gpt.c @@ -29,30 +29,52 @@ * * @return - zero on successful expand and env is set */ -static char extract_env(const char *str, char **env) +static int extract_env(const char *str, char **env) { + int ret = -1; char *e, *s; - +#ifdef CONFIG_RANDOM_UUID + char uuid_str[UUID_STR_LEN + 1]; +#endif if (!str || strlen(str) 4) return -1; - if ((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}')) { - s = strdup(str); - if (s == NULL) - return -1; - memset(s + strlen(s) - 1, '\0', 1); - memmove(s, s + 2, strlen(s) - 1); + if (!((strncmp(str, ${, 2) == 0) (str[strlen(str) - 1] == '}'))) + return -1; + + s = strdup(str); + if (s == NULL) + return -1; + + memset(s + strlen(s) - 1, '\0', 1); + memmove(s, s + 2, strlen(s) - 1); + + e = getenv(s); + if (e == NULL) { +#ifdef CONFIG_RANDOM_UUID + debug(%s unset. , str); + gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_STD); + setenv(s, uuid_str); + e = getenv(s); - free(s); - if (e == NULL) { - printf(Environmental '%s' not set\n, str); - return -1; /* env not set */ + if (e) { + debug(Set to random.\n); + ret = 0; + } else { + debug(Can't get random UUID.\n); } - *env = e; - return 0; +#else + debug(%s unset.\n, str); +#endif + } else { + debug(%s get from environment.\n, str); + ret = 0; } - return -1; + *env = e; + free(s); + + return ret; } /** @@ -299,8 +321,16 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; } - if (gpt_default(blk_dev_desc, argv[4])) + puts(Writing GPT: ); + + ret = gpt_default(blk_dev_desc, argv[4]); + if (!ret) { + puts(success!\n); + return CMD_RET_SUCCESS; + } else { + puts(error!\n); return CMD_RET_FAILURE; + } } else { return CMD_RET_USAGE; } diff --git a/doc/README.gpt b/doc/README.gpt index 5c133f3..51515c8 100644 --- a/doc/README.gpt +++ b/doc/README.gpt @@ -101,7 +101,7 @@ Offset SizeDescription 40 8 B First usable LBA for partitions (primary partition table last LBA + 1) 48 8 B Last usable LBA (secondary partition table first LBA - 1) -56 16 BDisk GUID (also referred as UUID on UNIXes) +56 16 BDisk GUID (also referred as UUID on UNIXes) in big endian 72 8 B Partition entries starting LBA (always 2 in primary copy) 80 4 B Number of partition entries 84 4 B Size of a partition entry (usually 128) @@ -132,8 +132,8 @@ of the Primary. -- Offset SizeDescription - 0 16 BPartition type GUID - 16 16 BUnique partition GUID + 0 16 BPartition type GUID (Big Endian) + 16 16 BUnique partition GUID in (Big Endian) 32 8 BFirst LBA (Little Endian) 40 8 BLast LBA (inclusive) 48 8 BAttribute flags [+] @@ -160,6 +160,9 @@ To restore GUID partition table one needs to: Fields 'name', 'size' and