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