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