--- fwmaker/src/cmds.c 2026/01/04 18:08:18 1.1 +++ fwmaker/src/cmds.c 2026/01/04 18:59:16 1.3 @@ -1,3 +1,48 @@ +/************************************************************************* +* (C) 2025 AITNET ltd - Sofia/Bulgaria - +* by Michael Pounov +* +* $Author: misho $ +* $Id: cmds.c,v 1.3 2026/01/04 18:59:16 misho Exp $ +* +************************************************************************** +The ELWIX and AITNET software is distributed under the following +terms: + +All of the documentation and software included in the ELWIX and AITNET +Releases is copyrighted by ELWIX - Sofia/Bulgaria + +Copyright 2004 - 2025 + by Michael Pounov . All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: +This product includes software developed by Michael Pounov +ELWIX - Embedded LightWeight unIX and its contributors. +4. Neither the name of AITNET nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. +*/ #include "global.h" #include "cmds.h" #include "image.h" @@ -10,7 +55,8 @@ cmd_Show(void *lb, int idx, char **args) printf("FW Image file: %s\n", image); printf("FW Image size: %zu\n", imgsiz); - printf("FW Image descriptor: %d\n\n", imgfd); + printf("FW Image descriptor: %d\n", imgfd); + printf("FW Image empty byte: 0x%02x\n\n", fillCh); printf("MTD loaded: 0x%zx\n", mtd.mtd_fsiz); printf("MTD file: %s\n", mtd.mtd_file); @@ -228,6 +274,10 @@ cmd_Mtd(void *lb, int idx, char **args) int cmd_Image(void *lb, int idx, char **args) { + u_char buf[BUFSIZ]; + int wlen; + size_t siz; + ETRACE(); args++; @@ -269,19 +319,52 @@ cmd_Image(void *lb, int idx, char **args) return -1; } if (imageOpen(O_CREAT) > 2) { - imgsiz = (size_t) strtol(args[1], NULL, 0); + memset(buf, fillCh, sizeof buf); + imgsiz = siz = (size_t) strtol(args[1], NULL, 0); if (ftruncate(imgfd, imgsiz) == -1) { ESYSERR(0); imageClose(); unlink(image); return -1; - } else - EVERBOSE(1, "Image '%s' created with size=%lu\n", image, imgsiz); + } + lseek(imgfd, 0, SEEK_SET); + while (siz > 0) { + wlen = MIN(siz, sizeof buf); + wlen = write(imgfd, buf, wlen); + if (wlen < 1) { + ESYSERR(0); + imageClose(); + unlink(image); + return -1; + } else + siz -= wlen; + } + EVERBOSE(1, "Image '%s' created successful with size=%lu/remain=#%lu bytes\n", + image, imgsiz, siz); } } else { printf("Error:: unknown command '%s'\n", args[0]); return -1; } + + return 0; +} + +int +cmd_FillCh(void *lb, int idx, char **args) +{ + char str[STRSIZ]; + + ETRACE(); + + args++; + if (!args[0]) { + if (!dialog(lb, "Byte=", str, sizeof str)) + fillCh = (u_char) strtol(str, NULL, 0); + else + return -1; + } else + fillCh = (u_char) strtol(args[0], NULL, 0); return 0; }