Annotation of embedtools/src/ube.c, revision 1.1.2.10

1.1.2.10! misho       1: /*************************************************************************
        !             2:  * (C) 2014 AITNET - Sofia/Bulgaria - <office@aitbg.com>
        !             3:  *  by Michael Pounov <misho@aitbg.com>
        !             4:  *
        !             5:  * $Author: misho $
        !             6:  * $Id: cfger.c,v 1.1.2.2 2014/01/30 00:55:19 misho Exp $
        !             7:  *
        !             8:  *************************************************************************
        !             9: The ELWIX and AITNET software is distributed under the following
        !            10: terms:
        !            11: 
        !            12: All of the documentation and software included in the ELWIX and AITNET
        !            13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
        !            14: 
        !            15: Copyright 2004 - 2014
        !            16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
        !            17: 
        !            18: Redistribution and use in source and binary forms, with or without
        !            19: modification, are permitted provided that the following conditions
        !            20: are met:
        !            21: 1. Redistributions of source code must retain the above copyright
        !            22:    notice, this list of conditions and the following disclaimer.
        !            23: 2. Redistributions in binary form must reproduce the above copyright
        !            24:    notice, this list of conditions and the following disclaimer in the
        !            25:    documentation and/or other materials provided with the distribution.
        !            26: 3. All advertising materials mentioning features or use of this software
        !            27:    must display the following acknowledgement:
        !            28: This product includes software developed by Michael Pounov <misho@elwix.org>
        !            29: ELWIX - Embedded LightWeight unIX and its contributors.
        !            30: 4. Neither the name of AITNET nor the names of its contributors
        !            31:    may be used to endorse or promote products derived from this software
        !            32:    without specific prior written permission.
        !            33: 
        !            34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
        !            35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            44: SUCH DAMAGE.
        !            45: */
1.1.2.1   misho      46: #include "global.h"
                     47: #include "ub_env.h"
                     48: 
                     49: 
1.1.2.4   misho      50: cfg_root_t cfg;
1.1.2.2   misho      51: int Verbose;
                     52: extern char compiled[], compiledby[], compilehost[];
                     53: 
                     54: 
                     55: static void
                     56: Usage()
                     57: {
                     58:        printf( " -= U-Boot-Env =- Tool for u-boot-env nand map management\n"
                     59:                "=== %s === %s@%s ===\n\n"
                     60:                "  Syntax: ube [options] [set_value]\n"
                     61:                "\n"
1.1.2.4   misho      62:                "\t-c <cfgfile>\tConfig file [default: /etc/ube.conf]\n"
1.1.2.5   misho      63:                "\t-d <descr>\tDrive description into config [default: 64K]\n"
1.1.2.2   misho      64:                "\t-g <name>\tSet parameter to value\n"
                     65:                "\t-s <name>\tGet parameter value\n"
1.1.2.3   misho      66:                "\t-q\t\tQuiet mode\n"
1.1.2.2   misho      67:                "\t-v\t\tVerbose ...\n"
                     68:                "\n", compiled, compiledby, compilehost);
                     69: }
                     70: 
                     71: int
                     72: main(int argc, char **argv)
                     73: {
1.1.2.4   misho      74:        char ch, mode = 0, szName[STRSIZ] = { 0 }, szVal[STRSIZ] = { 0 }, 
1.1.2.5   misho      75:             szCfgName[PATH_MAX], szSec[STRSIZ];
1.1.2.3   misho      76:        const char *str;
1.1.2.6   misho      77:        int ret = 0;
1.1.2.2   misho      78: 
1.1.2.4   misho      79:        strlcpy(szCfgName, UBE_CFGNAME, sizeof szCfgName);
1.1.2.5   misho      80:        strlcpy(szSec, UBE_SECTION, sizeof szSec);
                     81:        while ((ch = getopt(argc, argv, "hvqg:s:c:d:")) != -1)
1.1.2.2   misho      82:                switch (ch) {
                     83:                        case 'g':
1.1.2.3   misho      84:                                mode |= 1;
1.1.2.2   misho      85:                                strlcpy(szName, optarg, sizeof szName);
                     86:                                break;
                     87:                        case 's':
1.1.2.3   misho      88:                                mode |= 2;
1.1.2.2   misho      89:                                strlcpy(szName, optarg, sizeof szName);
                     90:                                break;
1.1.2.4   misho      91:                        case 'c':
                     92:                                strlcpy(szCfgName, optarg, sizeof szCfgName);
                     93:                                break;
1.1.2.5   misho      94:                        case 'd':
                     95:                                strlcpy(szSec, optarg, sizeof szSec);
                     96:                                break;
1.1.2.2   misho      97:                        case 'v':
                     98:                                Verbose++;
                     99:                                break;
1.1.2.3   misho     100:                        case 'q':
                    101:                                mode |= 0x80;
                    102:                                break;
1.1.2.2   misho     103:                        case 'h':
                    104:                        default:
                    105:                                Usage();
                    106:                                return 1;
                    107:                }
                    108:        argc -= optind;
                    109:        argv += optind;
1.1.2.3   misho     110:        if ((mode & 0x7f) == 2 && argc)
                    111:                strlcpy(szVal, *argv, sizeof szVal);
                    112: 
                    113:        VERB(1) printf("u-boot-env: mode=0x%hhx name=%s value=%s\n", mode, szName, szVal);
                    114: 
1.1.2.4   misho     115:        if (cfgLoadConfig(szCfgName, &cfg)) {
                    116:                printf("Error:: cfgLoadConfig() #%d - %s\n", cfg_GetErrno(), cfg_GetError());
                    117:                return 1;
                    118:        }
                    119: 
1.1.2.6   misho     120:        if (ub_load(szSec)) {
1.1.2.8   misho     121:                ret = 1;
                    122:                goto end;
1.1.2.6   misho     123:        }
                    124: 
1.1.2.3   misho     125:        if (!(mode & 0x7f)) {
                    126:                VERB(2) printf("u-boot-env: list variables\n");
1.1.2.9   misho     127:                ub_env(szSec);
1.1.2.2   misho     128:        }
                    129: 
1.1.2.3   misho     130:        if ((mode & 0x7f) & 1) {
                    131:                VERB(2) printf("u-boot-env: get variable %s\n", szName);
1.1.2.7   misho     132:                str = ub_getenv(szSec, szName);
1.1.2.3   misho     133:                if (!str) {
                    134:                        printf("Error:: Variable %s not found!\n", szName);
1.1.2.6   misho     135:                        ret = 2;
                    136:                        goto end;
1.1.2.3   misho     137:                } else if (mode & 0x80)
                    138:                        printf("%s\n", str);
                    139:                else
1.1.2.7   misho     140:                        printf("%s=%s\n", szName, str);
1.1.2.3   misho     141:        }
                    142: 
                    143:        if ((mode & 0x7f) & 2) {
                    144:                VERB(2) printf("u-boot-env: set variable %s\n", szName);
1.1.2.7   misho     145:                ret = ub_setenv(szSec, szName, argc ? szVal : NULL);
1.1.2.3   misho     146:                if (ret) {
                    147:                        printf("Error:: Writing variable %s!\n", szName);
1.1.2.6   misho     148:                        ret = 3;
                    149:                        goto end;
1.1.2.3   misho     150:                }
                    151:                if (!(mode & 0x80))
                    152:                        printf("Done\n");
                    153:        }
1.1.2.2   misho     154: 
1.1.2.6   misho     155: end:
                    156:        ub_unload();
1.1.2.4   misho     157:        cfgUnloadConfig(&cfg);
1.1.2.6   misho     158:        return ret;
1.1.2.2   misho     159: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>