[U-Boot] [PATCH] arm: disable alignment fault checking with EFI_LOADER
robdclark at gmail.com
Mon Aug 7 12:19:30 UTC 2017
Device-path structures in UEFI are only byte aligned, which can result
in unaligned access faults (either in u-boot or the efi payload which is
loaded). From the UEFI spec (sect 10.3.1 in UEFI spec v2.7):
A Device Path is a series of generic Device Path nodes. The first
Device Path node starts at byte offset zero of the Device Path.
The next Device Path node starts at the end of the previous Device
Path node. Therefore all nodes are byte-packed data structures that
may appear on any byte boundary. All code references to device path
notes must assume all fields are unaligned. Since every Device Path
node contains a length field in a known place, it is possible to
traverse Device Path nodes that are of an unknown type. There is
no limit to the number, type, or sequence of nodes in a Device Path.
This isn't a matter of "just fix u-boot", it is baked into the spec.
Not enabling alignment faults is consistent with what TianoCore edk2
For armv6 and earlier, we probably still need hacks to pad the device-
path nodes, which isn't quite in line with the spec, and sanitize
device-paths passed in from the efi payload. But we can at least dtrt
on armv7 (and aarch64 which already doesn't enable alignment faults).
Probably we can skip clearing the bit when EFI_LOADER is enabled, since
'0' is the reset value. But I guess safest to clear it just in case an
early stage in the boot chain set it.
Signed-off-by: Rob Clark <robdclark at gmail.com>
Only tested in qemu, and it is unclear if alignment faults are even
trapped in qemu. If someone wants to test, then try (on top of the
"enough UEFI for standard distro boot" patchset) either fallback.efi
(which uses gnu-efi lib to parse device-paths to string) or any efi
payload that uses the device-path-to-text protocol. Either of those
should trigger unaligned accesses. Grub's lsefi command should also
trigger unaligned faults.
arch/arm/cpu/armv7/start.S | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index f06fd28940..c1cec30af6 100644
@@ -149,7 +149,11 @@ ENTRY(cpu_init_cp15)
mrc p15, 0, r0, c1, c0, 0
bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
+ bic r0, r0, #0x00000002 @ clear bit 1 (--A-) Align
orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB
bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache
More information about the U-Boot