-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathparse_ascii.c
139 lines (117 loc) · 3.02 KB
/
parse_ascii.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (c) 2019. Yizhou Shan. All rights reserved.
* Contact: syzwhat@gmail.com
*
* This file can parse the ultrascale+ bitstream files.
*/
#include <arpa/inet.h>
#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdbool.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define NR_BYTES_OF_ICAP (4)
#define REG_CRC 0
#define REG_FAR 1
#define REG_FDRI 2
/*
* This file can parse .rba and .rbt file
* They are ASICC files.
*/
int main(int argc, char **argv)
{
char *fname, *str_nr_words_to_parse;
int ret;
int i, nr_words, val;
FILE *fp;
char *line;
size_t len;
ssize_t nread;
bool p_idcode = false;
if (argc != 3) {
printf("Usage: ./parse bitstream.rba nr_icap_words\n");
exit(-1);
}
fname = argv[1];
str_nr_words_to_parse = argv[2];
fp = fopen(fname, "r");
if (!fp) {
printf("Fail to open: %s\n", fname);
exit(-1);
}
nr_words = atoi(str_nr_words_to_parse);
printf("File Name: %s\n", fname);
if (nr_words == -1) {
nr_words = INT_MAX;
}
len = 512;
line = malloc(len);
i = 0;
while (i < nr_words) {
nread = getline(&line, &len, fp);
if (nread == -1) {
goto done;
}
if (line[0] != '0' && line[0] != '1') {
continue;
}
val = strtol(line, NULL, 2);
//if (val != 0) {
if (1) {
printf("[%10d] %08x ", i, val);
/*
* Don't bother.
* Just keep it ugly.
*/
if (val == 0xaa995566) {
printf(" SYNC\n");
}
else if (val == 0x000000BB) {
printf("Bus Width Sync\n");
}
else if (val == 0x30002001) {
printf("Write to FAR\n");
}
else if (val == 0x28006000) {
printf("Read from FDRO\n");
}
else if (val == 0x30000001) {
printf("Write to CRC\n");
}
else if (val == 0x30018001) {
printf("Write to IDCODE\n");
p_idcode = true;
}
else if (val == 0x11220044) {
printf("Bus Width Detect\n");
}
else if (val == 0x30004000) {
printf("Write to FDRI\n");
}
else if (val == 0x30008001) {
printf("Write to CMD\n");
}
else if ((val & 0xf0000000) == 0x30000000) {
int regs;
regs = val & 0x0003E000;
regs = regs >> 13;
printf("Write to regs %d\n", regs);
}
else if (p_idcode) {
printf("IDCODE=%x\n", val & 0x0FFFFFFF);
p_idcode = false;
}
else {
printf("\n");
}
}
i++;
}
done:
return 0;
}