xref: /aosp_15_r20/external/coreboot/src/vendorcode/google/chromeos/tpm_factory_config.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <assert.h>
4 #include <console/console.h>
5 #include <drivers/vpd/vpd.h>
6 #include <security/tpm/tss.h>
7 #include <types.h>
8 #include <vendorcode/google/chromeos/chromeos.h>
9 
10 #define CHROMEBOOK_PLUS_HARD_BRANDED BIT(4)
11 
chromeos_get_factory_config(void)12 uint64_t chromeos_get_factory_config(void)
13 {
14 	static uint64_t factory_config = UNDEFINED_FACTORY_CONFIG;
15 
16 	if (factory_config != UNDEFINED_FACTORY_CONFIG)
17 		return factory_config;
18 
19 	/* Initialize TPM driver. */
20 	tpm_result_t rc = tlcl_lib_init();
21 	if (rc != TPM_SUCCESS) {
22 		printk(BIOS_ERR, "%s:%d - tlcl_lib_init() failed: %#x\n",
23 		       __func__, __LINE__, rc);
24 		return UNDEFINED_FACTORY_CONFIG;
25 	}
26 
27 	rc = tlcl_cr50_get_factory_config(&factory_config);
28 
29 	if (rc != TPM_SUCCESS) {
30 		printk(BIOS_ERR, "%s:%d - tlcl_cr50_get_factory_config() failed: %#x\n",
31 		       __func__, __LINE__, rc);
32 		return UNDEFINED_FACTORY_CONFIG;
33 	}
34 
35 	assert(factory_config != UNDEFINED_FACTORY_CONFIG);
36 
37 	return factory_config;
38 }
39 
40 /*
41  * Determines whether a ChromeOS device is branded as a Chromebook-Plus
42  * based on specific bit flags:
43  *
44  * - Bit 4 (0x10): Indicates whether the device chassis has the
45  *                 "chromebook-plus" branding.
46  */
chromeos_device_branded_plus_hard(void)47 bool chromeos_device_branded_plus_hard(void)
48 {
49 	uint64_t factory_config = chromeos_get_factory_config();
50 
51 	if (factory_config == UNDEFINED_FACTORY_CONFIG)
52 		return false;
53 
54 	return (factory_config & CHROMEBOOK_PLUS_HARD_BRANDED) == CHROMEBOOK_PLUS_HARD_BRANDED;
55 }
56 
57 /*
58  * Use 'feature_level' populated by ChromeOS libsegmentation library to know if the device
59  * is a chromebook plus or not.
60  *
61  * Note: After powerwash or dev/normal mode switch, the splash screen may be incorrect
62  * on first boot until VPD is updated.
63  */
chromeos_device_branded_plus_soft(void)64 bool chromeos_device_branded_plus_soft(void)
65 {
66 	if (vpd_get_feature_level() > 1)
67 		return true;
68 
69 	return false;
70 }
71