[v1 PATCH 0/1] Add boot hartid to a Device tree

The RISC-V booting protocol requires the hart id to be present in "a0" register. This is not a problem for bootm/booti commands as they directly jump to Linux kernel. However, bootefi jumps to a EFI boot stub code in Linux kernel which acts a loader and jumps to real Linux after terminating the boot services. This boot stub code has to be aware of the boot hart id so that it can set it in "a0" before jumping to Linux kernel. Currently, UEFI protocol doesn't have any mechanism to pass the boot hart id to an EFI executable. We should keep it this way as this is a RISC-V specific requirement rather than a UEFI requirement. Out of the all possible options, device tree seemed to be the best choice to do this job. The detailed discussion can be found in the following thread (the patch in discussion is no longer required)
https://patchwork.ozlabs.org/patch/1233664/
This patch updates the device tree in arch_fixup_fdt() which is common for all booting commands. As a result, the DT modification doesn't require any efi related arch specific functions and all DT related modifications are contained at one place. However, the hart id node will be available for Linux even if the kernel is booted using bootm command.
Changes from previous version: 1. Renamed the DT node property to "boot-hartid" from "efi-boot-hartid". 2. Changed the property type to u32 instead of u64 for RV32 compatibility.
Atish Patra (1): riscv: Add boot hartid to Device tree
arch/riscv/lib/bootm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
-- 2.24.0

Linux booting protocol mandates that register "a0" contains the hartid. However, U-boot can not pass the hartid via a0 during via standard UEFI protocol. DT nodes are commonly used to pass such information to the OS.
Add a DT node under chosen node to indicate the boot hartid. EFI stub in Linux kernel will parse this node and pass it to the real kernel in "a0" before jumping to it.
Signed-off-by: Atish Patra atish.patra@wdc.com --- arch/riscv/lib/bootm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index fad16901c5f2..dd359a45c2e1 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -28,6 +28,19 @@ __weak void board_quiesce_devices(void)
int arch_fixup_fdt(void *blob) { + u32 size; + int chosen_offset, err; + + size = fdt_totalsize(blob); + err = fdt_open_into(blob, blob, size + 32); + if (err < 0) { + printf("Device Tree can't be expanded to accommodate new node"); + return -1; + } + chosen_offset = fdt_path_offset(blob, "/chosen"); + fdt_setprop_u32(blob, chosen_offset, "boot-hartid", + gd->arch.boot_hart); + return 0; }
participants (1)
-
Atish Patra