Skip to content

Commit 6f83a79

Browse files
authored
Merge pull request #456 from rizlik/backport_debug0
qemu x86 fsp: fix support for DEBUG=0 build; fix conditional OTP compilation in Makefile
2 parents ca3e8dc + a413cc1 commit 6f83a79

File tree

15 files changed

+68
-50
lines changed

15 files changed

+68
-50
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ BOOTLOADER_PARTITION_SIZE?=$$(( $(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLAS
137137
all: $(MAIN_TARGET)
138138

139139
stage1: stage1/loader_stage1.bin
140+
stage1/loader_stage1.bin: wolfboot.elf
140141
stage1/loader_stage1.bin: FORCE
141142
@echo "\t[BIN] $@"
142143
$(Q)$(MAKE) -C $(dir $@) $(notdir $@)

arch.mk

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,10 @@ endif
671671
ifeq ($(filter $(TARGET),x86_fsp_qemu kontron_vx3060_s2),$(TARGET))
672672
FSP=1
673673
CFLAGS+=-DWOLFBOOT_FSP=1
674-
CFLAGS+=-ffunction-sections -fdata-sections
674+
CFLAGS+=-ffunction-sections -fdata-sections -ffreestanding -nostdlib -static
675+
# some std libc have headers that bring in extra symbols used in
676+
# FORTIFY_SOURCE realated checks. Use -U_FORTIFY_SOURCE to avoid that.
677+
CFLAGS+=-U_FORTIFY_SOURCE
675678
ifeq ($(TARGET), kontron_vx3060_s2)
676679
FSP_TGL=1
677680
CFLAGS+=-DWOLFBOOT_TGL=1
@@ -840,9 +843,7 @@ CFLAGS+=-DWOLFBOOT_ORIGIN=$(WOLFBOOT_ORIGIN)
840843
CFLAGS+=-DBOOTLOADER_PARTITION_SIZE=$(BOOTLOADER_PARTITION_SIZE)
841844

842845
## Debug
843-
ifeq ($(DEBUG),1)
844-
WOLFCRYPT_OBJS+=./lib/wolfssl/wolfcrypt/src/logging.o
845-
endif
846+
WOLFCRYPT_OBJS+=./lib/wolfssl/wolfcrypt/src/logging.o
846847

847848
# Debug UART
848849
ifeq ($(DEBUG_UART),1)

config/examples/kontron_vx3060_s2.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ TARGET=kontron_vx3060_s2
33
WOLFBOOT_SMALL_STACK=0
44
SIGN=ECC384
55
HASH=SHA256
6-
DEBUG=1
6+
DEBUG=0
77
SPMATH=1
88
ENCRYPTION=0
99
WOLFBOOT_NO_PARTITIONS=1
@@ -63,4 +63,5 @@ DISK_LOCK=0
6363
WOLFTPM=1
6464
WOLFBOOT_TPM_SEAL=1
6565
WOLFBOOT_TPM_SEAL_KEY_ID=1
66-
WOLFBOOT_UNIVERSAL_KEYSTORE=1
66+
WOLFBOOT_UNIVERSAL_KEYSTORE=1
67+
DEBUG_SYMBOLS=1

config/examples/x86_fsp_qemu_seal.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ TARGET=x86_fsp_qemu
33
WOLFBOOT_SMALL_STACK=0
44
SIGN=ECC384
55
HASH=SHA256
6-
DEBUG=1
6+
DEBUG=0
77
SPMATH=1
88
FORCE_32BIT=1
99
ENCRYPTION=0
@@ -45,4 +45,5 @@ MEASURED_PCR_A=0
4545
WOLFBOOT_TPM_SEAL=1
4646
WOLFBOOT_TPM_SEAL_KEY_ID=1
4747
DISK_LOCK=1
48-
WOLFBOOT_UNIVERSAL_KEYSTORE=1
48+
WOLFBOOT_UNIVERSAL_KEYSTORE=1
49+
DEBUG_SYMBOLS=1

hal/x86_uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int uart_init(uint32_t bitrate, uint8_t data, char parity, uint8_t stop)
142142

143143
mode = 0;
144144
mode |= data;
145-
mode |= (stop << 2);
145+
mode |= (stops << 2);
146146
mode |= (parity_bits << 3);
147147
write_reg(X86_UART_LCR, mode);
148148

include/user_settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@
4040
#define SIZEOF_LONG_LONG 8
4141

4242
#define CTYPE_USER /* don't let wolfCrypt types.h include ctype.h */
43+
#ifndef toupper
4344
extern int toupper(int c);
45+
#endif
46+
#ifndef tolower
4447
extern int tolower(int c);
48+
#endif
4549
#define XTOUPPER(c) toupper((c))
4650
#define XTOLOWER(c) tolower((c))
4751

src/boot_x86_fsp.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ const uint8_t __attribute__((section(".sig_wolfboot_raw")))
8888
#define PCI_DEVICE_CONTROLLER_TO_PEX 0x6
8989
#define PCIE_TRAINING_TIMEOUT_MS (100)
9090

91+
/* compile time alignment checks */
92+
#define ALIGN_CHECK(value, alignment) ((value) & ((alignment)-1)) == 0
93+
#if !ALIGN_CHECK(FSP_S_LOAD_BASE - IMAGE_HEADER_SIZE, 16)
94+
#error "FSP_S_LOAD_BASE must be aligned on a 16 bytes boundary"
95+
#endif
96+
#if !ALIGN_CHECK(WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE, 16)
97+
#error "WOLFBOOT_LOAD_BASE must be aligned on a 16 bytes boundary"
98+
#endif
99+
91100
typedef uint32_t (*memory_init_cb)(void *udp, struct efi_hob **HobList);
92101
typedef uint32_t (*temp_ram_exit_cb)(void *udp);
93102
typedef uint32_t (*silicon_init_cb)(void *udp);
@@ -492,6 +501,8 @@ static int fsp_silicon_init(struct fsp_info_header *fsp_info, uint8_t *fsp_s_bas
492501
memcpy(silicon_init_parameter, fsp_s_base + fsp_info->CfgRegionOffset,
493502
FSP_S_PARAM_SIZE);
494503
status = fsp_machine_update_s_parameters(silicon_init_parameter);
504+
if (status != 0)
505+
panic();
495506
SiliconInit = (silicon_init_cb)(fsp_s_base + fsp_info->FspSiliconInitEntryOffset);
496507

497508
#if defined(WOLFBOOT_DUMP_FSP_UPD)
@@ -744,7 +755,7 @@ void start(uint32_t stack_base, uint32_t stack_top, uint64_t timestamp,
744755
uint8_t *fsp_m_base, done = 0;
745756
struct efi_hob *hobList, *it;
746757
memory_init_cb MemoryInit;
747-
uint64_t top_address;
758+
uint64_t top_address = MEMORY_4GB;
748759
uint32_t new_stack;
749760
uint32_t status;
750761
uint16_t type;
@@ -836,7 +847,7 @@ void start(uint32_t stack_base, uint32_t stack_top, uint64_t timestamp,
836847
hob_dump_memory_map(hobList);
837848
#endif /* DEBUG */
838849

839-
if (top_address > MEMORY_4GB) {
850+
if (top_address >= MEMORY_4GB) {
840851
panic();
841852
}
842853

src/elf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
8888
/* Load class and endianess */
8989
is_elf32 = (h32->ident[4] == ELF_CLASS_32);
9090
is_le = (h32->ident[5] == ELF_ENDIAN_LITTLE);
91+
(void)is_le;
9192

9293
/* Verify this is an executable */
9394
if (GET_H16(type) != ELF_HET_EXEC) {

src/update_disk.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ extern uint8_t _end_wb[];
7979
*/
8080
void RAMFUNCTION wolfBoot_start(void)
8181
{
82+
uint8_t p_hdr[IMAGE_HEADER_SIZE] __attribute__((aligned(16)));
8283
struct stage2_parameter *stage2_params;
8384
struct wolfBoot_image os_image;
84-
uint8_t p_hdr[IMAGE_HEADER_SIZE];
8585
int pA_ver = 0, pB_ver = 0;
8686
uint32_t cur_part = 0;
8787
int ret = -1;
@@ -135,8 +135,8 @@ void RAMFUNCTION wolfBoot_start(void)
135135
selected = 0;
136136

137137
stage2_params = stage2_get_parameters();
138-
/* load the image just after wolfboot */
139-
load_address = (uint32_t *)(_end_wb);
138+
/* load the image just after wolfboot, 16 bytes aligned */
139+
load_address = (uint32_t *)((((uintptr_t)_end_wb) + 0xf) & ~0xf);
140140
wolfBoot_printf("Load address 0x%x\r\n", load_address);
141141
do {
142142
failures++;

src/x86/ahci.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ int init_sata_controller(uint32_t bus, uint32_t dev, uint32_t fun)
171171
uint32_t ahci_enable(uint32_t bus, uint32_t dev, uint32_t fun)
172172
{
173173
uint16_t reg16;
174-
uint32_t iobar;
175174
uint32_t reg;
176175
uint32_t bar;
177176

@@ -180,8 +179,6 @@ uint32_t ahci_enable(uint32_t bus, uint32_t dev, uint32_t fun)
180179

181180
bar = pci_config_read32(bus, dev, fun, AHCI_ABAR_OFFSET);
182181
AHCI_DEBUG_PRINTF("PCI BAR: %08x\r\n", bar);
183-
iobar = pci_config_read32(bus, dev, fun, AHCI_AIDPBA_OFFSET);
184-
AHCI_DEBUG_PRINTF("PCI I/O space: %08x\r\n", iobar);
185182

186183
reg |= PCI_COMMAND_BUS_MASTER;
187184
reg |= PCI_COMMAND_MEM_SPACE;
@@ -197,29 +194,6 @@ uint32_t ahci_enable(uint32_t bus, uint32_t dev, uint32_t fun)
197194
return bar;
198195
}
199196

200-
/**
201-
* @brief Dumps the status of the specified AHCI port.
202-
*
203-
* This function dumps the status of the AHCI port with the given index.
204-
* It prints the status of various port registers for debugging purposes.
205-
*
206-
* @param base The AHCI Base Address Register (ABAR) for accessing AHCI registers.
207-
* @param i The index of the AHCI port to dump status for.
208-
*/
209-
void ahci_dump_port(uint32_t base, int i)
210-
{
211-
uint32_t cmd, ci, is, tfd, serr, ssst;
212-
213-
cmd = mmio_read32(AHCI_PxCMD(base, i));
214-
ci = mmio_read32(AHCI_PxCI(base, i));
215-
is = mmio_read32(AHCI_PxIS(base, i));
216-
tfd = mmio_read32(AHCI_PxTFD(base, i));
217-
serr = mmio_read32(AHCI_PxSERR(base, i));
218-
ssst = mmio_read32(AHCI_PxSSTS(base, i));
219-
AHCI_DEBUG_PRINTF("%d: cmd:0x%x ci:0x%x is: 0x%x tfd: 0x%x serr: 0x%x ssst: 0x%x\r\n",
220-
i, cmd, ci, is, tfd, serr, ssst);
221-
}
222-
223197
#ifdef WOLFBOOT_ATA_DISK_LOCK
224198
#ifdef WOLFBOOT_ATA_DISK_LOCK_PASSWORD
225199
static int sata_get_unlock_secret(uint8_t *secret, int *secret_size)
@@ -362,7 +336,7 @@ static int sata_get_unlock_secret(uint8_t *secret, int *secret_size)
362336
#error "implement get_tpm_policy "
363337
#endif
364338

365-
if (policy_size > TPM_MAX_POLICY_SIZE)
339+
if (policy_size > TPM_MAX_POLICY_SIZE || ret != 0)
366340
return -1;
367341

368342
memcpy(policy, pol, policy_size);
@@ -464,15 +438,21 @@ int sata_unlock_disk(int drv, int freeze)
464438
}
465439
r = ata_identify_device(drv);
466440
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
441+
if (r != 0)
442+
return -1;
467443
ata_st = ata_security_get_state(drv);
468444
wolfBoot_printf("ATA: State SEC%d\r\n", ata_st);
469445
}
470446
else if (ata_st == ATA_SEC4) {
471447
AHCI_DEBUG_PRINTF("ATA identify: calling device unlock\r\n", r);
472448
r = ata_security_unlock_device(drv, (char*)secret, 0);
473449
AHCI_DEBUG_PRINTF("ATA device unlock: returned %d\r\n", r);
450+
if (r != 0)
451+
return -1;
474452
r = ata_identify_device(drv);
475453
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
454+
if (r != 0)
455+
return -1;
476456
ata_st = ata_security_get_state(drv);
477457
if (ata_st == ATA_SEC5) {
478458
if (freeze) {
@@ -487,6 +467,8 @@ int sata_unlock_disk(int drv, int freeze)
487467
}
488468
r = ata_identify_device(drv);
489469
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
470+
if (r != 0)
471+
return -1;
490472
}
491473
}
492474
ata_st = ata_security_get_state(drv);
@@ -583,6 +565,7 @@ void sata_enable(uint32_t base)
583565

584566
cap = mmio_read32(AHCI_HBA_CAP(base));
585567
n_ports = (cap & 0x1F) + 1;
568+
(void)n_ports;
586569
sata_only = (cap & AHCI_CAP_SAM);
587570
cap_sud = (cap & AHCI_CAP_SSS);
588571

@@ -601,8 +584,8 @@ void sata_enable(uint32_t base)
601584
if ((ports_impl & (1 << i)) != 0) {
602585
uint32_t reg;
603586
uint32_t ssts = mmio_read32(AHCI_PxSSTS(base, i));
604-
uint8_t ipm = (ssts >> 8) & 0xFF;
605587
uint8_t det = ssts & 0x0F;
588+
uint8_t ipm;
606589
volatile struct hba_cmd_header *hdr;
607590

608591

@@ -736,6 +719,7 @@ void sata_enable(uint32_t base)
736719
AHCI_DEBUG_PRINTF("ATA%d associated to AHCI port %d\r\n",
737720
drv, i);
738721
r = ata_identify_device(drv);
722+
(void)r;
739723
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
740724
}
741725
} else {

0 commit comments

Comments
 (0)