On 01.12.20 16:01, [ext] Silvano Cirujano Cuesta wrote:
> The tools bg_setenv and bg_printenv are mostly oriented at running systems
> that have the partitions providing BG environments already mounted.
> 
> This patch extends bg_printenv so that the environment can be read directly
> from whatever valid BG environment file. This usage is very usefull in
> development, diagnose, testing,... scenarios.
> 
> Signed-off-by: Silvano Cirujano Cuesta <[email protected]>
> ---
>  env/env_api_fat.c         |  4 +--
>  env/env_config_file.c     | 18 +++++++---
>  include/env_config_file.h |  3 +-
>  tools/bg_setenv.c         | 69 +++++++++++++++++++++++++++++++++++----
>  4 files changed, 80 insertions(+), 14 deletions(-)
> 
> diff --git a/env/env_api_fat.c b/env/env_api_fat.c
> index c443408..130c161 100644
> --- a/env/env_api_fat.c
> +++ b/env/env_api_fat.c
> @@ -67,7 +67,7 @@ bool read_env(CONFIG_PART *part, BG_ENVDATA *env)
>                       part->mountpoint);
>       }
>       FILE *config;
> -     config = open_config_file(part, "rb");
> +     config = open_config_file_from_part(part, "rb");
>       if (!config) {
>               return false;
>       }
> @@ -105,7 +105,7 @@ bool write_env(CONFIG_PART *part, BG_ENVDATA *env)
>                       part->mountpoint);
>       }
>       FILE *config;
> -     config = open_config_file(part, "wb");
> +     config = open_config_file_from_part(part, "wb");
>       if (!config) {
>               VERBOSE(stderr, "Could not open config file for writing.\n");
>               return false;
> diff --git a/env/env_config_file.c b/env/env_config_file.c
> index 873fe10..e270fbb 100644
> --- a/env/env_config_file.c
> +++ b/env/env_config_file.c
> @@ -18,7 +18,18 @@
>  #include "env_disk_utils.h"
>  #include "env_config_file.h"
>  
> -FILE *open_config_file(CONFIG_PART *cfgpart, char *mode)
> +FILE *open_config_file(char *configfilepath, char *mode)
> +{
> +     VERBOSE(stdout, "Probing config file at %s.\n", configfilepath);
> +     FILE *config = fopen(configfilepath, mode);
> +     if (config) {
> +             return config;
> +     } else {
> +             return NULL;
> +     }
> +}
> +
> +FILE *open_config_file_from_part(CONFIG_PART *cfgpart, char *mode)
>  {
>       char *configfilepath;
>  
> @@ -33,8 +44,7 @@ FILE *open_config_file(CONFIG_PART *cfgpart, char *mode)
>       strcpy(configfilepath, cfgpart->mountpoint);
>       strcat(configfilepath, "/");
>       strcat(configfilepath, FAT_ENV_FILENAME);
> -     VERBOSE(stdout, "Probing config file at %s.\n", configfilepath);
> -     FILE *config = fopen(configfilepath, mode);
> +     FILE *config = open_config_file(configfilepath, mode);
>       free(configfilepath);
>       return config;
>  }
> @@ -74,7 +84,7 @@ bool probe_config_file(CONFIG_PART *cfgpart)
>                       cfgpart->devpath, cfgpart->mountpoint);
>               bool result = false;
>               FILE *config;
> -             if (!(config = open_config_file(cfgpart, "rb"))) {
> +             if (!(config = open_config_file_from_part(cfgpart, "rb"))) {
>                       printf_debug(
>                           "Could not open config file on partition %s.\n",
>                           FAT_ENV_FILENAME);
> diff --git a/include/env_config_file.h b/include/env_config_file.h
> index 8fbe8fa..2679174 100644
> --- a/include/env_config_file.h
> +++ b/include/env_config_file.h
> @@ -15,7 +15,8 @@
>  #ifndef __ENV_CONFIG_FILE_H__
>  #define __ENV_CONFIG_FILE_H__
>  
> -FILE *open_config_file(CONFIG_PART *cfgpart, char *mode);
> +FILE *open_config_file_from_part(CONFIG_PART *cfgpart, char *mode);
> +FILE *open_config_file(char *configfilepath, char *mode);
>  int close_config_file(FILE *config_file_handle);
>  bool probe_config_file(CONFIG_PART *cfgpart);
>  
> diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
> index d068a2b..53c004a 100644
> --- a/tools/bg_setenv.c
> +++ b/tools/bg_setenv.c
> @@ -18,6 +18,7 @@
>  #include "ebgenv.h"
>  #include "uservars.h"
>  #include "version.h"
> +#include "env_config_file.h"
>  
>  static char doc[] =
>       "bg_setenv/bg_printenv - Environment tool for the EFI Boot Guard";
> @@ -47,12 +48,14 @@ static struct argp_option options_setenv[] = {
>  };
>  
>  static struct argp_option options_printenv[] = {
> +     {"filepath", 'f', "ENVFILE", 0, "Read environment from file. Expects "
> +                                     "a valid EFI Boot Guard environment 
> file."},
>       {"verbose", 'v', 0, 0, "Be verbose"},
>       {"version", 'V', 0, 0, "Print version"},
> -     {}
> -};
> +     {0}};

Applied both - just dropping the bottom half of the hunk and aligned the
style of the top half.

Thanks,
Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/400fe83c-198d-5c58-9160-98e72444fe07%40siemens.com.

Reply via email to