Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Elyes HAOUAS | 944da48 | 2021-02-01 21:30:13 +0100 | [diff] [blame] | 2 | |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 4 | #include <bootstate.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 5 | #include <cbfs.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 6 | #include <commonlib/region.h> |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | #include <cpu/cpu.h> |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 9 | #include <crc_byte.h> |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 10 | #include <elog.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 11 | #include <fmap.h> |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 12 | #include <intelbasecode/debug_feature.h> |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 13 | #include <intelblocks/cse.h> |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 14 | #include <intelblocks/cse_layout.h> |
Kapil Porwal | 53e5d1f | 2024-06-17 11:32:58 +0000 | [diff] [blame^] | 15 | #include <intelblocks/cse_lite.h> |
Subrata Banik | da527ec | 2022-11-24 15:42:35 +0530 | [diff] [blame] | 16 | #include <intelblocks/spi.h> |
Sridhar Siricilla | 87e36c4 | 2020-05-03 19:08:18 +0530 | [diff] [blame] | 17 | #include <security/vboot/misc.h> |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 18 | #include <security/vboot/vboot_common.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 19 | #include <soc/intel/common/reset.h> |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 20 | #include <timestamp.h> |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 21 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 22 | #include "cse_lite_cmos.h" |
| 23 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 24 | static struct get_bp_info_rsp cse_bp_info_rsp; |
| 25 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 26 | enum cse_fw_state { |
| 27 | /* The CMOS and CBMEM have the current fw version. */ |
| 28 | CSE_FW_WARM_BOOT, |
| 29 | |
| 30 | /* The CMOS has the current fw version, and the CBMEM is wiped out. */ |
| 31 | CSE_FW_COLD_BOOT, |
| 32 | |
| 33 | /* The CMOS and CBMEM are not initialized or not same as running firmware version.*/ |
| 34 | CSE_FW_INVALID, |
| 35 | }; |
| 36 | |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 37 | static const char * const cse_regions[] = {"RO", "RW"}; |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 38 | |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 39 | static struct cse_specific_info cse_info; |
| 40 | |
Subrata Banik | da527ec | 2022-11-24 15:42:35 +0530 | [diff] [blame] | 41 | void cse_log_ro_write_protection_info(bool mfg_mode) |
| 42 | { |
| 43 | bool cse_ro_wp_en = is_spi_wp_cse_ro_en(); |
| 44 | |
| 45 | printk(BIOS_DEBUG, "ME: WP for RO is enabled : %s\n", |
| 46 | cse_ro_wp_en ? "YES" : "NO"); |
| 47 | |
| 48 | if (cse_ro_wp_en) { |
| 49 | uint32_t base, limit; |
| 50 | spi_get_wp_cse_ro_range(&base, &limit); |
| 51 | printk(BIOS_DEBUG, "ME: RO write protection scope - Start=0x%X, End=0x%X\n", |
| 52 | base, limit); |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * If manufacturing mode is disabled, but CSE RO is not write protected, |
| 57 | * log error. |
| 58 | */ |
| 59 | if (!mfg_mode && !cse_ro_wp_en) |
| 60 | printk(BIOS_ERR, "ME: Write protection for CSE RO is not enabled\n"); |
| 61 | } |
| 62 | |
Sridhar Siricilla | dd7d51d | 2023-01-10 15:05:07 +0530 | [diff] [blame] | 63 | enum cb_err cse_get_boot_performance_data(struct cse_boot_perf_rsp *boot_perf_rsp) |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 64 | { |
| 65 | struct cse_boot_perf_req { |
| 66 | struct mkhi_hdr hdr; |
| 67 | uint32_t reserved; |
| 68 | } __packed; |
| 69 | |
| 70 | struct cse_boot_perf_req req = { |
| 71 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 72 | .hdr.command = MKHI_BUP_COMMON_GET_BOOT_PERF_DATA, |
| 73 | .reserved = 0, |
| 74 | }; |
| 75 | |
| 76 | size_t resp_size = sizeof(struct cse_boot_perf_rsp); |
| 77 | |
Sridhar Siricilla | 6836da2 | 2022-02-23 23:36:45 +0530 | [diff] [blame] | 78 | if (heci_send_receive(&req, sizeof(req), boot_perf_rsp, &resp_size, |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 79 | HECI_MKHI_ADDR)) { |
| 80 | printk(BIOS_ERR, "cse_lite: Could not get boot performance data\n"); |
Sridhar Siricilla | dd7d51d | 2023-01-10 15:05:07 +0530 | [diff] [blame] | 81 | return CB_ERR; |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (boot_perf_rsp->hdr.result) { |
| 85 | printk(BIOS_ERR, "cse_lite: Get boot performance data resp failed: %d\n", |
| 86 | boot_perf_rsp->hdr.result); |
Sridhar Siricilla | dd7d51d | 2023-01-10 15:05:07 +0530 | [diff] [blame] | 87 | return CB_ERR; |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Sridhar Siricilla | dd7d51d | 2023-01-10 15:05:07 +0530 | [diff] [blame] | 90 | return CB_SUCCESS; |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 93 | static const struct cse_bp_info *cse_get_bp_info_from_rsp(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 94 | { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 95 | return &cse_bp_info_rsp.bp_info; |
| 96 | } |
| 97 | |
| 98 | static uint8_t cse_get_current_bp(void) |
| 99 | { |
| 100 | const struct cse_bp_info *cse_bp_info = cse_get_bp_info_from_rsp(); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 101 | return cse_bp_info->current_bp; |
| 102 | } |
| 103 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 104 | static const struct cse_bp_entry *cse_get_bp_entry(enum boot_partition_id bp) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 105 | { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 106 | const struct cse_bp_info *cse_bp_info = cse_get_bp_info_from_rsp(); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 107 | return &cse_bp_info->bp_entries[bp]; |
| 108 | } |
| 109 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 110 | static bool is_cse_fpt_info_valid(const struct cse_specific_info *info) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 111 | { |
| 112 | uint32_t crc = ~CRC(info, offsetof(struct cse_specific_info, crc), crc32_byte); |
| 113 | |
| 114 | /* |
| 115 | * Authenticate the CBMEM persistent data. |
| 116 | * |
| 117 | * The underlying assumption is that an event (i.e., CSE upgrade/downgrade) which |
| 118 | * could change the values stored in this region has to also trigger the global |
| 119 | * reset. Hence, CBMEM persistent data won't be available any time after such |
| 120 | * event (global reset or cold reset) being initiated. |
| 121 | * |
| 122 | * During warm boot scenarios CBMEM contents remain persistent hence, we don't |
| 123 | * want to override the existing data in CBMEM to avoid any additional boot latency. |
| 124 | */ |
| 125 | if (info->crc != crc) |
| 126 | return false; |
| 127 | |
| 128 | return true; |
| 129 | } |
| 130 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 131 | static void store_cse_info_crc(struct cse_specific_info *info) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 132 | { |
| 133 | info->crc = ~CRC(info, offsetof(struct cse_specific_info, crc), crc32_byte); |
| 134 | } |
| 135 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 136 | static enum cse_fw_state get_cse_state(const struct fw_version *cur_cse_fw_ver, |
| 137 | struct fw_version *cmos_cse_fw_ver, const struct fw_version *cbmem_cse_fw_ver) |
| 138 | { |
| 139 | enum cse_fw_state state = CSE_FW_WARM_BOOT; |
| 140 | size_t size = sizeof(struct fw_version); |
| 141 | /* |
| 142 | * Compare if stored CSE version (from the previous boot) is same as current |
| 143 | * running CSE version. |
| 144 | */ |
| 145 | if (memcmp(cmos_cse_fw_ver, cur_cse_fw_ver, size)) { |
| 146 | /* |
| 147 | * CMOS CSE versioin is invalid, possibly two scenarios |
| 148 | * 1. CSE FW update |
| 149 | * 2. First boot |
| 150 | */ |
| 151 | state = CSE_FW_INVALID; |
| 152 | } else { |
| 153 | /* |
| 154 | * Check if current running CSE version is same as previous stored CSE |
| 155 | * version aka CBMEM region is still valid. |
| 156 | */ |
| 157 | if (memcmp(cbmem_cse_fw_ver, cur_cse_fw_ver, size)) |
| 158 | state = CSE_FW_COLD_BOOT; |
| 159 | } |
| 160 | return state; |
| 161 | } |
| 162 | |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 163 | /* |
| 164 | * Helper function that stores current CSE firmware version to CBMEM memory, |
| 165 | * except during recovery mode. |
| 166 | */ |
Krishna P Bhat D | 64ec6a7 | 2023-09-21 22:19:47 +0530 | [diff] [blame] | 167 | static void cse_store_rw_fw_version(void) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 168 | { |
Krishna P Bhat D | 64ec6a7 | 2023-09-21 22:19:47 +0530 | [diff] [blame] | 169 | const struct cse_bp_entry *cse_bp; |
| 170 | cse_bp = cse_get_bp_entry(RW); |
| 171 | |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 172 | if (vboot_recovery_mode_enabled()) |
| 173 | return; |
| 174 | |
| 175 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_IN_ROMSTAGE)) { |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 176 | /* update current CSE version and return */ |
| 177 | memcpy(&(cse_info.cse_fwp_version.cur_cse_fw_version), |
| 178 | &(cse_bp->fw_ver), sizeof(struct fw_version)); |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 179 | return; |
| 180 | } |
| 181 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 182 | struct cse_specific_info *cse_info_in_cbmem = cbmem_add(CBMEM_ID_CSE_INFO, |
| 183 | sizeof(*cse_info_in_cbmem)); |
| 184 | if (!cse_info_in_cbmem) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 185 | return; |
| 186 | |
| 187 | /* Avoid CBMEM update if CBMEM already has persistent data */ |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 188 | if (is_cse_fpt_info_valid(cse_info_in_cbmem)) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 189 | return; |
| 190 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 191 | struct cse_specific_info cse_info_in_cmos; |
| 192 | cmos_read_fw_partition_info(&cse_info_in_cmos); |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 193 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 194 | /* Get current cse firmware state */ |
| 195 | enum cse_fw_state fw_state = get_cse_state(&(cse_bp->fw_ver), |
| 196 | &(cse_info_in_cmos.cse_fwp_version.cur_cse_fw_version), |
| 197 | &(cse_info_in_cbmem->cse_fwp_version.cur_cse_fw_version)); |
| 198 | |
| 199 | /* Reset CBMEM data and update current CSE version */ |
| 200 | memset(cse_info_in_cbmem, 0, sizeof(*cse_info_in_cbmem)); |
| 201 | memcpy(&(cse_info_in_cbmem->cse_fwp_version.cur_cse_fw_version), |
| 202 | &(cse_bp->fw_ver), sizeof(struct fw_version)); |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 203 | |
| 204 | /* Update the CRC */ |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 205 | store_cse_info_crc(cse_info_in_cbmem); |
| 206 | |
| 207 | if (fw_state == CSE_FW_INVALID) { |
| 208 | /* |
| 209 | * Current CMOS data is outdated, which could be due to CSE update or |
| 210 | * rollback, hence, need to update CMOS with current CSE FPT versions. |
| 211 | */ |
| 212 | cmos_write_fw_partition_info(cse_info_in_cbmem); |
| 213 | } |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | #if CONFIG(SOC_INTEL_CSE_LITE_SYNC_IN_ROMSTAGE) |
| 217 | /* Function to copy PRERAM CSE specific info to pertinent CBMEM. */ |
| 218 | static void preram_cse_info_sync_to_cbmem(int is_recovery) |
| 219 | { |
Kapil Porwal | 53e5d1f | 2024-06-17 11:32:58 +0000 | [diff] [blame^] | 220 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 221 | return; |
| 222 | |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 223 | if (vboot_recovery_mode_enabled() || !CONFIG(SOC_INTEL_STORE_CSE_FW_VERSION)) |
| 224 | return; |
| 225 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 226 | struct cse_specific_info *cse_info_in_cbmem = cbmem_add(CBMEM_ID_CSE_INFO, |
| 227 | sizeof(*cse_info_in_cbmem)); |
| 228 | if (!cse_info_in_cbmem) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 229 | return; |
| 230 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 231 | /* Warm Reboot: Avoid sync into CBMEM if CBMEM already has persistent data */ |
| 232 | if (is_cse_fpt_info_valid(cse_info_in_cbmem)) |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 233 | return; |
| 234 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 235 | /* Update CBMEM with PRERAM CSE specific info and update the CRC */ |
| 236 | memcpy(cse_info_in_cbmem, &cse_info, sizeof(struct cse_specific_info)); |
| 237 | store_cse_info_crc(cse_info_in_cbmem); |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 238 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 239 | struct cse_specific_info cse_info_in_cmos; |
| 240 | cmos_read_fw_partition_info(&cse_info_in_cmos); |
| 241 | |
| 242 | if (!memcmp(&(cse_info_in_cmos.cse_fwp_version.cur_cse_fw_version), |
| 243 | &(cse_info_in_cbmem->cse_fwp_version.cur_cse_fw_version), |
| 244 | sizeof(struct fw_version))) { |
| 245 | /* Cold Reboot: Avoid sync into CMOS if CMOS already has persistent data */ |
| 246 | if (is_cse_fpt_info_valid(&cse_info_in_cmos)) |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Current CMOS data is outdated, which could be due to CSE update or |
| 252 | * rollback, hence, need to update CMOS with current CSE FPT versions. |
| 253 | */ |
| 254 | cmos_write_fw_partition_info(cse_info_in_cbmem); |
Subrata Banik | 65a6d17 | 2023-08-13 13:03:50 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | CBMEM_CREATION_HOOK(preram_cse_info_sync_to_cbmem); |
| 258 | #endif |
| 259 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 260 | static void cse_print_boot_partition_info(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 261 | { |
| 262 | const struct cse_bp_entry *cse_bp; |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 263 | const struct cse_bp_info *cse_bp_info = cse_get_bp_info_from_rsp(); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 264 | |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 265 | printk(BIOS_DEBUG, "cse_lite: Number of partitions = %d\n", |
| 266 | cse_bp_info->total_number_of_bp); |
| 267 | printk(BIOS_DEBUG, "cse_lite: Current partition = %s\n", |
| 268 | GET_BP_STR(cse_bp_info->current_bp)); |
| 269 | printk(BIOS_DEBUG, "cse_lite: Next partition = %s\n", GET_BP_STR(cse_bp_info->next_bp)); |
| 270 | printk(BIOS_DEBUG, "cse_lite: Flags = 0x%x\n", cse_bp_info->flags); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 271 | |
| 272 | /* Log version info of RO & RW partitions */ |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 273 | cse_bp = cse_get_bp_entry(RO); |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 274 | printk(BIOS_DEBUG, "cse_lite: %s version = %d.%d.%d.%d (Status=0x%x, Start=0x%x, End=0x%x)\n", |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 275 | GET_BP_STR(RO), cse_bp->fw_ver.major, cse_bp->fw_ver.minor, |
| 276 | cse_bp->fw_ver.hotfix, cse_bp->fw_ver.build, |
| 277 | cse_bp->status, cse_bp->start_offset, |
| 278 | cse_bp->end_offset); |
| 279 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 280 | cse_bp = cse_get_bp_entry(RW); |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 281 | printk(BIOS_DEBUG, "cse_lite: %s version = %d.%d.%d.%d (Status=0x%x, Start=0x%x, End=0x%x)\n", |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 282 | GET_BP_STR(RW), cse_bp->fw_ver.major, cse_bp->fw_ver.minor, |
| 283 | cse_bp->fw_ver.hotfix, cse_bp->fw_ver.build, |
| 284 | cse_bp->status, cse_bp->start_offset, |
| 285 | cse_bp->end_offset); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Checks prerequisites for MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO and |
| 290 | * MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO HECI commands. |
| 291 | * It allows execution of the Boot Partition commands in below scenarios: |
| 292 | * - When CSE boots from RW partition (COM: Normal and CWS: Normal) |
| 293 | * - When CSE boots from RO partition (COM: Soft Temp Disable and CWS: Normal) |
| 294 | * - After HMRFPO_ENABLE command is issued to CSE (COM: SECOVER_MEI_MSG and CWS: Normal) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 295 | * The prerequisite check should be handled in cse_get_bp_info() and |
| 296 | * cse_set_next_boot_partition() since the CSE's current operation mode is changed between these |
| 297 | * cmd handler calls. |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 298 | */ |
| 299 | static bool cse_is_bp_cmd_info_possible(void) |
| 300 | { |
| 301 | if (cse_is_hfs1_cws_normal()) { |
| 302 | if (cse_is_hfs1_com_normal()) |
| 303 | return true; |
| 304 | if (cse_is_hfs1_com_secover_mei_msg()) |
| 305 | return true; |
| 306 | if (cse_is_hfs1_com_soft_temp_disable()) |
| 307 | return true; |
| 308 | } |
| 309 | return false; |
| 310 | } |
| 311 | |
Krishna Prasad Bhat | 4f062ec | 2023-09-21 23:33:34 +0530 | [diff] [blame] | 312 | static struct get_bp_info_rsp *sync_cse_bp_info_to_cbmem(void) |
| 313 | { |
| 314 | struct get_bp_info_rsp *cse_bp_info_in_cbmem = cbmem_find(CBMEM_ID_CSE_BP_INFO); |
| 315 | |
| 316 | if (cse_bp_info_in_cbmem != NULL) |
| 317 | return cse_bp_info_in_cbmem; |
| 318 | |
| 319 | cse_bp_info_in_cbmem = cbmem_add(CBMEM_ID_CSE_BP_INFO, |
| 320 | sizeof(struct get_bp_info_rsp)); |
| 321 | |
| 322 | if (!cse_bp_info_in_cbmem) { |
| 323 | printk(BIOS_ERR, "Unable to store Boot Parition Info in cbmem\n"); |
| 324 | return NULL; |
| 325 | } |
| 326 | |
| 327 | /* Copy the CSE Boot Partition Info command response to cbmem */ |
| 328 | memcpy(cse_bp_info_in_cbmem, &cse_bp_info_rsp, sizeof(struct get_bp_info_rsp)); |
| 329 | |
| 330 | return cse_bp_info_in_cbmem; |
| 331 | } |
| 332 | |
| 333 | static bool is_cse_bp_info_valid(struct get_bp_info_rsp *bp_info_rsp) |
| 334 | { |
| 335 | /* |
| 336 | * In case the cse_bp_info_rsp header group ID, command is incorrect or is_resp is 0, |
| 337 | * then return false to indicate cse_bp_info is not valid. |
| 338 | */ |
| 339 | return (bp_info_rsp->hdr.group_id != MKHI_GROUP_ID_BUP_COMMON || |
| 340 | bp_info_rsp->hdr.command != MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO || |
| 341 | !bp_info_rsp->hdr.is_resp) ? false : true; |
| 342 | } |
| 343 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 344 | static enum cb_err cse_get_bp_info(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 345 | { |
| 346 | struct get_bp_info_req { |
| 347 | struct mkhi_hdr hdr; |
| 348 | uint8_t reserved[4]; |
| 349 | } __packed; |
| 350 | |
| 351 | struct get_bp_info_req info_req = { |
| 352 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 353 | .hdr.command = MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO, |
| 354 | .reserved = {0}, |
| 355 | }; |
| 356 | |
Krishna Prasad Bhat | 4f062ec | 2023-09-21 23:33:34 +0530 | [diff] [blame] | 357 | /* |
| 358 | * If SOC_INTEL_CSE_LITE_SYNC_IN_RAMSTAGE config is selected and memory has been |
| 359 | * initialized, check if there is cse bp info response stored in cbmem. Once the data |
| 360 | * is validated, copy it to the global cse_bp_info_rsp so that it can be used by other |
| 361 | * functions. In case, data is not available in cbmem or invalid, continue to send the |
| 362 | * GET_BOOT_PARTITION_INFO command, else return. |
| 363 | */ |
| 364 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_IN_RAMSTAGE) && cbmem_online()) { |
| 365 | struct get_bp_info_rsp *cse_bp_info_in_cbmem = sync_cse_bp_info_to_cbmem(); |
| 366 | if (cse_bp_info_in_cbmem) { |
| 367 | if (is_cse_bp_info_valid(cse_bp_info_in_cbmem)) { |
| 368 | memcpy(&cse_bp_info_rsp, cse_bp_info_in_cbmem, |
| 369 | sizeof(struct get_bp_info_rsp)); |
| 370 | return CB_SUCCESS; |
| 371 | } |
| 372 | } |
| 373 | } else { |
| 374 | /* |
| 375 | * If SOC_INTEL_CSE_LITE_SYNC_IN_ROMSTAGE config is selected, check if the |
| 376 | * global cse bp info response stored in global cse_bp_info_rsp is valid. |
| 377 | * In case, it is not valid, continue to send the GET_BOOT_PARTITION_INFO |
| 378 | * command, else return. |
| 379 | */ |
| 380 | if (is_cse_bp_info_valid(&cse_bp_info_rsp)) |
| 381 | return CB_SUCCESS; |
| 382 | } |
| 383 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 384 | if (!cse_is_bp_cmd_info_possible()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 385 | printk(BIOS_ERR, "cse_lite: CSE does not meet prerequisites\n"); |
Sridhar Siricilla | 4b6e8ca | 2023-01-10 14:43:18 +0530 | [diff] [blame] | 386 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | size_t resp_size = sizeof(struct get_bp_info_rsp); |
| 390 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 391 | if (heci_send_receive(&info_req, sizeof(info_req), &cse_bp_info_rsp, &resp_size, |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 392 | HECI_MKHI_ADDR)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 393 | printk(BIOS_ERR, "cse_lite: Could not get partition info\n"); |
Sridhar Siricilla | 4b6e8ca | 2023-01-10 14:43:18 +0530 | [diff] [blame] | 394 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 395 | } |
| 396 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 397 | if (cse_bp_info_rsp.hdr.result) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 398 | printk(BIOS_ERR, "cse_lite: Get partition info resp failed: %d\n", |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 399 | cse_bp_info_rsp.hdr.result); |
Sridhar Siricilla | 4b6e8ca | 2023-01-10 14:43:18 +0530 | [diff] [blame] | 400 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 401 | } |
| 402 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 403 | cse_print_boot_partition_info(); |
Sridhar Siricilla | 4b6e8ca | 2023-01-10 14:43:18 +0530 | [diff] [blame] | 404 | return CB_SUCCESS; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 405 | } |
Krishna Prasad Bhat | 4f062ec | 2023-09-21 23:33:34 +0530 | [diff] [blame] | 406 | |
| 407 | void cse_fill_bp_info(void) |
| 408 | { |
Kapil Porwal | 53e5d1f | 2024-06-17 11:32:58 +0000 | [diff] [blame^] | 409 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 410 | return; |
| 411 | |
Krishna Prasad Bhat | 4f062ec | 2023-09-21 23:33:34 +0530 | [diff] [blame] | 412 | if (vboot_recovery_mode_enabled()) |
| 413 | return; |
| 414 | |
| 415 | if (cse_get_bp_info() != CB_SUCCESS) |
| 416 | cse_trigger_vboot_recovery(CSE_COMMUNICATION_ERROR); |
| 417 | } |
| 418 | |
| 419 | /* Function to copy PRERAM CSE BP info to pertinent CBMEM. */ |
| 420 | static void preram_cse_bp_info_sync_to_cbmem(int is_recovery) |
| 421 | { |
Kapil Porwal | 53e5d1f | 2024-06-17 11:32:58 +0000 | [diff] [blame^] | 422 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 423 | return; |
| 424 | |
Krishna Prasad Bhat | 4f062ec | 2023-09-21 23:33:34 +0530 | [diff] [blame] | 425 | if (vboot_recovery_mode_enabled()) |
| 426 | return; |
| 427 | |
| 428 | sync_cse_bp_info_to_cbmem(); |
| 429 | } |
| 430 | |
| 431 | CBMEM_CREATION_HOOK(preram_cse_bp_info_sync_to_cbmem); |
| 432 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 433 | /* |
| 434 | * It sends HECI command to notify CSE about its next boot partition. When coreboot wants |
| 435 | * CSE to boot from certain partition (BP1 <RO> or BP2 <RW>), then this command can be used. |
| 436 | * The CSE's valid bootable partitions are BP1(RO) and BP2(RW). |
| 437 | * This function must be used before EOP. |
| 438 | * Returns false on failure and true on success. |
| 439 | */ |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 440 | static enum cb_err cse_set_next_boot_partition(enum boot_partition_id bp) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 441 | { |
| 442 | struct set_boot_partition_info_req { |
| 443 | struct mkhi_hdr hdr; |
| 444 | uint8_t next_bp; |
| 445 | uint8_t reserved[3]; |
| 446 | } __packed; |
| 447 | |
| 448 | struct set_boot_partition_info_req switch_req = { |
| 449 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 450 | .hdr.command = MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO, |
| 451 | .next_bp = bp, |
| 452 | .reserved = {0}, |
| 453 | }; |
| 454 | |
| 455 | if (bp != RO && bp != RW) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 456 | printk(BIOS_ERR, "cse_lite: Incorrect partition id(%d) is provided", bp); |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 457 | return CB_ERR_ARG; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 458 | } |
| 459 | |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 460 | printk(BIOS_INFO, "cse_lite: Set Boot Partition Info Command (%s)\n", GET_BP_STR(bp)); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 461 | |
| 462 | if (!cse_is_bp_cmd_info_possible()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 463 | printk(BIOS_ERR, "cse_lite: CSE does not meet prerequisites\n"); |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 464 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | struct mkhi_hdr switch_resp; |
| 468 | size_t sw_resp_sz = sizeof(struct mkhi_hdr); |
| 469 | |
Sridhar Siricilla | 6836da2 | 2022-02-23 23:36:45 +0530 | [diff] [blame] | 470 | if (heci_send_receive(&switch_req, sizeof(switch_req), &switch_resp, &sw_resp_sz, |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 471 | HECI_MKHI_ADDR)) |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 472 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 473 | |
| 474 | if (switch_resp.result) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 475 | printk(BIOS_ERR, "cse_lite: Set Boot Partition Info Response Failed: %d\n", |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 476 | switch_resp.result); |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 477 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 478 | } |
| 479 | |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 480 | return CB_SUCCESS; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 481 | } |
| 482 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 483 | static enum cb_err cse_data_clear_request(void) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 484 | { |
| 485 | struct data_clr_request { |
| 486 | struct mkhi_hdr hdr; |
| 487 | uint8_t reserved[4]; |
| 488 | } __packed; |
| 489 | |
| 490 | struct data_clr_request data_clr_rq = { |
| 491 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 492 | .hdr.command = MKHI_BUP_COMMON_DATA_CLEAR, |
| 493 | .reserved = {0}, |
| 494 | }; |
| 495 | |
| 496 | if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_soft_temp_disable() || |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 497 | cse_get_current_bp() != RO) { |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 498 | printk(BIOS_ERR, "cse_lite: CSE doesn't meet DATA CLEAR cmd prerequisites\n"); |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 499 | return CB_ERR; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | printk(BIOS_DEBUG, "cse_lite: Sending DATA CLEAR HECI command\n"); |
| 503 | |
| 504 | struct mkhi_hdr data_clr_rsp; |
| 505 | size_t data_clr_rsp_sz = sizeof(data_clr_rsp); |
| 506 | |
Sridhar Siricilla | 6836da2 | 2022-02-23 23:36:45 +0530 | [diff] [blame] | 507 | if (heci_send_receive(&data_clr_rq, sizeof(data_clr_rq), &data_clr_rsp, |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 508 | &data_clr_rsp_sz, HECI_MKHI_ADDR)) { |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 509 | return CB_ERR; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | if (data_clr_rsp.result) { |
| 513 | printk(BIOS_ERR, "cse_lite: CSE DATA CLEAR command response failed: %d\n", |
| 514 | data_clr_rsp.result); |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 515 | return CB_ERR; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 516 | } |
| 517 | |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 518 | return CB_SUCCESS; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 519 | } |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 520 | |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 521 | __weak void cse_board_reset(void) |
| 522 | { |
| 523 | /* Default weak implementation, does nothing. */ |
| 524 | } |
| 525 | |
Jeremy Compostella | 08b5200d | 2023-01-19 11:32:25 -0700 | [diff] [blame] | 526 | __weak void cse_fw_update_misc_oper(void) |
| 527 | { |
| 528 | /* Default weak implementation, does nothing. */ |
| 529 | } |
| 530 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 531 | /* Set the CSE's next boot partition and issues system reset */ |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 532 | static enum cb_err cse_set_and_boot_from_next_bp(enum boot_partition_id bp) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 533 | { |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 534 | if (cse_set_next_boot_partition(bp) != CB_SUCCESS) |
| 535 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 536 | |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 537 | /* Allow the board to perform a reset for CSE RO<->RW jump */ |
| 538 | cse_board_reset(); |
| 539 | |
| 540 | /* If board does not perform the reset, then perform global_reset */ |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 541 | do_global_reset(); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 542 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 543 | die("cse_lite: Failed to reset the system\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 544 | |
| 545 | /* Control never reaches here */ |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 546 | return CB_ERR; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 547 | } |
| 548 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 549 | static enum cb_err cse_boot_to_rw(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 550 | { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 551 | if (cse_get_current_bp() == RW) |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 552 | return CB_SUCCESS; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 553 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 554 | return cse_set_and_boot_from_next_bp(RW); |
| 555 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 556 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 557 | /* Check if CSE RW data partition is valid or not */ |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 558 | static bool cse_is_rw_dp_valid(void) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 559 | { |
| 560 | const struct cse_bp_entry *rw_bp; |
| 561 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 562 | rw_bp = cse_get_bp_entry(RW); |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 563 | return rw_bp->status != BP_STATUS_DATA_FAILURE; |
| 564 | } |
| 565 | |
| 566 | /* |
| 567 | * It returns true if RW partition doesn't indicate BP_STATUS_DATA_FAILURE |
| 568 | * otherwise false if any operation fails. |
| 569 | */ |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 570 | static enum cb_err cse_fix_data_failure_err(void) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 571 | { |
| 572 | /* |
| 573 | * If RW partition status indicates BP_STATUS_DATA_FAILURE, |
| 574 | * - Send DATA CLEAR HECI command to CSE |
| 575 | * - Send SET BOOT PARTITION INFO(RW) command to set CSE's next partition |
| 576 | * - Issue GLOBAL RESET HECI command. |
| 577 | */ |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 578 | if (cse_is_rw_dp_valid()) |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 579 | return CB_SUCCESS; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 580 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 581 | if (cse_data_clear_request() != CB_SUCCESS) |
Sridhar Siricilla | 8f9c153 | 2023-01-10 14:38:51 +0530 | [diff] [blame] | 582 | return CB_ERR; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 583 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 584 | return cse_boot_to_rw(); |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 585 | } |
| 586 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 587 | static const struct fw_version *cse_get_bp_entry_version(enum boot_partition_id bp) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 588 | { |
| 589 | const struct cse_bp_entry *cse_bp; |
| 590 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 591 | cse_bp = cse_get_bp_entry(bp); |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 592 | return &cse_bp->fw_ver; |
| 593 | } |
| 594 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 595 | static const struct fw_version *cse_get_rw_version(void) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 596 | { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 597 | return cse_get_bp_entry_version(RW); |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 598 | } |
| 599 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 600 | static void cse_get_bp_entry_range(enum boot_partition_id bp, uint32_t *start_offset, |
| 601 | uint32_t *end_offset) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 602 | { |
| 603 | const struct cse_bp_entry *cse_bp; |
| 604 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 605 | cse_bp = cse_get_bp_entry(bp); |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 606 | |
| 607 | if (start_offset) |
| 608 | *start_offset = cse_bp->start_offset; |
| 609 | |
| 610 | if (end_offset) |
| 611 | *end_offset = cse_bp->end_offset; |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 612 | } |
| 613 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 614 | static bool cse_is_rw_bp_status_valid(void) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 615 | { |
| 616 | const struct cse_bp_entry *rw_bp; |
| 617 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 618 | rw_bp = cse_get_bp_entry(RW); |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 619 | |
| 620 | if (rw_bp->status == BP_STATUS_PARTITION_NOT_PRESENT || |
| 621 | rw_bp->status == BP_STATUS_GENERAL_FAILURE) { |
| 622 | printk(BIOS_ERR, "cse_lite: RW BP (status:%u) is not valid\n", rw_bp->status); |
| 623 | return false; |
| 624 | } |
| 625 | return true; |
| 626 | } |
| 627 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 628 | static enum cb_err cse_boot_to_ro(void) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 629 | { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 630 | if (cse_get_current_bp() == RO) |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 631 | return CB_SUCCESS; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 632 | |
| 633 | return cse_set_and_boot_from_next_bp(RO); |
| 634 | } |
| 635 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 636 | static enum cb_err cse_get_rw_rdev(struct region_device *rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 637 | { |
| 638 | if (fmap_locate_area_as_rdev_rw(CONFIG_SOC_INTEL_CSE_FMAP_NAME, rdev) < 0) { |
| 639 | printk(BIOS_ERR, "cse_lite: Failed to locate %s in FMAP\n", |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 640 | CONFIG_SOC_INTEL_CSE_FMAP_NAME); |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 641 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 642 | } |
| 643 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 644 | return CB_SUCCESS; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 645 | } |
| 646 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 647 | static bool cse_is_rw_bp_sign_valid(const struct region_device *target_rdev) |
| 648 | { |
| 649 | uint32_t cse_bp_sign; |
| 650 | |
| 651 | if (rdev_readat(target_rdev, &cse_bp_sign, 0, CSE_RW_SIGN_SIZE) != CSE_RW_SIGN_SIZE) { |
| 652 | printk(BIOS_ERR, "cse_lite: Failed to read RW boot partition signature\n"); |
| 653 | return false; |
| 654 | } |
| 655 | |
| 656 | return cse_bp_sign == CSE_RW_SIGNATURE; |
| 657 | } |
| 658 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 659 | static enum cb_err cse_get_target_rdev(struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 660 | { |
| 661 | struct region_device cse_region_rdev; |
| 662 | size_t size; |
| 663 | uint32_t start_offset; |
| 664 | uint32_t end_offset; |
| 665 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 666 | if (cse_get_rw_rdev(&cse_region_rdev) != CB_SUCCESS) |
| 667 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 668 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 669 | cse_get_bp_entry_range(RW, &start_offset, &end_offset); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 670 | size = end_offset + 1 - start_offset; |
| 671 | |
| 672 | if (rdev_chain(target_rdev, &cse_region_rdev, start_offset, size)) |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 673 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 674 | |
| 675 | printk(BIOS_DEBUG, "cse_lite: CSE RW partition: offset = 0x%x, size = 0x%x\n", |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 676 | (uint32_t)start_offset, (uint32_t)size); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 677 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 678 | return CB_SUCCESS; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 679 | } |
| 680 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 681 | /* |
Sridhar Siricilla | b9277ba | 2021-11-27 13:57:40 +0530 | [diff] [blame] | 682 | * Compare versions of CSE CBFS sub-component and CSE sub-component partition |
| 683 | * In case of CSE component comparison: |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 684 | * If ver_cmp_status = 0, no update is required |
| 685 | * If ver_cmp_status < 0, coreboot downgrades CSE RW region |
| 686 | * If ver_cmp_status > 0, coreboot upgrades CSE RW region |
| 687 | */ |
Sridhar Siricilla | b9277ba | 2021-11-27 13:57:40 +0530 | [diff] [blame] | 688 | static int cse_compare_sub_part_version(const struct fw_version *a, const struct fw_version *b) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 689 | { |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 690 | if (a->major != b->major) |
| 691 | return a->major - b->major; |
| 692 | else if (a->minor != b->minor) |
| 693 | return a->minor - b->minor; |
| 694 | else if (a->hotfix != b->hotfix) |
| 695 | return a->hotfix - b->hotfix; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 696 | else |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 697 | return a->build - b->build; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 698 | } |
| 699 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 700 | static enum cb_err cse_erase_rw_region(const struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 701 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 702 | if (rdev_eraseat(target_rdev, 0, region_device_sz(target_rdev)) < 0) { |
| 703 | printk(BIOS_ERR, "cse_lite: CSE RW partition could not be erased\n"); |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 704 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 705 | } |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 706 | return CB_SUCCESS; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 707 | } |
| 708 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 709 | static enum cb_err cse_copy_rw(const struct region_device *target_rdev, const void *buf, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 710 | size_t offset, size_t size) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 711 | { |
| 712 | if (rdev_writeat(target_rdev, buf, offset, size) < 0) { |
| 713 | printk(BIOS_ERR, "cse_lite: Failed to update CSE firmware\n"); |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 714 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 715 | } |
| 716 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 717 | return CB_SUCCESS; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 718 | } |
| 719 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 720 | enum cse_update_status { |
| 721 | CSE_UPDATE_NOT_REQUIRED, |
| 722 | CSE_UPDATE_UPGRADE, |
| 723 | CSE_UPDATE_DOWNGRADE, |
| 724 | CSE_UPDATE_CORRUPTED, |
| 725 | CSE_UPDATE_METADATA_ERROR, |
| 726 | }; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 727 | |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 728 | static bool read_ver_field(const char *start, char **curr, size_t size, uint16_t *ver_field) |
| 729 | { |
| 730 | if ((*curr - start) >= size) { |
| 731 | printk(BIOS_ERR, "cse_lite: Version string read overflow!\n"); |
| 732 | return false; |
| 733 | } |
| 734 | |
| 735 | *ver_field = skip_atoi(curr); |
| 736 | (*curr)++; |
| 737 | return true; |
| 738 | } |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 739 | |
Ashish Kumar Mishra | 2ee7162 | 2023-04-25 17:23:21 +0530 | [diff] [blame] | 740 | static enum cb_err get_cse_ver_from_cbfs(struct fw_version *cbfs_rw_version) |
| 741 | { |
| 742 | char *version_str, *cbfs_ptr; |
| 743 | size_t size; |
| 744 | |
| 745 | if (cbfs_rw_version == NULL) |
| 746 | return CB_ERR; |
| 747 | |
| 748 | cbfs_ptr = cbfs_map(CONFIG_SOC_INTEL_CSE_RW_VERSION_CBFS_NAME, &size); |
| 749 | version_str = cbfs_ptr; |
| 750 | if (!version_str) { |
| 751 | printk(BIOS_ERR, "cse_lite: Failed to get %s\n", |
| 752 | CONFIG_SOC_INTEL_CSE_RW_VERSION_CBFS_NAME); |
| 753 | return CB_ERR; |
| 754 | } |
| 755 | |
| 756 | if (!read_ver_field(version_str, &cbfs_ptr, size, &cbfs_rw_version->major) || |
| 757 | !read_ver_field(version_str, &cbfs_ptr, size, &cbfs_rw_version->minor) || |
| 758 | !read_ver_field(version_str, &cbfs_ptr, size, &cbfs_rw_version->hotfix) || |
| 759 | !read_ver_field(version_str, &cbfs_ptr, size, &cbfs_rw_version->build)) { |
| 760 | cbfs_unmap(version_str); |
| 761 | return CB_ERR; |
| 762 | } |
| 763 | |
| 764 | cbfs_unmap(version_str); |
| 765 | return CB_SUCCESS; |
| 766 | } |
| 767 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 768 | static enum cse_update_status cse_check_update_status(struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 769 | { |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 770 | int ret; |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 771 | struct fw_version cbfs_rw_version; |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 772 | |
| 773 | if (!cse_is_rw_bp_sign_valid(target_rdev)) |
| 774 | return CSE_UPDATE_CORRUPTED; |
| 775 | |
Ashish Kumar Mishra | 2ee7162 | 2023-04-25 17:23:21 +0530 | [diff] [blame] | 776 | if (get_cse_ver_from_cbfs(&cbfs_rw_version) == CB_ERR) |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 777 | return CSE_UPDATE_METADATA_ERROR; |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 778 | |
| 779 | printk(BIOS_DEBUG, "cse_lite: CSE CBFS RW version : %d.%d.%d.%d\n", |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 780 | cbfs_rw_version.major, |
| 781 | cbfs_rw_version.minor, |
| 782 | cbfs_rw_version.hotfix, |
| 783 | cbfs_rw_version.build); |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 784 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 785 | ret = cse_compare_sub_part_version(&cbfs_rw_version, cse_get_rw_version()); |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 786 | if (ret == 0) |
| 787 | return CSE_UPDATE_NOT_REQUIRED; |
| 788 | else if (ret < 0) |
| 789 | return CSE_UPDATE_DOWNGRADE; |
| 790 | else |
| 791 | return CSE_UPDATE_UPGRADE; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 792 | } |
| 793 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 794 | static enum cb_err cse_write_rw_region(const struct region_device *target_rdev, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 795 | const void *cse_cbfs_rw, const size_t cse_cbfs_rw_sz) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 796 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 797 | /* Points to CSE CBFS RW image after boot partition signature */ |
| 798 | uint8_t *cse_cbfs_rw_wo_sign = (uint8_t *)cse_cbfs_rw + CSE_RW_SIGN_SIZE; |
| 799 | |
| 800 | /* Size of CSE CBFS RW image without boot partition signature */ |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 801 | uint32_t cse_cbfs_rw_wo_sign_sz = cse_cbfs_rw_sz - CSE_RW_SIGN_SIZE; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 802 | |
| 803 | /* Update except CSE RW signature */ |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 804 | if (cse_copy_rw(target_rdev, cse_cbfs_rw_wo_sign, CSE_RW_SIGN_SIZE, |
| 805 | cse_cbfs_rw_wo_sign_sz) != CB_SUCCESS) |
| 806 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 807 | |
| 808 | /* Update CSE RW signature to indicate update is complete */ |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 809 | if (cse_copy_rw(target_rdev, (void *)cse_cbfs_rw, 0, CSE_RW_SIGN_SIZE) != CB_SUCCESS) |
| 810 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 811 | |
| 812 | printk(BIOS_INFO, "cse_lite: CSE RW Update Successful\n"); |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 813 | return CB_SUCCESS; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 814 | } |
| 815 | |
Sridhar Siricilla | 0aa1ac4 | 2022-03-09 20:35:32 +0530 | [diff] [blame] | 816 | static bool is_cse_fw_update_enabled(void) |
| 817 | { |
| 818 | if (!CONFIG(SOC_INTEL_CSE_RW_UPDATE)) |
| 819 | return false; |
| 820 | |
Kapil Porwal | 83cd6f9 | 2024-05-26 16:23:17 +0000 | [diff] [blame] | 821 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 822 | return false; |
| 823 | |
Sridhar Siricilla | 0aa1ac4 | 2022-03-09 20:35:32 +0530 | [diff] [blame] | 824 | if (CONFIG(SOC_INTEL_COMMON_BASECODE_DEBUG_FEATURE)) |
| 825 | return !is_debug_cse_fw_update_disable(); |
| 826 | |
| 827 | return true; |
| 828 | } |
| 829 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 830 | static enum csme_failure_reason cse_update_rw(const void *cse_cbfs_rw, const size_t cse_blob_sz, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 831 | struct region_device *target_rdev) |
| 832 | { |
Sridhar Siricilla | abeb688 | 2020-12-07 15:55:10 +0530 | [diff] [blame] | 833 | if (region_device_sz(target_rdev) < cse_blob_sz) { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 834 | printk(BIOS_ERR, "RW update does not fit. CSE RW flash region size: %zx," |
| 835 | "Update blob size:%zx\n", region_device_sz(target_rdev), cse_blob_sz); |
Sridhar Siricilla | abeb688 | 2020-12-07 15:55:10 +0530 | [diff] [blame] | 836 | return CSE_LITE_SKU_LAYOUT_MISMATCH_ERROR; |
| 837 | } |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 838 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 839 | if (cse_erase_rw_region(target_rdev) != CB_SUCCESS) |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 840 | return CSE_LITE_SKU_FW_UPDATE_ERROR; |
| 841 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 842 | if (cse_write_rw_region(target_rdev, cse_cbfs_rw, cse_blob_sz) != CB_SUCCESS) |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 843 | return CSE_LITE_SKU_FW_UPDATE_ERROR; |
| 844 | |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 845 | return CSE_NO_ERROR; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 846 | } |
| 847 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 848 | static enum cb_err cse_prep_for_rw_update(enum cse_update_status status) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 849 | { |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 850 | if (status == CSE_UPDATE_CORRUPTED) |
| 851 | elog_add_event(ELOG_TYPE_PSR_DATA_LOST); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 852 | /* |
| 853 | * To set CSE's operation mode to HMRFPO mode: |
| 854 | * 1. Ensure CSE to boot from RO(BP1) |
| 855 | * 2. Send HMRFPO_ENABLE command to CSE |
| 856 | */ |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 857 | if (cse_boot_to_ro() != CB_SUCCESS) |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 858 | return CB_ERR; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 859 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 860 | if ((status == CSE_UPDATE_DOWNGRADE) || (status == CSE_UPDATE_CORRUPTED)) { |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 861 | /* Reset the PSR backup command status in CMOS */ |
| 862 | if (CONFIG(SOC_INTEL_CSE_LITE_PSR)) |
| 863 | update_psr_backup_status(PSR_BACKUP_PENDING); |
| 864 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 865 | if (cse_data_clear_request() != CB_SUCCESS) { |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 866 | printk(BIOS_ERR, "cse_lite: CSE data clear failed!\n"); |
Krishna Prasad Bhat | 6ba8348 | 2023-08-03 12:15:32 +0530 | [diff] [blame] | 867 | return CB_ERR; |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 868 | } |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 869 | } |
| 870 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 871 | return cse_hmrfpo_enable(); |
| 872 | } |
| 873 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 874 | static enum csme_failure_reason cse_trigger_fw_update(enum cse_update_status status, |
| 875 | struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 876 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 877 | enum csme_failure_reason rv; |
Krishna P Bhat D | 75a423e | 2022-04-20 15:50:06 +0530 | [diff] [blame] | 878 | void *cse_cbfs_rw = NULL; |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 879 | size_t size; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 880 | |
Krishna P Bhat D | 75a423e | 2022-04-20 15:50:06 +0530 | [diff] [blame] | 881 | if (CONFIG(SOC_INTEL_CSE_LITE_COMPRESS_ME_RW)) { |
Rizwan Qureshi | d81d80c | 2023-09-29 07:31:17 +0530 | [diff] [blame] | 882 | cse_cbfs_rw = cbfs_cbmem_alloc(CONFIG_SOC_INTEL_CSE_RW_CBFS_NAME, |
| 883 | CBMEM_ID_CSE_UPDATE, &size); |
Krishna P Bhat D | 75a423e | 2022-04-20 15:50:06 +0530 | [diff] [blame] | 884 | } else { |
Rizwan Qureshi | d81d80c | 2023-09-29 07:31:17 +0530 | [diff] [blame] | 885 | cse_cbfs_rw = cbfs_map(CONFIG_SOC_INTEL_CSE_RW_CBFS_NAME, &size); |
Krishna P Bhat D | 75a423e | 2022-04-20 15:50:06 +0530 | [diff] [blame] | 886 | } |
Rizwan Qureshi | d81d80c | 2023-09-29 07:31:17 +0530 | [diff] [blame] | 887 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 888 | if (!cse_cbfs_rw) { |
| 889 | printk(BIOS_ERR, "cse_lite: CSE CBFS RW blob could not be mapped\n"); |
| 890 | return CSE_LITE_SKU_RW_BLOB_NOT_FOUND; |
| 891 | } |
| 892 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 893 | if (cse_prep_for_rw_update(status) != CB_SUCCESS) { |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 894 | rv = CSE_COMMUNICATION_ERROR; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 895 | goto error_exit; |
| 896 | } |
| 897 | |
Jeremy Compostella | 08b5200d | 2023-01-19 11:32:25 -0700 | [diff] [blame] | 898 | cse_fw_update_misc_oper(); |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 899 | rv = cse_update_rw(cse_cbfs_rw, size, target_rdev); |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 900 | |
| 901 | error_exit: |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 902 | cbfs_unmap(cse_cbfs_rw); |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 903 | return rv; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 904 | } |
| 905 | |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 906 | static bool is_psr_data_backed_up(void) |
| 907 | { |
| 908 | /* Track PSR backup status in CMOS */ |
| 909 | return (get_psr_backup_status() == PSR_BACKUP_DONE); |
| 910 | } |
| 911 | |
Anil Kumar | a2d10bb | 2023-05-01 11:44:47 -0700 | [diff] [blame] | 912 | static bool is_psr_supported(void) |
| 913 | { |
| 914 | uint32_t feature_status; |
| 915 | |
| 916 | /* |
| 917 | * Check if SoC has support for PSR feature typically PSR feature |
| 918 | * is only supported by vpro SKU |
| 919 | * |
| 920 | */ |
| 921 | if (cse_get_fw_feature_state(&feature_status) != CB_SUCCESS) { |
| 922 | printk(BIOS_ERR, "cse_get_fw_feature_state command failed !\n"); |
| 923 | return false; |
| 924 | } |
| 925 | |
| 926 | if (!(feature_status & ME_FW_FEATURE_PSR)) { |
| 927 | printk(BIOS_DEBUG, "PSR is not supported in this SKU !\n"); |
| 928 | return false; |
| 929 | } |
| 930 | |
| 931 | return true; |
| 932 | } |
| 933 | |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 934 | /* |
| 935 | * PSR data needs to be backed up prior to downgrade. So switch the CSE boot mode to RW, send |
| 936 | * PSR back-up command to CSE and update the PSR back-up state in CMOS. |
| 937 | */ |
| 938 | static void backup_psr_data(void) |
| 939 | { |
| 940 | printk(BIOS_DEBUG, "cse_lite: Initiate PSR data backup flow\n"); |
| 941 | /* Switch CSE to RW to send PSR_HECI_FW_DOWNGRADE_BACKUP command */ |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 942 | if (cse_boot_to_rw() != CB_SUCCESS) { |
| 943 | elog_add_event(ELOG_TYPE_PSR_DATA_LOST); |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 944 | goto update_and_exit; |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 945 | } |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 946 | /* |
Anil Kumar | a2d10bb | 2023-05-01 11:44:47 -0700 | [diff] [blame] | 947 | * The function to check for PSR feature support can only be called after |
| 948 | * switching to RW partition. The command MKHI_FWCAPS_GET_FW_FEATURE_STATE |
| 949 | * that gives feature state is supported by a process that is loaded only |
| 950 | * when CSE boots from RW. |
| 951 | * |
| 952 | */ |
| 953 | if (!is_psr_supported()) |
| 954 | goto update_and_exit; |
| 955 | |
| 956 | /* |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 957 | * Prerequisites: |
| 958 | * 1) HFSTS1 Current Working State is Normal |
| 959 | * 2) HFSTS1 Current Operation Mode is Normal |
| 960 | */ |
| 961 | if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_normal()) { |
| 962 | printk(BIOS_DEBUG, "cse_lite: PSR_HECI_FW_DOWNGRADE_BACKUP command " |
| 963 | "prerequisites not met!\n"); |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 964 | elog_add_event(ELOG_TYPE_PSR_DATA_LOST); |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 965 | goto update_and_exit; |
| 966 | } |
| 967 | |
| 968 | /* Send PSR_HECI_FW_DOWNGRADE_BACKUP command */ |
| 969 | struct psr_heci_fw_downgrade_backup_req { |
| 970 | struct psr_heci_header header; |
| 971 | } __packed; |
| 972 | |
| 973 | struct psr_heci_fw_downgrade_backup_req req = { |
| 974 | .header.command = PSR_HECI_FW_DOWNGRADE_BACKUP, |
| 975 | }; |
| 976 | |
| 977 | struct psr_heci_fw_downgrade_backup_res { |
| 978 | struct psr_heci_header header; |
| 979 | uint32_t status; |
| 980 | } __packed; |
| 981 | |
| 982 | struct psr_heci_fw_downgrade_backup_res backup_psr_resp; |
| 983 | size_t resp_size = sizeof(backup_psr_resp); |
| 984 | |
| 985 | printk(BIOS_DEBUG, "cse_lite: Send PSR_HECI_FW_DOWNGRADE_BACKUP command\n"); |
| 986 | if (heci_send_receive(&req, sizeof(req), |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 987 | &backup_psr_resp, &resp_size, HECI_PSR_ADDR)) { |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 988 | printk(BIOS_ERR, "cse_lite: could not backup PSR data\n"); |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 989 | elog_add_event_byte(ELOG_TYPE_PSR_DATA_BACKUP, ELOG_PSR_DATA_BACKUP_FAILED); |
| 990 | } else { |
| 991 | if (backup_psr_resp.status != PSR_STATUS_SUCCESS) { |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 992 | printk(BIOS_ERR, "cse_lite: PSR_HECI_FW_DOWNGRADE_BACKUP command " |
| 993 | "returned %u\n", backup_psr_resp.status); |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 994 | elog_add_event_byte(ELOG_TYPE_PSR_DATA_BACKUP, |
| 995 | ELOG_PSR_DATA_BACKUP_FAILED); |
| 996 | } else { |
| 997 | elog_add_event_byte(ELOG_TYPE_PSR_DATA_BACKUP, |
| 998 | ELOG_PSR_DATA_BACKUP_SUCCESS); |
| 999 | } |
| 1000 | } |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 1001 | |
| 1002 | update_and_exit: |
| 1003 | /* |
| 1004 | * An attempt to send PSR back-up command has been made. Update this info in CMOS and |
| 1005 | * send success once backup_psr_data() has been called. We do not want to put the system |
| 1006 | * into recovery for PSR data backup command pre-requisites not being met. |
Krishna Prasad Bhat | b58fd2d | 2023-06-12 15:04:08 +0530 | [diff] [blame] | 1007 | * We cannot do much if CSE fails to backup the PSR data, except create an event log. |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 1008 | */ |
| 1009 | update_psr_backup_status(PSR_BACKUP_DONE); |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | static void initiate_psr_data_backup(void) |
| 1013 | { |
| 1014 | if (is_psr_data_backed_up()) |
| 1015 | return; |
| 1016 | |
| 1017 | backup_psr_data(); |
| 1018 | } |
| 1019 | |
Anil Kumar | e46af3f | 2023-10-03 21:31:53 -0700 | [diff] [blame] | 1020 | /* |
| 1021 | * Check if a CSE Firmware update is required |
| 1022 | * returns true if an update is required, false otherwise |
| 1023 | */ |
| 1024 | bool is_cse_fw_update_required(void) |
| 1025 | { |
| 1026 | struct fw_version cbfs_rw_version; |
| 1027 | |
| 1028 | if (!is_cse_fw_update_enabled()) |
| 1029 | return false; |
| 1030 | |
| 1031 | /* |
| 1032 | * First, check if cse_bp_info_rsp global structure is populated. |
| 1033 | * If not, it implies that cse_fill_bp_info() function is not called. |
| 1034 | */ |
| 1035 | if (!is_cse_bp_info_valid(&cse_bp_info_rsp)) |
| 1036 | return false; |
| 1037 | |
| 1038 | if (get_cse_ver_from_cbfs(&cbfs_rw_version) == CB_ERR) |
| 1039 | return false; |
| 1040 | |
| 1041 | return !!cse_compare_sub_part_version(&cbfs_rw_version, cse_get_rw_version()); |
| 1042 | } |
| 1043 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1044 | static uint8_t cse_fw_update(void) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 1045 | { |
| 1046 | struct region_device target_rdev; |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 1047 | enum cse_update_status status; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 1048 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1049 | if (cse_get_target_rdev(&target_rdev) != CB_SUCCESS) { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 1050 | printk(BIOS_ERR, "cse_lite: Failed to get CSE RW Partition\n"); |
| 1051 | return CSE_LITE_SKU_RW_ACCESS_ERROR; |
| 1052 | } |
| 1053 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1054 | status = cse_check_update_status(&target_rdev); |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 1055 | if (status == CSE_UPDATE_NOT_REQUIRED) |
| 1056 | return CSE_NO_ERROR; |
| 1057 | if (status == CSE_UPDATE_METADATA_ERROR) |
| 1058 | return CSE_LITE_SKU_RW_METADATA_NOT_FOUND; |
Anil Kumar | 7b2edc3 | 2023-04-18 11:03:34 -0700 | [diff] [blame] | 1059 | if (CONFIG(SOC_INTEL_CSE_LITE_PSR) && status == CSE_UPDATE_DOWNGRADE) |
| 1060 | initiate_psr_data_backup(); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 1061 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 1062 | printk(BIOS_DEBUG, "cse_lite: CSE RW update is initiated\n"); |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1063 | return cse_trigger_fw_update(status, &target_rdev); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1064 | } |
| 1065 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1066 | static const char *cse_sub_part_str(enum bpdt_entry_type type) |
| 1067 | { |
| 1068 | switch (type) { |
| 1069 | case IOM_FW: |
| 1070 | return "IOM"; |
| 1071 | case NPHY_FW: |
| 1072 | return "NPHY"; |
| 1073 | default: |
| 1074 | return "Unknown"; |
| 1075 | } |
| 1076 | } |
| 1077 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1078 | static enum cb_err cse_locate_area_as_rdev_rw(size_t bp, struct region_device *cse_rdev) |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1079 | { |
| 1080 | struct region_device cse_region_rdev; |
| 1081 | uint32_t size; |
| 1082 | uint32_t start_offset; |
| 1083 | uint32_t end_offset; |
| 1084 | |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 1085 | if (cse_get_rw_rdev(&cse_region_rdev) != CB_SUCCESS) |
| 1086 | return CB_ERR; |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1087 | |
| 1088 | if (!strcmp(cse_regions[bp], "RO")) |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1089 | cse_get_bp_entry_range(RO, &start_offset, &end_offset); |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1090 | else |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1091 | cse_get_bp_entry_range(RW, &start_offset, &end_offset); |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1092 | |
| 1093 | size = end_offset + 1 - start_offset; |
| 1094 | |
| 1095 | if (rdev_chain(cse_rdev, &cse_region_rdev, start_offset, size)) |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 1096 | return CB_ERR; |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1097 | |
| 1098 | printk(BIOS_DEBUG, "cse_lite: CSE %s partition: offset = 0x%x, size = 0x%x\n", |
| 1099 | cse_regions[bp], start_offset, size); |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 1100 | return CB_SUCCESS; |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1101 | } |
| 1102 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1103 | static enum cb_err cse_sub_part_get_target_rdev(struct region_device *target_rdev, size_t bp, |
| 1104 | enum bpdt_entry_type type) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1105 | { |
| 1106 | struct bpdt_header bpdt_hdr; |
| 1107 | struct region_device cse_rdev; |
| 1108 | struct bpdt_entry bpdt_entries[MAX_SUBPARTS]; |
| 1109 | uint8_t i; |
| 1110 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1111 | if (cse_locate_area_as_rdev_rw(bp, &cse_rdev) != CB_SUCCESS) { |
Sridhar Siricilla | 52479c7 | 2022-03-30 09:25:49 +0530 | [diff] [blame] | 1112 | printk(BIOS_ERR, "cse_lite: Failed to locate %s in the CSE Region\n", |
| 1113 | cse_regions[bp]); |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1114 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | if ((rdev_readat(&cse_rdev, &bpdt_hdr, 0, BPDT_HEADER_SZ)) != BPDT_HEADER_SZ) { |
| 1118 | printk(BIOS_ERR, "cse_lite: Failed to read BPDT header from CSE region\n"); |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1119 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | if ((rdev_readat(&cse_rdev, bpdt_entries, BPDT_HEADER_SZ, |
| 1123 | (bpdt_hdr.descriptor_count * BPDT_ENTRY_SZ))) != |
| 1124 | (bpdt_hdr.descriptor_count * BPDT_ENTRY_SZ)) { |
| 1125 | printk(BIOS_ERR, "cse_lite: Failed to read BPDT entries from CSE region\n"); |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1126 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /* walk through BPDT entries to identify sub-partition's payload offset and size */ |
| 1130 | for (i = 0; i < bpdt_hdr.descriptor_count; i++) { |
| 1131 | if (bpdt_entries[i].type == type) { |
| 1132 | printk(BIOS_INFO, "cse_lite: Sub-partition %s- offset = 0x%x," |
| 1133 | "size = 0x%x\n", cse_sub_part_str(type), bpdt_entries[i].offset, |
| 1134 | bpdt_entries[i].size); |
| 1135 | |
| 1136 | if (rdev_chain(target_rdev, &cse_rdev, bpdt_entries[i].offset, |
| 1137 | bpdt_entries[i].size)) |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1138 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1139 | else |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1140 | return CB_SUCCESS; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | printk(BIOS_ERR, "cse_lite: Sub-partition %s is not found\n", cse_sub_part_str(type)); |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1145 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1146 | } |
| 1147 | |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1148 | static enum cb_err cse_get_sub_part_fw_version(enum bpdt_entry_type type, |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1149 | const struct region_device *rdev, |
| 1150 | struct fw_version *fw_ver) |
| 1151 | { |
| 1152 | struct subpart_entry subpart_entry; |
| 1153 | struct subpart_entry_manifest_header man_hdr; |
| 1154 | |
| 1155 | if ((rdev_readat(rdev, &subpart_entry, SUBPART_HEADER_SZ, SUBPART_ENTRY_SZ)) |
| 1156 | != SUBPART_ENTRY_SZ) { |
| 1157 | printk(BIOS_ERR, "cse_lite: Failed to read %s sub partition entry\n", |
| 1158 | cse_sub_part_str(type)); |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1159 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | if ((rdev_readat(rdev, &man_hdr, subpart_entry.offset_bytes, SUBPART_MANIFEST_HDR_SZ)) |
| 1163 | != SUBPART_MANIFEST_HDR_SZ) { |
| 1164 | printk(BIOS_ERR, "cse_lite: Failed to read %s Sub part entry #0 manifest\n", |
| 1165 | cse_sub_part_str(type)); |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1166 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | fw_ver->major = man_hdr.binary_version.major; |
| 1170 | fw_ver->minor = man_hdr.binary_version.minor; |
| 1171 | fw_ver->hotfix = man_hdr.binary_version.hotfix; |
| 1172 | fw_ver->build = man_hdr.binary_version.build; |
| 1173 | |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1174 | return CB_SUCCESS; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | static void cse_sub_part_get_source_fw_version(void *subpart_cbfs_rw, struct fw_version *fw_ver) |
| 1178 | { |
| 1179 | uint8_t *ptr = (uint8_t *)subpart_cbfs_rw; |
| 1180 | struct subpart_entry *subpart_entry; |
| 1181 | struct subpart_entry_manifest_header *man_hdr; |
| 1182 | |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 1183 | subpart_entry = (struct subpart_entry *)(ptr + SUBPART_HEADER_SZ); |
| 1184 | man_hdr = (struct subpart_entry_manifest_header *)(ptr + subpart_entry->offset_bytes); |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1185 | |
| 1186 | fw_ver->major = man_hdr->binary_version.major; |
| 1187 | fw_ver->minor = man_hdr->binary_version.minor; |
| 1188 | fw_ver->hotfix = man_hdr->binary_version.hotfix; |
| 1189 | fw_ver->build = man_hdr->binary_version.build; |
| 1190 | } |
| 1191 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1192 | static enum cb_err cse_prep_for_component_update(void) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1193 | { |
| 1194 | /* |
| 1195 | * To set CSE's operation mode to HMRFPO mode: |
| 1196 | * 1. Ensure CSE to boot from RO(BP1) |
| 1197 | * 2. Send HMRFPO_ENABLE command to CSE |
| 1198 | */ |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1199 | if (cse_boot_to_ro() != CB_SUCCESS) |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1200 | return CB_ERR; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1201 | |
| 1202 | return cse_hmrfpo_enable(); |
| 1203 | } |
| 1204 | |
Sridhar Siricilla | 0ae7a8b | 2023-01-10 17:12:01 +0530 | [diff] [blame] | 1205 | static enum csme_failure_reason cse_sub_part_trigger_update(enum bpdt_entry_type type, |
| 1206 | uint8_t bp, const void *subpart_cbfs_rw, const size_t blob_sz, |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1207 | struct region_device *target_rdev) |
| 1208 | { |
| 1209 | if (region_device_sz(target_rdev) < blob_sz) { |
| 1210 | printk(BIOS_ERR, "cse_lite: %s Target sub-partition size: %zx, " |
| 1211 | "smaller than blob size:%zx, abort update\n", |
| 1212 | cse_sub_part_str(type), region_device_sz(target_rdev), blob_sz); |
| 1213 | return CSE_LITE_SKU_SUB_PART_LAYOUT_MISMATCH_ERROR; |
| 1214 | } |
| 1215 | |
| 1216 | /* Erase CSE Lite sub-partition */ |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 1217 | if (cse_erase_rw_region(target_rdev) != CB_SUCCESS) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1218 | return CSE_LITE_SKU_SUB_PART_UPDATE_FAIL; |
| 1219 | |
| 1220 | /* Update CSE Lite sub-partition */ |
Sridhar Siricilla | 2e6c559 | 2023-01-10 16:16:57 +0530 | [diff] [blame] | 1221 | if (cse_copy_rw(target_rdev, (void *)subpart_cbfs_rw, 0, blob_sz) != CB_SUCCESS) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1222 | return CSE_LITE_SKU_SUB_PART_UPDATE_FAIL; |
| 1223 | |
| 1224 | printk(BIOS_INFO, "cse_lite: CSE %s %s Update successful\n", GET_BP_STR(bp), |
| 1225 | cse_sub_part_str(type)); |
| 1226 | |
| 1227 | return CSE_LITE_SKU_PART_UPDATE_SUCCESS; |
| 1228 | } |
| 1229 | |
Sridhar Siricilla | 0ae7a8b | 2023-01-10 17:12:01 +0530 | [diff] [blame] | 1230 | static enum csme_failure_reason handle_cse_sub_part_fw_update_rv(enum csme_failure_reason rv) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1231 | { |
| 1232 | switch (rv) { |
| 1233 | case CSE_LITE_SKU_PART_UPDATE_SUCCESS: |
| 1234 | case CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ: |
| 1235 | return rv; |
| 1236 | default: |
| 1237 | cse_trigger_vboot_recovery(rv); |
| 1238 | } |
| 1239 | /* Control never reaches here */ |
| 1240 | return rv; |
| 1241 | } |
| 1242 | |
| 1243 | static enum csme_failure_reason cse_sub_part_fw_component_update(enum bpdt_entry_type type, |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1244 | const char *name) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1245 | { |
| 1246 | struct region_device target_rdev; |
| 1247 | struct fw_version target_fw_ver, source_fw_ver; |
| 1248 | enum csme_failure_reason rv; |
| 1249 | size_t size; |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1250 | |
| 1251 | void *subpart_cbfs_rw = cbfs_map(name, &size); |
| 1252 | if (!subpart_cbfs_rw) { |
| 1253 | printk(BIOS_ERR, "cse_lite: Not able to map %s CBFS file\n", |
| 1254 | cse_sub_part_str(type)); |
| 1255 | return CSE_LITE_SKU_SUB_PART_BLOB_ACCESS_ERR; |
| 1256 | } |
| 1257 | |
| 1258 | cse_sub_part_get_source_fw_version(subpart_cbfs_rw, &source_fw_ver); |
| 1259 | printk(BIOS_INFO, "cse_lite: CBFS %s FW Version: %x.%x.%x.%x\n", cse_sub_part_str(type), |
| 1260 | source_fw_ver.major, source_fw_ver.minor, source_fw_ver.hotfix, |
| 1261 | source_fw_ver.build); |
| 1262 | |
| 1263 | /* Trigger sub-partition update in CSE RO and CSE RW */ |
| 1264 | for (size_t bp = 0; bp < ARRAY_SIZE(cse_regions); bp++) { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1265 | if (cse_sub_part_get_target_rdev(&target_rdev, bp, type) != CB_SUCCESS) { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1266 | rv = CSE_LITE_SKU_SUB_PART_ACCESS_ERR; |
| 1267 | goto error_exit; |
| 1268 | } |
| 1269 | |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 1270 | if (cse_get_sub_part_fw_version(type, &target_rdev, &target_fw_ver) != CB_SUCCESS) { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1271 | rv = CSE_LITE_SKU_SUB_PART_ACCESS_ERR; |
| 1272 | goto error_exit; |
| 1273 | } |
| 1274 | |
| 1275 | printk(BIOS_INFO, "cse_lite: %s %s FW Version: %x.%x.%x.%x\n", cse_regions[bp], |
| 1276 | cse_sub_part_str(type), target_fw_ver.major, |
| 1277 | target_fw_ver.minor, target_fw_ver.hotfix, target_fw_ver.build); |
| 1278 | |
| 1279 | if (!cse_compare_sub_part_version(&target_fw_ver, &source_fw_ver)) { |
| 1280 | printk(BIOS_INFO, "cse_lite: %s %s update is not required\n", |
| 1281 | cse_regions[bp], cse_sub_part_str(type)); |
| 1282 | rv = CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ; |
| 1283 | continue; |
| 1284 | } |
| 1285 | |
| 1286 | printk(BIOS_INFO, "CSE %s %s Update initiated\n", GET_BP_STR(bp), |
| 1287 | cse_sub_part_str(type)); |
| 1288 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1289 | if (cse_prep_for_component_update() != CB_SUCCESS) { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1290 | rv = CSE_LITE_SKU_SUB_PART_ACCESS_ERR; |
| 1291 | goto error_exit; |
| 1292 | } |
| 1293 | |
| 1294 | rv = cse_sub_part_trigger_update(type, bp, subpart_cbfs_rw, |
| 1295 | size, &target_rdev); |
| 1296 | |
| 1297 | if (rv != CSE_LITE_SKU_PART_UPDATE_SUCCESS) |
| 1298 | goto error_exit; |
| 1299 | } |
| 1300 | error_exit: |
| 1301 | cbfs_unmap(subpart_cbfs_rw); |
| 1302 | return rv; |
| 1303 | } |
| 1304 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1305 | static enum csme_failure_reason cse_sub_part_fw_update(void) |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1306 | { |
| 1307 | if (skip_cse_sub_part_update()) { |
| 1308 | printk(BIOS_INFO, "CSE Sub-partition update not required\n"); |
| 1309 | return CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ; |
| 1310 | } |
| 1311 | |
Sridhar Siricilla | 0ae7a8b | 2023-01-10 17:12:01 +0530 | [diff] [blame] | 1312 | enum csme_failure_reason rv; |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1313 | rv = cse_sub_part_fw_component_update(IOM_FW, CONFIG_SOC_INTEL_CSE_IOM_CBFS_NAME); |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1314 | |
| 1315 | handle_cse_sub_part_fw_update_rv(rv); |
| 1316 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1317 | rv = cse_sub_part_fw_component_update(NPHY_FW, CONFIG_SOC_INTEL_CSE_NPHY_CBFS_NAME); |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1318 | |
| 1319 | return handle_cse_sub_part_fw_update_rv(rv); |
| 1320 | } |
| 1321 | |
Subrata Banik | 5ff0118 | 2023-04-20 11:08:17 +0530 | [diff] [blame] | 1322 | static void do_cse_fw_sync(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1323 | { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1324 | /* |
| 1325 | * If system is in recovery mode, skip CSE Lite update if CSE sub-partition update |
| 1326 | * is not enabled and continue to update CSE sub-partitions. |
| 1327 | */ |
| 1328 | if (vboot_recovery_mode_enabled() && !CONFIG(SOC_INTEL_CSE_SUB_PART_UPDATE)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1329 | printk(BIOS_DEBUG, "cse_lite: Skip switching to RW in the recovery path\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1330 | return; |
| 1331 | } |
| 1332 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 1333 | /* If CSE SKU type is not Lite, skip enabling CSE Lite SKU */ |
| 1334 | if (!cse_is_hfs3_fw_sku_lite()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1335 | printk(BIOS_ERR, "cse_lite: Not a CSE Lite SKU\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1336 | return; |
| 1337 | } |
| 1338 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1339 | if (cse_get_bp_info() != CB_SUCCESS) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1340 | printk(BIOS_ERR, "cse_lite: Failed to get CSE boot partition info\n"); |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1341 | |
| 1342 | /* If system is in recovery mode, don't trigger recovery again */ |
| 1343 | if (!vboot_recovery_mode_enabled()) { |
| 1344 | cse_trigger_vboot_recovery(CSE_COMMUNICATION_ERROR); |
| 1345 | } else { |
| 1346 | printk(BIOS_ERR, "cse_lite: System is already in Recovery Mode, " |
| 1347 | "so no action\n"); |
| 1348 | return; |
| 1349 | } |
| 1350 | } |
| 1351 | |
Krishna P Bhat D | 64ec6a7 | 2023-09-21 22:19:47 +0530 | [diff] [blame] | 1352 | /* Store the CSE RW Firmware Version into CBMEM */ |
| 1353 | if (CONFIG(SOC_INTEL_STORE_CSE_FW_VERSION)) |
| 1354 | cse_store_rw_fw_version(); |
| 1355 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1356 | /* |
| 1357 | * If system is in recovery mode, CSE Lite update has to be skipped but CSE |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1358 | * sub-partitions like NPHY and IOM have to be updated. If CSE sub-partition update |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1359 | * fails during recovery, just continue to boot. |
| 1360 | */ |
| 1361 | if (CONFIG(SOC_INTEL_CSE_SUB_PART_UPDATE) && vboot_recovery_mode_enabled()) { |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1362 | if (cse_sub_part_fw_update() == CSE_LITE_SKU_PART_UPDATE_SUCCESS) { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1363 | cse_board_reset(); |
| 1364 | do_global_reset(); |
| 1365 | die("ERROR: GLOBAL RESET Failed to reset the system\n"); |
| 1366 | } |
| 1367 | |
| 1368 | return; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1369 | } |
| 1370 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1371 | if (cse_fix_data_failure_err() != CB_SUCCESS) |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 1372 | cse_trigger_vboot_recovery(CSE_LITE_SKU_DATA_WIPE_ERROR); |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 1373 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 1374 | /* |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1375 | * CSE firmware update is skipped if SOC_INTEL_CSE_RW_UPDATE is not defined and |
Sridhar Siricilla | 0aa1ac4 | 2022-03-09 20:35:32 +0530 | [diff] [blame] | 1376 | * runtime debug control flag is not enabled. The driver triggers recovery if CSE CBFS |
| 1377 | * RW metadata or CSE CBFS RW blob is not available. |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 1378 | */ |
Sridhar Siricilla | 0aa1ac4 | 2022-03-09 20:35:32 +0530 | [diff] [blame] | 1379 | if (is_cse_fw_update_enabled()) { |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 1380 | uint8_t rv; |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1381 | rv = cse_fw_update(); |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 1382 | if (rv) |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 1383 | cse_trigger_vboot_recovery(rv); |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 1384 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1385 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1386 | if (CONFIG(SOC_INTEL_CSE_SUB_PART_UPDATE)) |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1387 | cse_sub_part_fw_update(); |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1388 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1389 | if (!cse_is_rw_bp_status_valid()) |
Tim Wawrzynczak | f2801f4 | 2021-06-22 11:25:14 -0600 | [diff] [blame] | 1390 | cse_trigger_vboot_recovery(CSE_LITE_SKU_RW_JUMP_ERROR); |
Sridahr Siricilla | 54b0356 | 2021-06-18 10:59:30 +0530 | [diff] [blame] | 1391 | |
Krishna Prasad Bhat | c3c71c37 | 2023-08-07 21:48:23 +0530 | [diff] [blame] | 1392 | if (cse_boot_to_rw() != CB_SUCCESS) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1393 | printk(BIOS_ERR, "cse_lite: Failed to switch to RW\n"); |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 1394 | cse_trigger_vboot_recovery(CSE_LITE_SKU_RW_SWITCH_ERROR); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1395 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1396 | } |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 1397 | |
Subrata Banik | 5ff0118 | 2023-04-20 11:08:17 +0530 | [diff] [blame] | 1398 | void cse_fw_sync(void) |
| 1399 | { |
Kapil Porwal | 83cd6f9 | 2024-05-26 16:23:17 +0000 | [diff] [blame] | 1400 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 1401 | return; |
| 1402 | |
Subrata Banik | 5ff0118 | 2023-04-20 11:08:17 +0530 | [diff] [blame] | 1403 | timestamp_add_now(TS_CSE_FW_SYNC_START); |
| 1404 | do_cse_fw_sync(); |
| 1405 | timestamp_add_now(TS_CSE_FW_SYNC_END); |
| 1406 | } |
| 1407 | |
Subrata Banik | 7f66adb | 2023-04-14 00:35:38 +0530 | [diff] [blame] | 1408 | static enum cb_err send_get_fpt_partition_info_cmd(enum fpt_partition_id id, |
| 1409 | struct fw_version_resp *resp) |
| 1410 | { |
| 1411 | enum cse_tx_rx_status ret; |
| 1412 | struct fw_version_msg { |
| 1413 | struct mkhi_hdr hdr; |
| 1414 | enum fpt_partition_id partition_id; |
| 1415 | } __packed msg = { |
| 1416 | .hdr = { |
| 1417 | .group_id = MKHI_GROUP_ID_GEN, |
| 1418 | .command = GEN_GET_IMAGE_FW_VERSION, |
| 1419 | }, |
| 1420 | .partition_id = id, |
| 1421 | }; |
| 1422 | |
| 1423 | /* |
| 1424 | * Prerequisites: |
| 1425 | * 1) HFSTS1 CWS is Normal |
| 1426 | * 2) HFSTS1 COM is Normal |
| 1427 | * 3) Only sent after DID (accomplished by compiling this into ramstage) |
| 1428 | */ |
| 1429 | |
| 1430 | if (cse_is_hfs1_com_soft_temp_disable() || !cse_is_hfs1_cws_normal() || |
| 1431 | !cse_is_hfs1_com_normal()) { |
| 1432 | printk(BIOS_ERR, |
| 1433 | "HECI: Prerequisites not met for Get Image Firmware Version command\n"); |
| 1434 | return CB_ERR; |
| 1435 | } |
| 1436 | |
| 1437 | size_t resp_size = sizeof(struct fw_version_resp); |
| 1438 | ret = heci_send_receive(&msg, sizeof(msg), resp, &resp_size, HECI_MKHI_ADDR); |
| 1439 | |
| 1440 | if (ret || resp->hdr.result) { |
| 1441 | printk(BIOS_ERR, "CSE: Failed to get partition information for %d: 0x%x\n", |
| 1442 | id, resp->hdr.result); |
| 1443 | return CB_ERR; |
| 1444 | } |
| 1445 | |
| 1446 | return CB_SUCCESS; |
| 1447 | } |
| 1448 | |
Subrata Banik | 044fc9f | 2023-04-14 02:34:37 +0530 | [diff] [blame] | 1449 | static enum cb_err cse_get_fpt_partition_info(enum fpt_partition_id id, |
| 1450 | struct fw_version_resp *resp) |
Subrata Banik | 7f66adb | 2023-04-14 00:35:38 +0530 | [diff] [blame] | 1451 | { |
| 1452 | if (vboot_recovery_mode_enabled()) { |
| 1453 | printk(BIOS_WARNING, |
| 1454 | "CSE: Skip sending Get Image Info command during recovery mode!\n"); |
| 1455 | return CB_ERR; |
| 1456 | } |
| 1457 | |
| 1458 | if (id == FPT_PARTITION_NAME_ISHC && !CONFIG(DRIVERS_INTEL_ISH)) { |
| 1459 | printk(BIOS_WARNING, "CSE: Info request denied, no ISH partition\n"); |
| 1460 | return CB_ERR; |
| 1461 | } |
| 1462 | |
| 1463 | return send_get_fpt_partition_info_cmd(id, resp); |
| 1464 | } |
| 1465 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1466 | static bool is_ish_version_valid(struct cse_fw_ish_version_info *version) |
| 1467 | { |
| 1468 | const struct fw_version invalid_fw = {0, 0, 0, 0}; |
| 1469 | if (!memcmp(&version->cur_ish_fw_version, &invalid_fw, sizeof(struct fw_version))) |
| 1470 | return false; |
| 1471 | return true; |
| 1472 | } |
| 1473 | |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1474 | /* |
| 1475 | * Helper function to read ISH version from CSE FPT using HECI command. |
| 1476 | * |
| 1477 | * The HECI command only be executed after memory has been initialized. |
| 1478 | * This is because the command relies on resources that are not available |
| 1479 | * until DRAM initialization command has been sent. |
| 1480 | */ |
| 1481 | static void store_ish_version(void) |
| 1482 | { |
Kapil Porwal | 53e5d1f | 2024-06-17 11:32:58 +0000 | [diff] [blame^] | 1483 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 1484 | return; |
| 1485 | |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1486 | if (!ENV_RAMSTAGE) |
| 1487 | return; |
| 1488 | |
| 1489 | if (vboot_recovery_mode_enabled()) |
| 1490 | return; |
| 1491 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1492 | struct cse_specific_info *cse_info_in_cbmem = cbmem_find(CBMEM_ID_CSE_INFO); |
| 1493 | if (cse_info_in_cbmem == NULL) |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1494 | return; |
| 1495 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1496 | struct cse_specific_info cse_info_in_cmos; |
| 1497 | cmos_read_fw_partition_info(&cse_info_in_cmos); |
Subrata Banik | 88512b0 | 2023-08-17 15:44:52 +0000 | [diff] [blame] | 1498 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1499 | struct cse_fw_partition_info *cbmem_version = &(cse_info_in_cbmem->cse_fwp_version); |
| 1500 | struct cse_fw_partition_info *cmos_version = &(cse_info_in_cmos.cse_fwp_version); |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1501 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1502 | /* Get current cse firmware state */ |
| 1503 | enum cse_fw_state fw_state = get_cse_state( |
| 1504 | &(cbmem_version->cur_cse_fw_version), |
| 1505 | &(cmos_version->ish_partition_info.prev_cse_fw_version), |
| 1506 | &(cbmem_version->ish_partition_info.prev_cse_fw_version)); |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1507 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1508 | if (fw_state == CSE_FW_WARM_BOOT) { |
| 1509 | return; |
| 1510 | } else { |
| 1511 | if (fw_state == CSE_FW_COLD_BOOT && |
| 1512 | is_ish_version_valid(&(cmos_version->ish_partition_info))) { |
| 1513 | /* CMOS data is persistent across cold boots */ |
| 1514 | memcpy(&(cse_info_in_cbmem->cse_fwp_version.ish_partition_info), |
| 1515 | &(cse_info_in_cmos.cse_fwp_version.ish_partition_info), |
| 1516 | sizeof(struct cse_fw_ish_version_info)); |
| 1517 | store_cse_info_crc(cse_info_in_cbmem); |
| 1518 | } else { |
| 1519 | /* |
| 1520 | * Current running CSE version is different than previous stored CSE version |
| 1521 | * which could be due to CSE update or rollback, hence, need to send ISHC |
| 1522 | * partition info cmd to know the currently running ISH version. |
| 1523 | */ |
| 1524 | struct fw_version_resp resp; |
| 1525 | if (cse_get_fpt_partition_info(FPT_PARTITION_NAME_ISHC, |
| 1526 | &resp) == CB_SUCCESS) { |
| 1527 | /* Update stored CSE version with current cse version */ |
| 1528 | memcpy(&(cbmem_version->ish_partition_info.prev_cse_fw_version), |
| 1529 | &(cbmem_version->cur_cse_fw_version), sizeof(struct fw_version)); |
Subrata Banik | 88512b0 | 2023-08-17 15:44:52 +0000 | [diff] [blame] | 1530 | |
Dinesh Gehlot | a9232d8 | 2023-06-10 11:53:47 +0000 | [diff] [blame] | 1531 | /* Retrieve and update current ish version */ |
| 1532 | memcpy(&(cbmem_version->ish_partition_info.cur_ish_fw_version), |
| 1533 | &(resp.manifest_data.version), sizeof(struct fw_version)); |
| 1534 | |
| 1535 | /* Update the CRC */ |
| 1536 | store_cse_info_crc(cse_info_in_cbmem); |
| 1537 | |
| 1538 | /* Update CMOS with current CSE FPT versions.*/ |
| 1539 | cmos_write_fw_partition_info(cse_info_in_cbmem); |
| 1540 | } |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | |
Kapil Porwal | 53e5d1f | 2024-06-17 11:32:58 +0000 | [diff] [blame^] | 1545 | static void preram_create_cbmem_cse_info(int is_recovery) |
| 1546 | { |
| 1547 | if (!CONFIG(SOC_INTEL_CSE_LITE_SYNC_BY_PAYLOAD)) |
| 1548 | return; |
| 1549 | |
| 1550 | /* |
| 1551 | * CBMEM_ID_CSE_INFO will be used by the payload to - |
| 1552 | * 1. Avoid reading ISH firmware version on consecutive boots. |
| 1553 | * 2. Track state of PSR data during CSE downgrade operation. |
| 1554 | */ |
| 1555 | void *temp = cbmem_add(CBMEM_ID_CSE_INFO, sizeof(struct cse_specific_info)); |
| 1556 | if (!temp) |
| 1557 | printk(BIOS_ERR, "cse_lite: Couldn't create CBMEM_ID_CSE_INFO\n"); |
| 1558 | |
| 1559 | /* |
| 1560 | * CBMEM_ID_CSE_BP_INFO will be used by the payload to avoid reading CSE |
| 1561 | * boot partition information on consecutive boots. |
| 1562 | */ |
| 1563 | temp = cbmem_add(CBMEM_ID_CSE_BP_INFO, sizeof(struct get_bp_info_rsp)); |
| 1564 | if (!temp) |
| 1565 | printk(BIOS_ERR, "cse_lite: Couldn't create CBMEM_ID_CSE_BP_INFO\n"); |
| 1566 | } |
| 1567 | |
| 1568 | CBMEM_CREATION_HOOK(preram_create_cbmem_cse_info); |
| 1569 | |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 1570 | static void ramstage_cse_misc_ops(void *unused) |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 1571 | { |
Subrata Banik | db7b35a | 2023-04-19 20:48:01 +0530 | [diff] [blame] | 1572 | if (acpi_get_sleep_type() == ACPI_S3) |
| 1573 | return; |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 1574 | |
Subrata Banik | 5ff0118 | 2023-04-20 11:08:17 +0530 | [diff] [blame] | 1575 | if (CONFIG(SOC_INTEL_CSE_LITE_SYNC_IN_RAMSTAGE)) |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 1576 | cse_fw_sync(); |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 1577 | |
| 1578 | /* |
Subrata Banik | 3c06f1e | 2023-06-13 02:12:30 +0530 | [diff] [blame] | 1579 | * Store the ISH RW Firmware Version into CBMEM if ISH partition |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 1580 | * is available |
| 1581 | */ |
Subrata Banik | f27a41f | 2023-06-13 10:32:09 +0530 | [diff] [blame] | 1582 | if (soc_is_ish_partition_enabled()) |
Subrata Banik | b1b7c53 | 2023-04-14 01:36:13 +0530 | [diff] [blame] | 1583 | store_ish_version(); |
Krishna P Bhat D | e3178a1 | 2022-04-21 16:40:06 +0530 | [diff] [blame] | 1584 | } |
| 1585 | |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 1586 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, ramstage_cse_misc_ops, NULL); |