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