19 static int read_section(FILE *input_file,
int length_size,
char section,
20 uint32_t *buffer_length, uint8_t **
buffer)
22 uint8_t length_buffer[4];
27 if ((length_size != 2) && (length_size != 4)) {
28 LOG_ERROR(
"BUG: length_size neither 2 nor 4");
32 read_count = fread(§ion_char, 1, 1, input_file);
36 if (section_char != section)
39 read_count = fread(length_buffer, 1, length_size, input_file);
40 if (read_count != length_size)
63 struct stat input_stat;
66 if (!filename || !bit_file)
69 if (stat(filename, &input_stat) == -1) {
70 LOG_ERROR(
"couldn't stat() %s: %s", filename, strerror(errno));
74 if (S_ISDIR(input_stat.st_mode)) {
79 if (input_stat.st_size == 0) {
84 input_file = fopen(filename,
"rb");
86 LOG_ERROR(
"couldn't open %s: %s", filename, strerror(errno));
97 if (read_count != 13) {
98 LOG_ERROR(
"couldn't read unknown_header from file '%s'", filename);
145 free(bit_file->
date);
146 free(bit_file->
time);
147 free(bit_file->
data);
#define ERROR_COMMAND_SYNTAX_ERROR
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
#define ERROR_PLD_FILE_LOAD_FAILED
uint8_t unknown_header[13]
static uint32_t be_to_h_u32(const uint8_t *buf)
static uint16_t be_to_h_u16(const uint8_t *buf)
void xilinx_free_bit_file(struct xilinx_bit_file *bit_file)
int xilinx_read_bit_file(struct xilinx_bit_file *bit_file, const char *filename)
static int read_section(FILE *input_file, int length_size, char section, uint32_t *buffer_length, uint8_t **buffer)