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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
extern int tb_console_init(void);
extern char __image_copy_end[];
extern void __NO_RETURN tb_boot_linux(uintptr_t ep, uintptr_t fw_arg);
extern uintptr_t tb_dtb_relocate(uintptr_t dtb, void *scratch,
size_t scratch_size, size_t grow);
extern int tb_dtb_add_chosen_prop(uintptr_t dtb, const char *name,
const void *val, size_t len);
static size_t initrd_size;
void tashaboot_main(uintptr_t fw_arg)
{
struct tb_image img;
int ret;
if (tb_console_init())
return;
dprintf(ALWAYS, "tashaboot " TB_VERSION "\n");
{
extern int tb_mmu_enable(void);
extern int tb_mmu_selftest(void);
extern void tb_mmu_disable(void);
if (tb_mmu_enable() == 0) {
if (tb_mmu_selftest() == 0)
dprintf(ALWAYS, "mmu: identity map on\n");
else
dprintf(ALWAYS, "mmu: self test failed, "
"running unmapped\n");
tb_mmu_disable();
}
}
{
extern int tb_dtb_patch_memory(uintptr_t dtb,
uint64_t base,
uint64_t size);
int r;
r = 0; (void)r;
{
uint32_t *cells = (uint32_t *)(fw_arg + 0x16c);
int i;
dprintf(ALWAYS, "cells after:");
for (i = 0; i < 4; i++)
dprintf(ALWAYS, " %08x", cells[i]);
dprintf(ALWAYS, "\n");
}
}
{
extern unsigned long *tb_spin_gates_ptr;
extern int tb_dtb_patch_spin_table(uintptr_t dtb,
uintptr_t *gates,
int ngates);
int n;
if (tb_spin_gates_ptr) {
extern unsigned char tb_pen_stamps[8];
int c;
n = tb_dtb_patch_spin_table(fw_arg,
tb_spin_gates_ptr, 8);
dprintf(ALWAYS, "dtb: %d release addrs patched\n", n);
for (c = 1; c < 8; c++) {
if (tb_pen_stamps[c])
break;
}
dprintf(ALWAYS, "pen: %s\n",
c < 8 ? "secondaries waiting" :
"no secondaries parked");
}
}
ret = tb_load_semihosting(TB_BOOTFILE, TB_LOAD_ADDR, &img);
if (ret) {
dprintf(ALWAYS, "load failed (%d), halting\n", ret);
platform_halt();
}
{
uint8_t *dtb_scratch = (uint8_t *)0x45000000ULL;
uintptr_t newdtb;
newdtb = tb_dtb_relocate(fw_arg, dtb_scratch,
0x10000, 0x200);
if (!newdtb) {
dprintf(ALWAYS, "dtb: relocate failed\n");
platform_halt();
}
fw_arg = newdtb;
}
{
int r = tb_load_raw(TB_INITRD_FILE, TB_INITRD_ADDR,
&initrd_size);
if (r == 0)
dprintf(ALWAYS, "initrd at %lx, %lx bytes\n",
(unsigned long)TB_INITRD_ADDR,
(unsigned long)initrd_size);
else
dprintf(ALWAYS, "no initrd (%d)\n", r);
}
{
uint8_t start_cells[8], end_cells[8];
uint64_t start = TB_INITRD_ADDR;
uint64_t end = TB_INITRD_ADDR + initrd_size;
int a, b;
for (int i = 0; i < 8; i++) {
start_cells[i] = (uint8_t)(start >> (56 - 8 * i));
end_cells[i] = (uint8_t)(end >> (56 - 8 * i));
}
a = tb_dtb_add_chosen_prop(fw_arg, "linux,initrd-start",
start_cells, 8);
b = tb_dtb_add_chosen_prop(fw_arg, "linux,initrd-end",
end_cells, 8);
dprintf(ALWAYS, "dtb: initrd props %d %d\n", a, b);
}
dprintf(ALWAYS, "loaded %llu bytes at %lx, entry %lx\n",
(unsigned long long)img.size, img.load, img.ep);
dprintf(ALWAYS, "jumping\n");
tb_boot_linux(img.ep, fw_arg);
}
|