Repository navigation
Expand file tree
/
Copy pathboot_loader.c
More file actions
250 lines (210 loc) · 5.51 KB
/
Copy pathboot_loader.c
File metadata and controls
250 lines (210 loc) · 5.51 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2016 Intel Corporation. All rights reserved.
//
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
#include <cavs/lib/pm_memory.h>
#include <sof/bit.h>
#include <sof/lib/cache.h>
#include <sof/lib/io.h>
#include <sof/lib/memory.h>
#include <sof/lib/shim.h>
#include <sof/lib/wait.h>
#include <sof/platform.h>
#include <sof/sof.h>
#include <sof/trace/trace.h>
#include <ipc/trace.h>
#include <rimage/sof/user/manifest.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#if CONFIG_SUECREEK
#define MANIFEST_BASE BOOT_LDR_MANIFEST_BASE
#else
#define MANIFEST_BASE IMR_BOOT_LDR_MANIFEST_BASE
#endif
#define MANIFEST_SEGMENT_COUNT 3
/* generic string compare cloned into the bootloader to
* compact code and make it more readable
*/
int strcmp(const char *s1, const char *s2)
{
while (*s1 != 0 && *s2 != 0) {
if (*s1 < *s2)
return -1;
if (*s1 > *s2)
return 1;
s1++;
s2++;
}
/* did both string end */
if (*s1 != 0)
return 1;
if (*s2 != 0)
return -1;
/* match */
return 0;
}
/* memcopy used by boot loader */
static inline void bmemcpy(void *dest, void *src, size_t bytes)
{
uint32_t *d = dest;
uint32_t *s = src;
int i;
for (i = 0; i < (bytes >> 2); i++)
d[i] = s[i];
dcache_writeback_region(dest, bytes);
}
/* bzero used by bootloader */
static inline void bbzero(void *dest, size_t bytes)
{
uint32_t *d = dest;
int i;
for (i = 0; i < (bytes >> 2); i++)
d[i] = 0;
dcache_writeback_region(dest, bytes);
}
static void parse_module(struct sof_man_fw_header *hdr,
struct sof_man_module *mod)
{
int i;
uint32_t bias;
/* each module has 3 segments */
for (i = 0; i < MANIFEST_SEGMENT_COUNT; i++) {
trace_point(TRACE_BOOT_LDR_PARSE_SEGMENT + i);
switch (mod->segment[i].flags.r.type) {
case SOF_MAN_SEGMENT_TEXT:
case SOF_MAN_SEGMENT_DATA:
bias = (mod->segment[i].file_offset -
SOF_MAN_ELF_TEXT_OFFSET);
/* copy from IMR to SRAM */
bmemcpy((void *)mod->segment[i].v_base_addr,
(void *)((int)hdr + bias),
mod->segment[i].flags.r.length *
HOST_PAGE_SIZE);
break;
case SOF_MAN_SEGMENT_BSS:
/* copy from IMR to SRAM */
bbzero((void *)mod->segment[i].v_base_addr,
mod->segment[i].flags.r.length *
HOST_PAGE_SIZE);
break;
default:
/* ignore */
break;
}
}
}
/* On Sue Creek the boot loader is attached separately, no need to skip it */
#if CONFIG_SUECREEK
#define MAN_SKIP_ENTRIES 0
#else
#define MAN_SKIP_ENTRIES 1
#endif
/* parse FW manifest and copy modules */
static void parse_manifest(void)
{
struct sof_man_fw_desc *desc =
(struct sof_man_fw_desc *)MANIFEST_BASE;
struct sof_man_fw_header *hdr = &desc->header;
struct sof_man_module *mod;
int i;
/* copy module to SRAM - skip bootloader module */
for (i = MAN_SKIP_ENTRIES; i < hdr->num_module_entries; i++) {
trace_point(TRACE_BOOT_LDR_PARSE_MODULE + i);
mod = (struct sof_man_module *)((char *)desc +
SOF_MAN_MODULE_OFFSET(i));
parse_module(hdr, mod);
}
}
#if PLATFORM_MEM_INIT_AT_BOOT
static uint32_t get_fw_size_in_use(void)
{
struct sof_man_fw_desc *desc =
(struct sof_man_fw_desc *)MANIFEST_BASE;
struct sof_man_fw_header *hdr = &desc->header;
struct sof_man_module *mod;
uint32_t fw_size_in_use = 0xffffffff;
int i;
/* Calculate fw size passed in BASEFW module in MANIFEST */
for (i = MAN_SKIP_ENTRIES; i < hdr->num_module_entries; i++) {
trace_point(TRACE_BOOT_LDR_PARSE_MODULE + i);
mod = (struct sof_man_module *)((char *)desc +
SOF_MAN_MODULE_OFFSET(i));
if (strcmp((char *)mod->name, "BASEFW"))
continue;
for (i = 0; i < MANIFEST_SEGMENT_COUNT; i++) {
if (mod->segment[i].flags.r.type
== SOF_MAN_SEGMENT_BSS) {
fw_size_in_use = mod->segment[i].v_base_addr
- HP_SRAM_BASE
+ (mod->segment[i].flags.r.length
* HOST_PAGE_SIZE);
}
}
}
return fw_size_in_use;
}
static uint32_t hp_sram_power_memory(uint32_t memory_size, bool enable)
{
uint32_t start_bank;
uint32_t end_bank;
uint32_t ebb_in_use;
/* calculate total number of used SRAM banks (EBB)
* to power up only necessary banks
*/
ebb_in_use = DIV_ROUND_UP(memory_size, SRAM_BANK_SIZE);
start_bank = enable ? 0 : ebb_in_use;
end_bank = (enable ? ebb_in_use : PLATFORM_HPSRAM_EBB_COUNT) - 1;
cavs_pm_memory_hp_sram_banks_power_gate(start_bank, end_bank, enable);
return 0;
}
static int32_t hp_sram_power_off_unused_banks(uint32_t memory_size)
{
/* keep enabled only memory banks used by FW */
return hp_sram_power_memory(memory_size, false);
}
static int32_t hp_sram_init(void)
{
return hp_sram_power_memory(HP_SRAM_SIZE, true);
}
#endif
/* boot primary core */
void boot_primary_core(void)
{
#if PLATFORM_MEM_INIT_AT_BOOT
int32_t result;
#endif
trace_point(TRACE_BOOT_LDR_ENTRY);
#if PLATFORM_MEM_INIT_AT_BOOT
/* init the HPSRAM */
trace_point(TRACE_BOOT_LDR_HPSRAM);
result = hp_sram_init();
if (result < 0) {
platform_panic(SOF_IPC_PANIC_MEM);
return;
}
#endif
#if CONFIG_LP_SRAM
/* init the LPSRAM */
trace_point(TRACE_BOOT_LDR_LPSRAM);
cavs_pm_memory_lp_sram_banks_power_gate(0,
PLATFORM_LPSRAM_EBB_COUNT - 1,
true);
#endif
#if CONFIG_L1_DRAM
/* Power ON L1 DRAM memory */
trace_point(TRACE_BOOT_LDR_L1DRAM);
cavs_pm_memory_l1_dram_banks_power_gate(CONFIG_L1_DRAM_MEMORY_BANKS - 1,
0, true);
#endif
/* parse manifest and copy modules */
trace_point(TRACE_BOOT_LDR_MANIFEST);
parse_manifest();
#if PLATFORM_MEM_INIT_AT_BOOT
hp_sram_power_off_unused_banks(get_fw_size_in_use());
#endif
/* now call SOF entry */
trace_point(TRACE_BOOT_LDR_JUMP);
_ResetVector();
}