ramips: fix USW-Flex reversed switch-port order
[openwrt/staging/hauke.git] / tools / firmware-utils / src / mkcasfw.c
index e294ad659c0efcdfe5bb40a0f54a8d8615d3d10a..8d3ea40509d4ab09ac24755d9dc4f38e69480f41 100644 (file)
@@ -1,13 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
- *  $Id$
  *
  *  Copyright (C) 2007 OpenWrt.org
  *  Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
- *
- *  This program is free software; you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License version 2 as published
- *  by the Free Software Foundation.
- *
  */
 
 #include <stdio.h>
@@ -259,7 +254,7 @@ static struct board_info boards[] = {
 #define ERRS(fmt, ...) do { \
        int save = errno; \
        fflush(0); \
-       fprintf(stderr, "[%s] *** error: " fmt "\n", \
+       fprintf(stderr, "[%s] *** error: " fmt ": %s\n", \
                        progname, ## __VA_ARGS__, strerror(save)); \
 } while (0)
 
@@ -464,8 +459,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) {
@@ -525,8 +521,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_TYPE_8:
                csum8_update(p,len,css);
@@ -555,6 +553,10 @@ csum_get(struct csum_state *css)
                break;
        case CSUM_TYPE_32:
                ret = csum32_get(css);
+               break;
+       default:
+               ERR("invalid checksum size\n");
+               return 0;
        }
 
        return ret;
@@ -565,19 +567,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;
@@ -709,7 +713,7 @@ image_writeout(FILE *outfile, struct image_desc *desc)
 
        /* write padding data if neccesary */
        padlen = desc->out_size - desc->file_size;
-       DBG(1,"padding desc, length=%d", padlen);
+       DBG(1,"padding desc, length=%zu", padlen);
        res = write_out_padding(outfile, padlen, desc->padc, &css);
 
        desc->csum = csum_get(&css);
@@ -756,6 +760,9 @@ write_out_header(FILE *outfile)
                res = write_out_data(outfile, (uint8_t *)&tmp.nfs,
                                        sizeof(tmp.nfs), NULL);
                break;
+       default:
+               ERR("invalid header type\n");
+               return -EINVAL;
        }
 
        return res;
@@ -764,8 +771,7 @@ write_out_header(FILE *outfile)
 int
 write_out_images(FILE *outfile)
 {
-       struct image_desc *desc;
-       int i, res;
+       int res;
 
        res = image_writeout(outfile, &kernel_image);
        if (res)
@@ -840,7 +846,6 @@ parse_opt_image(char ch, char *arg)
 {
        char buf[MAX_ARG_LEN];
        char *argv[MAX_ARG_COUNT];
-       int argc;
        char *p;
        struct image_desc *desc = NULL;
        int i;
@@ -865,7 +870,7 @@ parse_opt_image(char ch, char *arg)
        if (!desc)
                return ERR_FATAL;
 
-       argc = parse_arg(arg, buf, argv);
+       parse_arg(arg, buf, argv);
 
        i = 0;
        p = argv[i++];
@@ -887,9 +892,6 @@ parse_opt_image(char ch, char *arg)
 int
 process_images(void)
 {
-       struct image_desc *desc;
-       uint32_t offs = 0;
-       int i;
        int res;
 
        kernel_image.out_size = board->max_kernel_size;
@@ -986,11 +988,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");