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
|
extern int tb_console_init(const void *dtb);
extern void __NO_RETURN tb_boot_linux(uintptr_t ep, const void *dtb);
static int tb_read_memory(const void *dtb, uintptr_t *base, uint32 *size)
{
const fdt32_t *prop;
int len;
int node;
node = fdt_path_offset(dtb, "/memory@40000000");
if (node < 0)
node = fdt_path_offset(dtb, "/memory");
if (node < 0)
return -1;
prop = fdt_getprop(dtb, node, "reg", &len);
if (!prop || len < 12)
return -1;
*base = ((uintptr_t)fdt32_to_cpu(prop[0]) << 32) |
fdt32_to_cpu(prop[1]);
*size = fdt32_to_cpu(prop[2]);
return 0;
}
static const char *tb_get_cmdline(const void *dtb)
{
const char *cmdline;
int len;
int node;
node = fdt_path_offset(dtb, "/chosen");
if (node < 0)
return NULL;
cmdline = fdt_getprop(dtb, node, "bootargs", &len);
if (!cmdline || len <= 0)
return NULL;
return cmdline;
}
static const char *tb_get_bootfile(const void *dtb)
{
const char *bootfile;
int len;
int node;
node = fdt_path_offset(dtb, "/chosen");
if (node < 0)
return NULL;
bootfile = fdt_getprop(dtb, node, "tashaboot,bootfile", &len);
if (!bootfile || len <= 0)
return NULL;
return bootfile;
}
void tashaboot_main(const void *dtb)
{
struct tb_image img;
uintptr_t mem_base = 0;
uint32 mem_size = 0;
const char *cmdline;
const char *bootfile;
int ret;
if (tb_console_init(dtb))
return;
dprintf(ALWAYS, "tashaboot " TB_VERSION "\n");
dprintf(ALWAYS, "dtb at %p\n", dtb);
if (fdt_check_header(dtb)) {
dprintf(ALWAYS, "bad dtb header, halting\n");
platform_halt();
}
if (tb_read_memory(dtb, &mem_base, &mem_size)) {
dprintf(ALWAYS, "no usable memory node, halting\n");
platform_halt();
}
dprintf(ALWAYS, "memory %lx-%lx\n", mem_base, mem_base + mem_size);
cmdline = tb_get_cmdline(dtb);
if (cmdline)
dprintf(ALWAYS, "cmdline: %s\n", cmdline);
if (!smh_probe()) {
dprintf(ALWAYS, "no semihosting host, halting\n");
platform_halt();
}
bootfile = tb_get_bootfile(dtb);
if (!bootfile)
bootfile = "Image";
ret = tb_load_semihosting(bootfile, TB_LOAD_ADDR, mem_base, mem_size, &img);
if (ret) {
dprintf(ALWAYS, "load failed (%d), halting\n", ret);
platform_halt();
}
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, dtb);
}
|