arch: x86: zefi: Reduce data section alignment requirement from 8 to 4

It's not safe to assume that the data section is 8-byte aligned.
Assuming 4-byte alignment seems to work however, and results in
simpler code than arbitrary alignment support.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2020-07-17 14:38:29 +03:00 committed by Anas Nashif
commit 38333afe0e
2 changed files with 16 additions and 16 deletions

View file

@ -72,24 +72,24 @@ uintptr_t __abi efi_entry(void *img_handle, struct efi_system_table *sys_tab)
printf("*** Zephyr EFI Loader ***\n");
for (int i = 0; i < sizeof(zefi_zsegs)/sizeof(zefi_zsegs[0]); i++) {
int nqwords = zefi_zsegs[i].sz;
uint64_t *dst = (uint64_t *)zefi_zsegs[i].addr;
int nwords = zefi_zsegs[i].sz;
uint32_t *dst = (uint32_t *)zefi_zsegs[i].addr;
printf("Zeroing %d bytes of memory at %p\n", 8 * nqwords, dst);
for (int j = 0; j < nqwords; j++) {
printf("Zeroing %d bytes of memory at %p\n", 4 * nwords, dst);
for (int j = 0; j < nwords; j++) {
dst[j] = 0;
}
}
for (int i = 0; i < sizeof(zefi_dsegs)/sizeof(zefi_dsegs[0]); i++) {
int nqwords = zefi_dsegs[i].sz;
int nwords = zefi_dsegs[i].sz;
int off = zefi_dsegs[i].off;
uint64_t *dst = (uint64_t *)zefi_dsegs[i].addr;
uint64_t *src = &((uint64_t *)EXT_DATA_START)[off];
uint32_t *dst = (uint32_t *)zefi_dsegs[i].addr;
uint32_t *src = &((uint32_t *)EXT_DATA_START)[off];
printf("Copying %d data bytes to %p from image offset %d\n",
8 * nqwords, dst, zefi_dsegs[i].off);
for (int j = 0; j < nqwords; j++) {
4 * nwords, dst, zefi_dsegs[i].off);
for (int j = 0; j < nwords; j++) {
dst[j] = src[j];
}
}

View file

@ -50,23 +50,23 @@ def build_elf(elf_file):
assert h.p_memsz >= h.p_filesz
assert (h.p_vaddr % 8) == 0
assert (h.p_filesz % 8) == 0
assert (h.p_filesz % 4) == 0
assert len(seg.data()) == h.p_filesz
if h.p_filesz > 0:
sd = seg.data()
verbose("%d bytes of data at 0x%x, data offset %d"
% (len(sd), h.p_vaddr, len(data_blob)))
data_segs.append((h.p_vaddr, len(sd) / 8, len(data_blob) / 8))
data_segs.append((h.p_vaddr, len(sd) / 4, len(data_blob) / 4))
data_blob = data_blob + sd
if h.p_memsz > h.p_filesz:
bytesz = h.p_memsz - h.p_filesz
if bytesz % 8:
bytesz += 8 - (bytesz % 8)
if bytesz % 4:
bytesz += 4 - (bytesz % 4)
addr = h.p_vaddr + h.p_filesz
verbose("%d bytes of zero-fill at 0x%x" % (bytesz, addr))
zero_segs.append((addr, bytesz / 8))
zero_segs.append((addr, bytesz / 4))
verbose(f"{len(data_blob)} bytes of data to include in image")
@ -77,8 +77,8 @@ def build_elf(elf_file):
cf.write("/* GENERATED CODE. DO NOT EDIT. */\n\n")
cf.write("/* Sizes and offsets specified in 8-byte units.\n")
cf.write(" * All addresses 8-byte aligned.\n")
cf.write("/* Sizes and offsets specified in 4-byte units.\n")
cf.write(" * All addresses 4-byte aligned.\n")
cf.write(" */\n")
cf.write("struct data_seg { uint64_t addr; uint32_t sz; uint32_t off; };\n\n")