-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickboot_gold.cc
More file actions
157 lines (126 loc) · 4.72 KB
/
Copy pathquickboot_gold.cc
File metadata and controls
157 lines (126 loc) · 4.72 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* 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 silver file and convert it to gold.
*/
# include "read_bit_file.h"
# include "replace_register_write.h"
# include "test_image_compat.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_silver = 0;
const char*id_text = 0;
bool bpi16_gen = false;
bool spi_gen = false;
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], "--silver=",9) == 0) {
path_silver = argv[optarg] + 9;
} else if (strcmp(argv[optarg],"--bpi16") == 0) {
bpi16_gen = true;
} else if (strcmp(argv[optarg],"--spi") == 0) {
spi_gen = true;
} else if (strncmp(argv[optarg],"--id=",5) == 0) {
id_text = argv[optarg] + 5;
} else {
fprintf(stderr, "Unknown flag: %s\n", argv[optarg]);
return -1;
}
}
if (spi_gen==false && bpi16_gen==false) {
fprintf(stderr, "BPI16 or SPI? Please specify --bpi16 or --spi\n");
return -1;
}
if (spi_gen && bpi16_gen) {
fprintf(stderr, "Please specify only one of --bpi16 or --spi\n");
return -1;
}
if (path_out == 0) {
fprintf(stderr, "No output file? Please specify --output=<path>\n");
return -1;
}
if (path_silver == 0) {
fprintf(stderr, "No silver file file? Please specify --silver=<path>\n");
return -1;
}
// Read the silver file, strip any header, and be ready.
FILE*fd_silver = fopen(path_silver, "rb");
if (fd_silver == 0) {
fprintf(stderr, "Unable to open silver file: %s\n", path_silver);
return -1;
}
fprintf(stdout, "Reading silver file: %s\n", path_silver);
fflush(stdout);
vector<uint8_t> vec_silver;
read_bit_file(vec_silver, fd_silver);
if (vec_silver.size() == 0)
return -1;
fclose(fd_silver);
fd_silver = 0;
if (! test_silver_image_compatible(vec_silver)) {
fprintf(stderr, "Silver file %s not compatible with Quickboot assembly.\n", path_silver);
return -1;
}
if (id_text) {
fprintf(stdout, "Writing id string \"%s\" into prefix\n", id_text);
memcpy(&vec_silver[0], id_text, strlen(id_text)+1);
}
const uint32_t AXSS_old = replace_register_write(vec_silver, 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_silver, 0x0d, AXSS_target);
fprintf(stdout, "... AXSS: 0x%08x (was: 0x%08x)\n", AXSS_target, AXSS_old);
}
if (bpi16_gen) {
uint32_t COR0 = replace_register_write(vec_silver, 0x09, 0x062055dc);
fprintf(stdout, "COR0 (gold): 0x062055dc (was: 0x%08x)\n", COR0);
uint32_t COR1 = replace_register_write(vec_silver, 0x0e, 0x0000000e);
fprintf(stdout, "COR1 (gold): 0x0000000e (was: 0x%08x)\n", COR1);
}
fprintf(stdout, "Disable CRC in gold stream (Replace CRC with Reset CRC)\n");
while (disable_stream_crc(vec_silver)) {
/* 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_silver[0], 1, vec_silver.size(), fd_out);
assert(rc == vec_silver.size());
fclose(fd_out);
return 0;
}