Annotation of fwmaker/src/fwmaker.c, revision 1.3
1.3 ! misho 1: /*************************************************************************
! 2: * (C) 2025 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
! 3: * by Michael Pounov <misho@elwix.org>
! 4: *
! 5: * $Author: misho $
! 6: * $Id: elwix.c,v 1.11 2024/01/22 15:24:28 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 - 2025
! 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 misho 46: #include "global.h"
47: #include "cmds.h"
48: #include "image.h"
49:
50:
51: linebuffer_t *line;
52: struct tagMtd mtd;
53: char image[MAXPATHLEN];
54: int imgfd;
55: size_t imgsiz;
1.2 misho 56: u_char fillCh = 0x0;
1.1 misho 57:
58:
59: void
60: Usage()
61: {
62: printf( " -= FWMAKER =- Firmware maker software ver.%s\n"
63: " (C)`25 ELWIX by Michael Pounov <misho@elwix.org> \n"
64: "==================================================\n"
1.2 misho 65: " Syntax: fwmaker [-options] <image> [command [args]]\n\n"
1.1 misho 66: "\t-i\t\t\tPrompt command\n"
1.2 misho 67: "\t-C <byte>\t\tFill empty bytes [default=0x0]\n"
1.1 misho 68: "\t-d <0xmask>\t\tDebug mode\n"
69: "\t-v\t\t\tVerbose, more -v more verbosity\n"
70: "\t-h\t\t\tHelp, this screen\n", "0.1");
71: }
72:
73: static void
74: prepareCli()
75: {
76: cli_addCommand(line, "image", 1, cmd_Image, "image command", "image management");
77: cli_addCommand(line, "mtd", 1, cmd_Mtd, "mtd command", "mtd partition");
78: cli_addCommand(line, "show", 1, cmd_Show, "show command", "shows parameters");
1.2 misho 79:
80: cli_addCommand(line, "fill_byte", 2, cmd_FillCh, "fill_byte command",
81: "fill image empty areas with byte");
1.1 misho 82: }
83:
84: int
85: main(int argc, char **argv)
86: {
87: int ch, imode = 0, ret = 0;
88: char **args, cmdline[BUFSIZ] = { 0 };
89:
1.2 misho 90: while ((ch = getopt(argc, argv, "hvid:C:")) != -1)
1.1 misho 91: switch (ch) {
1.2 misho 92: case 'C':
93: fillCh = (u_char) strtol(optarg, NULL, 0);
94: break;
1.1 misho 95: case 'i':
96: imode = 42;
97: break;
98: case 'd':
99: e_Debug = strtol(optarg, NULL, 0);
100: break;
101: case 'v':
102: e_incVerbose;
103: break;
104: case 'h':
105: default:
106: Usage();
107: return 1;
108: }
109: argc -= optind;
110: argv += optind;
111: if (!argc) {
112: printf("Error:: image not found!\n");
113: return 1;
114: } else {
115: strlcpy(image, *argv, sizeof image);
116: argc--;
117: argv++;
118:
119: imageOpen(0);
120: }
121:
122: openlog("fwmaker", LOG_PID | LOG_PERROR, LOG_USER);
123:
124: if (imode) {
125: if (!argc) {
126: printf("Error:: missing command line ...\n");
127: imageClose();
128: return 1;
129: } else
130: args = argv;
131: while (*args) {
132: strlcat(cmdline, *args++, sizeof cmdline);
133: strlcat(cmdline, " ", sizeof cmdline);
134: }
135: EVERBOSE(2, "imode: cmdline=%s", cmdline);
136: }
137:
138: line = cliInit(STDIN_FILENO, STDOUT_FILENO, "fwmaker");
139: if (!line) {
140: ELIBERR(cli);
141: imageClose();
142: return 2;
143: } else
144: EDEBUG(ELWIX_DEBUG_IO, "CLI init");
145:
146: prepareCli();
147:
148: if (imode)
149: ret = cliRun(line, cmdline, 0);
150: else
151: ret = cliLoop(line, NULL, -1);
152:
153: cliEnd(line);
154: imageClose();
155: EDEBUG(ELWIX_DEBUG_IO, "CLI end");
156: EDBGS(ELWIX_DEBUG_MEMORY)
157: mpool_dump(NULL, NULL);
158: closelog();
159: return ret;
160: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>