ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off

When parsing the device tree to find the memory node, we are still running
with the MMU off, which means unaligned memory accesses are not allowed.
Since the FDT only mandates 32-bit alignment, 64-bit quantities are not
guaranteed to appear naturally aligned, and so should be accessed using
32-bit accesses instead.

Reported-by: Julien Grall <julien.grall@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Ard Biesheuvel 2016-09-13 15:13:31 +01:00
parent dd82465a9f
commit 94a3845be6
2 changed files with 12 additions and 16 deletions

View File

@ -65,17 +65,15 @@ FindMemnode (
return FALSE;
}
if (AddressCells == 1) {
*SystemMemoryBase = fdt32_to_cpu (*Prop);
} else {
*SystemMemoryBase = fdt64_to_cpu (*(UINT64 *)Prop);
*SystemMemoryBase = fdt32_to_cpu (Prop[0]);
if (AddressCells > 1) {
*SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
}
Prop += AddressCells;
if (SizeCells == 1) {
*SystemMemorySize = fdt32_to_cpu (*Prop);
} else {
*SystemMemorySize = fdt64_to_cpu (*(UINT64 *)Prop);
*SystemMemorySize = fdt32_to_cpu (Prop[0]);
if (SizeCells > 1) {
*SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
}
return TRUE;

View File

@ -65,17 +65,15 @@ FindMemnode (
return FALSE;
}
if (AddressCells == 1) {
*SystemMemoryBase = fdt32_to_cpu (*Prop);
} else {
*SystemMemoryBase = fdt64_to_cpu (*(UINT64 *)Prop);
*SystemMemoryBase = fdt32_to_cpu (Prop[0]);
if (AddressCells > 1) {
*SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);
}
Prop += AddressCells;
if (SizeCells == 1) {
*SystemMemorySize = fdt32_to_cpu (*Prop);
} else {
*SystemMemorySize = fdt64_to_cpu (*(UINT64 *)Prop);
*SystemMemorySize = fdt32_to_cpu (Prop[0]);
if (SizeCells > 1) {
*SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);
}
return TRUE;