firmware-utils: replace GPL 2.0+ boilerplate/reference with SPDX
[project/firmware-utils.git] / src / mkcsysimg.c
index c00096f87d5f8868507da2fc5c42bc8cac85e5d2..2347e63da119c6de20b9403c9d1417d6b8fda96d 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  *
  *  Copyright (C) 2007-2009 Gabor Juhos <juhosg@openwrt.org>
@@ -5,21 +6,6 @@
  *  This program was based on the code found in various Linux
  *  source tarballs released by Edimax for it's devices.
  *  Original author: David Hsu <davidhsu@realtek.com.tw>
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU General Public License
- *  as published by the Free Software Foundation; either version 2
- *  of the License, or (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the
- *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- *  Boston, MA  02110-1301, USA.
  */
 
 #include <stdio.h>
@@ -199,7 +185,7 @@ static struct board_info boards[] = {
 #define ERRS(fmt, ...) do { \
        int save = errno; \
        fflush(0); \
-       fprintf(stderr, "[%s] *** error: " fmt "\n", progname, ## __VA_ARGS__ \
+       fprintf(stderr, "[%s] *** error: " fmt ": %s\n", progname, ## __VA_ARGS__ \
                , strerror(save)); \
 } while (0)
 
@@ -423,8 +409,9 @@ csum8_get(struct csum_state *css)
 
 
 void
-csum16_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum16_update(void *data, uint32_t len, struct csum_state *css)
 {
+       uint8_t *p = data;
        uint16_t t;
 
        if (css->odd) {
@@ -468,8 +455,10 @@ csum_init(struct csum_state *css, int size)
 
 
 void
-csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
+csum_update(void *data, uint32_t len, struct csum_state *css)
 {
+       uint8_t *p = data;
+
        switch (css->size) {
        case CSUM_SIZE_8:
                csum8_update(p,len,css);
@@ -493,6 +482,9 @@ csum_get(struct csum_state *css)
        case CSUM_SIZE_16:
                ret = csum16_get(css);
                break;
+       default:
+               ERR("invalid checksum size\n");
+               return 0;
        }
 
        return ret;
@@ -503,19 +495,21 @@ csum_get(struct csum_state *css)
  * routines to write data to the output file
  */
 int
-write_out_data(FILE *outfile, uint8_t *data, size_t len,
+write_out_data(FILE *outfile, void *data, size_t len,
                struct csum_state *css)
 {
+       uint8_t *ptr = data;
+
        errno = 0;
 
-       fwrite(data, len, 1, outfile);
+       fwrite(ptr, len, 1, outfile);
        if (errno) {
                ERRS("unable to write output file");
                return ERR_FATAL;
        }
 
        if (css) {
-               csum_update(data, len, css);
+               csum_update(ptr, len, css);
        }
 
        return 0;
@@ -647,7 +641,7 @@ block_writeout_data(FILE *outfile, struct csys_block *block)
 
        /* write padding data if neccesary */
        padlen = block->size_avail - block->file_size;
-       DBG(1,"padding block, length=%d", padlen);
+       DBG(1,"padding block, length=%zu", padlen);
        res = write_out_padding(outfile, padlen, block->padc, block->css);
 
        return res;
@@ -792,7 +786,6 @@ parse_opt_block(char ch, char *arg)
 {
        char buf[MAX_ARG_LEN];
        char *argv[MAX_ARG_COUNT];
-       int argc;
        char *p;
        struct csys_block *block;
        int i;
@@ -854,7 +847,7 @@ parse_opt_block(char ch, char *arg)
                return ERR_FATAL;
        }
 
-       argc = parse_arg(arg, buf, argv);
+       parse_arg(arg, buf, argv);
 
        i = 0;
        p = argv[i++];
@@ -1122,11 +1115,11 @@ main(int argc, char *argv[])
                        res = ERR_FATAL;
 
                if (keep_invalid_images == 0) {
-                       WARN("generation of invalid images disabled", ofname);
+                       WARN("generation of invalid images \"%s\" disabled", ofname);
                        goto out;
                }
 
-               WARN("generating invalid image", ofname);
+               WARN("generating invalid image: \"%s\"", ofname);
        }
 
        outfile = fopen(ofname, "w");