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