* [RFC PATCH V2 0/2] RISCV_EFI_BOOT_PROTOCOL support in U-boot
@ 2022-01-28 15:18 Sunil V L
2022-01-28 15:18 ` [RFC PATCH V2 1/2] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support Sunil V L
2022-01-28 15:18 ` [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL Sunil V L
0 siblings, 2 replies; 5+ messages in thread
From: Sunil V L @ 2022-01-28 15:18 UTC (permalink / raw)
To: Heinrich Schuchardt
Cc: u-boot, Ard Biesheuvel, Anup Patel, Atish Patra, Abner Chang,
Jessica Clarke, Sunil V L
This patch series adds the support in u-boot for new RISCV_EFI_BOOT_PROTOCOL for RISC-V
UEFI platforms. This protocol is required to communicate the boot hart ID to the
bootloader/kernel which need to follow the EFI calling conventions.
The latest draft spec of this new protocol is available at
https://github.com/riscv-non-isa/riscv-uefi/releases/download/1.0-rc2/RISCV_UEFI_PROTOCOL-spec.pdf
This u-boot patches can be found in:
riscv_boot_protocol_rfc_v2 branch at https://github.com/vlsunil/u-boot.git
These patches are tested in qemu. To fully test the feature, we need
Linux changes which consume this protocol.
The linux patch can be found in:
riscv_boot_protocol_rfc_v2 branch at https://github.com/vlsunil/linux.git
Changes since RFC V1:
- Used EFI_ENTRY/EXIT and removed need for static variable
- Addressed other comments from Heinrich
- Added unit test patch
Sunil V L (2):
efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support
efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL
include/efi_api.h | 4 +
include/efi_loader.h | 2 +
include/efi_riscv.h | 24 ++++++
lib/efi_loader/Kconfig | 8 ++
lib/efi_loader/Makefile | 1 +
lib/efi_loader/efi_riscv.c | 60 +++++++++++++
lib/efi_loader/efi_setup.c | 6 ++
lib/efi_selftest/Makefile | 1 +
lib/efi_selftest/efi_selftest_riscv.c | 119 ++++++++++++++++++++++++++
9 files changed, 225 insertions(+)
create mode 100644 include/efi_riscv.h
create mode 100644 lib/efi_loader/efi_riscv.c
create mode 100644 lib/efi_selftest/efi_selftest_riscv.c
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [RFC PATCH V2 1/2] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support 2022-01-28 15:18 [RFC PATCH V2 0/2] RISCV_EFI_BOOT_PROTOCOL support in U-boot Sunil V L @ 2022-01-28 15:18 ` Sunil V L 2022-01-28 17:04 ` Heinrich Schuchardt 2022-01-28 15:18 ` [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL Sunil V L 1 sibling, 1 reply; 5+ messages in thread From: Sunil V L @ 2022-01-28 15:18 UTC (permalink / raw) To: Heinrich Schuchardt Cc: u-boot, Ard Biesheuvel, Anup Patel, Atish Patra, Abner Chang, Jessica Clarke, Sunil V L 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 <sunilvl@ventanamicro.com> --- include/efi_api.h | 4 +++ include/efi_loader.h | 2 ++ include/efi_riscv.h | 24 +++++++++++++++ lib/efi_loader/Kconfig | 8 +++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_riscv.c | 60 ++++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 6 ++++ 7 files changed, 105 insertions(+) create mode 100644 include/efi_riscv.h create mode 100644 lib/efi_loader/efi_riscv.c diff --git a/include/efi_api.h b/include/efi_api.h index 8d5d835bd0..f123d0557c 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -438,6 +438,10 @@ struct efi_runtime_services { EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) +#define RISCV_EFI_BOOT_PROTOCOL_GUID \ + EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, \ + 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf) + /** * struct efi_configuration_table - EFI Configuration Table * diff --git a/include/efi_loader.h b/include/efi_loader.h index 701efcd2b6..1fa75b40fe 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -527,6 +527,8 @@ efi_status_t efi_disk_register(void); 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); /* Called by efi_init_obj_list() to do initial measurement */ efi_status_t efi_tcg2_do_initial_measurement(void); /* measure the pe-coff image, extend PCR and add Event Log */ diff --git a/include/efi_riscv.h b/include/efi_riscv.h new file mode 100644 index 0000000000..4bd39c4366 --- /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 <efi_api.h> + +#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; diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 24f9a2bb75..716436e1d3 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -369,4 +369,12 @@ config EFI_ESRT help Enabling this option creates the ESRT UEFI system table. +config EFI_RISCV_BOOT_PROTOCOL + bool "RISCV_EFI_BOOT_PROTOCOL support" + default y + depends on RISCV + help + Provide a RISCV_EFI_BOOT_PROTOCOL implementation on RISC-V + platforms. + endif diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index fd344cea29..b2c664d108 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -62,6 +62,7 @@ obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o 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-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o diff --git a/lib/efi_loader/efi_riscv.c b/lib/efi_loader/efi_riscv.c new file mode 100644 index 0000000000..bccfefd8fb --- /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 <common.h> +#include <efi_loader.h> +#include <efi_variable.h> +#include <log.h> +#include <asm/global_data.h> +#include <efi_riscv.h> + +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; +} diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 49172e3579..380adc15c8 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -247,6 +247,12 @@ efi_status_t efi_init_obj_list(void) 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) -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH V2 1/2] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support 2022-01-28 15:18 ` [RFC PATCH V2 1/2] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support Sunil V L @ 2022-01-28 17:04 ` Heinrich Schuchardt 0 siblings, 0 replies; 5+ messages in thread From: Heinrich Schuchardt @ 2022-01-28 17:04 UTC (permalink / raw) To: Sunil V L Cc: u-boot, Ard Biesheuvel, Anup Patel, Atish Patra, Abner Chang, Jessica Clarke, Heinrich Schuchardt On 1/28/22 16:18, Sunil V L wrote: > 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 <sunilvl@ventanamicro.com> > --- > include/efi_api.h | 4 +++ > include/efi_loader.h | 2 ++ > include/efi_riscv.h | 24 +++++++++++++++ > lib/efi_loader/Kconfig | 8 +++++ > lib/efi_loader/Makefile | 1 + > lib/efi_loader/efi_riscv.c | 60 ++++++++++++++++++++++++++++++++++++++ > lib/efi_loader/efi_setup.c | 6 ++++ > 7 files changed, 105 insertions(+) > create mode 100644 include/efi_riscv.h > create mode 100644 lib/efi_loader/efi_riscv.c > > diff --git a/include/efi_api.h b/include/efi_api.h > index 8d5d835bd0..f123d0557c 100644 > --- a/include/efi_api.h > +++ b/include/efi_api.h > @@ -438,6 +438,10 @@ struct efi_runtime_services { > EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ > 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) > > +#define RISCV_EFI_BOOT_PROTOCOL_GUID \ > + EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, \ > + 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf) > + > /** > * struct efi_configuration_table - EFI Configuration Table > * > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 701efcd2b6..1fa75b40fe 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -527,6 +527,8 @@ efi_status_t efi_disk_register(void); > 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); > /* Called by efi_init_obj_list() to do initial measurement */ > efi_status_t efi_tcg2_do_initial_measurement(void); > /* measure the pe-coff image, extend PCR and add Event Log */ > diff --git a/include/efi_riscv.h b/include/efi_riscv.h > new file mode 100644 > index 0000000000..4bd39c4366 > --- /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 <efi_api.h> > + > +#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; > diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig > index 24f9a2bb75..716436e1d3 100644 > --- a/lib/efi_loader/Kconfig > +++ b/lib/efi_loader/Kconfig > @@ -369,4 +369,12 @@ config EFI_ESRT > help > Enabling this option creates the ESRT UEFI system table. > > +config EFI_RISCV_BOOT_PROTOCOL > + bool "RISCV_EFI_BOOT_PROTOCOL support" > + default y > + depends on RISCV > + help > + Provide a RISCV_EFI_BOOT_PROTOCOL implementation on RISC-V > + platforms. I will add a sentence mentioning what the protocol is good for when merging. Otherwise looks good to me. Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> > + > endif > diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile > index fd344cea29..b2c664d108 100644 > --- a/lib/efi_loader/Makefile > +++ b/lib/efi_loader/Makefile > @@ -62,6 +62,7 @@ obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o > 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-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o > > diff --git a/lib/efi_loader/efi_riscv.c b/lib/efi_loader/efi_riscv.c > new file mode 100644 > index 0000000000..bccfefd8fb > --- /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 <common.h> > +#include <efi_loader.h> > +#include <efi_variable.h> > +#include <log.h> > +#include <asm/global_data.h> > +#include <efi_riscv.h> > + > +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; > +} > diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c > index 49172e3579..380adc15c8 100644 > --- a/lib/efi_loader/efi_setup.c > +++ b/lib/efi_loader/efi_setup.c > @@ -247,6 +247,12 @@ efi_status_t efi_init_obj_list(void) > 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) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL 2022-01-28 15:18 [RFC PATCH V2 0/2] RISCV_EFI_BOOT_PROTOCOL support in U-boot Sunil V L 2022-01-28 15:18 ` [RFC PATCH V2 1/2] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support Sunil V L @ 2022-01-28 15:18 ` Sunil V L 2022-01-28 17:00 ` Heinrich Schuchardt 1 sibling, 1 reply; 5+ messages in thread From: Sunil V L @ 2022-01-28 15:18 UTC (permalink / raw) To: Heinrich Schuchardt Cc: u-boot, Ard Biesheuvel, Anup Patel, Atish Patra, Abner Chang, Jessica Clarke, Sunil V L Add a test for the RISCV_EFI_BOOT_PROTOCOL. Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> --- lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_riscv.c | 119 ++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_riscv.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 9ff6e1760c..0b05f8a591 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -64,6 +64,7 @@ obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_selftest_rng.o obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_selftest_tcg2.o +obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_selftest_riscv.o ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) obj-y += efi_selftest_fdt.o diff --git a/lib/efi_selftest/efi_selftest_riscv.c b/lib/efi_selftest/efi_selftest_riscv.c new file mode 100644 index 0000000000..9d2182e61f --- /dev/null +++ b/lib/efi_selftest/efi_selftest_riscv.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_riscv + * + * Copyright (c) 2022 Ventana Micro Systems Inc + * + * Test the RISCV_EFI_BOOT_PROTOCOL. + * + * The following services are tested: + * get_boot_hartid + */ + +#include <efi_selftest.h> +#include <efi_riscv.h> +#include <linux/libfdt.h> + +static const struct efi_system_table *systemtab; +static const struct efi_boot_services *boottime; +static const char *fdt; +static const efi_guid_t riscv_efi_boot_protocol_guid = RISCV_EFI_BOOT_PROTOCOL_GUID; +static const efi_guid_t fdt_guid = EFI_FDT_GUID; + +/** + * efi_st_get_config_table() - get configuration table + * + * @guid: GUID of the configuration table + * Return: pointer to configuration table or NULL + */ +static void *efi_st_get_config_table(const efi_guid_t *guid) +{ + size_t i; + + for (i = 0; i < systab.nr_tables; i++) { + if (!guidcmp(guid, &systemtab->tables[i].guid)) + return systemtab->tables[i].table; + } + return NULL; +} + +/* + * Setup unit test. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t img_handle, + const struct efi_system_table *systable) +{ + systemtab = systable; + boottime = systable->boottime; + + fdt = efi_st_get_config_table(&fdt_guid); + + if (!fdt) { + efi_st_error("Missing device tree\n"); + return EFI_ST_FAILURE; + } + return EFI_ST_SUCCESS; +} + +/* + * Execute unit test. + * + * @return: EFI_ST_SUCCESS for success + */ +static int execute(void) +{ + efi_status_t ret; + struct riscv_efi_boot_protocol *prot; + efi_uintn_t efi_hartid, fdt_hartid; + int chosen_node, len; + const fdt32_t *prop; + + /* Get riscv boot protocol */ + ret = boottime->locate_protocol(&riscv_efi_boot_protocol_guid, NULL, + (void **)&prot); + if (ret != EFI_SUCCESS) { + efi_st_error("RISC-V Boot Protocol not available\n"); + return EFI_ST_FAILURE; + } + + /* Get Boot Hart ID from EFI protocol */ + ret = prot->get_boot_hartid(prot, &efi_hartid); + if (ret != EFI_SUCCESS) { + efi_st_error("Could not retrieve boot hart ID\n"); + return EFI_ST_FAILURE; + } + + /* Get Boot Hart ID from FDT */ + chosen_node = fdt_path_offset(fdt, "/chosen"); + if (chosen_node < 0) { + efi_st_error("/chosen node not found\n"); + return EFI_ST_FAILURE; + } + + prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len); + if (!prop || len != sizeof(u32)) { + efi_st_error("boot-hartid not found\n"); + return EFI_ST_FAILURE; + } + + fdt_hartid = fdt32_to_cpu(*prop); + + /* Boot Hart ID should be same */ + if (efi_hartid != fdt_hartid) { + efi_st_error("boot-hartid is not same in EFI and FDT\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(riscv) = { + .name = "riscv", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, +}; -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL 2022-01-28 15:18 ` [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL Sunil V L @ 2022-01-28 17:00 ` Heinrich Schuchardt 0 siblings, 0 replies; 5+ messages in thread From: Heinrich Schuchardt @ 2022-01-28 17:00 UTC (permalink / raw) To: Sunil V L Cc: u-boot, Ard Biesheuvel, Anup Patel, Atish Patra, Abner Chang, Jessica Clarke On 1/28/22 16:18, Sunil V L wrote: > Add a test for the RISCV_EFI_BOOT_PROTOCOL. > > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> > --- > lib/efi_selftest/Makefile | 1 + > lib/efi_selftest/efi_selftest_riscv.c | 119 ++++++++++++++++++++++++++ > 2 files changed, 120 insertions(+) > create mode 100644 lib/efi_selftest/efi_selftest_riscv.c > > diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile > index 9ff6e1760c..0b05f8a591 100644 > --- a/lib/efi_selftest/Makefile > +++ b/lib/efi_selftest/Makefile > @@ -64,6 +64,7 @@ obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o > obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_selftest_rng.o > obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o > obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_selftest_tcg2.o > +obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_selftest_riscv.o > > ifeq ($(CONFIG_GENERATE_ACPI_TABLE),) > obj-y += efi_selftest_fdt.o > diff --git a/lib/efi_selftest/efi_selftest_riscv.c b/lib/efi_selftest/efi_selftest_riscv.c > new file mode 100644 > index 0000000000..9d2182e61f > --- /dev/null > +++ b/lib/efi_selftest/efi_selftest_riscv.c > @@ -0,0 +1,119 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * efi_selftest_riscv > + * > + * Copyright (c) 2022 Ventana Micro Systems Inc > + * > + * Test the RISCV_EFI_BOOT_PROTOCOL. > + * > + * The following services are tested: > + * get_boot_hartid > + */ > + > +#include <efi_selftest.h> > +#include <efi_riscv.h> > +#include <linux/libfdt.h> > + > +static const struct efi_system_table *systemtab; > +static const struct efi_boot_services *boottime; > +static const char *fdt; > +static const efi_guid_t riscv_efi_boot_protocol_guid = RISCV_EFI_BOOT_PROTOCOL_GUID; > +static const efi_guid_t fdt_guid = EFI_FDT_GUID; > + > +/** > + * efi_st_get_config_table() - get configuration table > + * > + * @guid: GUID of the configuration table > + * Return: pointer to configuration table or NULL > + */ > +static void *efi_st_get_config_table(const efi_guid_t *guid) > +{ > + size_t i; > + > + for (i = 0; i < systab.nr_tables; i++) { > + if (!guidcmp(guid, &systemtab->tables[i].guid)) > + return systemtab->tables[i].table; > + } > + return NULL; > +} > + > +/* > + * Setup unit test. > + * > + * @handle: handle of the loaded image > + * @systable: system table > + * @return: EFI_ST_SUCCESS for success > + */ > +static int setup(const efi_handle_t img_handle, > + const struct efi_system_table *systable) > +{ > + systemtab = systable; > + boottime = systable->boottime; > + > + fdt = efi_st_get_config_table(&fdt_guid); > + > + if (!fdt) { > + efi_st_error("Missing device tree\n"); > + return EFI_ST_FAILURE; > + } > + return EFI_ST_SUCCESS; > +} > + > +/* > + * Execute unit test. > + * > + * @return: EFI_ST_SUCCESS for success > + */ > +static int execute(void) > +{ > + efi_status_t ret; > + struct riscv_efi_boot_protocol *prot; > + efi_uintn_t efi_hartid, fdt_hartid; > + int chosen_node, len; > + const fdt32_t *prop; > + > + /* Get riscv boot protocol */ > + ret = boottime->locate_protocol(&riscv_efi_boot_protocol_guid, NULL, > + (void **)&prot); > + if (ret != EFI_SUCCESS) { > + efi_st_error("RISC-V Boot Protocol not available\n"); > + return EFI_ST_FAILURE; > + } > + > + /* Get Boot Hart ID from EFI protocol */ > + ret = prot->get_boot_hartid(prot, &efi_hartid); > + if (ret != EFI_SUCCESS) { > + efi_st_error("Could not retrieve boot hart ID\n"); > + return EFI_ST_FAILURE; > + } > + > + /* Get Boot Hart ID from FDT */ > + chosen_node = fdt_path_offset(fdt, "/chosen"); > + if (chosen_node < 0) { > + efi_st_error("/chosen node not found\n"); > + return EFI_ST_FAILURE; > + } > + > + prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len); Thanks a lot for providing a test. In the UEFI selftests we are not having access to gd. We should not call into U-Boot except using the UEFI API. Otherwise any printf() (e.g. debug output) in the called function will cause a crash. I will add a patch to move get_property() of efi_selftest_fdt.c to an exported function and tweak your patch accordingly. > + if (!prop || len != sizeof(u32)) { > + efi_st_error("boot-hartid not found\n"); > + return EFI_ST_FAILURE; > + } > + > + fdt_hartid = fdt32_to_cpu(*prop); We should do the same for f2h() in efi_selftest_fdt.c. Otherwise looks good to me. Best regards Heinrich > + > + /* Boot Hart ID should be same */ > + if (efi_hartid != fdt_hartid) { > + efi_st_error("boot-hartid is not same in EFI and FDT\n"); > + return EFI_ST_FAILURE; > + } > + > + return EFI_ST_SUCCESS; > +} > + > +EFI_UNIT_TEST(riscv) = { > + .name = "riscv", > + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, > + .setup = setup, > + .execute = execute, > +}; ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-28 17:05 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-01-28 15:18 [RFC PATCH V2 0/2] RISCV_EFI_BOOT_PROTOCOL support in U-boot Sunil V L 2022-01-28 15:18 ` [RFC PATCH V2 1/2] efi_loader: Enable RISCV_EFI_BOOT_PROTOCOL support Sunil V L 2022-01-28 17:04 ` Heinrich Schuchardt 2022-01-28 15:18 ` [RFC PATCH V2 2/2] efi_selftest: unit test for RISCV_EFI_BOOT_PROTOCOL Sunil V L 2022-01-28 17:00 ` Heinrich Schuchardt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox