[U-Boot] [PATCH V2 3/3] cmd:gpt: randomly generate each partition uuid if undefined

Stephen Warren swarren at wwwdotorg.org
Mon Mar 10 18:44:25 CET 2014


On 03/05/2014 09:45 AM, Przemyslaw Marczak wrote:
> Changes:
> - randomly generate each partition uuid if undefined
> - print info about generated uuid
> - save environment on gpt write success
> - update doc/README.gpt

> 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;
> +	char uuid_str[37];
>  
>  	if (!str || strlen(str) < 4)
>  		return -1;
> @@ -43,16 +45,25 @@ static char extract_env(const char *str, char **env)
>  		memset(s + strlen(s) - 1, '\0', 1);
>  		memmove(s, s + 2, strlen(s) - 1);
>  		e = getenv(s);
> -		free(s);
>  		if (e == NULL) {
> -			printf("Environmental '%s' not set\n", str);
> -			return -1; /* env not set */
> +			printf("%s unset. ", str);
> +			gen_rand_uuid_str(uuid_str);
> +			setenv(s, uuid_str);
> +
> +			e = getenv(s);
> +			if (e) {
> +				puts("Setting to random.\n");

Shouldn't this be printed right after the "if (e == NULL)" check above?
That's where the decision is made to generate a random UUID.

Here, "if (!e)", the code should return an error.

But, I still don't like changing the environment. Why can't the above
few lines be:

+ 			gen_rand_uuid_str(uuid_str);
+			e = uuid_str;

> diff --git a/doc/README.gpt b/doc/README.gpt

>  "uuid" program is recommended to generate UUID string. Moreover it can decode
>  (-d switch) passed in UUID string. It can be used to generate partitions UUID
>  passed to u-boot environment variables.
> +If each partition "uuid" no exists then it will be randomly generated.

"If each" means "if all of them", implying that it's an all-or-nothing
solution, and the random generation only happens of none of the UUIDs
were supplied, not on a UUID-by-UUID basis. So, s/each/a/ or s/each/any/.


More information about the U-Boot mailing list