Skip to content

Commit b49ecbe

Browse files
rizlikdanielinux
authored andcommitted
fsp: improve debugging
1 parent 8796af8 commit b49ecbe

7 files changed

Lines changed: 38 additions & 17 deletions

File tree

include/x86/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ void cpuid(uint32_t eax_param,
6666
uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
6767
int cpuid_is_1gb_page_supported();
6868
void switch_to_long_mode(uint64_t *entry, uint32_t page_table);
69+
void x86_log_memory_load(uint32_t start, uint32_t end, const char *name);
6970
#endif /* COMMON_H */

src/boot_x86_fsp.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,30 +200,34 @@ static int check_memory_ranges()
200200
static void load_wolfboot(void)
201201
{
202202
size_t wolfboot_size, bss_size;
203+
uint32_t wolfboot_start;
203204

204205
if (check_memory_ranges() != 0) {
205206
wolfBoot_printf("wolfboot overlaps with loader data...stop" ENDLINE);
206207
panic();
207208
}
208209

209-
wolfBoot_printf("loading wolfboot at %x..." ENDLINE,
210-
(uint32_t)WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE);
210+
wolfboot_start = (uint32_t)WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE;
211211
wolfboot_size = _wolfboot_flash_end - _wolfboot_flash_start;
212-
memcpy((uint8_t*)WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE,
213-
_wolfboot_flash_start, wolfboot_size);
212+
x86_log_memory_load(wolfboot_start, wolfboot_start + wolfboot_size,
213+
"wolfboot");
214+
memcpy((uint8_t*)wolfboot_start,_wolfboot_flash_start, wolfboot_size);
214215
bss_size = wb_end_bss - wb_start_bss;
216+
x86_log_memory_load((uint32_t)(uintptr_t)wb_start_bss,
217+
(uint32_t)(uintptr_t)(wb_start_bss + bss_size),
218+
"wolfboot .bss");
215219
memset(wb_start_bss, 0, bss_size);
216220
wolfBoot_printf("load wolfboot end" ENDLINE);
217221
}
218222

219223
static void load_fsp_s_to_ram(void)
220224
{
221225
size_t fsp_s_size;
222-
wolfBoot_printf("loading FSP_S at %x..." ENDLINE,
223-
(uint32_t)(FSP_S_LOAD_BASE - IMAGE_HEADER_SIZE));
226+
uint32_t fsp_start;
227+
fsp_start = FSP_S_LOAD_BASE - IMAGE_HEADER_SIZE;
224228
fsp_s_size = _end_fsp_s - _fsp_s_hdr;
225-
memcpy((uint8_t*)FSP_S_LOAD_BASE - IMAGE_HEADER_SIZE,
226-
_fsp_s_hdr, fsp_s_size);
229+
x86_log_memory_load(fsp_start, fsp_start + fsp_s_size, "FSPS");
230+
memcpy((uint8_t*)fsp_start, _fsp_s_hdr, fsp_s_size);
227231
}
228232

229233
/*!
@@ -252,8 +256,8 @@ static void jump_into_wolfboot(void)
252256
uint32_t cr3;
253257
int ret;
254258

255-
wolfBoot_printf("building identity map at %x...\r\n",
256-
(uint32_t)params->page_table);
259+
x86_log_memory_load((uint32_t)(uintptr_t)params->page_table,params->page_table + x86_paging_get_page_table_size(),
260+
"IdentityPageTablePage");
257261
ret = x86_paging_build_identity_mapping(MEMORY_4GB,
258262
(uint8_t*)(uintptr_t)params->page_table);
259263
if (ret != 0) {
@@ -334,11 +338,15 @@ static inline void memory_init_data_bss(void)
334338
{
335339
uint32_t *datamem_p;
336340
uint32_t *dataflash_p;
341+
x86_log_memory_load((uint32_t)(uintptr_t)_start_data,
342+
(uint32_t)(uintptr_t)_end_data, "stage1 .data");
337343
datamem_p = (uint32_t *)_start_data;
338344
dataflash_p = (uint32_t *)_stored_data;
339345
while(datamem_p < (uint32_t *)_end_data) {
340346
*(datamem_p++) = *(dataflash_p++);
341347
}
348+
x86_log_memory_load((uint32_t)(uintptr_t)_start_bss,
349+
(uint32_t)(uintptr_t)_end_bss, "stage1 .bss");
342350
memset(_start_bss, 0, (_end_bss - _start_bss));
343351
}
344352

@@ -696,6 +704,7 @@ void start(uint32_t stack_base, uint32_t stack_top, uint64_t timestamp,
696704
stage2_params->tpm_policy_size);
697705
#endif
698706

707+
wolfBoot_printf("TOLUM: 0x%x\r\n", stage2_params->tolum);
699708
/* change_stack_and_invoke() never returns.
700709
*
701710
* Execution here is eventually transferred to memory_ready_entry

src/elf.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#if defined(DEBUG) || defined(ELF_PARSER)
3737
#if DEBUG_ELF == 0
3838
#undef DEBUG_ELF
39-
#else
40-
#define DEBUG_ELF
4139
#endif
4240
#endif
4341

src/pci.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static int pci_program_bar(uint8_t bus, uint8_t dev, uint8_t fun,
424424
orig_bar = pci_config_read32(bus, dev, fun, bar_off);
425425
pci_config_write32(bus, dev, fun, bar_off, 0xffffffff);
426426
bar_value = pci_config_read32(bus, dev,fun, bar_off);
427-
PCI_DEBUG_PRINTF("bar value: 0x%x\r\n", bar_value);
427+
PCI_DEBUG_PRINTF("bar value after writing 0xff..ff: 0x%x\r\n", bar_value);
428428

429429
if (bar_value == 0) {
430430
PCI_DEBUG_PRINTF("PCI enum: %x:%x.%x bar: %d val: %x - skipping\r\n",
@@ -437,13 +437,12 @@ static int pci_program_bar(uint8_t bus, uint8_t dev, uint8_t fun,
437437
bar_align = bar_value & PCI_ENUM_MM_BAR_MASK;
438438
is_prefetch = pci_enum_is_prefetch(bar_value);
439439
if (pci_enum_is_64bit(bar_value)) {
440-
PCI_DEBUG_PRINTF("bar is 64bit\r\n");
441440
orig_bar2 = pci_config_read32(bus, dev, fun, bar_off + 4);
442441
pci_config_write32(bus, dev, fun, bar_off + 4, 0xffffffff);
443442
reg = pci_config_read32(bus, dev, fun, bar_off + 4);
444443
PCI_DEBUG_PRINTF("bar high 32bit: %d\r\n", reg);
445444
if (reg != 0xffffffff) {
446-
PCI_DEBUG_PRINTF("Too big BAR, skipping\r\n");
445+
PCI_DEBUG_PRINTF("Device wants too much memory, skipping\r\n");
447446
pci_config_write32(bus, dev, fun, bar_off + 4, orig_bar2);
448447
goto restore_bar;
449448
}
@@ -477,8 +476,10 @@ static int pci_program_bar(uint8_t bus, uint8_t dev, uint8_t fun,
477476

478477
/* check max length */
479478
ret = pci_enum_next_aligned32(*base, &bar_value, align, limit);
480-
if (ret != 0)
479+
if (ret != 0) {
480+
wolfBoot_printf("Not memory space for mapping the PCI device... skipping\r\n");
481481
goto restore_bar;
482+
}
482483

483484
pci_config_write32(bus, dev, fun, bar_off, bar_value);
484485
if (*is_64bit)

src/update_disk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void RAMFUNCTION wolfBoot_start(void)
132132
stage2_params = stage2_get_parameters();
133133
/* load the image just after wolfboot */
134134
load_address = (uint32_t *)(_end_wb);
135-
wolfBoot_printf("Load address %x\r\n", load_address);
135+
wolfBoot_printf("Load address 0x%x\r\n", load_address);
136136
do {
137137
failures++;
138138
if (selected)
@@ -161,6 +161,9 @@ void RAMFUNCTION wolfBoot_start(void)
161161
}
162162

163163
/* Read the image into RAM */
164+
x86_log_memory_load((uint32_t)(uintptr_t)load_address,
165+
(uint32_t)(uintptr_t)load_address + img_size,
166+
"ELF");
164167
wolfBoot_printf("Loading image from disk...");
165168
load_off = 0;
166169
do {

src/x86/common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef COMMON_H_
3232
#define COMMON_H_
3333

34+
#include <printf.h>
3435
#include <stdint.h>
3536

3637
#include <x86/common.h>
@@ -362,4 +363,9 @@ void switch_to_long_mode(uint64_t *entry, uint32_t page_table)
362363
_entry();
363364
}
364365
#endif /* BUILD_LOADER_STAGE1 */
366+
367+
void x86_log_memory_load(uint32_t start, uint32_t end, const char *name)
368+
{
369+
wolfBoot_printf("mem: [ 0x%x, 0x%x ] - %s (0x%x) \n\r", start, end, name, end - start);
370+
}
365371
#endif /* COMMON_H_ */

src/x86/mptable.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ void mptable_setup(void)
496496
struct mptable *_mp;
497497

498498
_mp = (struct mptable *)MPTABLE_LOAD_BASE;
499+
x86_log_memory_load((uint32_t)MPTABLE_LOAD_BASE,
500+
(uint32_t)MPTABLE_LOAD_BASE + sizeof(struct mptable),
501+
"MPTABLE");
499502
memcpy(_mp, (void*)&_mptable, sizeof(struct mptable));
500503
apic_id = mmio_read32(LOCAL_APIC_ID);
501504
apic_ver = mmio_read32(LOCAL_APIC_VER);

0 commit comments

Comments
 (0)