12
12
#include "boot.h" // boot_add_cbfs
13
13
#include "disk.h" // MAXDESCSIZE
14
14
#include "config.h" // CONFIG_*
15
#include "acpi.h" // find_acpi_features
16
#include "pci.h" // pci_probe_devices
17
#include "paravirt.h" // PlatformRunningOn
17
20
/****************************************************************
146
u64 maxram = 0, maxram_over4G = 0;
147
152
int i, count = MEM_RANGE_COUNT(cbm);
148
153
for (i=0; i<count; i++) {
149
154
struct cb_memory_range *m = &cbm->map[i];
150
155
u32 type = m->type;
151
if (type == CB_MEM_TABLE) {
156
if (type == CB_MEM_TABLE)
152
157
type = E820_RESERVED;
153
} else if (type == E820_ACPI || type == E820_RAM) {
154
u64 end = m->start + m->size;
155
if (end > 0x100000000ull) {
156
end -= 0x100000000ull;
157
if (end > maxram_over4G)
159
} else if (end > maxram)
162
158
add_e820(m->start, m->size, type);
166
RamSizeOver4G = maxram_over4G;
168
161
// Ughh - coreboot likes to set a map at 0x0000-0x1000, but this
169
162
// confuses grub. So, override it.
170
163
add_e820(0, 16*1024, E820_RAM);
174
167
CBvendor = &cbmb->strings[cbmb->vendor_idx];
175
168
CBpart = &cbmb->strings[cbmb->part_idx];
169
if (strcmp(CBvendor, "Emulation") == 0 &&
170
memcmp(CBpart, "QEMU", 4) == 0) {
171
PlatformRunningOn |= PF_QEMU;
176
173
dprintf(1, "Found mainboard %s %s\n", CBvendor, CBpart);
207
coreboot_copy_biostable(void)
202
coreboot_platform_setup(void)
204
if (!CONFIG_COREBOOT)
209
208
struct cb_memory *cbm = CBMemTable;
210
if (! CONFIG_COREBOOT || !cbm)
213
212
dprintf(3, "Relocating coreboot bios tables\n");
290
291
char filename[0];
294
struct cbfs_romfile_s {
295
struct romfile_s file;
296
struct cbfs_file *fhdr;
293
301
// Copy a file to memory (uncompressing if necessary)
295
303
cbfs_copyfile(struct romfile_s *file, void *dst, u32 maxlen)
297
if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH)
305
if (!CONFIG_COREBOOT_FLASH)
300
u32 size = file->rawsize;
301
void *src = file->data;
308
struct cbfs_romfile_s *cfile;
309
cfile = container_of(file, struct cbfs_romfile_s, file);
310
u32 size = cfile->rawsize;
311
void *src = cfile->data;
303
313
// Compressed - copy to temp ram and uncompress it.
304
314
void *temp = malloc_tmphigh(size);
338
348
dprintf(1, "Found CBFS header at %p\n", hdr);
340
struct cbfs_file *cfile = (void *)(0 - be32_to_cpu(hdr->romsize)
341
+ be32_to_cpu(hdr->offset));
350
struct cbfs_file *fhdr = (void *)(0 - be32_to_cpu(hdr->romsize)
351
+ be32_to_cpu(hdr->offset));
343
if (cfile < (struct cbfs_file *)(0xFFFFFFFF - be32_to_cpu(hdr->romsize)))
353
if (fhdr < (struct cbfs_file *)(0xFFFFFFFF - be32_to_cpu(hdr->romsize)))
345
u64 magic = cfile->magic;
355
u64 magic = fhdr->magic;
346
356
if (magic != CBFS_FILE_MAGIC)
348
struct romfile_s *file = malloc_tmp(sizeof(*file));
358
struct cbfs_romfile_s *cfile = malloc_tmp(sizeof(*cfile));
353
memset(file, 0, sizeof(*file));
354
strtcpy(file->name, cfile->filename, sizeof(file->name));
355
dprintf(3, "Found CBFS file: %s\n", file->name);
356
file->size = file->rawsize = be32_to_cpu(cfile->len);
357
file->id = (u32)cfile;
358
file->copy = cbfs_copyfile;
359
file->data = (void*)cfile + be32_to_cpu(cfile->offset);
360
int len = strlen(file->name);
361
if (len > 5 && strcmp(&file->name[len-5], ".lzma") == 0) {
363
memset(cfile, 0, sizeof(*cfile));
364
strtcpy(cfile->file.name, fhdr->filename, sizeof(cfile->file.name));
365
cfile->file.size = cfile->rawsize = be32_to_cpu(fhdr->len);
367
cfile->file.copy = cbfs_copyfile;
368
cfile->data = (void*)fhdr + be32_to_cpu(fhdr->offset);
369
int len = strlen(cfile->file.name);
370
if (len > 5 && strcmp(&cfile->file.name[len-5], ".lzma") == 0) {
362
371
// Using compression.
364
file->name[len-5] = '\0';
365
file->size = *(u32*)(file->data + LZMA_PROPERTIES_SIZE);
373
cfile->file.name[len-5] = '\0';
374
cfile->file.size = *(u32*)(cfile->data + LZMA_PROPERTIES_SIZE);
376
romfile_add(&cfile->file);
369
cfile = (void*)ALIGN((u32)file->data + file->size, be32_to_cpu(hdr->align));
378
fhdr = (void*)ALIGN((u32)cfile->data + cfile->file.size
379
, be32_to_cpu(hdr->align));
393
cbfs_run_payload(struct cbfs_file *file)
403
cbfs_run_payload(struct cbfs_file *fhdr)
395
if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH || !file)
405
if (!CONFIG_COREBOOT_FLASH || !fhdr)
397
dprintf(1, "Run %s\n", file->filename);
398
struct cbfs_payload *pay = (void*)file + be32_to_cpu(file->offset);
407
dprintf(1, "Run %s\n", fhdr->filename);
408
struct cbfs_payload *pay = (void*)fhdr + be32_to_cpu(fhdr->offset);
399
409
struct cbfs_payload_segment *seg = pay->segments;
401
411
void *src = (void*)pay + be32_to_cpu(seg->offset);
444
454
cbfs_payload_setup(void)
446
if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH)
456
if (!CONFIG_COREBOOT_FLASH)
448
458
struct romfile_s *file = NULL;
450
460
file = romfile_findprefix("img/", file);
463
struct cbfs_romfile_s *cfile;
464
cfile = container_of(file, struct cbfs_romfile_s, file);
453
465
const char *filename = file->name;
454
466
char *desc = znprintf(MAXDESCSIZE, "Payload [%s]", &filename[4]);
455
boot_add_cbfs((void*)file->id, desc
456
, bootprio_find_named_rom(filename, 0));
467
boot_add_cbfs(cfile->fhdr, desc, bootprio_find_named_rom(filename, 0));