Commit d4e1b2c6 authored by Pavel Boldin's avatar Pavel Boldin Committed by Sergei Poselenov

updating fw_env utilities

(cherry picked from commit 9243d92608ef0c356e0cd5f9ce2d409da82b2a42)
parent db7eccfb
This diff is collapsed.
......@@ -42,34 +42,94 @@
#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] [variable name]\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, "ns:h",
long_options, NULL)) != EOF) {
switch (c) {
case 'n':
/* handled in fw_printenv */
break;
case 's':
script_file = optarg;
break;
case 'h':
usage();
return EXIT_SUCCESS;
default: /* '?' */
fprintf(stderr, "Try `%s --help' for more information."
"\n", cmdname);
return EXIT_FAILURE;
}
}
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 +137,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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment