Skip to content

Commit 829f7b1

Browse files
committed
fix: add image alignment costraints
1 parent 441200f commit 829f7b1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/boot_x86_fsp.c

Lines changed: 9 additions & 0 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);

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++;

0 commit comments

Comments
 (0)