-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_image_compat.cc
More file actions
85 lines (70 loc) · 2.28 KB
/
Copy pathtest_image_compat.cc
File metadata and controls
85 lines (70 loc) · 2.28 KB
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
/*
* Copyright (c) 2017 Picture Elements, Inc.
* Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "test_image_compat.h"
# include "extract_register_write.h"
# include <cstdio>
using namespace std;
bool test_basic_image_compatibility(const std::vector<uint8_t>&vec)
{
const uint8_t magic_sync[4] = {0xaa, 0x99, 0x55, 0x66};
size_t match = 0;
size_t ptr = 0;
while (ptr < 0x100 && match < 4) {
if (vec[ptr+match] == magic_sync[match]) {
match += 1;
} else {
ptr += 1;
match = 0;
}
}
if (match < 4) {
fprintf(stderr, "Unable to find sync word in bit file.\n");
return false;
}
ptr += match;
const uint8_t magic_iprog[8] = {0x30, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x0f};
match = 0;
while (ptr < 0x100 && match < 8) {
if (vec[ptr+match] == magic_iprog[match]) {
match += 1;
} else {
ptr += 1;
match = 0;
}
}
if (match < 8) {
return true;
}
fprintf(stderr, "Found IPROG command in bit stream.\n");
return false;
}
bool test_silver_image_compatible(const std::vector<uint8_t>&vec)
{
if (!test_basic_image_compatibility(vec)) {
fprintf(stderr, "Silver image fails basic tests.\n");
return false;
}
uint32_t AXSS = extract_register_write(vec, 0x0d);
if (AXSS != 0x53494c56 && ((AXSS&0xff000000) != 0x53000000)) {
fprintf(stderr, "Found AXSS=0x%08x\n (s/b 0x53494c56)\n", AXSS);
return false;
}
return true;
}