Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 3 | #include <assert.h> |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <security/tpm/tss.h> |
Subrata Banik | d968b85 | 2023-12-28 23:37:27 +0530 | [diff] [blame] | 6 | #include <types.h> |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 7 | #include <vendorcode/google/chromeos/chromeos.h> |
| 8 | |
Subrata Banik | d968b85 | 2023-12-28 23:37:27 +0530 | [diff] [blame] | 9 | #define CHROMEBOOK_PLUS_HARD_BRANDED BIT(4) |
| 10 | #define CHROMEBOOK_PLUS_SOFT_BRANDED BIT(0) |
| 11 | #define CHROMEBOOK_PLUS_DEVICE (CHROMEBOOK_PLUS_HARD_BRANDED | CHROMEBOOK_PLUS_SOFT_BRANDED) |
| 12 | |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 13 | uint64_t chromeos_get_factory_config(void) |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 14 | { |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 15 | static uint64_t factory_config = UNDEFINED_FACTORY_CONFIG; |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 16 | |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 17 | if (factory_config != UNDEFINED_FACTORY_CONFIG) |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 18 | return factory_config; |
| 19 | |
| 20 | /* Initialize TPM driver. */ |
| 21 | tpm_result_t rc = tlcl_lib_init(); |
| 22 | if (rc != TPM_SUCCESS) { |
| 23 | printk(BIOS_ERR, "%s:%d - tlcl_lib_init() failed: %#x\n", |
| 24 | __func__, __LINE__, rc); |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 25 | return UNDEFINED_FACTORY_CONFIG; |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 26 | } |
| 27 | |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 28 | rc = tlcl_cr50_get_factory_config(&factory_config); |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 29 | |
| 30 | if (rc != TPM_SUCCESS) { |
| 31 | printk(BIOS_ERR, "%s:%d - tlcl_cr50_get_factory_config() failed: %#x\n", |
| 32 | __func__, __LINE__, rc); |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 33 | return UNDEFINED_FACTORY_CONFIG; |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 34 | } |
| 35 | |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 36 | assert(factory_config != UNDEFINED_FACTORY_CONFIG); |
| 37 | |
Subrata Banik | 73505f1 | 2023-12-27 21:13:25 +0530 | [diff] [blame] | 38 | return factory_config; |
| 39 | } |
Subrata Banik | d968b85 | 2023-12-28 23:37:27 +0530 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Determines whether a ChromeOS device is branded as a Chromebook Plus |
| 43 | * based on specific bit flags: |
| 44 | * |
| 45 | * - Bit 4 (0x10): Indicates whether the device chassis has the |
| 46 | * "chromebook-plus" branding. |
| 47 | * - Bits 3-0 (0x1): Must be 0x1 to signify compliance with Chromebook Plus |
| 48 | * hardware specifications. |
| 49 | * |
| 50 | * To be considered a Chromebook Plus, either of these conditions needs to be met. |
| 51 | */ |
| 52 | bool chromeos_device_branded_plus(void) |
| 53 | { |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 54 | uint64_t factory_config = chromeos_get_factory_config(); |
Subrata Banik | d968b85 | 2023-12-28 23:37:27 +0530 | [diff] [blame] | 55 | |
Subrata Banik | 8e7251c | 2024-01-02 23:28:49 +0530 | [diff] [blame^] | 56 | if (factory_config == UNDEFINED_FACTORY_CONFIG) |
Subrata Banik | d968b85 | 2023-12-28 23:37:27 +0530 | [diff] [blame] | 57 | return false; |
| 58 | |
| 59 | return factory_config & CHROMEBOOK_PLUS_DEVICE; |
| 60 | } |