tools/env: allow config filename to be passed via command line argument
When for example generating/manipulating SD card/eMMC images which contain U-Boot and its environment(s), it is handy to use a given configuration file instead of the compiled-in default one. And since the default configuration file is expected under /etc it's hard for an usual linux user account without special permissions to use fw_printenv/fw_setenv for this purpose. So allow to pass an optional filename via a new '-c' command line argument. Example: $ ln -s fw_printenv tools/env/fw_setenv $ cat fw_env.config test.img 0x20000 0x20000 test.img 0x40000 0x20000 $ tools/env/fw_printenv -c ./fw_env.config fdt_file fdt_file=imx28-duckbill.dtb $ tools/env/fw_setenv -c ./fw_env.config fdt_file imx28-duckbill-spi.dtb $ tools/env/fw_printenv -c ./fw_env.config fdt_file fdt_file=imx28-duckbill-spi.dtb Signed-off-by: Michael Heimpold <mhei@heimpold.de>
This commit is contained in:
parent
f5b76de440
commit
9884f44cab
|
|
@ -124,6 +124,7 @@ static int parse_config (void);
|
||||||
|
|
||||||
#if defined(CONFIG_FILE)
|
#if defined(CONFIG_FILE)
|
||||||
static int get_config (char *);
|
static int get_config (char *);
|
||||||
|
static char *config_file = CONFIG_FILE;
|
||||||
#endif
|
#endif
|
||||||
static inline ulong getenvsize (void)
|
static inline ulong getenvsize (void)
|
||||||
{
|
{
|
||||||
|
|
@ -246,6 +247,19 @@ int fw_printenv (int argc, char *argv[])
|
||||||
int i, n_flag;
|
int i, n_flag;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
|
#ifdef CONFIG_FILE
|
||||||
|
if (argc >= 2 && strcmp(argv[1], "-c") == 0) {
|
||||||
|
if (argc < 3) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"## Error: '-c' option requires the config file to use\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
config_file = argv[2];
|
||||||
|
argv += 2;
|
||||||
|
argc -= 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (argc >= 2 && strcmp(argv[1], "-a") == 0) {
|
if (argc >= 2 && strcmp(argv[1], "-a") == 0) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
|
@ -486,6 +500,19 @@ int fw_setenv(int argc, char *argv[])
|
||||||
char *name;
|
char *name;
|
||||||
char *value = NULL;
|
char *value = NULL;
|
||||||
|
|
||||||
|
#ifdef CONFIG_FILE
|
||||||
|
if (argc >= 2 && strcmp(argv[1], "-c") == 0) {
|
||||||
|
if (argc < 3) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"## Error: '-c' option requires the config file to use\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
config_file = argv[2];
|
||||||
|
argv += 2;
|
||||||
|
argc -= 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -1364,9 +1391,9 @@ static int parse_config ()
|
||||||
|
|
||||||
#if defined(CONFIG_FILE)
|
#if defined(CONFIG_FILE)
|
||||||
/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
|
/* Fills in DEVNAME(), ENVSIZE(), DEVESIZE(). Or don't. */
|
||||||
if (get_config (CONFIG_FILE)) {
|
if (get_config (config_file)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Cannot parse config file: %s\n", strerror (errno));
|
"Cannot parse config file '%s': %s\n", config_file, strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,13 @@ void usage(void)
|
||||||
|
|
||||||
fprintf(stderr, "fw_printenv/fw_setenv, "
|
fprintf(stderr, "fw_printenv/fw_setenv, "
|
||||||
"a command line interface to U-Boot environment\n\n"
|
"a command line interface to U-Boot environment\n\n"
|
||||||
|
#ifndef CONFIG_FILE
|
||||||
"usage:\tfw_printenv [-a key] [-n] [variable name]\n"
|
"usage:\tfw_printenv [-a key] [-n] [variable name]\n"
|
||||||
"\tfw_setenv [-a key] [variable name] [variable value]\n"
|
"\tfw_setenv [-a key] [variable name] [variable value]\n"
|
||||||
|
#else
|
||||||
|
"usage:\tfw_printenv [-c /my/fw_env.config] [-a key] [-n] [variable name]\n"
|
||||||
|
"\tfw_setenv [-c /my/fw_env.config] [-a key] [variable name] [variable value]\n"
|
||||||
|
#endif
|
||||||
"\tfw_setenv -s [ file ]\n"
|
"\tfw_setenv -s [ file ]\n"
|
||||||
"\tfw_setenv -s - < [ file ]\n\n"
|
"\tfw_setenv -s - < [ file ]\n\n"
|
||||||
"The file passed as argument contains only pairs "
|
"The file passed as argument contains only pairs "
|
||||||
|
|
@ -98,12 +103,15 @@ int main(int argc, char *argv[])
|
||||||
cmdname = p + 1;
|
cmdname = p + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "a:ns:h",
|
while ((c = getopt_long (argc, argv, "a:c:ns:h",
|
||||||
long_options, NULL)) != EOF) {
|
long_options, NULL)) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
/* AES key, handled later */
|
/* AES key, handled later */
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
/* handled later */
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
/* handled in fw_printenv */
|
/* handled in fw_printenv */
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue