make style

This commit is contained in:
Philippe Teuwen 2019-03-10 00:00:59 +01:00
parent 0d9223a547
commit 0373696662
483 changed files with 56514 additions and 52451 deletions

View file

@ -59,7 +59,7 @@ static void usage(void)
static voidpf fpga_deflate_malloc(voidpf opaque, uInt items, uInt size)
{
return calloc(items*size, sizeof(uint8_t));
return calloc(items * size, sizeof(uint8_t));
}
@ -101,24 +101,24 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
if (hardnested_mode) {
fprintf(stderr,
#if __WORDSIZE == 64
"Input file too big (> %" PRIu64 " bytes). This is probably not a hardnested bitflip state table.\n"
"Input file too big (> %" PRIu64 " bytes). This is probably not a hardnested bitflip state table.\n"
#else
"Input file too big (> %lu bytes). This is probably not a hardnested bitflip state table.\n"
"Input file too big (> %lu bytes). This is probably not a hardnested bitflip state table.\n"
#endif
, HARDNESTED_TABLE_SIZE);
, HARDNESTED_TABLE_SIZE);
} else {
fprintf(stderr, "Input files too big (total > %lu bytes). These are probably not PM3 FPGA config files.\n", num_infiles * FPGA_CONFIG_SIZE);
}
for(uint16_t j = 0; j < num_infiles; j++) {
for (uint16_t j = 0; j < num_infiles; j++) {
fclose(infile[j]);
}
free(fpga_config);
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
for(uint16_t j = 0; j < num_infiles; j++) {
for(uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
for (uint16_t j = 0; j < num_infiles; j++) {
for (uint16_t k = 0; k < FPGA_INTERLEAVE_SIZE; k++) {
c = (uint8_t)fgetc(infile[j]);
if (!feof(infile[j])) {
fpga_config[i++] = c;
@ -138,11 +138,11 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
compressed_fpga_stream.opaque = Z_NULL;
ret = deflateInit2(&compressed_fpga_stream,
COMPRESS_LEVEL,
Z_DEFLATED,
COMPRESS_WINDOW_BITS,
COMPRESS_MEM_LEVEL,
COMPRESS_STRATEGY);
COMPRESS_LEVEL,
Z_DEFLATED,
COMPRESS_WINDOW_BITS,
COMPRESS_MEM_LEVEL,
COMPRESS_STRATEGY);
// estimate the size of the compressed output
uint32_t outsize_max = deflateBound(&compressed_fpga_stream, compressed_fpga_stream.avail_in);
@ -152,10 +152,10 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
if (ret == Z_OK) {
ret = deflateTune(&compressed_fpga_stream,
COMPRESS_GOOD_LENGTH,
COMPRESS_MAX_LAZY,
COMPRESS_MAX_NICE_LENGTH,
COMPRESS_MAX_CHAIN);
COMPRESS_GOOD_LENGTH,
COMPRESS_MAX_LAZY,
COMPRESS_MAX_NICE_LENGTH,
COMPRESS_MAX_CHAIN);
}
if (ret == Z_OK) {
@ -168,14 +168,14 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
fprintf(stderr, "Error in deflate(): %d %s\n", ret, compressed_fpga_stream.msg);
free(outbuf);
deflateEnd(&compressed_fpga_stream);
for(uint16_t j = 0; j < num_infiles; j++) {
for (uint16_t j = 0; j < num_infiles; j++) {
fclose(infile[j]);
}
fclose(outfile);
free(infile);
free(fpga_config);
return(EXIT_FAILURE);
}
return (EXIT_FAILURE);
}
for (i = 0; i < compressed_fpga_stream.total_out; i++) {
fputc(outbuf[i], outfile);
@ -183,21 +183,21 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
free(outbuf);
deflateEnd(&compressed_fpga_stream);
for(uint16_t j = 0; j < num_infiles; j++) {
for (uint16_t j = 0; j < num_infiles; j++) {
fclose(infile[j]);
}
fclose(outfile);
free(infile);
free(fpga_config);
return(EXIT_SUCCESS);
return (EXIT_SUCCESS);
}
int zlib_decompress(FILE *infile, FILE *outfile)
{
#define DECOMPRESS_BUF_SIZE 1024
#define DECOMPRESS_BUF_SIZE 1024
uint8_t outbuf[DECOMPRESS_BUF_SIZE];
uint8_t inbuf[DECOMPRESS_BUF_SIZE];
int32_t ret;
@ -253,12 +253,12 @@ int zlib_decompress(FILE *infile, FILE *outfile)
}
fclose(outfile);
fclose(infile);
return(EXIT_SUCCESS);
return (EXIT_SUCCESS);
} else {
fprintf(stderr, "Error. Inflate() returned error %d, %s", ret, compressed_fpga_stream.msg);
fclose(outfile);
fclose(infile);
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
}
@ -273,7 +273,7 @@ int zlib_decompress(FILE *infile, FILE *outfile)
static int bitparse_find_section(FILE *infile, char section_name, unsigned int *section_length)
{
int result = 0;
#define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section
#define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section
uint16_t numbytes = 0;
while (numbytes < MAX_FPGA_BIT_STREAM_HEADER_SEARCH) {
char current_name = (char)fgetc(infile);
@ -284,15 +284,15 @@ static int bitparse_find_section(FILE *infile, char section_name, unsigned int *
}
unsigned int current_length = 0;
switch (current_name) {
case 'e':
/* Four byte length field */
current_length += fgetc(infile) << 24;
current_length += fgetc(infile) << 16;
numbytes += 2;
default: /* Fall through, two byte length field */
current_length += fgetc(infile) << 8;
current_length += fgetc(infile) << 0;
numbytes += 2;
case 'e':
/* Four byte length field */
current_length += fgetc(infile) << 24;
current_length += fgetc(infile) << 16;
numbytes += 2;
default: /* Fall through, two byte length field */
current_length += fgetc(infile) << 8;
current_length += fgetc(infile) << 0;
numbytes += 2;
}
if (current_name != 'e' && current_length > 255) {
@ -315,7 +315,7 @@ static int bitparse_find_section(FILE *infile, char section_name, unsigned int *
return result;
}
static int FpgaGatherVersion(FILE *infile, char* infile_name, char *dst, int len)
static int FpgaGatherVersion(FILE *infile, char *infile_name, char *dst, int len)
{
unsigned int fpga_info_len;
char tempstr[40] = {0x00};
@ -325,52 +325,53 @@ static int FpgaGatherVersion(FILE *infile, char* infile_name, char *dst, int len
for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
if (fgetc(infile) != bitparse_fixed_header[i]) {
fprintf(stderr, "Invalid FPGA file. Aborting...\n\n");
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
}
if (!memcmp("fpga_lf", basename(infile_name), 7))
strncat(dst, "LF", len-1);
strncat(dst, "LF", len - 1);
else if (!memcmp("fpga_hf", basename(infile_name), 7))
strncat(dst, "HF", len-1);
strncat(dst, "HF", len - 1);
strncat(dst, " image built", len-1);
strncat(dst, " image built", len - 1);
if (bitparse_find_section(infile, 'b', &fpga_info_len)) {
strncat(dst, " for ", len-1);
strncat(dst, " for ", len - 1);
for (uint16_t i = 0; i < fpga_info_len; i++) {
char c = (char)fgetc(infile);
if (i < sizeof(tempstr)) {
tempstr[i] = c;
}
}
strncat(dst, tempstr, len-1);
strncat(dst, tempstr, len - 1);
}
if (bitparse_find_section(infile, 'c', &fpga_info_len)) {
strncat(dst, " on ", len-1);
strncat(dst, " on ", len - 1);
for (uint16_t i = 0; i < fpga_info_len; i++) {
char c = (char)fgetc(infile);
if (i < sizeof(tempstr)) {
tempstr[i] = c;
}
}
strncat(dst, tempstr, len-1);
strncat(dst, tempstr, len - 1);
}
if (bitparse_find_section(infile, 'd', &fpga_info_len)) {
strncat(dst, " at ", len-1);
strncat(dst, " at ", len - 1);
for (uint16_t i = 0; i < fpga_info_len; i++) {
char c = (char)fgetc(infile);
if (i < sizeof(tempstr)) {
tempstr[i] = c;
}
}
strncat(dst, tempstr, len-1);
strncat(dst, tempstr, len - 1);
}
return 0;
}
static void print_version_info_preamble(FILE *outfile, int num_infiles) {
static void print_version_info_preamble(FILE *outfile, int num_infiles)
{
fprintf(outfile, "//-----------------------------------------------------------------------------\n");
fprintf(outfile, "// piwi, 2018\n");
fprintf(outfile, "//\n");
@ -388,7 +389,8 @@ static void print_version_info_preamble(FILE *outfile, int num_infiles) {
fprintf(outfile, "const char* const fpga_version_information[%d] = {\n", num_infiles);
}
static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int num_infiles, FILE *outfile) {
static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int num_infiles, FILE *outfile)
{
char version_string[80] = "";
@ -397,10 +399,10 @@ static int generate_fpga_version_info(FILE *infile[], char *infile_names[], int
for (int i = 0; i < num_infiles; i++) {
FpgaGatherVersion(infile[i], infile_names[i], version_string, sizeof(version_string));
fprintf(outfile, "\t\" %s\"", version_string);
if (i != num_infiles-1) {
if (i != num_infiles - 1) {
fprintf(outfile, ",");
}
fprintf(outfile,"\n");
fprintf(outfile, "\n");
}
fprintf(outfile, "};\n");
return 0;
@ -414,25 +416,25 @@ int main(int argc, char **argv)
if (argc == 1 || argc == 2) {
usage();
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
if (!strcmp(argv[1], "-d")) { // Decompress
infiles = calloc(1, sizeof(FILE*));
infiles = calloc(1, sizeof(FILE *));
if (argc != 4) {
usage();
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
infiles[0] = fopen(argv[2], "rb");
if (infiles[0] == NULL) {
fprintf(stderr, "Error. Cannot open input file %s\n\n", argv[2]);
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
outfile = fopen(argv[3], "wb");
if (outfile == NULL) {
fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[3]);
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
return zlib_decompress(infiles[0], outfile);
@ -444,38 +446,38 @@ int main(int argc, char **argv)
if (!strcmp(argv[1], "-t")) { // compress one hardnested table
if (argc != 4) {
usage();
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
hardnested_mode = true;
num_input_files = 1;
} else if (!strcmp(argv[1], "-v")) { // generate version info
generate_version_file = true;
num_input_files = argc-3;
num_input_files = argc - 3;
} else { // compress 1..n fpga files
num_input_files = argc-2;
num_input_files = argc - 2;
}
infiles = calloc(num_input_files, sizeof(FILE*));
infile_names = calloc(num_input_files, sizeof(char*));
infiles = calloc(num_input_files, sizeof(FILE *));
infile_names = calloc(num_input_files, sizeof(char *));
for (uint16_t i = 0; i < num_input_files; i++) {
infile_names[i] = argv[i+((hardnested_mode || generate_version_file)?2:1)];
infile_names[i] = argv[i + ((hardnested_mode || generate_version_file) ? 2 : 1)];
infiles[i] = fopen(infile_names[i], "rb");
if (infiles[i] == NULL) {
fprintf(stderr, "Error. Cannot open input file %s\n\n", infile_names[i]);
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
}
outfile = fopen(argv[argc-1], "wb");
outfile = fopen(argv[argc - 1], "wb");
if (outfile == NULL) {
fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[argc-1]);
return(EXIT_FAILURE);
fprintf(stderr, "Error. Cannot open output file %s\n\n", argv[argc - 1]);
return (EXIT_FAILURE);
}
if (generate_version_file) {
if (generate_fpga_version_info(infiles, infile_names, num_input_files, outfile)) {
return(EXIT_FAILURE);
return (EXIT_FAILURE);
}
} else {
return zlib_compress(infiles, num_input_files, outfile, hardnested_mode);
return zlib_compress(infiles, num_input_files, outfile, hardnested_mode);
}
}
}