jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / pld / xilinx_bit.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /***************************************************************************
4 * Copyright (C) 2006 by Dominic Rath *
5 * Dominic.Rath@gmx.de *
6 ***************************************************************************/
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #include "xilinx_bit.h"
13 #include "pld.h"
14 #include <helper/log.h>
15
16 #include <helper/system.h>
17
18 static int read_section(FILE *input_file, int length_size, char section,
19 uint32_t *buffer_length, uint8_t **buffer)
20 {
21 uint8_t length_buffer[4];
22 int length;
23 char section_char;
24 int read_count;
25
26 if ((length_size != 2) && (length_size != 4)) {
27 LOG_ERROR("BUG: length_size neither 2 nor 4");
28 return ERROR_PLD_FILE_LOAD_FAILED;
29 }
30
31 read_count = fread(&section_char, 1, 1, input_file);
32 if (read_count != 1)
33 return ERROR_PLD_FILE_LOAD_FAILED;
34
35 if (section_char != section)
36 return ERROR_PLD_FILE_LOAD_FAILED;
37
38 read_count = fread(length_buffer, 1, length_size, input_file);
39 if (read_count != length_size)
40 return ERROR_PLD_FILE_LOAD_FAILED;
41
42 if (length_size == 4)
43 length = be_to_h_u32(length_buffer);
44 else /* (length_size == 2) */
45 length = be_to_h_u16(length_buffer);
46
47 if (buffer_length)
48 *buffer_length = length;
49
50 *buffer = malloc(length);
51
52 read_count = fread(*buffer, 1, length, input_file);
53 if (read_count != length)
54 return ERROR_PLD_FILE_LOAD_FAILED;
55
56 return ERROR_OK;
57 }
58
59 int xilinx_read_bit_file(struct xilinx_bit_file *bit_file, const char *filename)
60 {
61 FILE *input_file;
62 int read_count;
63
64 if (!filename || !bit_file)
65 return ERROR_COMMAND_SYNTAX_ERROR;
66
67 input_file = fopen(filename, "rb");
68 if (!input_file) {
69 LOG_ERROR("couldn't open %s: %s", filename, strerror(errno));
70 return ERROR_PLD_FILE_LOAD_FAILED;
71 }
72
73 bit_file->source_file = NULL;
74 bit_file->part_name = NULL;
75 bit_file->date = NULL;
76 bit_file->time = NULL;
77 bit_file->data = NULL;
78
79 read_count = fread(bit_file->unknown_header, 1, 13, input_file);
80 if (read_count != 13) {
81 LOG_ERROR("couldn't read unknown_header from file '%s'", filename);
82 fclose(input_file);
83 return ERROR_PLD_FILE_LOAD_FAILED;
84 }
85
86 if (read_section(input_file, 2, 'a', NULL, &bit_file->source_file) != ERROR_OK) {
87 xilinx_free_bit_file(bit_file);
88 fclose(input_file);
89 return ERROR_PLD_FILE_LOAD_FAILED;
90 }
91
92 if (read_section(input_file, 2, 'b', NULL, &bit_file->part_name) != ERROR_OK) {
93 xilinx_free_bit_file(bit_file);
94 fclose(input_file);
95 return ERROR_PLD_FILE_LOAD_FAILED;
96 }
97
98 if (read_section(input_file, 2, 'c', NULL, &bit_file->date) != ERROR_OK) {
99 xilinx_free_bit_file(bit_file);
100 fclose(input_file);
101 return ERROR_PLD_FILE_LOAD_FAILED;
102 }
103
104 if (read_section(input_file, 2, 'd', NULL, &bit_file->time) != ERROR_OK) {
105 xilinx_free_bit_file(bit_file);
106 fclose(input_file);
107 return ERROR_PLD_FILE_LOAD_FAILED;
108 }
109
110 if (read_section(input_file, 4, 'e', &bit_file->length, &bit_file->data) != ERROR_OK) {
111 xilinx_free_bit_file(bit_file);
112 fclose(input_file);
113 return ERROR_PLD_FILE_LOAD_FAILED;
114 }
115
116 LOG_DEBUG("bit_file: %s %s %s,%s %" PRIu32 "", bit_file->source_file, bit_file->part_name,
117 bit_file->date, bit_file->time, bit_file->length);
118
119 fclose(input_file);
120
121 return ERROR_OK;
122 }
123
124 void xilinx_free_bit_file(struct xilinx_bit_file *bit_file)
125 {
126 free(bit_file->source_file);
127 free(bit_file->part_name);
128 free(bit_file->date);
129 free(bit_file->time);
130 free(bit_file->data);
131 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)