From 8cf2586c6d6319111126c0aec83e262acdd45d9b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 9 Apr 2021 10:43:07 +0200 Subject: [PATCH] firmware-utils: fix -Wpointer-sign warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Rafał Miłecki --- src/add_header.c | 2 +- src/cyg_crc.h | 12 ++++++------ src/cyg_crc16.c | 3 ++- src/cyg_crc32.c | 10 ++++++---- src/dns313-header.c | 8 +++++--- src/fw.h | 8 ++++---- src/mkbrnimg.c | 7 ++++--- src/mkcasfw.c | 15 ++++++++++----- src/mkcsysimg.c | 15 ++++++++++----- src/mkmylofw.c | 8 +++++--- src/mkrtn56uimg.c | 2 +- src/mkwrggimg.c | 2 +- src/mkwrgimg.c | 2 +- src/mkzynfw.c | 16 ++++++++++------ src/sha1.c | 3 ++- src/sha1.h | 2 +- src/spw303v.c | 6 ++++-- src/xorimage.c | 14 ++++++++------ 18 files changed, 81 insertions(+), 54 deletions(-) diff --git a/src/add_header.c b/src/add_header.c index 37775c3..726e54c 100644 --- a/src/add_header.c +++ b/src/add_header.c @@ -65,7 +65,7 @@ static uint32_t crc32buf(unsigned char *buf, size_t len) } struct header { - unsigned char model[16]; + char model[16]; uint32_t crc; }; diff --git a/src/cyg_crc.h b/src/cyg_crc.h index 7b59803..6866971 100644 --- a/src/cyg_crc.h +++ b/src/cyg_crc.h @@ -74,34 +74,34 @@ typedef uint16_t cyg_uint16; // Compute a CRC, using the POSIX 1003 definition __externC cyg_uint32 -cyg_posix_crc32(unsigned char *s, int len); +cyg_posix_crc32(void *s, int len); // Gary S. Brown's 32 bit CRC __externC cyg_uint32 -cyg_crc32(unsigned char *s, int len); +cyg_crc32(void *s, int len); // Gary S. Brown's 32 bit CRC, but accumulate the result from a // previous CRC calculation __externC cyg_uint32 -cyg_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len); +cyg_crc32_accumulate(cyg_uint32 crc, void *s, int len); // Ethernet FCS Algorithm __externC cyg_uint32 -cyg_ether_crc32(unsigned char *s, int len); +cyg_ether_crc32(void *s, int len); // Ethernet FCS algorithm, but accumulate the result from a previous // CRC calculation. __externC cyg_uint32 -cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len); +cyg_ether_crc32_accumulate(cyg_uint32 crc, void *s, int len); // 16 bit CRC with polynomial x^16+x^12+x^5+1 __externC cyg_uint16 -cyg_crc16(unsigned char *s, int len); +cyg_crc16(void *s, int len); #endif // _SERVICES_CRC_CRC_H_ diff --git a/src/cyg_crc16.c b/src/cyg_crc16.c index 8b37352..3861ff0 100644 --- a/src/cyg_crc16.c +++ b/src/cyg_crc16.c @@ -96,8 +96,9 @@ static const cyg_uint16 crc16_tab[] = { }; cyg_uint16 -cyg_crc16(unsigned char *buf, int len) +cyg_crc16(void *ptr, int len) { + unsigned char *buf = ptr; int i; cyg_uint16 cksum; diff --git a/src/cyg_crc32.c b/src/cyg_crc32.c index 9462598..f13221e 100644 --- a/src/cyg_crc32.c +++ b/src/cyg_crc32.c @@ -127,8 +127,9 @@ static const cyg_uint32 crc32_tab[] = { /* This is the standard Gary S. Brown's 32 bit CRC algorithm, but accumulate the CRC into the result of a previous CRC. */ cyg_uint32 -cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len) +cyg_crc32_accumulate(cyg_uint32 crc32val, void *ptr, int len) { + unsigned char *s = ptr; int i; for (i = 0; i < len; i++) { @@ -139,7 +140,7 @@ cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len) /* This is the standard Gary S. Brown's 32 bit CRC algorithm */ cyg_uint32 -cyg_crc32(unsigned char *s, int len) +cyg_crc32(void *s, int len) { return (cyg_crc32_accumulate(0,s,len)); } @@ -148,8 +149,9 @@ cyg_crc32(unsigned char *s, int len) result from a previous CRC calculation. This uses the Ethernet FCS algorithm.*/ cyg_uint32 -cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len) +cyg_ether_crc32_accumulate(cyg_uint32 crc32val, void *ptr, int len) { + unsigned char *s = ptr; int i; if (s == 0) return 0L; @@ -164,7 +166,7 @@ cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len) /* Return a 32-bit CRC of the contents of the buffer, using the Ethernet FCS algorithm. */ cyg_uint32 -cyg_ether_crc32(unsigned char *s, int len) +cyg_ether_crc32(void *s, int len) { return cyg_ether_crc32_accumulate(0,s,len); } diff --git a/src/dns313-header.c b/src/dns313-header.c index c5c70e1..42dd677 100644 --- a/src/dns313-header.c +++ b/src/dns313-header.c @@ -102,9 +102,11 @@ static const uint32_t crc32_table[256] = { }; static uint32_t crc32(uint32_t crc, - const unsigned char *buf, + const void *data, unsigned int len) { + const uint8_t *buf = data; + crc = crc ^ 0xffffffffUL; do { crc = crc32_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); @@ -112,7 +114,7 @@ static uint32_t crc32(uint32_t crc, return crc ^ 0xffffffffUL; } -static void be_wr(unsigned char *buf, uint32_t val) +static void be_wr(char *buf, uint32_t val) { buf[0] = (val >> 24) & 0xFFU; buf[1] = (val >> 16) & 0xFFU; @@ -129,7 +131,7 @@ int main(int argc, char **argv) int ret = 0; const char *pathin; const char *pathout; - unsigned char *buffer; + char *buffer; uint32_t sum; size_t bufsize; size_t bytes; diff --git a/src/fw.h b/src/fw.h index 778143d..c8fb99b 100644 --- a/src/fw.h +++ b/src/fw.h @@ -31,15 +31,15 @@ #define PART_NAME_LENGTH 16 typedef struct header { - uint8_t magic[MAGIC_LENGTH]; - uint8_t version[256]; + char magic[MAGIC_LENGTH]; + char version[256]; u_int32_t crc; u_int32_t pad; } __attribute__ ((packed)) header_t; typedef struct part { - uint8_t magic[MAGIC_LENGTH]; - uint8_t name[PART_NAME_LENGTH]; + char magic[MAGIC_LENGTH]; + char name[PART_NAME_LENGTH]; uint8_t pad[12]; u_int32_t memaddr; u_int32_t index; diff --git a/src/mkbrnimg.c b/src/mkbrnimg.c index b7a73ff..9cddda3 100644 --- a/src/mkbrnimg.c +++ b/src/mkbrnimg.c @@ -52,12 +52,13 @@ static void init_crc32() } } -static uint32_t crc32buf(unsigned char *buf, size_t len) +static uint32_t crc32buf(const void *buf, size_t len) { uint32_t crc = 0xFFFFFFFF; + const uint8_t *in = buf; - for (; len; len--, buf++) - crc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB); + for (; len; len--, in++) + crc = crc32[(uint8_t)crc ^ *in] ^ (crc >> BPB); return ~crc; } diff --git a/src/mkcasfw.c b/src/mkcasfw.c index 904000c..0e7aa17 100644 --- a/src/mkcasfw.c +++ b/src/mkcasfw.c @@ -463,8 +463,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) { @@ -524,8 +525,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); @@ -568,19 +571,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; diff --git a/src/mkcsysimg.c b/src/mkcsysimg.c index e156f79..0ddb54c 100644 --- a/src/mkcsysimg.c +++ b/src/mkcsysimg.c @@ -423,8 +423,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 +469,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); @@ -506,19 +509,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; diff --git a/src/mkmylofw.c b/src/mkmylofw.c index c049ce4..5722365 100644 --- a/src/mkmylofw.c +++ b/src/mkmylofw.c @@ -478,18 +478,20 @@ process_partitions(void) * routines to write data to the output file */ int -write_out_data(FILE *outfile, uint8_t *data, size_t len, uint32_t *crc) +write_out_data(FILE *outfile, void *data, size_t len, uint32_t *crc) { + uint8_t *ptr = data; + errno = 0; - fwrite(data, len, 1, outfile); + fwrite(ptr, len, 1, outfile); if (errno) { errmsg(1,"unable to write output file"); return -1; } if (crc) { - update_crc(data, len, crc); + update_crc(ptr, len, crc); } return 0; diff --git a/src/mkrtn56uimg.c b/src/mkrtn56uimg.c index b6c891b..689dc8b 100644 --- a/src/mkrtn56uimg.c +++ b/src/mkrtn56uimg.c @@ -67,7 +67,7 @@ typedef struct image_header { uint8_t ih_type; uint8_t ih_comp; union { - uint8_t ih_name[IH_NMLEN]; + char ih_name[IH_NMLEN]; asus_t asus; } tail; } image_header_t; diff --git a/src/mkwrggimg.c b/src/mkwrggimg.c index 9995b9a..d2c42b0 100644 --- a/src/mkwrggimg.c +++ b/src/mkwrggimg.c @@ -114,7 +114,7 @@ static void get_digest(struct wrgg03_header *header, char *data, int size) MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname)); MD5_Update(&ctx, data, size); - MD5_Final(header->digest, &ctx); + MD5_Final((unsigned char *)header->digest, &ctx); } int main(int argc, char *argv[]) diff --git a/src/mkwrgimg.c b/src/mkwrgimg.c index 3915d14..6ba2fd1 100644 --- a/src/mkwrgimg.c +++ b/src/mkwrgimg.c @@ -100,7 +100,7 @@ static void get_digest(struct wrg_header *header, char *data, int size) MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname)); MD5_Update(&ctx, data, size); - MD5_Final(header->digest, &ctx); + MD5_Final((unsigned char *)header->digest, &ctx); } int main(int argc, char *argv[]) diff --git a/src/mkzynfw.c b/src/mkzynfw.c index 2cd769d..365264c 100644 --- a/src/mkzynfw.c +++ b/src/mkzynfw.c @@ -444,8 +444,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; @@ -499,19 +501,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; @@ -541,7 +545,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; @@ -611,7 +615,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)); diff --git a/src/sha1.c b/src/sha1.c index 3ab1332..40cc78c 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -225,8 +225,9 @@ void sha1_process( sha1_context *ctx, uchar data[64] ) ctx->state[4] += E; } -void sha1_update( sha1_context *ctx, uchar *input, uint length ) +void sha1_update( sha1_context *ctx, void *data, uint length ) { + uchar *input = data; ulong left, fill; if( ! length ) return; diff --git a/src/sha1.h b/src/sha1.h index 425267a..990a527 100644 --- a/src/sha1.h +++ b/src/sha1.h @@ -26,7 +26,7 @@ sha1_context; * Core SHA-1 functions */ void sha1_starts( sha1_context *ctx ); -void sha1_update( sha1_context *ctx, uchar *input, uint length ); +void sha1_update( sha1_context *ctx, void *input, uint length ); void sha1_finish( sha1_context *ctx, uchar digest[20] ); /* diff --git a/src/spw303v.c b/src/spw303v.c index 9638b80..980f41d 100644 --- a/src/spw303v.c +++ b/src/spw303v.c @@ -117,10 +117,12 @@ static char fake_data[] = { }; -uint32_t crc32(uint32_t crc, uint8_t *data, size_t len) +uint32_t crc32(uint32_t crc, const void *data, size_t len) { + const uint8_t *in = data; + while (len--) - crc = (crc >> 8) ^ crc32tab[(crc ^ *data++) & 0xFF]; + crc = (crc >> 8) ^ crc32tab[(crc ^ *in++) & 0xFF]; return crc; } diff --git a/src/xorimage.c b/src/xorimage.c index 4d1cd2d..e13531a 100644 --- a/src/xorimage.c +++ b/src/xorimage.c @@ -29,15 +29,17 @@ static char default_pattern[] = "12345678"; static int is_hex_pattern; -int xor_data(uint8_t *data, size_t len, const uint8_t *pattern, int p_len, int p_off) +int xor_data(void *data, size_t len, const void *pattern, int p_len, int p_off) { - int offset = p_off; + const uint8_t *key = pattern; + uint8_t *d = data; + while (len--) { - *data ^= pattern[offset]; - data++; - offset = (offset + 1) % p_len; + *d ^= key[p_off]; + d++; + p_off = (p_off + 1) % p_len; } - return offset; + return p_off; } -- 2.30.2