fw_env_main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Command line user interface to firmware (=U-Boot) environment.
  25. *
  26. * Implements:
  27. * fw_printenv [ name ... ]
  28. * - prints the values of the environment variables
  29. * "name", or the whole environment if no names are
  30. * specified
  31. * fw_setenv name [ value ... ]
  32. * - If a name without any values is given, the variable
  33. * with this name is deleted from the environment;
  34. * otherwise, all "value" arguments are concatenated,
  35. * separated by sinlge blank characters, and the
  36. * resulting string is assigned to the environment
  37. * variable "name"
  38. */
  39. #include <stdio.h>
  40. #include <string.h>
  41. #include <stdlib.h>
  42. #include "fw_env.h"
  43. #define CMD_PRINTENV "fw_printenv"
  44. #define CMD_SETENV "fw_setenv"
  45. int
  46. main(int argc, char *argv[])
  47. {
  48. char *p;
  49. char *cmdname = *argv;
  50. if ((p = strrchr (cmdname, '/')) != NULL) {
  51. cmdname = p + 1;
  52. }
  53. if (strcmp(cmdname, CMD_PRINTENV) == 0) {
  54. fw_printenv (argc, argv);
  55. return (EXIT_SUCCESS);
  56. } else if (strcmp(cmdname, CMD_SETENV) == 0) {
  57. if (fw_setenv (argc, argv) != 0)
  58. return (EXIT_FAILURE);
  59. return (EXIT_SUCCESS);
  60. }
  61. fprintf (stderr,
  62. "Identity crisis - may be called as `" CMD_PRINTENV
  63. "' or as `" CMD_SETENV "' but not as `%s'\n",
  64. cmdname);
  65. return (EXIT_FAILURE);
  66. }