From c47377df22b7eb83ea1b38ac93fdab5e37993b1b Mon Sep 17 00:00:00 2001 From: Mike Engel Date: Mon, 12 Jul 2021 17:11:39 +0200 Subject: [PATCH] recovery-utils: add check into recover library if dualboot is enabled This commit add a verification into the recovery library to avoid that it is executed when in dualboot mode. Signed-off-by: Mike Engel https://onedigi.atlassian.net/browse/DEL-7580 (cherry picked from commit 30aa4a74448043b9fa14f47c6f398f4dedee1747) --- .../recovery-utils/include/recovery.h | 7 +++ .../recovery-utils/lib/recovery.c | 54 +++++++++++++++++++ 2 files changed, 61 insertions(+) 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 e73a86951..a94551a4c 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,4 +70,11 @@ 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 debdcdc2c..6781b8930 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 @@ -83,6 +83,12 @@ static int append_recovery_command(const char *value) int rcvr_cmd_len; int ret = 0; + /* Check if we are in dualboot mode */ + if (is_dualboot_enabled()) { + fprintf(stderr, "Error: dualboot enabled recovery cannot be used\n"); + goto err; + } + ret = uboot_getenv("recovery_command", &old_recovery_cmd); if (ret) { fprintf(stderr, "Error: getenv 'recovery_command'\n"); @@ -584,6 +590,12 @@ int update_firmware(const char *swu_path) int file_prefix_len = 0; int ret = -1; + /* Check if we are in dualboot mode */ + if (is_dualboot_enabled()) { + fprintf(stderr, "Error: dualboot enabled recovery cannot be used\n"); + goto err; + } + /* Verify input parameter */ if (!swu_path) { fprintf(stderr, "Error: NULL 'swu_path'\n"); @@ -624,6 +636,12 @@ int reboot_recovery(unsigned int reboot_timeout) { int ret = 0; + /* Check if we are in dualboot mode */ + if (is_dualboot_enabled()) { + fprintf(stderr, "Error: dualboot enabled recovery cannot be used\n"); + goto err; + } + sync(); printf("\nThe recovery commands have been properly configured and " @@ -668,6 +686,12 @@ int set_encryption_key(char *key, unsigned char force) int ret = -1; unsigned char i = 0; + /* Check if we are in dualboot mode */ + if (is_dualboot_enabled()) { + fprintf(stderr, "Error: dualboot enabled recovery cannot be used\n"); + return ret; + } + /* Initialize arrays */ parts[0] = NULL; encrypted[0] = NULL; @@ -768,6 +792,12 @@ int encrypt_partitions(char *to_encrypt, char *to_unencrypt, unsigned char force int ret; + /* Check if we are in dualboot mode */ + if (is_dualboot_enabled()) { + fprintf(stderr, "Error: dualboot enabled recovery cannot be used\n"); + return 1; + } + /* If both lists are empty, we have nothing to do */ if (!to_encrypt && !to_unencrypt) return 1; @@ -932,3 +962,27 @@ 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; + } + + /* Is dualboot enabled */ + if (!strcmp(var, "no")) + ret = 0; + else + ret = 1; + + return ret; +}