blob: 44fb9f0fefddb216320f8e9fbd796441a2d6d5d5 [file] [log] [blame]
Subrata Banik73505f12023-12-27 21:13:25 +05301/* SPDX-License-Identifier: GPL-2.0-only */
2
Subrata Banik8e7251c2024-01-02 23:28:49 +05303#include <assert.h>
Subrata Banik73505f12023-12-27 21:13:25 +05304#include <console/console.h>
5#include <security/tpm/tss.h>
Subrata Banikd968b852023-12-28 23:37:27 +05306#include <types.h>
Subrata Banik73505f12023-12-27 21:13:25 +05307#include <vendorcode/google/chromeos/chromeos.h>
8
Subrata Banikd968b852023-12-28 23:37:27 +05309#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 Banik8e7251c2024-01-02 23:28:49 +053013uint64_t chromeos_get_factory_config(void)
Subrata Banik73505f12023-12-27 21:13:25 +053014{
Subrata Banik8e7251c2024-01-02 23:28:49 +053015 static uint64_t factory_config = UNDEFINED_FACTORY_CONFIG;
Subrata Banik73505f12023-12-27 21:13:25 +053016
Subrata Banik8e7251c2024-01-02 23:28:49 +053017 if (factory_config != UNDEFINED_FACTORY_CONFIG)
Subrata Banik73505f12023-12-27 21:13:25 +053018 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 Banik8e7251c2024-01-02 23:28:49 +053025 return UNDEFINED_FACTORY_CONFIG;
Subrata Banik73505f12023-12-27 21:13:25 +053026 }
27
Subrata Banik8e7251c2024-01-02 23:28:49 +053028 rc = tlcl_cr50_get_factory_config(&factory_config);
Subrata Banik73505f12023-12-27 21:13:25 +053029
30 if (rc != TPM_SUCCESS) {
31 printk(BIOS_ERR, "%s:%d - tlcl_cr50_get_factory_config() failed: %#x\n",
32 __func__, __LINE__, rc);
Subrata Banik8e7251c2024-01-02 23:28:49 +053033 return UNDEFINED_FACTORY_CONFIG;
Subrata Banik73505f12023-12-27 21:13:25 +053034 }
35
Subrata Banik8e7251c2024-01-02 23:28:49 +053036 assert(factory_config != UNDEFINED_FACTORY_CONFIG);
37
Subrata Banik73505f12023-12-27 21:13:25 +053038 return factory_config;
39}
Subrata Banikd968b852023-12-28 23:37:27 +053040
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 */
52bool chromeos_device_branded_plus(void)
53{
Subrata Banik8e7251c2024-01-02 23:28:49 +053054 uint64_t factory_config = chromeos_get_factory_config();
Subrata Banikd968b852023-12-28 23:37:27 +053055
Subrata Banik8e7251c2024-01-02 23:28:49 +053056 if (factory_config == UNDEFINED_FACTORY_CONFIG)
Subrata Banikd968b852023-12-28 23:37:27 +053057 return false;
58
59 return factory_config & CHROMEBOOK_PLUS_DEVICE;
60}