ramips: fix USW-Flex reversed switch-port order
[openwrt/staging/hauke.git] / tools / firmware-utils / src / mkzynfw.c
index f3343df7269a93e03ddeb67f19e7625b45690186..e856112f1645d2991d973d3d073162d13eacefba 100644 (file)
@@ -1,16 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  *
  *  Copyright (C) 2007-2008 OpenWrt.org
  *  Copyright (C) 2007-2008 Gabor Juhos <juhosg at openwrt.org>
- *
- *  This code was based on the information of the ZyXEL's firmware
- *  image format written by Kolja Waschk, can be found at:
- *  http://www.ixo.de/info/zyxel_uclinux
- *
- *  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>
@@ -27,6 +19,7 @@
 #if defined(__CYGWIN__)
 #  include <byteswap.h>
 #endif
+#include <inttypes.h>
 
 #include "zynos.h"
 
@@ -443,8 +436,10 @@ csum_init(struct csum_state *css)
 
 
 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;
+
        if (len == 0)
                return;
 
@@ -498,19 +493,21 @@ csum_buf(uint8_t *p, uint32_t len)
  * 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) {
                ERR("unable to write output file");
                return -1;
        }
 
        if (css) {
-               csum_update(data, len, css);
+               csum_update(ptr, len, css);
        }
 
        return 0;
@@ -540,7 +537,7 @@ write_out_padding(FILE *outfile, size_t len, uint8_t padc,
 
 
 int
-write_out_data_align(FILE *outfile, uint8_t *data, size_t len, size_t align,
+write_out_data_align(FILE *outfile, void *data, size_t len, size_t align,
                struct csum_state *css)
 {
        size_t padlen;
@@ -610,7 +607,7 @@ write_out_mmap(FILE *outfile, struct fw_mmap *mmap, struct csum_state *css)
        mh->count=0;
 
        /* Build user data section */
-       data = buf+sizeof(*mh);
+       data = (char *)buf + sizeof(*mh);
        data += sprintf(data, "Vendor 1 %d", board->vendor);
        *data++ = '\0';
        data += sprintf(data, "Model 1 %d", BE16_TO_HOST(board->model));
@@ -687,7 +684,7 @@ write_out_file(FILE *outfile, char *name, size_t len, struct csum_state *css)
        FILE *f;
        int res;
 
-       DBG(2, "writing out file, name=%s, len=%d",
+       DBG(2, "writing out file, name=%s, len=%zu",
                name, len);
 
        errno = 0;
@@ -921,7 +918,6 @@ parse_opt_block(char ch, char *arg)
 {
        char buf[MAX_ARG_LEN];
        char *argv[MAX_ARG_COUNT];
-       int argc;
        char *p;
        struct fw_block *block;
        int i;
@@ -950,7 +946,7 @@ parse_opt_block(char ch, char *arg)
                break;
        }
 
-       argc = parse_arg(arg, buf, argv);
+       parse_arg(arg, buf, argv);
 
        i = 0;
        p = argv[i++];
@@ -988,7 +984,7 @@ calc_block_offsets(int type, uint32_t *offset)
        uint32_t avail;
        int i, res;
 
-       DBG(1,"calculating block offsets, starting with %lu",
+       DBG(1,"calculating block offsets, starting with %" PRIu32,
                *offset);
 
        res = 0;
@@ -999,12 +995,13 @@ calc_block_offsets(int type, uint32_t *offset)
                        continue;
 
                next_offs = ALIGN(*offset, block->align);
-               avail = board->flash_size - board->romio_offs - next_offs;
+               avail = board->flash_size - next_offs;
                if (block->file_size > avail) {
                        ERR("file %s is too big, offset = %u, size=%u,"
-                               " align = %u", block->file_name,
+                               " avail = %u, align = %u", block->file_name,
                                (unsigned)next_offs,
                                (unsigned)block->file_size,
+                               (unsigned)avail,
                                (unsigned)block->align);
                        res = -1;
                        break;