From 9a519570ba79f4336322867b2f1484694d8b7a60 Mon Sep 17 00:00:00 2001 From: Hector Palacios Date: Wed, 25 Aug 2021 12:11:59 +0200 Subject: [PATCH] recovery: rework is_dualboot_enabled() function - The function is only used internally in this file, so make it static. - Convert the function from 'int' to 'bool', since no other values are evaluated. - Only return true if the variable 'dualboot' is set to 'yes'. Before, the function returned true if 'dualboot' was different than 'no'. Signed-off-by: Hector Palacios --- .../recovery-utils/include/recovery.h | 7 --- .../recovery-utils/lib/recovery.c | 56 +++++++++---------- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/include/recovery.h b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/include/recovery.h index a94551a4c..e73a86951 100644 --- a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/include/recovery.h +++ b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/include/recovery.h @@ -70,11 +70,4 @@ int set_encryption_key(char *key, unsigned char force); */ int encrypt_partitions(char *to_encrypt, char *to_unencrypt, unsigned char force); -/* - * Check if device has dualboot enabled. - * - * Return: 1 if enabled and 0 if disabled, -1 on error when reading the environment - */ -int is_dualboot_enabled(void); - #endif /* RECOVERY_H */ diff --git a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c index d053a932c..8e91a96ce 100644 --- a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c +++ b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c @@ -19,6 +19,7 @@ #define _GNU_SOURCE /* For GNU version of basename */ +#include #include #include #include @@ -72,6 +73,32 @@ static char *emmc_parts_blacklist[] = { static char *rootfs[] = { "rootfs", NULL }; +/* + * Function: is_device_closed + * Description: check if the device is in dualboot mode + */ +static bool is_dualboot_enabled(void) +{ + const char *var; + bool ret = false; + + /* Parse dualboot */ + if (uboot_getenv("dualboot", &var)) { + fprintf(stderr, "Error: getenv 'dualboot'\n"); + return false; + } + + /* Consider dualboot not enabled if variable doesn't exist */ + if (!var) + return false; + + /* Is dualboot enabled */ + if (!strcmp(var, "yes")) + ret = true; + + return ret; +} + /* * Function: append_recovery_command * Description: append configuration to the 'recovery_command' variable @@ -961,32 +988,3 @@ err: return ret < 0 ? -1 : ret; } - -/* - * Function: is_device_closed - * Description: check if the device is in dualboot mode - */ -int is_dualboot_enabled (void) -{ - const char *var; - int ret; - - /* Parse dualboot */ - ret = uboot_getenv("dualboot", &var); - if (ret) { - fprintf(stderr, "Error: getenv 'dualboot'\n"); - return 0; - } - - /* Consider dualboot not enabled if variable doesn't exist */ - if (!var) - return 0; - - /* Is dualboot enabled */ - if (!strcmp(var, "no")) - ret = 0; - else - ret = 1; - - return ret; -}