diff -Nru u-boot-2021.01+dfsg/debian/changelog u-boot-2021.01+dfsg/debian/changelog --- u-boot-2021.01+dfsg/debian/changelog 2022-11-25 14:51:54.000000000 +0000 +++ u-boot-2021.01+dfsg/debian/changelog 2023-01-11 18:29:44.000000000 +0000 @@ -1,3 +1,14 @@ +u-boot (2021.01+dfsg-3ubuntu0~20.04.6) focal; urgency=medium + + * Provide RISCV_EFI_BOOT_PROTOCOL (LP: #1998513) + d/p/riscv64/0001-efi_loader-Enable-RISCV_EFI_BOOT_PROTOCOL-support.patch + d/p/riscv64/0001-efi_loader-use-EFI_EXIT-in-efi_riscv_get_boot_hartid.patch + * Add /chosen/boot-hartid to device-tree even if there is no chosen node + (LP: #1998513) + d/p/riscv64/0001-riscv-Fix-arch_fixup_fdt-always-failing-without-chos.patch + + -- Heinrich Schuchardt Wed, 11 Jan 2023 19:29:44 +0100 + u-boot (2021.01+dfsg-3ubuntu0~20.04.5) focal-security; urgency=medium * SECURITY UPDATE: unchecked length field in DFU implementation diff -Nru u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-Enable-RISCV_EFI_BOOT_PROTOCOL-support.patch u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-Enable-RISCV_EFI_BOOT_PROTOCOL-support.patch --- u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-Enable-RISCV_EFI_BOOT_PROTOCOL-support.patch 1970-01-01 00:00:00.000000000 +0000 +++ u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-Enable-RISCV_EFI_BOOT_PROTOCOL-support.patch 2023-01-11 18:29:44.000000000 +0000 @@ -0,0 +1,183 @@ +From: Sunil V L +Date: Fri, 28 Jan 2022 20:48:44 +0530 +Subject: [PATCH] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support + +This adds support for new RISCV_EFI_BOOT_PROTOCOL to +communicate the boot hart ID to bootloader/kernel on RISC-V +UEFI platforms. + +The specification of the protocol is hosted at: +https://github.com/riscv-non-isa/riscv-uefi + +Signed-off-by: Sunil V L +Reviewed-by: Heinrich Schuchardt +Origin: https://lore.kernel.org/u-boot/20220128151845.114159-2-sunilvl@ventanamicro.com/ +Updated: 2022-12-01 +--- + include/efi_api.h | 4 +++ + include/efi_loader.h | 2 ++ + include/efi_riscv.h | 24 +++++++++++++++ + lib/efi_loader/Kconfig | 10 +++++++ + lib/efi_loader/Makefile | 1 + + lib/efi_loader/efi_riscv.c | 60 ++++++++++++++++++++++++++++++++++++++ + lib/efi_loader/efi_setup.c | 6 ++++ + 7 files changed, 107 insertions(+) + create mode 100644 include/efi_riscv.h + create mode 100644 lib/efi_loader/efi_riscv.c + +--- a/include/efi_api.h ++++ b/include/efi_api.h +@@ -356,6 +356,10 @@ + EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, \ + 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d) + ++#define RISCV_EFI_BOOT_PROTOCOL_GUID \ ++ EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, \ ++ 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf) ++ + struct efi_configuration_table { + efi_guid_t guid; + void *table; +--- a/include/efi_loader.h ++++ b/include/efi_loader.h +@@ -412,6 +412,8 @@ + efi_status_t efi_rng_register(void); + /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */ + efi_status_t efi_tcg2_register(void); ++/* Called by efi_init_obj_list() to install RISCV_EFI_BOOT_PROTOCOL */ ++efi_status_t efi_riscv_register(void); + /* Create handles and protocols for the partitions of a block device */ + int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, + const char *if_typename, int diskid, +--- /dev/null ++++ b/include/efi_riscv.h +@@ -0,0 +1,24 @@ ++/* SPDX-License-Identifier: GPL-2.0+ */ ++/* ++ * RISCV_EFI_BOOT_PROTOCOL ++ * ++ * Copyright (c) 2022 Ventana Micro Systems Inc ++ */ ++ ++#include ++ ++#define RISCV_EFI_BOOT_PROTOCOL_REVISION 0x00010000 ++ ++/** ++ * struct riscv_efi_boot_protocol - RISCV_EFI_BOOT_PROTOCOL ++ * @revision: Version of the protocol implemented ++ * @get_boot_hartid: Get the boot hart ID ++ */ ++struct riscv_efi_boot_protocol { ++ u64 revision; ++ ++ efi_status_t (EFIAPI * get_boot_hartid) (struct riscv_efi_boot_protocol *this, ++ efi_uintn_t *boot_hartid); ++}; ++ ++extern struct riscv_efi_boot_protocol riscv_efi_boot_prot; +--- a/lib/efi_loader/Kconfig ++++ b/lib/efi_loader/Kconfig +@@ -240,4 +240,14 @@ + it is signed with a trusted key. To do that, you need to install, + at least, PK, KEK and db. + ++config EFI_RISCV_BOOT_PROTOCOL ++ bool "RISCV_EFI_BOOT_PROTOCOL support" ++ default y ++ depends on RISCV ++ help ++ The EFI_RISCV_BOOT_PROTOCOL is used to transfer the boot hart ID ++ to the next boot stage. It should be enabled as it is meant to ++ replace the transfer via the device-tree. The latter is not ++ possible on systems using ACPI. ++ + endif +--- a/lib/efi_loader/Makefile ++++ b/lib/efi_loader/Makefile +@@ -54,6 +54,7 @@ + obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o + obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o + obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o ++obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o + obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o + obj-y += efi_signature.o + +--- /dev/null ++++ b/lib/efi_loader/efi_riscv.c +@@ -0,0 +1,60 @@ ++// SPDX-License-Identifier: GPL-2.0+ ++/* ++ * Defines APIs that allow an OS to interact with UEFI firmware to query ++ * information about the boot hart ID. ++ * ++ * Copyright (c) 2022, Ventana Micro Systems Inc ++ */ ++ ++#define LOG_CATEGORY LOGC_EFI ++#include ++#include ++#include ++#include ++#include ++#include ++ ++DECLARE_GLOBAL_DATA_PTR; ++ ++static const efi_guid_t efi_guid_riscv_boot_protocol = RISCV_EFI_BOOT_PROTOCOL_GUID; ++ ++/** ++ * efi_riscv_get_boot_hartid() - return boot hart ID ++ * @this: RISCV_EFI_BOOT_PROTOCOL instance ++ * @boot_hartid: caller allocated memory to return boot hart id ++ * Return: status code ++ */ ++static efi_status_t EFIAPI ++efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this, ++ efi_uintn_t *boot_hartid) ++{ ++ EFI_ENTRY("%p, %p", this, boot_hartid); ++ ++ if (this != &riscv_efi_boot_prot || !boot_hartid) ++ return EFI_INVALID_PARAMETER; ++ ++ *boot_hartid = gd->arch.boot_hart; ++ ++ return EFI_EXIT(EFI_SUCCESS); ++} ++ ++struct riscv_efi_boot_protocol riscv_efi_boot_prot = { ++ .revision = RISCV_EFI_BOOT_PROTOCOL_REVISION, ++ .get_boot_hartid = efi_riscv_get_boot_hartid ++}; ++ ++/** ++ * efi_riscv_register() - register RISCV_EFI_BOOT_PROTOCOL ++ * ++ * Return: status code ++ */ ++efi_status_t efi_riscv_register(void) ++{ ++ efi_status_t ret = EFI_SUCCESS; ++ ++ ret = efi_add_protocol(efi_root, &efi_guid_riscv_boot_protocol, ++ (void *)&riscv_efi_boot_prot); ++ if (ret != EFI_SUCCESS) ++ log_err("Cannot install RISCV_EFI_BOOT_PROTOCOL\n"); ++ return ret; ++} +--- a/lib/efi_loader/efi_setup.c ++++ b/lib/efi_loader/efi_setup.c +@@ -189,6 +189,12 @@ + if (ret != EFI_SUCCESS) + goto out; + ++ if (IS_ENABLED(CONFIG_EFI_RISCV_BOOT_PROTOCOL)) { ++ ret = efi_riscv_register(); ++ if (ret != EFI_SUCCESS) ++ goto out; ++ } ++ + /* Secure boot */ + ret = efi_init_secure_boot(); + if (ret != EFI_SUCCESS) diff -Nru u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-use-EFI_EXIT-in-efi_riscv_get_boot_hartid.patch u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-use-EFI_EXIT-in-efi_riscv_get_boot_hartid.patch --- u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-use-EFI_EXIT-in-efi_riscv_get_boot_hartid.patch 1970-01-01 00:00:00.000000000 +0000 +++ u-boot-2021.01+dfsg/debian/patches/riscv64/0001-efi_loader-use-EFI_EXIT-in-efi_riscv_get_boot_hartid.patch 2023-01-11 18:29:44.000000000 +0000 @@ -0,0 +1,34 @@ +From 6ed52775b8c40ea4532a9af25866542b11639b44 Mon Sep 17 00:00:00 2001 +From: Heinrich Schuchardt +Date: Wed, 11 Jan 2023 19:08:01 +0100 +Subject: [PATCH 1/1] efi_loader: use EFI_EXIT in efi_riscv_get_boot_hartid + +After calling EFI_ENTRY we have to call EFI_EXIT before returning. + +Add a missing EFI_EXIT(). + +Fixes: 1ccf87165e38 ("efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support") +Reported-by: Dave Jones +Signed-off-by: Heinrich Schuchardt +Origin: https://lore.kernel.org/u-boot/20230111181301.12122-1-heinrich.schuchardt@canonical.com/T/#u +Updated: 2023-01-11 +--- + lib/efi_loader/efi_riscv.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/efi_loader/efi_riscv.c b/lib/efi_loader/efi_riscv.c +index bccfefd8fb..064172755b 100644 +--- a/lib/efi_loader/efi_riscv.c ++++ b/lib/efi_loader/efi_riscv.c +@@ -31,7 +31,7 @@ efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this, + EFI_ENTRY("%p, %p", this, boot_hartid); + + if (this != &riscv_efi_boot_prot || !boot_hartid) +- return EFI_INVALID_PARAMETER; ++ return EFI_EXIT(EFI_INVALID_PARAMETER); + + *boot_hartid = gd->arch.boot_hart; + +-- +2.37.2 + diff -Nru u-boot-2021.01+dfsg/debian/patches/riscv64/0001-riscv-Fix-arch_fixup_fdt-always-failing-without-chos.patch u-boot-2021.01+dfsg/debian/patches/riscv64/0001-riscv-Fix-arch_fixup_fdt-always-failing-without-chos.patch --- u-boot-2021.01+dfsg/debian/patches/riscv64/0001-riscv-Fix-arch_fixup_fdt-always-failing-without-chos.patch 1970-01-01 00:00:00.000000000 +0000 +++ u-boot-2021.01+dfsg/debian/patches/riscv64/0001-riscv-Fix-arch_fixup_fdt-always-failing-without-chos.patch 2023-01-11 18:29:44.000000000 +0000 @@ -0,0 +1,48 @@ +From: Sean Anderson +Date: Fri, 14 May 2021 22:36:16 -0400 +Subject: [PATCH] riscv: Fix arch_fixup_fdt always failing without /chosen + +If /chosen was missing, chosen_offset would never get updated with the new +/chosen node. This would cause fdt_setprop_u32 to fail. This patch fixes +this by setting chosen_offset. In addition, log any errors from setting +boot-hartid as well. + +Fixes: 5370478d1c7 ("riscv: Add boot hartid to device tree") +Signed-off-by: Sean Anderson +Reviewed-by: Bin Meng +Reviewed-by: Rick Chen +Reviewed-by: Atish Patra +Origin: https://lore.kernel.org/u-boot/20210515023616.2488191-1-seanga2@gmail.com/ +--- + arch/riscv/lib/fdt_fixup.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c +index 1f3f23621c..f636b28449 100644 +--- a/arch/riscv/lib/fdt_fixup.c ++++ b/arch/riscv/lib/fdt_fixup.c +@@ -151,14 +151,17 @@ int arch_fixup_fdt(void *blob) + } + chosen_offset = fdt_path_offset(blob, "/chosen"); + if (chosen_offset < 0) { +- err = fdt_add_subnode(blob, 0, "chosen"); +- if (err < 0) { ++ chosen_offset = fdt_add_subnode(blob, 0, "chosen"); ++ if (chosen_offset < 0) { + log_err("chosen node cannot be added\n"); +- return err; ++ return chosen_offset; + } + } + /* Overwrite the boot-hartid as U-Boot is the last stage BL */ +- fdt_setprop_u32(blob, chosen_offset, "boot-hartid", gd->arch.boot_hart); ++ err = fdt_setprop_u32(blob, chosen_offset, "boot-hartid", ++ gd->arch.boot_hart); ++ if (err < 0) ++ return log_msg_ret("could not set boot-hartid", err); + #endif + + /* Copy the reserved-memory node to the DT used by OS */ +-- +2.37.2 + diff -Nru u-boot-2021.01+dfsg/debian/patches/series u-boot-2021.01+dfsg/debian/patches/series --- u-boot-2021.01+dfsg/debian/patches/series 2022-11-25 14:51:18.000000000 +0000 +++ u-boot-2021.01+dfsg/debian/patches/series 2023-01-11 18:29:44.000000000 +0000 @@ -65,6 +65,9 @@ riscv64/0041-Fix-CRC32-checksum-for-SiFive-HiFive-EEPROM.patch riscv64/sifive-unmatched-default-fdt-files.patch riscv64/use-preboot-unmatched.patch +riscv64/0001-riscv-Fix-arch_fixup_fdt-always-failing-without-chos.patch +riscv64/0001-efi_loader-Enable-RISCV_EFI_BOOT_PROTOCOL-support.patch +riscv64/0001-efi_loader-use-EFI_EXIT-in-efi_riscv_get_boot_hartid.patch n900/bootz_and_raw_initrd.patch