Merge tag 'tpm-03092022' of https://source.denx.de/u-boot/custodians/u-boot-tpm
authorTom Rini <trini@konsulko.com>
Sat, 3 Sep 2022 18:55:37 +0000 (14:55 -0400)
committerTom Rini <trini@konsulko.com>
Sat, 3 Sep 2022 18:55:37 +0000 (14:55 -0400)
TPM fixes and state reporting

25 files changed:
arch/arm/dts/r7s72100-gr-peach-u-boot.dts
arch/arm/dts/r8a774c0-u-boot.dtsi
arch/arm/dts/r8a77950-u-boot.dtsi
arch/arm/dts/r8a77960-u-boot.dtsi
arch/arm/dts/r8a77965-u-boot.dtsi
arch/arm/dts/r8a77970-u-boot.dtsi
arch/arm/dts/r8a77980-u-boot.dtsi
arch/arm/dts/r8a77990-u-boot.dtsi
arch/arm/dts/r8a77995-u-boot.dtsi
arch/arm/dts/r8a779a0-u-boot.dtsi
board/renesas/rcar-common/common.c
drivers/mtd/renesas_rpc_hf.c
drivers/spi/renesas_rpc_spi.c
drivers/usb/gadget/f_fastboot.c
include/efi_api.h
include/efi_loader.h
lib/efi_loader/Kconfig
lib/efi_loader/Makefile
lib/efi_loader/efi_conformance.c [new file with mode: 0644]
lib/efi_loader/efi_console.c
lib/efi_loader/efi_device_path_to_text.c
lib/efi_loader/efi_setup.c
lib/efi_loader/helloworld.c
lib/efi_selftest/efi_selftest_miniapp_exception.c
lib/uuid.c

index f48121a..5b176a9 100644 (file)
@@ -46,8 +46,8 @@
        };
 
 
-       rpc: rpc@ee200000 {
-               compatible = "renesas,rpc-r7s72100", "renesas,rpc";
+       rpc: spi@ee200000 {
+               compatible = "renesas,r7s72100-rpc-if";
                reg = <0x3fefa000 0x100>, <0x18000000 0x08000000>;
                bank-width = <2>;
                num-cs = <1>;
index af1c861..d296106 100644 (file)
@@ -10,8 +10,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rcar-gen3-rpc", "renesas,rpc-r8a774c0";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a774c0-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0x04000000>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index 5a11651..2306c7b 100644 (file)
@@ -13,8 +13,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a7795", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a7795-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index f1cae1c..f64e5a4 100644 (file)
@@ -13,8 +13,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a7796", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a7796-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index 9cc6f20..c4abcc5 100644 (file)
@@ -13,8 +13,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a77965", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a77965-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index ac3c6be..614caa9 100644 (file)
@@ -13,8 +13,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a77970", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a77970-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index 365d40a..54f01c9 100644 (file)
@@ -13,8 +13,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a77980", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a77980-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index 6655abe..50bbbe1 100644 (file)
@@ -9,8 +9,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a77990", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a77990-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index 0917a80..347b59a 100644 (file)
@@ -9,8 +9,8 @@
 
 / {
        soc {
-               rpc: rpc@ee200000 {
-                       compatible = "renesas,rpc-r8a77995", "renesas,rpc";
+               rpc: spi@ee200000 {
+                       compatible = "renesas,r8a77995-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x100>, <0 0x08000000 0 0>;
                        clocks = <&cpg CPG_MOD 917>;
                        bank-width = <2>;
index 83dbe3f..9f2772a 100644 (file)
@@ -10,7 +10,7 @@
 / {
        soc {
                rpc: spi@ee200000 {
-                       compatible = "renesas,rpc-r8a779a0", "renesas,rcar-gen3-rpc";
+                       compatible = "renesas,r8a779a0-rpc-if", "renesas,rcar-gen3-rpc-if";
                        reg = <0 0xee200000 0 0x200>, <0 0x08000000 0 0x04000000>;
                        clocks = <&cpg CPG_MOD 629>;
                        bank-width = <2>;
index 0352d34..daa1beb 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <common.h>
 #include <dm.h>
+#include <fdt_support.h>
 #include <init.h>
 #include <asm/global_data.h>
 #include <dm/uclass-internal.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/* If the firmware passed a device tree use it for U-Boot DRAM setup. */
+/* If the firmware passed a device tree use it for e.g. U-Boot DRAM setup. */
 extern u64 rcar_atf_boot_args[];
 
+#define FDT_RPC_PATH   "/soc/spi@ee200000"
+
 int fdtdec_board_setup(const void *fdt_blob)
 {
        void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
@@ -81,7 +84,7 @@ static int is_mem_overlap(void *blob, int first_mem_node, int curr_mem_node)
        return 0;
 }
 
-int ft_board_setup(void *blob, struct bd_info *bd)
+static void scrub_duplicate_memory(void *blob)
 {
        /*
         * Scrub duplicate /memory@* node entries here. Some R-Car DTs might
@@ -119,6 +122,45 @@ int ft_board_setup(void *blob, struct bd_info *bd)
                first_mem_node = 0;
                mem = 0;
        }
+}
+
+static void update_rpc_status(void *blob)
+{
+       void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+       int offset, enabled;
+
+       /*
+        * Check if the DT fragment received from TF-A had its RPC-IF device node
+        * enabled.
+        */
+       if (fdt_magic(atf_fdt_blob) != FDT_MAGIC)
+               return;
+
+       offset = fdt_path_offset(atf_fdt_blob, FDT_RPC_PATH);
+       if (offset < 0)
+               return;
+
+       enabled = fdtdec_get_is_enabled(atf_fdt_blob, offset);
+       if (!enabled)
+               return;
+
+       /*
+        * Find the RPC-IF device node, and enable it if it has a flash subnode.
+        */
+       offset = fdt_path_offset(blob, FDT_RPC_PATH);
+       if (offset < 0)
+               return;
+
+       if (fdt_subnode_offset(blob, offset, "flash") < 0)
+               return;
+
+       fdt_status_okay(blob, offset);
+}
+
+int ft_board_setup(void *blob, struct bd_info *bd)
+{
+       scrub_duplicate_memory(blob);
+       update_rpc_status(blob);
 
        return 0;
 }
index 2c61ce7..aca7a6c 100644 (file)
@@ -388,7 +388,8 @@ static int rpc_hf_probe(struct udevice *dev)
 }
 
 static const struct udevice_id rpc_hf_ids[] = {
-       { .compatible = "renesas,rpc" },
+       { .compatible = "renesas,r7s72100-rpc-if" },
+       { .compatible = "renesas,rcar-gen3-rpc-if" },
        {}
 };
 
index 26b6aa8..cb2b8fb 100644 (file)
@@ -449,13 +449,8 @@ static const struct dm_spi_ops rpc_spi_ops = {
 };
 
 static const struct udevice_id rpc_spi_ids[] = {
-       { .compatible = "renesas,rpc-r7s72100" },
-       { .compatible = "renesas,rpc-r8a7795" },
-       { .compatible = "renesas,rpc-r8a7796" },
-       { .compatible = "renesas,rpc-r8a77965" },
-       { .compatible = "renesas,rpc-r8a77970" },
-       { .compatible = "renesas,rpc-r8a77995" },
-       { .compatible = "renesas,rcar-gen3-rpc" },
+       { .compatible = "renesas,r7s72100-rpc-if" },
+       { .compatible = "renesas,rcar-gen3-rpc-if" },
        { }
 };
 
index 8ba55aa..d0e92c7 100644 (file)
@@ -119,6 +119,7 @@ static struct usb_descriptor_header *fb_fs_function[] = {
        (struct usb_descriptor_header *)&interface_desc,
        (struct usb_descriptor_header *)&fs_ep_in,
        (struct usb_descriptor_header *)&fs_ep_out,
+       NULL,
 };
 
 static struct usb_descriptor_header *fb_hs_function[] = {
index 83c0108..9bb0d44 100644 (file)
@@ -226,6 +226,22 @@ enum efi_reset_type {
        EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \
                 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a)
 
+#define EFI_CONFORMANCE_PROFILES_TABLE_GUID \
+       EFI_GUID(0x36122546, 0xf7ef, 0x4c8f, 0xbd, 0x9b, \
+                0xeb, 0x85, 0x25, 0xb5, 0x0c, 0x0b)
+
+#define EFI_CONFORMANCE_PROFILES_TABLE_VERSION 1
+
+#define EFI_CONFORMANCE_PROFILE_EBBR_2_0_GUID \
+       EFI_GUID(0xcce33c35, 0x74ac, 0x4087, 0xbc, 0xe7, \
+                0x8b, 0x29, 0xb0, 0x2e, 0xeb, 0x27)
+
+struct efi_conformance_profiles_table {
+       u16 version;
+       u16 number_of_profiles;
+       efi_guid_t      conformance_profiles[];
+} __packed;
+
 struct efi_capsule_header {
        efi_guid_t capsule_guid;
        u32 header_size;
index 9611aec..545ba06 100644 (file)
@@ -1053,6 +1053,13 @@ extern u8 num_image_type_guids;
 efi_status_t efi_esrt_register(void);
 
 /**
+ * efi_ecpt_register() - Install the ECPT system table.
+ *
+ * Return: status code
+ */
+efi_status_t efi_ecpt_register(void);
+
+/**
  * efi_esrt_populate() - Populates the ESRT entries from the FMP instances
  * present in the system.
  * If an ESRT already exists, the old ESRT is replaced in the system table.
index 5cfff8c..b8fb270 100644 (file)
@@ -385,6 +385,23 @@ config EFI_ESRT
        help
          Enabling this option creates the ESRT UEFI system table.
 
+config EFI_ECPT
+       bool "Enable the UEFI ECPT generation"
+       default y
+       help
+         Enabling this option created the ECPT UEFI table.
+
+config EFI_EBBR_2_0_CONFORMANCE
+       bool "Add the EBBRv2.0 conformance entry to the ECPT table"
+       depends on EFI_ECPT
+       depends on EFI_LOADER_HII
+       depends on EFI_RISCV_BOOT_PROTOCOL || !RISCV
+       depends on EFI_RNG_PROTOCOL || !DM_RNG
+       depends on EFI_UNICODE_COLLATION_PROTOCOL2
+       default y
+       help
+         Enabling this option adds the EBBRv2.0 conformance entry to the ECPT UEFI table.
+
 config EFI_RISCV_BOOT_PROTOCOL
        bool "RISCV_EFI_BOOT_PROTOCOL support"
        default y
index f54c244..e187d2a 100644 (file)
@@ -76,6 +76,7 @@ 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
+obj-$(CONFIG_EFI_ECPT) += efi_conformance.o
 
 EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE))
 $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE)
diff --git a/lib/efi_loader/efi_conformance.c b/lib/efi_loader/efi_conformance.c
new file mode 100644 (file)
index 0000000..a49aae9
--- /dev/null
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ *  EFI conformance profile table
+ *
+ *  Copyright (C) 2022 Arm Ltd.
+ */
+
+#include <common.h>
+#include <efi_loader.h>
+#include <log.h>
+#include <efi_api.h>
+#include <malloc.h>
+
+static const efi_guid_t efi_ecpt_guid = EFI_CONFORMANCE_PROFILES_TABLE_GUID;
+static const efi_guid_t efi_ebbr_2_0_guid =
+       EFI_CONFORMANCE_PROFILE_EBBR_2_0_GUID;
+
+/**
+ * efi_ecpt_register() - Install the ECPT system table.
+ *
+ * Return: status code
+ */
+efi_status_t efi_ecpt_register(void)
+{
+       int num_entries = 0;
+       struct efi_conformance_profiles_table *ecpt;
+       efi_status_t ret;
+       size_t ecpt_size;
+
+       ecpt_size = num_entries * sizeof(efi_guid_t)
+               + sizeof(struct efi_conformance_profiles_table);
+       ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, ecpt_size,
+                               (void **)&ecpt);
+
+       if (ret != EFI_SUCCESS) {
+               log_err("Out of memory\n");
+
+               return ret;
+       }
+
+       if (CONFIG_IS_ENABLED(EFI_EBBR_2_0_CONFORMANCE))
+               guidcpy(&ecpt->conformance_profiles[num_entries++],
+                       &efi_ebbr_2_0_guid);
+
+       ecpt->version = EFI_CONFORMANCE_PROFILES_TABLE_VERSION;
+       ecpt->number_of_profiles = num_entries;
+
+       /* Install the ECPT in the system configuration table. */
+       ret = efi_install_configuration_table(&efi_ecpt_guid, (void *)ecpt);
+       if (ret != EFI_SUCCESS) {
+               log_err("Failed to install ECPT\n");
+               efi_free_pool(ecpt);
+
+               return ret;
+       }
+
+       log_debug("ECPT created\n");
+
+       return EFI_SUCCESS;
+}
index 3164fd4..ee9dc6b 100644 (file)
@@ -987,12 +987,14 @@ static efi_status_t EFIAPI efi_cin_read_key_stroke_ex(
        efi_cin_check();
 
        if (!key_available) {
+               memset(key_data, 0, sizeof(struct efi_key_data));
                ret = EFI_NOT_READY;
                goto out;
        }
        /*
         * CTRL+A - CTRL+Z have to be signaled as a - z.
         * SHIFT+CTRL+A - SHIFT+CTRL+Z have to be signaled as A - Z.
+        * CTRL+\ - CTRL+_ have to be signaled as \ - _.
         */
        switch (next_key.key.unicode_char) {
        case 0x01 ... 0x07:
@@ -1005,6 +1007,9 @@ static efi_status_t EFIAPI efi_cin_read_key_stroke_ex(
                        next_key.key.unicode_char += 0x40;
                else
                        next_key.key.unicode_char += 0x60;
+               break;
+       case 0x1c ... 0x1f:
+                       next_key.key.unicode_char += 0x40;
        }
        *key_data = next_key;
        key_available = false;
index 6c428ee..9062058 100644 (file)
@@ -190,13 +190,14 @@ static char *dp_msging(char *s, struct efi_device_path *dp)
                struct efi_device_path_nvme *ndp =
                        (struct efi_device_path_nvme *)dp;
                u32 ns_id;
-               int i;
 
                memcpy(&ns_id, &ndp->ns_id, sizeof(ns_id));
                s += sprintf(s, "NVMe(0x%x,", ns_id);
-               for (i = 0; i < sizeof(ndp->eui64); ++i)
+
+               /* Display byte 7 first, byte 0 last */
+               for (int i = 0; i < 8; ++i)
                        s += sprintf(s, "%s%02x", i ? "-" : "",
-                                    ndp->eui64[i]);
+                                    ndp->eui64[i ^ 7]);
                s += sprintf(s, ")");
 
                break;
index 45a9a1d..c633fcd 100644 (file)
@@ -274,6 +274,12 @@ efi_status_t efi_init_obj_list(void)
        if (ret != EFI_SUCCESS)
                goto out;
 
+       if (IS_ENABLED(CONFIG_EFI_ECPT)) {
+               ret = efi_ecpt_register();
+               if (ret != EFI_SUCCESS)
+                       goto out;
+       }
+
        if (IS_ENABLED(CONFIG_EFI_ESRT)) {
                ret = efi_esrt_register();
                if (ret != EFI_SUCCESS)
index 10666dc..d565f32 100644 (file)
@@ -29,24 +29,66 @@ static struct efi_system_table *systable;
 static struct efi_boot_services *boottime;
 static struct efi_simple_text_output_protocol *con_out;
 
+/*
+ * Print an unsigned 32bit value as decimal number to an u16 string
+ *
+ * @value:     value to be printed
+ * @buf:       pointer to buffer address
+ *             on return position of terminating zero word
+ */
+static void uint2dec(u32 value, u16 **buf)
+{
+       u16 *pos = *buf;
+       int i;
+       u16 c;
+       u64 f;
+
+       /*
+        * Increment by .5 and multiply with
+        * (2 << 60) / 1,000,000,000 = 0x44B82FA0.9B5A52CC
+        * to move the first digit to bit 60-63.
+        */
+       f = 0x225C17D0;
+       f += (0x9B5A52DULL * value) >> 28;
+       f += 0x44B82FA0ULL * value;
+
+       for (i = 0; i < 10; ++i) {
+               /* Write current digit */
+               c = f >> 60;
+               if (c || pos != *buf)
+                       *pos++ = c + '0';
+               /* Eliminate current digit */
+               f &= 0xfffffffffffffff;
+               /* Get next digit */
+               f *= 0xaULL;
+       }
+       if (pos == *buf)
+               *pos++ = '0';
+       *pos = 0;
+       *buf = pos;
+}
+
 /**
  * print_uefi_revision() - print UEFI revision number
  */
 static void print_uefi_revision(void)
 {
-       u16 rev[] = u"0.0.0";
-
-       rev[0] = (systable->hdr.revision >> 16) + '0';
-       rev[4] = systable->hdr.revision & 0xffff;
-       for (; rev[4] >= 10;) {
-               rev[4] -= 10;
-               ++rev[2];
+       u16 rev[13] = {0};
+       u16 *buf = rev;
+       u16 digit;
+
+       uint2dec(systable->hdr.revision >> 16, &buf);
+       *buf++ = '.';
+       uint2dec(systable->hdr.revision & 0xffff, &buf);
+
+       /* Minor revision is only to be shown if non-zero */
+       digit = *--buf;
+       if (digit == '0') {
+               *buf = 0;
+       } else {
+               *buf++ = '.';
+               *buf = digit;
        }
-       /* Third digit is only to be shown if non-zero */
-       if (rev[4])
-               rev[4] += '0';
-       else
-               rev[3] = 0;
 
        con_out->output_string(con_out, u"Running on UEFI ");
        con_out->output_string(con_out, rev);
index 79f9a67..a9ad381 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <common.h>
 #include <efi_api.h>
+#include <host_arch.h>
 
 /*
  * Entry point of the EFI application.
@@ -33,11 +34,17 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
        asm volatile (".word 0xe7f7defb\n");
 #elif defined(CONFIG_RISCV)
        asm volatile (".word 0xffffffff\n");
+#elif defined(CONFIG_X86)
+       asm volatile (".word 0xffff\n");
 #elif defined(CONFIG_SANDBOX)
+#if (HOST_ARCH == HOST_ARCH_ARM || HOST_ARCH == HOST_ARCH_AARCH64)
+       asm volatile (".word 0xe7f7defb\n");
+#elif (HOST_ARCH == HOST_ARCH_RISCV32 || HOST_ARCH == HOST_ARCH_RISCV64)
        asm volatile (".word 0xffffffff\n");
-#elif defined(CONFIG_X86)
+#elif (HOST_ARCH == HOST_ARCH_X86 || HOST_ARCH == HOST_ARCH_X86_64)
        asm volatile (".word 0xffff\n");
 #endif
+#endif
        con_out->output_string(con_out, u"Exception not triggered.\n");
        return EFI_ABORTED;
 }
index 284f811..465e1ac 100644 (file)
@@ -220,6 +220,10 @@ static const struct {
                "TCG2 Final Events Table",
                EFI_TCG2_FINAL_EVENTS_TABLE_GUID,
        },
+       {
+               "EFI Conformance Profiles Table",
+               EFI_CONFORMANCE_PROFILES_TABLE_GUID,
+       },
 #ifdef CONFIG_EFI_RISCV_BOOT_PROTOCOL
        {
                "RISC-V Boot",