+// 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>
#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)
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) {
}
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);
break;
case CSUM_TYPE_32:
ret = csum32_get(css);
+ break;
+ default:
+ ERR("invalid checksum size\n");
+ return 0;
}
return ret;
* 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;
/* 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);
res = write_out_data(outfile, (uint8_t *)&tmp.nfs,
sizeof(tmp.nfs), NULL);
break;
+ default:
+ ERR("invalid header type\n");
+ return -EINVAL;
}
return res;
int
write_out_images(FILE *outfile)
{
- struct image_desc *desc;
- int i, res;
+ int res;
res = image_writeout(outfile, &kernel_image);
if (res)
{
char buf[MAX_ARG_LEN];
char *argv[MAX_ARG_COUNT];
- int argc;
char *p;
struct image_desc *desc = NULL;
int i;
if (!desc)
return ERR_FATAL;
- argc = parse_arg(arg, buf, argv);
+ parse_arg(arg, buf, argv);
i = 0;
p = argv[i++];
int
process_images(void)
{
- struct image_desc *desc;
- uint32_t offs = 0;
- int i;
int res;
kernel_image.out_size = board->max_kernel_size;
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");