[PATCH 5/5] cmd: Convert part uuid to use cmd_result

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Mar 1 01:03:43 CET 2021


Am 1. März 2021 00:47:18 MEZ schrieb Sean Anderson <seanga2 at gmail.com>:
>This is fairly straightforward. This allows
>	part uuid mmc 0 foo
>To be rewritten as
>	env set foo $(part uuid mmc 0)
>or even (if the variable is not required to be environmental)
>	foo=$(part uuid mmc 0)

Who needs this? Why?

Where do you document it?

Where are the tests?

Best regards

Heinrich


>
>Signed-off-by: Sean Anderson <seanga2 at gmail.com>
>---
>
> cmd/part.c | 18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
>
>diff --git a/cmd/part.c b/cmd/part.c
>index 3395c17b89..97e70d79ff 100644
>--- a/cmd/part.c
>+++ b/cmd/part.c
>@@ -19,9 +19,12 @@
> #include <config.h>
> #include <command.h>
> #include <env.h>
>+#include <malloc.h>
> #include <part.h>
> #include <vsprintf.h>
> 
>+DECLARE_GLOBAL_DATA_PTR;
>+
> enum cmd_part_info {
> 	CMD_PART_INFO_START = 0,
> 	CMD_PART_INFO_SIZE,
>@@ -43,12 +46,19 @@ static int do_part_uuid(int argc, char *const
>argv[])
> 	if (part < 0)
> 		return 1;
> 
>-	if (argc > 2)
>+	if (argc > 2) {
> 		env_set(argv[2], info.uuid);
>-	else
>-		printf("%s\n", info.uuid);
>+	} else {
>+		size_t result_size = sizeof(info.uuid) + 1;
> 
>-	return 0;
>+		gd->cmd_result = malloc(result_size);
>+		if (!gd->cmd_result)
>+			return CMD_RET_FAILURE;
>+
>+		snprintf(gd->cmd_result, result_size, "%s\n", info.uuid);
>+	}
>+
>+	return CMD_RET_SUCCESS;
> }
> 
> static int do_part_list(int argc, char *const argv[])



More information about the U-Boot mailing list