|
|
| version 1.1.1.1, 2026/01/04 18:08:18 | version 1.3, 2026/01/04 18:59:16 |
|---|---|
| Line 1 | Line 1 |
| /************************************************************************* | |
| * (C) 2025 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org> | |
| * by Michael Pounov <misho@elwix.org> | |
| * | |
| * $Author$ | |
| * $Id$ | |
| * | |
| ************************************************************************** | |
| 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 <info@elwix.org> | |
| Copyright 2004 - 2025 | |
| by Michael Pounov <misho@elwix.org>. 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 <misho@elwix.org> | |
| 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 "global.h" |
| #include "cmds.h" | #include "cmds.h" |
| #include "image.h" | #include "image.h" |
| Line 10 cmd_Show(void *lb, int idx, char **args) | Line 55 cmd_Show(void *lb, int idx, char **args) |
| printf("FW Image file: %s\n", image); | printf("FW Image file: %s\n", image); |
| printf("FW Image size: %zu\n", imgsiz); | 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 loaded: 0x%zx\n", mtd.mtd_fsiz); |
| printf("MTD file: %s\n", mtd.mtd_file); | printf("MTD file: %s\n", mtd.mtd_file); |
| Line 228 cmd_Mtd(void *lb, int idx, char **args) | Line 274 cmd_Mtd(void *lb, int idx, char **args) |
| int | int |
| cmd_Image(void *lb, int idx, char **args) | cmd_Image(void *lb, int idx, char **args) |
| { | { |
| u_char buf[BUFSIZ]; | |
| int wlen; | |
| size_t siz; | |
| ETRACE(); | ETRACE(); |
| args++; | args++; |
| Line 269 cmd_Image(void *lb, int idx, char **args) | Line 319 cmd_Image(void *lb, int idx, char **args) |
| return -1; | return -1; |
| } | } |
| if (imageOpen(O_CREAT) > 2) { | 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) { | if (ftruncate(imgfd, imgsiz) == -1) { |
| ESYSERR(0); | ESYSERR(0); |
| imageClose(); | imageClose(); |
| unlink(image); | unlink(image); |
| return -1; | 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 { | } else { |
| printf("Error:: unknown command '%s'\n", args[0]); | printf("Error:: unknown command '%s'\n", args[0]); |
| return -1; | 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; | return 0; |
| } | } |