|
15 | 15 | #include <asm/e820/api.h> |
16 | 16 | #include <asm/efi.h> |
17 | 17 | #include <asm/uv/uv.h> |
| 18 | +#include <asm/cpu_device_id.h> |
18 | 19 |
|
19 | 20 | #define EFI_MIN_RESERVE 5120 |
20 | 21 |
|
21 | 22 | #define EFI_DUMMY_GUID \ |
22 | 23 | EFI_GUID(0x4424ac57, 0xbe4b, 0x47dd, 0x9e, 0x97, 0xed, 0x50, 0xf0, 0x9f, 0x92, 0xa9) |
23 | 24 |
|
| 25 | +#define QUARK_CSH_SIGNATURE 0x5f435348 /* _CSH */ |
| 26 | +#define QUARK_SECURITY_HEADER_SIZE 0x400 |
| 27 | + |
| 28 | +/* |
| 29 | + * Header prepended to the standard EFI capsule on Quark systems the are based |
| 30 | + * on Intel firmware BSP. |
| 31 | + * @csh_signature: Unique identifier to sanity check signed module |
| 32 | + * presence ("_CSH"). |
| 33 | + * @version: Current version of CSH used. Should be one for Quark A0. |
| 34 | + * @modulesize: Size of the entire module including the module header |
| 35 | + * and payload. |
| 36 | + * @security_version_number_index: Index of SVN to use for validation of signed |
| 37 | + * module. |
| 38 | + * @security_version_number: Used to prevent against roll back of modules. |
| 39 | + * @rsvd_module_id: Currently unused for Clanton (Quark). |
| 40 | + * @rsvd_module_vendor: Vendor Identifier. For Intel products value is |
| 41 | + * 0x00008086. |
| 42 | + * @rsvd_date: BCD representation of build date as yyyymmdd, where |
| 43 | + * yyyy=4 digit year, mm=1-12, dd=1-31. |
| 44 | + * @headersize: Total length of the header including including any |
| 45 | + * padding optionally added by the signing tool. |
| 46 | + * @hash_algo: What Hash is used in the module signing. |
| 47 | + * @cryp_algo: What Crypto is used in the module signing. |
| 48 | + * @keysize: Total length of the key data including including any |
| 49 | + * padding optionally added by the signing tool. |
| 50 | + * @signaturesize: Total length of the signature including including any |
| 51 | + * padding optionally added by the signing tool. |
| 52 | + * @rsvd_next_header: 32-bit pointer to the next Secure Boot Module in the |
| 53 | + * chain, if there is a next header. |
| 54 | + * @rsvd: Reserved, padding structure to required size. |
| 55 | + * |
| 56 | + * See also QuartSecurityHeader_t in |
| 57 | + * Quark_EDKII_v1.2.1.1/QuarkPlatformPkg/Include/QuarkBootRom.h |
| 58 | + * from https://downloadcenter.intel.com/download/23197/Intel-Quark-SoC-X1000-Board-Support-Package-BSP |
| 59 | + */ |
| 60 | +struct quark_security_header { |
| 61 | + u32 csh_signature; |
| 62 | + u32 version; |
| 63 | + u32 modulesize; |
| 64 | + u32 security_version_number_index; |
| 65 | + u32 security_version_number; |
| 66 | + u32 rsvd_module_id; |
| 67 | + u32 rsvd_module_vendor; |
| 68 | + u32 rsvd_date; |
| 69 | + u32 headersize; |
| 70 | + u32 hash_algo; |
| 71 | + u32 cryp_algo; |
| 72 | + u32 keysize; |
| 73 | + u32 signaturesize; |
| 74 | + u32 rsvd_next_header; |
| 75 | + u32 rsvd[2]; |
| 76 | +}; |
| 77 | + |
24 | 78 | static efi_char16_t efi_dummy_name[6] = { 'D', 'U', 'M', 'M', 'Y', 0 }; |
25 | 79 |
|
26 | 80 | static bool efi_no_storage_paranoia; |
@@ -504,3 +558,86 @@ bool efi_poweroff_required(void) |
504 | 558 | { |
505 | 559 | return acpi_gbl_reduced_hardware || acpi_no_s5; |
506 | 560 | } |
| 561 | + |
| 562 | +#ifdef CONFIG_EFI_CAPSULE_QUIRK_QUARK_CSH |
| 563 | + |
| 564 | +static int qrk_capsule_setup_info(struct capsule_info *cap_info, void **pkbuff, |
| 565 | + size_t hdr_bytes) |
| 566 | +{ |
| 567 | + struct quark_security_header *csh = *pkbuff; |
| 568 | + |
| 569 | + /* Only process data block that is larger than the security header */ |
| 570 | + if (hdr_bytes < sizeof(struct quark_security_header)) |
| 571 | + return 0; |
| 572 | + |
| 573 | + if (csh->csh_signature != QUARK_CSH_SIGNATURE || |
| 574 | + csh->headersize != QUARK_SECURITY_HEADER_SIZE) |
| 575 | + return 1; |
| 576 | + |
| 577 | + /* Only process data block if EFI header is included */ |
| 578 | + if (hdr_bytes < QUARK_SECURITY_HEADER_SIZE + |
| 579 | + sizeof(efi_capsule_header_t)) |
| 580 | + return 0; |
| 581 | + |
| 582 | + pr_debug("Quark security header detected\n"); |
| 583 | + |
| 584 | + if (csh->rsvd_next_header != 0) { |
| 585 | + pr_err("multiple Quark security headers not supported\n"); |
| 586 | + return -EINVAL; |
| 587 | + } |
| 588 | + |
| 589 | + *pkbuff += csh->headersize; |
| 590 | + cap_info->total_size = csh->headersize; |
| 591 | + |
| 592 | + /* |
| 593 | + * Update the first page pointer to skip over the CSH header. |
| 594 | + */ |
| 595 | + cap_info->pages[0] += csh->headersize; |
| 596 | + |
| 597 | + return 1; |
| 598 | +} |
| 599 | + |
| 600 | +#define ICPU(family, model, quirk_handler) \ |
| 601 | + { X86_VENDOR_INTEL, family, model, X86_FEATURE_ANY, \ |
| 602 | + (unsigned long)&quirk_handler } |
| 603 | + |
| 604 | +static const struct x86_cpu_id efi_capsule_quirk_ids[] = { |
| 605 | + ICPU(5, 9, qrk_capsule_setup_info), /* Intel Quark X1000 */ |
| 606 | + { } |
| 607 | +}; |
| 608 | + |
| 609 | +int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff, |
| 610 | + size_t hdr_bytes) |
| 611 | +{ |
| 612 | + int (*quirk_handler)(struct capsule_info *, void **, size_t); |
| 613 | + const struct x86_cpu_id *id; |
| 614 | + int ret; |
| 615 | + |
| 616 | + if (hdr_bytes < sizeof(efi_capsule_header_t)) |
| 617 | + return 0; |
| 618 | + |
| 619 | + cap_info->total_size = 0; |
| 620 | + |
| 621 | + id = x86_match_cpu(efi_capsule_quirk_ids); |
| 622 | + if (id) { |
| 623 | + /* |
| 624 | + * The quirk handler is supposed to return |
| 625 | + * - a value > 0 if the setup should continue, after advancing |
| 626 | + * kbuff as needed |
| 627 | + * - 0 if not enough hdr_bytes are available yet |
| 628 | + * - a negative error code otherwise |
| 629 | + */ |
| 630 | + quirk_handler = (typeof(quirk_handler))id->driver_data; |
| 631 | + ret = quirk_handler(cap_info, &kbuff, hdr_bytes); |
| 632 | + if (ret <= 0) |
| 633 | + return ret; |
| 634 | + } |
| 635 | + |
| 636 | + memcpy(&cap_info->header, kbuff, sizeof(cap_info->header)); |
| 637 | + |
| 638 | + cap_info->total_size += cap_info->header.imagesize; |
| 639 | + |
| 640 | + return __efi_capsule_setup_info(cap_info); |
| 641 | +} |
| 642 | + |
| 643 | +#endif |
0 commit comments