-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickboot_gold3.cc
More file actions
124 lines (102 loc) · 3.82 KB
/
Copy pathquickboot_gold3.cc
File metadata and controls
124 lines (102 loc) · 3.82 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
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
/*
* 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.
*/
/*
* Take in a raw .bit file from Xilinx tools and convert it into a
* .bit file that is ready for field installation into the flash.
*
* NOTE: This program is NOT needed to prepare .bit file for input to
* the quickboot_builder3 program. Only use this program if you are
* NOT using the quickboot_builder3 program to prepare the gold image.
*/
# include "read_bit_file.h"
# include "replace_register_write.h"
# include "disable_stream_crc.h"
# include <vector>
# include <cstdio>
# include <cstdint>
# include <cstdlib>
# include <cstring>
# include <cassert>
using namespace std;
int main(int argc, char*argv[])
{
const char*path_out = 0;
const char*path_raw = 0;
for (int optarg = 1 ; optarg < argc ; optarg += 1) {
if (strncmp(argv[optarg], "--output=",9) == 0) {
path_out = argv[optarg] + 9;
} else if (strncmp(argv[optarg], "--raw=",6) == 0) {
path_raw = argv[optarg] + 6;
} else {
fprintf(stderr, "Unknown flag: %s\n", argv[optarg]);
return -1;
}
}
if (path_out == 0) {
fprintf(stderr, "No output file? Please specify --output=<path>\n");
return -1;
}
if (path_raw == 0) {
fprintf(stderr, "No raw input file? Please specify --raw=<path>\n");
return -1;
}
// Read the raw file, strip any header, and be ready.
FILE*fd_raw = fopen(path_raw, "rb");
if (fd_raw == 0) {
fprintf(stderr, "Unable to open raw file: %s\n", path_raw);
return -1;
}
fprintf(stdout, "Reading raw file: %s\n", path_raw);
fflush(stdout);
vector<uint8_t> vec_raw;
read_bit_file(vec_raw, fd_raw, 256+32);
if (vec_raw.size() == 0)
return -1;
fclose(fd_raw);
fd_raw = 0;
const uint32_t AXSS_old = replace_register_write(vec_raw, 0x0d, 0x474f4c44);
if (AXSS_old == 0) {
fprintf(stdout, "WARNING : AXSS is not present in source stream.\n");
} else if (AXSS_old == 0x53494c56) { // SILV
// Replace SILV with GOLD
fprintf(stdout, "... AXSS (gold): 0x474f4c44 (was: 0x%08x)\n", AXSS_old);
} else if ((AXSS_old & 0xff000000) == 0x53000000) { // S...
// Replace a leading S with G
uint32_t AXSS_target = (AXSS_old & 0x00ffffff) | 0x47000000;
replace_register_write(vec_raw, 0x0d, AXSS_target);
fprintf(stdout, "... AXSS (gold): 0x%08x (was: 0x%08x)\n", AXSS_target, AXSS_old);
}
// Edit the silver stream BSPI register value.
uint32_t BSPI = replace_register_write(vec_raw, 0x1f, 0x0c);
fprintf(stdout, "BSPI: 0x00000c (was: 0x%08x)\n", BSPI);
/* Gold images have the CRC disabled. */
while (disable_stream_crc(vec_raw)) {
/* repeat */
}
FILE*fd_out = fopen(path_out, "wb");
if (fd_out == 0) {
fprintf(stderr, "Unable to open output file: %s\n", path_out);
return -1;
}
size_t rc = fwrite(&vec_raw[0], 1, vec_raw.size(), fd_out);
assert(rc == vec_raw.size());
fclose(fd_out);
return 0;
}