diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-24 23:38:45 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-24 23:38:45 +0000 |
commit | a8da3a09a3fb34327cf02306726dad640e309f20 (patch) | |
tree | 313a27bd4a35051dc25ef2c004f3a07212023d9e /contrib/userspace-nvram/cli.c | |
parent | 18193fa5e9790e5c48ac42bb99f7477be2aed7f9 (diff) |
contrib/userspace-nvram:
- fix checksum calculation
- better handle invalid cli invokation
- get rid of hard coded erase size
- fix data type of crc8 function
Diffstat (limited to 'contrib/userspace-nvram/cli.c')
-rw-r--r-- | contrib/userspace-nvram/cli.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/contrib/userspace-nvram/cli.c b/contrib/userspace-nvram/cli.c index 3a071994c5..e3cd826d77 100644 --- a/contrib/userspace-nvram/cli.c +++ b/contrib/userspace-nvram/cli.c @@ -89,6 +89,7 @@ int main( int argc, const char *argv[] ) int commit = 0; int write = 0; int stat = 1; + int done = 0; int i; /* Ugly... iterate over arguments to see whether we can expect a write */ @@ -102,42 +103,39 @@ int main( int argc, const char *argv[] ) } - if( (nvram = write ? nvram_open_staging() : nvram_open_rdonly()) != NULL ) + if( (nvram = write ? nvram_open_staging() : nvram_open_rdonly()) != NULL && argc > 1 ) { for( i = 1; i < argc; i++ ) { if( !strcmp(argv[i], "show") ) { stat = do_show(nvram); + done++; } else if( !strcmp(argv[i], "get") && ++i < argc ) { stat = do_get(nvram, argv[i]); + done++; } else if( !strcmp(argv[i], "unset") && ++i < argc ) { stat = do_unset(nvram, argv[i]); + done++; } else if( !strcmp(argv[i], "set") && ++i < argc ) { stat = do_set(nvram, argv[i]); + done++; } else if( !strcmp(argv[i], "commit") ) { commit = 1; + done++; } else { - fprintf(stderr, - "Usage:\n" - " nvram show\n" - " nvram get variable\n" - " nvram set variable=value [set ...]\n" - " nvram unset variable [unset ...]\n" - " nvram commit\n" - ); - - return 1; + done = 0; + break; } } @@ -150,5 +148,31 @@ int main( int argc, const char *argv[] ) stat = staging_to_nvram(); } + if( !nvram ) + { + fprintf(stderr, + "Could not open nvram! Possible reasons are:\n" + " - No device found (/proc not mounted or no nvram present)\n" + " - Insufficient permissions to open mtd device\n" + " - Insufficient memory to complete operation\n" + " - Memory mapping failed or not supported\n" + ); + + stat = 1; + } + else if( !done ) + { + fprintf(stderr, + "Usage:\n" + " nvram show\n" + " nvram get variable\n" + " nvram set variable=value [set ...]\n" + " nvram unset variable [unset ...]\n" + " nvram commit\n" + ); + + stat = 1; + } + return stat; } |