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