Skip to content

Commit 8991296

Browse files
sameergoel01AKASHI Takahiro
authored andcommitted
efi/libstub/arm*: Set default address and size cells values for an empty dtb
In cases where a device tree is not provided (ie ACPI based system), an empty fdt is generated by efistub. #address-cells and #size-cells are not set in the empty fdt, so they default to 1 (4 byte wide). This can be an issue on 64-bit systems where values representing addresses, etc may be 8 bytes wide as the default value does not align with the general requirements for an empty DTB, and is fragile when passed to other agents as extra care is required to read the entire width of a value. This issue is observed on Qualcomm Technologies QDF24XX platforms when kexec-tools inserts 64-bit addresses into the "linux,elfcorehdr" and "linux,usable-memory-range" properties of the fdt. When the values are later consumed, they are truncated to 32-bit. Setting #address-cells and #size-cells to 2 at creation of the empty fdt resolves the observed issue, and makes the fdt less fragile. Signed-off-by: Sameer Goel <sgoel@codeaurora.org> Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Conflicts: drivers/firmware/efi/libstub/fdt.c due to missing commit abfb7b686a3e ("efi/libstub/arm*: Pass latest memory map to the kernel")
1 parent 9987607 commit 8991296

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

  • drivers/firmware/efi/libstub

drivers/firmware/efi/libstub/fdt.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616

1717
#include "efistub.h"
1818

19+
#define EFI_DT_ADDR_CELLS_DEFAULT 2
20+
#define EFI_DT_SIZE_CELLS_DEFAULT 2
21+
22+
static void fdt_update_cell_size(efi_system_table_t *sys_table, void *fdt)
23+
{
24+
int offset;
25+
26+
offset = fdt_path_offset(fdt, "/");
27+
/* Set the #address-cells and #size-cells values for an empty tree */
28+
29+
fdt_setprop_u32(fdt, offset, "#address-cells",
30+
EFI_DT_ADDR_CELLS_DEFAULT);
31+
32+
fdt_setprop_u32(fdt, offset, "#size-cells", EFI_DT_SIZE_CELLS_DEFAULT);
33+
}
34+
1935
efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
2036
unsigned long orig_fdt_size,
2137
void *fdt, int new_fdt_size, char *cmdline_ptr,
@@ -45,10 +61,18 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
4561
}
4662
}
4763

48-
if (orig_fdt)
64+
if (orig_fdt) {
4965
status = fdt_open_into(orig_fdt, fdt, new_fdt_size);
50-
else
66+
} else {
5167
status = fdt_create_empty_tree(fdt, new_fdt_size);
68+
if (status == 0) {
69+
/*
70+
* Any failure from the following function is non
71+
* critical
72+
*/
73+
fdt_update_cell_size(sys_table, fdt);
74+
}
75+
}
5276

5377
if (status != 0)
5478
goto fdt_set_fail;

0 commit comments

Comments
 (0)