1/* 2 * Frontend command-line utility for Linux NVRAM layer 3 * 4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved. 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * $Id: main.c,v 1.12 2005/04/23 03:30:03 Exp $ 19 */ 20 21#include <stdio.h> 22#include <stdlib.h> 23#include <string.h> 24 25#include <typedefs.h> 26#include <bcmnvram.h> 27 28void 29usage(void) 30{ 31 fprintf(stderr, 32 "usage: nvram [get name] [set name=value] " 33 "[unset name] [show] [commit] ...\n"); 34 exit(0); 35} 36 37/* NVRAM utility */ 38int 39main(int argc, char **argv) 40{ 41 char *name, *value, buf[NVRAM_SPACE]; 42 int size; 43 44 /* Skip program name */ 45 --argc; 46 ++argv; 47 48 if (!*argv) 49 usage(); 50 51 /* Process the arguments */ 52 for (; *argv; *++argv) { 53 if (!strcmp(*argv, "get")) { 54 if (*++argv) { 55 if ((value = nvram_get(*argv))) 56 puts(value); 57 } 58 } else if (!strcmp(*argv, "set")) { 59 if (*++argv) { 60 strncpy(value = buf, *argv, sizeof(buf)); 61 name = strsep(&value, "="); 62 nvram_set(name, value); 63 } 64 } else if (!strcmp(*argv, "unset")) { 65 if (*++argv) 66 nvram_unset(*argv); 67 } else if (!strcmp (*argv, "commit") || !strcmp (*argv, "save")) { /*Foxconn add, Jasmine Yang, 03/30/2006 */ 68 nvram_commit(); 69 } else if (!strcmp(*argv, "show") || 70 !strcmp(*argv, "dump")) { 71 nvram_getall(buf, sizeof(buf)); 72 for (name = buf; *name; name += strlen(name) + 1) 73 puts(name); 74 size = sizeof(struct nvram_header) + (int) name - (int) buf; 75 if (**argv != 'd') 76 fprintf(stderr, "size: %d bytes (%d left)\n", 77 size, NVRAM_SPACE - size); 78 } 79#ifdef ACOS_MODULES_ENABLE 80 else if (!strncmp (*argv, "loaddefault", 11)) /*Foxconn add, Jasmine Yang, 03/30/2006 */ 81 { 82 /* Write only NVRAM header to flash */ 83 extern int nvram_loaddefault(void); 84 nvram_loaddefault (); 85 } 86 else if (!strncmp (*argv, "version", 7)) /*Foxconn add, Jasmine Yang, 03/30/2006 */ 87 { 88 memset (buf, '\0', sizeof (buf)); 89 if ((value = nvram_safe_get ("pmon_ver"))) 90 { 91 strcpy (buf, "Boot Loader Version : CFE "); 92 strcat (buf, value); 93 strcat (buf, "\n"); 94 } 95 if ((value = nvram_safe_get ("os_version"))) 96 { 97 strcat (buf, "OS Version : Linux "); 98 strcat (buf, value); 99 strcat (buf, "\n"); 100 } 101 puts (buf); 102 } 103#endif 104 else 105 usage(); 106 } 107 108 return 0; 109} 110