firmware-utils: fix -Wpointer-sign warnings

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: maurerr <mariusd84@gmail.com>
This commit is contained in:
Rafał Miłecki 2021-04-09 10:43:07 +02:00 committed by maurerr
parent 5cdc6ee3ce
commit ba160eaa66
18 changed files with 81 additions and 54 deletions

View File

@ -65,7 +65,7 @@ static uint32_t crc32buf(unsigned char *buf, size_t len)
} }
struct header { struct header {
unsigned char model[16]; char model[16];
uint32_t crc; uint32_t crc;
}; };

View File

@ -74,34 +74,34 @@ typedef uint16_t cyg_uint16;
// Compute a CRC, using the POSIX 1003 definition // Compute a CRC, using the POSIX 1003 definition
__externC cyg_uint32 __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 // Gary S. Brown's 32 bit CRC
__externC cyg_uint32 __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 // Gary S. Brown's 32 bit CRC, but accumulate the result from a
// previous CRC calculation // previous CRC calculation
__externC cyg_uint32 __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 // Ethernet FCS Algorithm
__externC cyg_uint32 __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 // Ethernet FCS algorithm, but accumulate the result from a previous
// CRC calculation. // CRC calculation.
__externC cyg_uint32 __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 // 16 bit CRC with polynomial x^16+x^12+x^5+1
__externC cyg_uint16 __externC cyg_uint16
cyg_crc16(unsigned char *s, int len); cyg_crc16(void *s, int len);
#endif // _SERVICES_CRC_CRC_H_ #endif // _SERVICES_CRC_CRC_H_

View File

@ -96,8 +96,9 @@ static const cyg_uint16 crc16_tab[] = {
}; };
cyg_uint16 cyg_uint16
cyg_crc16(unsigned char *buf, int len) cyg_crc16(void *ptr, int len)
{ {
unsigned char *buf = ptr;
int i; int i;
cyg_uint16 cksum; cyg_uint16 cksum;

View File

@ -127,8 +127,9 @@ static const cyg_uint32 crc32_tab[] = {
/* This is the standard Gary S. Brown's 32 bit CRC algorithm, but /* This is the standard Gary S. Brown's 32 bit CRC algorithm, but
accumulate the CRC into the result of a previous CRC. */ accumulate the CRC into the result of a previous CRC. */
cyg_uint32 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; int i;
for (i = 0; i < len; 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 */ /* This is the standard Gary S. Brown's 32 bit CRC algorithm */
cyg_uint32 cyg_uint32
cyg_crc32(unsigned char *s, int len) cyg_crc32(void *s, int len)
{ {
return (cyg_crc32_accumulate(0,s,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 result from a previous CRC calculation. This uses the Ethernet FCS
algorithm.*/ algorithm.*/
cyg_uint32 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; int i;
if (s == 0) return 0L; 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 /* Return a 32-bit CRC of the contents of the buffer, using the
Ethernet FCS algorithm. */ Ethernet FCS algorithm. */
cyg_uint32 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); return cyg_ether_crc32_accumulate(0,s,len);
} }

View File

@ -102,9 +102,11 @@ static const uint32_t crc32_table[256] = {
}; };
static uint32_t crc32(uint32_t crc, static uint32_t crc32(uint32_t crc,
const unsigned char *buf, const void *data,
unsigned int len) unsigned int len)
{ {
const uint8_t *buf = data;
crc = crc ^ 0xffffffffUL; crc = crc ^ 0xffffffffUL;
do { do {
crc = crc32_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); crc = crc32_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
@ -112,7 +114,7 @@ static uint32_t crc32(uint32_t crc,
return crc ^ 0xffffffffUL; 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[0] = (val >> 24) & 0xFFU;
buf[1] = (val >> 16) & 0xFFU; buf[1] = (val >> 16) & 0xFFU;
@ -129,7 +131,7 @@ int main(int argc, char **argv)
int ret = 0; int ret = 0;
const char *pathin; const char *pathin;
const char *pathout; const char *pathout;
unsigned char *buffer; char *buffer;
uint32_t sum; uint32_t sum;
size_t bufsize; size_t bufsize;
size_t bytes; size_t bytes;

View File

@ -31,15 +31,15 @@
#define PART_NAME_LENGTH 16 #define PART_NAME_LENGTH 16
typedef struct header { typedef struct header {
uint8_t magic[MAGIC_LENGTH]; char magic[MAGIC_LENGTH];
uint8_t version[256]; char version[256];
u_int32_t crc; u_int32_t crc;
u_int32_t pad; u_int32_t pad;
} __attribute__ ((packed)) header_t; } __attribute__ ((packed)) header_t;
typedef struct part { typedef struct part {
uint8_t magic[MAGIC_LENGTH]; char magic[MAGIC_LENGTH];
uint8_t name[PART_NAME_LENGTH]; char name[PART_NAME_LENGTH];
uint8_t pad[12]; uint8_t pad[12];
u_int32_t memaddr; u_int32_t memaddr;
u_int32_t index; u_int32_t index;

View File

@ -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; uint32_t crc = 0xFFFFFFFF;
const uint8_t *in = buf;
for (; len; len--, buf++) for (; len; len--, in++)
crc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB); crc = crc32[(uint8_t)crc ^ *in] ^ (crc >> BPB);
return ~crc; return ~crc;
} }

View File

@ -463,8 +463,9 @@ csum8_get(struct csum_state *css)
void 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; uint16_t t;
if (css->odd) { if (css->odd) {
@ -524,8 +525,10 @@ csum_init(struct csum_state *css, int size)
} }
void 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) { switch (css->size) {
case CSUM_TYPE_8: case CSUM_TYPE_8:
csum8_update(p,len,css); csum8_update(p,len,css);
@ -568,19 +571,21 @@ csum_get(struct csum_state *css)
* routines to write data to the output file * routines to write data to the output file
*/ */
int 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) struct csum_state *css)
{ {
uint8_t *ptr = data;
errno = 0; errno = 0;
fwrite(data, len, 1, outfile); fwrite(ptr, len, 1, outfile);
if (errno) { if (errno) {
ERRS("unable to write output file"); ERRS("unable to write output file");
return ERR_FATAL; return ERR_FATAL;
} }
if (css) { if (css) {
csum_update(data, len, css); csum_update(ptr, len, css);
} }
return 0; return 0;

View File

@ -423,8 +423,9 @@ csum8_get(struct csum_state *css)
void 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; uint16_t t;
if (css->odd) { if (css->odd) {
@ -468,8 +469,10 @@ csum_init(struct csum_state *css, int size)
void 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) { switch (css->size) {
case CSUM_SIZE_8: case CSUM_SIZE_8:
csum8_update(p,len,css); csum8_update(p,len,css);
@ -506,19 +509,21 @@ csum_get(struct csum_state *css)
* routines to write data to the output file * routines to write data to the output file
*/ */
int 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) struct csum_state *css)
{ {
uint8_t *ptr = data;
errno = 0; errno = 0;
fwrite(data, len, 1, outfile); fwrite(ptr, len, 1, outfile);
if (errno) { if (errno) {
ERRS("unable to write output file"); ERRS("unable to write output file");
return ERR_FATAL; return ERR_FATAL;
} }
if (css) { if (css) {
csum_update(data, len, css); csum_update(ptr, len, css);
} }
return 0; return 0;

View File

@ -478,18 +478,20 @@ process_partitions(void)
* routines to write data to the output file * routines to write data to the output file
*/ */
int 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; errno = 0;
fwrite(data, len, 1, outfile); fwrite(ptr, len, 1, outfile);
if (errno) { if (errno) {
errmsg(1,"unable to write output file"); errmsg(1,"unable to write output file");
return -1; return -1;
} }
if (crc) { if (crc) {
update_crc(data, len, crc); update_crc(ptr, len, crc);
} }
return 0; return 0;

View File

@ -67,7 +67,7 @@ typedef struct image_header {
uint8_t ih_type; uint8_t ih_type;
uint8_t ih_comp; uint8_t ih_comp;
union { union {
uint8_t ih_name[IH_NMLEN]; char ih_name[IH_NMLEN];
asus_t asus; asus_t asus;
} tail; } tail;
} image_header_t; } image_header_t;

View File

@ -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, (char *)&header->devname, sizeof(header->devname));
MD5_Update(&ctx, data, size); MD5_Update(&ctx, data, size);
MD5_Final(header->digest, &ctx); MD5_Final((unsigned char *)header->digest, &ctx);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -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, (char *)&header->devname, sizeof(header->devname));
MD5_Update(&ctx, data, size); MD5_Update(&ctx, data, size);
MD5_Final(header->digest, &ctx); MD5_Final((unsigned char *)header->digest, &ctx);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])

View File

@ -444,8 +444,10 @@ csum_init(struct csum_state *css)
void 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) if (len == 0)
return; return;
@ -499,19 +501,21 @@ csum_buf(uint8_t *p, uint32_t len)
* routines to write data to the output file * routines to write data to the output file
*/ */
int 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) struct csum_state *css)
{ {
uint8_t *ptr = data;
errno = 0; errno = 0;
fwrite(data, len, 1, outfile); fwrite(ptr, len, 1, outfile);
if (errno) { if (errno) {
ERR("unable to write output file"); ERR("unable to write output file");
return -1; return -1;
} }
if (css) { if (css) {
csum_update(data, len, css); csum_update(ptr, len, css);
} }
return 0; return 0;
@ -541,7 +545,7 @@ write_out_padding(FILE *outfile, size_t len, uint8_t padc,
int 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) struct csum_state *css)
{ {
size_t padlen; size_t padlen;
@ -611,7 +615,7 @@ write_out_mmap(FILE *outfile, struct fw_mmap *mmap, struct csum_state *css)
mh->count=0; mh->count=0;
/* Build user data section */ /* Build user data section */
data = buf+sizeof(*mh); data = (char *)buf + sizeof(*mh);
data += sprintf(data, "Vendor 1 %d", board->vendor); data += sprintf(data, "Vendor 1 %d", board->vendor);
*data++ = '\0'; *data++ = '\0';
data += sprintf(data, "Model 1 %d", BE16_TO_HOST(board->model)); data += sprintf(data, "Model 1 %d", BE16_TO_HOST(board->model));

View File

@ -225,8 +225,9 @@ void sha1_process( sha1_context *ctx, uchar data[64] )
ctx->state[4] += E; 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; ulong left, fill;
if( ! length ) return; if( ! length ) return;

View File

@ -26,7 +26,7 @@ sha1_context;
* Core SHA-1 functions * Core SHA-1 functions
*/ */
void sha1_starts( sha1_context *ctx ); 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] ); void sha1_finish( sha1_context *ctx, uchar digest[20] );
/* /*

View File

@ -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--) while (len--)
crc = (crc >> 8) ^ crc32tab[(crc ^ *data++) & 0xFF]; crc = (crc >> 8) ^ crc32tab[(crc ^ *in++) & 0xFF];
return crc; return crc;
} }

View File

@ -29,15 +29,17 @@ static char default_pattern[] = "12345678";
static int is_hex_pattern; 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--) { while (len--) {
*data ^= pattern[offset]; *d ^= key[p_off];
data++; d++;
offset = (offset + 1) % p_len; p_off = (p_off + 1) % p_len;
} }
return offset; return p_off;
} }