1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-10-22 10:31:56 +02:00

Tools: set multiple variable with fw_setenv utility

Add a sort of batch mode to fw_setenv, allowing to set
multiple variables in one shot, without updating the flash after
each set as now. It is added the possibility to pass
a config file with a list of pairs <variable, value> to be set,
separated by a TAB character.

Signed-off-by: Stefano Babic <sbabic@denx.de>
This commit is contained in:
Stefano Babic
2010-05-24 12:08:16 +02:00
committed by Wolfgang Denk
parent 3746a5e65c
commit bd7b26f879
3 changed files with 289 additions and 53 deletions

View File

@@ -42,34 +42,87 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include "fw_env.h"
#define CMD_PRINTENV "fw_printenv"
#define CMD_SETENV "fw_setenv"
static struct option long_options[] = {
{"script", required_argument, NULL, 's'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
void usage(void)
{
fprintf(stderr, "fw_printenv/fw_setenv, "
"a command line interface to U-Boot environment\n\n"
"usage:\tfw_printenv\n"
"\tfw_setenv [variable name] [variable value]\n"
"\tfw_setenv -s [ file ]\n"
"\tfw_setenv -s - < [ file ]\n\n"
"The file passed as argument contains only pairs "
"name / value\n"
"Example:\n"
"# Any line starting with # is treated as comment\n"
"\n"
"\t netdev eth0\n"
"\t kernel_addr 400000\n"
"\t var1\n"
"\t var2 The quick brown fox jumps over the "
"lazy dog\n"
"\n"
"A variable without value will be dropped. It is possible\n"
"to put any number of spaces between the fields, but any\n"
"space inside the value is treated as part of the value "
"itself.\n\n"
);
}
int
main(int argc, char *argv[])
{
char *p;
char *cmdname = *argv;
char *script_file = NULL;
int c;
if ((p = strrchr (cmdname, '/')) != NULL) {
cmdname = p + 1;
}
while ((c = getopt_long (argc, argv, "s:h",
long_options, NULL)) != EOF) {
switch (c) {
case 's':
script_file = optarg;
break;
case 'h':
usage();
return EXIT_SUCCESS;
}
}
if (strcmp(cmdname, CMD_PRINTENV) == 0) {
if (fw_printenv (argc, argv) != 0)
return (EXIT_FAILURE);
return EXIT_FAILURE;
return (EXIT_SUCCESS);
return EXIT_SUCCESS;
} else if (strcmp(cmdname, CMD_SETENV) == 0) {
if (!script_file) {
if (fw_setenv(argc, argv) != 0)
return EXIT_FAILURE;
} else {
if (fw_parse_script(script_file) != 0)
return EXIT_FAILURE;
}
if (fw_setenv (argc, argv) != 0)
return (EXIT_FAILURE);
return (EXIT_SUCCESS);
return EXIT_SUCCESS;
}
@@ -77,5 +130,5 @@ main(int argc, char *argv[])
"Identity crisis - may be called as `" CMD_PRINTENV
"' or as `" CMD_SETENV "' but not as `%s'\n",
cmdname);
return (EXIT_FAILURE);
return EXIT_FAILURE;
}