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 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 3 | #include <console/console.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 4 | #include <cbfs.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 5 | #include <commonlib/region.h> |
| 6 | #include <fmap.h> |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 7 | #include <intelblocks/cse.h> |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 8 | #include <intelblocks/cse_layout.h> |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 9 | #include <security/vboot/vboot_common.h> |
Sridhar Siricilla | 87e36c4 | 2020-05-03 19:08:18 +0530 | [diff] [blame] | 10 | #include <security/vboot/misc.h> |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 11 | #include <soc/intel/common/reset.h> |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 12 | #include <arch/cpu.h> |
| 13 | |
| 14 | #define BPDT_HEADER_SZ sizeof(struct bpdt_header) |
| 15 | #define BPDT_ENTRY_SZ sizeof(struct bpdt_entry) |
| 16 | #define SUBPART_HEADER_SZ sizeof(struct subpart_hdr) |
| 17 | #define SUBPART_ENTRY_SZ sizeof(struct subpart_entry) |
| 18 | #define SUBPART_MANIFEST_HDR_SZ sizeof(struct subpart_entry_manifest_header) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 19 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 20 | /* Converts bp index to boot partition string */ |
| 21 | #define GET_BP_STR(bp_index) (bp_index ? "RW" : "RO") |
| 22 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 23 | /* CSE RW boot partition signature */ |
| 24 | #define CSE_RW_SIGNATURE 0x000055aa |
| 25 | |
| 26 | /* CSE RW boot partition signature size */ |
| 27 | #define CSE_RW_SIGN_SIZE sizeof(uint32_t) |
| 28 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 29 | /* |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 30 | * 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] | 31 | * 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] | 32 | * CSE Lite SKU Image Layout: |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 33 | * ------------- ------------------- --------------------- |
| 34 | * |CSE REGION | => | RO | RW | DATA | => | BP1 | BP2 | DATA | |
| 35 | * ------------- ------------------- --------------------- |
| 36 | */ |
| 37 | #define CSE_MAX_BOOT_PARTITIONS 3 |
| 38 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 39 | /* CSE Lite SKU's valid bootable partition identifiers */ |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 40 | enum boot_partition_id { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 41 | /* RO(BP1) contains recovery/minimal boot firmware */ |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 42 | RO = 0, |
| 43 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 44 | /* RW(BP2) contains fully functional CSE firmware */ |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 45 | RW = 1 |
| 46 | }; |
| 47 | |
| 48 | /* |
| 49 | * Boot partition status. |
| 50 | * The status is returned in response to MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO cmd. |
| 51 | */ |
| 52 | enum bp_status { |
| 53 | /* This value is returned when a partition has no errors */ |
| 54 | BP_STATUS_SUCCESS = 0, |
| 55 | |
| 56 | /* |
| 57 | * This value is returned when a partition should be present based on layout, but it is |
| 58 | * not valid. |
| 59 | */ |
| 60 | BP_STATUS_GENERAL_FAILURE = 1, |
| 61 | |
| 62 | /* This value is returned when a partition is not present per initial image layout */ |
| 63 | BP_STATUS_PARTITION_NOT_PRESENT = 2, |
| 64 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 65 | /* |
| 66 | * This value is returned when unexpected issues are detected in CSE Data area |
| 67 | * and CSE TCB-SVN downgrade scenario. |
| 68 | */ |
| 69 | BP_STATUS_DATA_FAILURE = 3, |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* |
| 73 | * Boot Partition Info Flags |
| 74 | * The flags are returned in response to MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO cmd. |
| 75 | */ |
| 76 | enum bp_info_flags { |
| 77 | |
| 78 | /* Redundancy Enabled: It indicates CSE supports RO(BP1) and RW(BP2) regions */ |
| 79 | BP_INFO_REDUNDANCY_EN = 1 << 0, |
| 80 | |
| 81 | /* It indicates RO(BP1) supports Minimal Recovery Mode */ |
| 82 | BP_INFO_MIN_RECOV_MODE_EN = 1 << 1, |
| 83 | |
| 84 | /* |
| 85 | * Read-only Config Enabled: It indicates HW protection to CSE RO region is enabled. |
| 86 | * The option is relevant only if the BP_INFO_MIN_RECOV_MODE_EN flag is enabled. |
| 87 | */ |
| 88 | BP_INFO_READ_ONLY_CFG = 1 << 2, |
| 89 | }; |
| 90 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 91 | /* CSE boot partition entry info */ |
| 92 | struct cse_bp_entry { |
| 93 | /* Boot partition version */ |
| 94 | struct fw_version fw_ver; |
| 95 | |
| 96 | /* Boot partition status */ |
| 97 | uint32_t status; |
| 98 | |
| 99 | /* Starting offset of the partition within CSE region */ |
| 100 | uint32_t start_offset; |
| 101 | |
| 102 | /* Ending offset of the partition within CSE region */ |
| 103 | uint32_t end_offset; |
| 104 | uint8_t reserved[12]; |
| 105 | } __packed; |
| 106 | |
| 107 | /* CSE boot partition info */ |
| 108 | struct cse_bp_info { |
| 109 | /* Number of boot partitions */ |
| 110 | uint8_t total_number_of_bp; |
| 111 | |
| 112 | /* Current boot partition */ |
| 113 | uint8_t current_bp; |
| 114 | |
| 115 | /* Next boot partition */ |
| 116 | uint8_t next_bp; |
| 117 | |
| 118 | /* Boot Partition Info Flags */ |
| 119 | uint8_t flags; |
| 120 | |
| 121 | /* Boot Partition Entry Info */ |
| 122 | struct cse_bp_entry bp_entries[CSE_MAX_BOOT_PARTITIONS]; |
| 123 | } __packed; |
| 124 | |
| 125 | struct get_bp_info_rsp { |
| 126 | struct mkhi_hdr hdr; |
| 127 | struct cse_bp_info bp_info; |
| 128 | } __packed; |
| 129 | |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame^] | 130 | |
| 131 | bool cse_get_boot_performance_data(struct cse_boot_perf_rsp *boot_perf_rsp) |
| 132 | { |
| 133 | struct cse_boot_perf_req { |
| 134 | struct mkhi_hdr hdr; |
| 135 | uint32_t reserved; |
| 136 | } __packed; |
| 137 | |
| 138 | struct cse_boot_perf_req req = { |
| 139 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 140 | .hdr.command = MKHI_BUP_COMMON_GET_BOOT_PERF_DATA, |
| 141 | .reserved = 0, |
| 142 | }; |
| 143 | |
| 144 | size_t resp_size = sizeof(struct cse_boot_perf_rsp); |
| 145 | |
| 146 | if (!heci_send_receive(&req, sizeof(req), boot_perf_rsp, &resp_size, |
| 147 | HECI_MKHI_ADDR)) { |
| 148 | printk(BIOS_ERR, "cse_lite: Could not get boot performance data\n"); |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | if (boot_perf_rsp->hdr.result) { |
| 153 | printk(BIOS_ERR, "cse_lite: Get boot performance data resp failed: %d\n", |
| 154 | boot_perf_rsp->hdr.result); |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 162 | static uint8_t cse_get_current_bp(const struct cse_bp_info *cse_bp_info) |
| 163 | { |
| 164 | return cse_bp_info->current_bp; |
| 165 | } |
| 166 | |
| 167 | static const struct cse_bp_entry *cse_get_bp_entry(enum boot_partition_id bp, |
| 168 | const struct cse_bp_info *cse_bp_info) |
| 169 | { |
| 170 | return &cse_bp_info->bp_entries[bp]; |
| 171 | } |
| 172 | |
| 173 | static void cse_print_boot_partition_info(const struct cse_bp_info *cse_bp_info) |
| 174 | { |
| 175 | const struct cse_bp_entry *cse_bp; |
| 176 | |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 177 | printk(BIOS_DEBUG, "cse_lite: Number of partitions = %d\n", |
| 178 | cse_bp_info->total_number_of_bp); |
| 179 | printk(BIOS_DEBUG, "cse_lite: Current partition = %s\n", |
| 180 | GET_BP_STR(cse_bp_info->current_bp)); |
| 181 | printk(BIOS_DEBUG, "cse_lite: Next partition = %s\n", GET_BP_STR(cse_bp_info->next_bp)); |
| 182 | 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] | 183 | |
| 184 | /* Log version info of RO & RW partitions */ |
| 185 | cse_bp = cse_get_bp_entry(RO, cse_bp_info); |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 186 | 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] | 187 | GET_BP_STR(RO), cse_bp->fw_ver.major, cse_bp->fw_ver.minor, |
| 188 | cse_bp->fw_ver.hotfix, cse_bp->fw_ver.build, |
| 189 | cse_bp->status, cse_bp->start_offset, |
| 190 | cse_bp->end_offset); |
| 191 | |
| 192 | cse_bp = cse_get_bp_entry(RW, cse_bp_info); |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 193 | 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] | 194 | GET_BP_STR(RW), cse_bp->fw_ver.major, cse_bp->fw_ver.minor, |
| 195 | cse_bp->fw_ver.hotfix, cse_bp->fw_ver.build, |
| 196 | cse_bp->status, cse_bp->start_offset, |
| 197 | cse_bp->end_offset); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Checks prerequisites for MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO and |
| 202 | * MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO HECI commands. |
| 203 | * It allows execution of the Boot Partition commands in below scenarios: |
| 204 | * - When CSE boots from RW partition (COM: Normal and CWS: Normal) |
| 205 | * - When CSE boots from RO partition (COM: Soft Temp Disable and CWS: Normal) |
| 206 | * - 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] | 207 | * The prerequisite check should be handled in cse_get_bp_info() and |
| 208 | * cse_set_next_boot_partition() since the CSE's current operation mode is changed between these |
| 209 | * cmd handler calls. |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 210 | */ |
| 211 | static bool cse_is_bp_cmd_info_possible(void) |
| 212 | { |
| 213 | if (cse_is_hfs1_cws_normal()) { |
| 214 | if (cse_is_hfs1_com_normal()) |
| 215 | return true; |
| 216 | if (cse_is_hfs1_com_secover_mei_msg()) |
| 217 | return true; |
| 218 | if (cse_is_hfs1_com_soft_temp_disable()) |
| 219 | return true; |
| 220 | } |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | static bool cse_get_bp_info(struct get_bp_info_rsp *bp_info_rsp) |
| 225 | { |
| 226 | struct get_bp_info_req { |
| 227 | struct mkhi_hdr hdr; |
| 228 | uint8_t reserved[4]; |
| 229 | } __packed; |
| 230 | |
| 231 | struct get_bp_info_req info_req = { |
| 232 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 233 | .hdr.command = MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO, |
| 234 | .reserved = {0}, |
| 235 | }; |
| 236 | |
| 237 | if (!cse_is_bp_cmd_info_possible()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 238 | printk(BIOS_ERR, "cse_lite: CSE does not meet prerequisites\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 239 | return false; |
| 240 | } |
| 241 | |
| 242 | size_t resp_size = sizeof(struct get_bp_info_rsp); |
| 243 | |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 244 | if (!heci_send_receive(&info_req, sizeof(info_req), bp_info_rsp, &resp_size, |
| 245 | HECI_MKHI_ADDR)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 246 | printk(BIOS_ERR, "cse_lite: Could not get partition info\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 247 | return false; |
| 248 | } |
| 249 | |
| 250 | if (bp_info_rsp->hdr.result) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 251 | printk(BIOS_ERR, "cse_lite: Get partition info resp failed: %d\n", |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 252 | bp_info_rsp->hdr.result); |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | cse_print_boot_partition_info(&bp_info_rsp->bp_info); |
| 257 | |
| 258 | return true; |
| 259 | } |
| 260 | /* |
| 261 | * It sends HECI command to notify CSE about its next boot partition. When coreboot wants |
| 262 | * CSE to boot from certain partition (BP1 <RO> or BP2 <RW>), then this command can be used. |
| 263 | * The CSE's valid bootable partitions are BP1(RO) and BP2(RW). |
| 264 | * This function must be used before EOP. |
| 265 | * Returns false on failure and true on success. |
| 266 | */ |
| 267 | static bool cse_set_next_boot_partition(enum boot_partition_id bp) |
| 268 | { |
| 269 | struct set_boot_partition_info_req { |
| 270 | struct mkhi_hdr hdr; |
| 271 | uint8_t next_bp; |
| 272 | uint8_t reserved[3]; |
| 273 | } __packed; |
| 274 | |
| 275 | struct set_boot_partition_info_req switch_req = { |
| 276 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 277 | .hdr.command = MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO, |
| 278 | .next_bp = bp, |
| 279 | .reserved = {0}, |
| 280 | }; |
| 281 | |
| 282 | if (bp != RO && bp != RW) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 283 | printk(BIOS_ERR, "cse_lite: Incorrect partition id(%d) is provided", bp); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 284 | return false; |
| 285 | } |
| 286 | |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 287 | 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] | 288 | |
| 289 | if (!cse_is_bp_cmd_info_possible()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 290 | printk(BIOS_ERR, "cse_lite: CSE does not meet prerequisites\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 291 | return false; |
| 292 | } |
| 293 | |
| 294 | struct mkhi_hdr switch_resp; |
| 295 | size_t sw_resp_sz = sizeof(struct mkhi_hdr); |
| 296 | |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 297 | if (!heci_send_receive(&switch_req, sizeof(switch_req), &switch_resp, &sw_resp_sz, |
| 298 | HECI_MKHI_ADDR)) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 299 | return false; |
| 300 | |
| 301 | if (switch_resp.result) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 302 | 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] | 303 | switch_resp.result); |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | return true; |
| 308 | } |
| 309 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 310 | static bool cse_data_clear_request(const struct cse_bp_info *cse_bp_info) |
| 311 | { |
| 312 | struct data_clr_request { |
| 313 | struct mkhi_hdr hdr; |
| 314 | uint8_t reserved[4]; |
| 315 | } __packed; |
| 316 | |
| 317 | struct data_clr_request data_clr_rq = { |
| 318 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 319 | .hdr.command = MKHI_BUP_COMMON_DATA_CLEAR, |
| 320 | .reserved = {0}, |
| 321 | }; |
| 322 | |
| 323 | if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_soft_temp_disable() || |
| 324 | cse_get_current_bp(cse_bp_info) != RO) { |
| 325 | printk(BIOS_ERR, "cse_lite: CSE doesn't meet DATA CLEAR cmd prerequisites\n"); |
| 326 | return false; |
| 327 | } |
| 328 | |
| 329 | printk(BIOS_DEBUG, "cse_lite: Sending DATA CLEAR HECI command\n"); |
| 330 | |
| 331 | struct mkhi_hdr data_clr_rsp; |
| 332 | size_t data_clr_rsp_sz = sizeof(data_clr_rsp); |
| 333 | |
| 334 | 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] | 335 | &data_clr_rsp_sz, HECI_MKHI_ADDR)) { |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 336 | return false; |
| 337 | } |
| 338 | |
| 339 | if (data_clr_rsp.result) { |
| 340 | printk(BIOS_ERR, "cse_lite: CSE DATA CLEAR command response failed: %d\n", |
| 341 | data_clr_rsp.result); |
| 342 | return false; |
| 343 | } |
| 344 | |
| 345 | return true; |
| 346 | } |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 347 | |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 348 | __weak void cse_board_reset(void) |
| 349 | { |
| 350 | /* Default weak implementation, does nothing. */ |
| 351 | } |
| 352 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 353 | /* Set the CSE's next boot partition and issues system reset */ |
| 354 | static bool cse_set_and_boot_from_next_bp(enum boot_partition_id bp) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 355 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 356 | if (!cse_set_next_boot_partition(bp)) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 357 | return false; |
| 358 | |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 359 | /* Allow the board to perform a reset for CSE RO<->RW jump */ |
| 360 | cse_board_reset(); |
| 361 | |
| 362 | /* If board does not perform the reset, then perform global_reset */ |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 363 | do_global_reset(); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 364 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 365 | die("cse_lite: Failed to reset the system\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 366 | |
| 367 | /* Control never reaches here */ |
| 368 | return false; |
| 369 | } |
| 370 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 371 | static bool cse_boot_to_rw(const struct cse_bp_info *cse_bp_info) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 372 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 373 | if (cse_get_current_bp(cse_bp_info) == RW) |
| 374 | return true; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 375 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 376 | return cse_set_and_boot_from_next_bp(RW); |
| 377 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 378 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 379 | /* Check if CSE RW data partition is valid or not */ |
| 380 | static bool cse_is_rw_dp_valid(const struct cse_bp_info *cse_bp_info) |
| 381 | { |
| 382 | const struct cse_bp_entry *rw_bp; |
| 383 | |
| 384 | rw_bp = cse_get_bp_entry(RW, cse_bp_info); |
| 385 | return rw_bp->status != BP_STATUS_DATA_FAILURE; |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * It returns true if RW partition doesn't indicate BP_STATUS_DATA_FAILURE |
| 390 | * otherwise false if any operation fails. |
| 391 | */ |
| 392 | static bool cse_fix_data_failure_err(const struct cse_bp_info *cse_bp_info) |
| 393 | { |
| 394 | /* |
| 395 | * If RW partition status indicates BP_STATUS_DATA_FAILURE, |
| 396 | * - Send DATA CLEAR HECI command to CSE |
| 397 | * - Send SET BOOT PARTITION INFO(RW) command to set CSE's next partition |
| 398 | * - Issue GLOBAL RESET HECI command. |
| 399 | */ |
| 400 | if (cse_is_rw_dp_valid(cse_bp_info)) |
| 401 | return true; |
| 402 | |
| 403 | if (!cse_data_clear_request(cse_bp_info)) |
| 404 | return false; |
| 405 | |
| 406 | return cse_boot_to_rw(cse_bp_info); |
| 407 | } |
| 408 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 409 | 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] | 410 | const struct cse_bp_info *bp_info) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 411 | { |
| 412 | const struct cse_bp_entry *cse_bp; |
| 413 | |
| 414 | cse_bp = cse_get_bp_entry(bp, bp_info); |
| 415 | return &cse_bp->fw_ver; |
| 416 | } |
| 417 | |
| 418 | static const struct fw_version *cse_get_rw_version(const struct cse_bp_info *cse_bp_info) |
| 419 | { |
| 420 | return cse_get_bp_entry_version(RW, cse_bp_info); |
| 421 | } |
| 422 | |
| 423 | 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] | 424 | 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] | 425 | { |
| 426 | const struct cse_bp_entry *cse_bp; |
| 427 | |
| 428 | cse_bp = cse_get_bp_entry(bp, cse_bp_info); |
| 429 | |
| 430 | if (start_offset) |
| 431 | *start_offset = cse_bp->start_offset; |
| 432 | |
| 433 | if (end_offset) |
| 434 | *end_offset = cse_bp->end_offset; |
| 435 | |
| 436 | } |
| 437 | |
| 438 | static bool cse_is_rw_bp_status_valid(const struct cse_bp_info *cse_bp_info) |
| 439 | { |
| 440 | const struct cse_bp_entry *rw_bp; |
| 441 | |
| 442 | rw_bp = cse_get_bp_entry(RW, cse_bp_info); |
| 443 | |
| 444 | if (rw_bp->status == BP_STATUS_PARTITION_NOT_PRESENT || |
| 445 | rw_bp->status == BP_STATUS_GENERAL_FAILURE) { |
| 446 | printk(BIOS_ERR, "cse_lite: RW BP (status:%u) is not valid\n", rw_bp->status); |
| 447 | return false; |
| 448 | } |
| 449 | return true; |
| 450 | } |
| 451 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 452 | static bool cse_boot_to_ro(const struct cse_bp_info *cse_bp_info) |
| 453 | { |
| 454 | if (cse_get_current_bp(cse_bp_info) == RO) |
| 455 | return true; |
| 456 | |
| 457 | return cse_set_and_boot_from_next_bp(RO); |
| 458 | } |
| 459 | |
| 460 | static bool cse_get_rw_rdev(struct region_device *rdev) |
| 461 | { |
| 462 | if (fmap_locate_area_as_rdev_rw(CONFIG_SOC_INTEL_CSE_FMAP_NAME, rdev) < 0) { |
| 463 | printk(BIOS_ERR, "cse_lite: Failed to locate %s in FMAP\n", |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 464 | CONFIG_SOC_INTEL_CSE_FMAP_NAME); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 465 | return false; |
| 466 | } |
| 467 | |
| 468 | return true; |
| 469 | } |
| 470 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 471 | static bool cse_is_rw_bp_sign_valid(const struct region_device *target_rdev) |
| 472 | { |
| 473 | uint32_t cse_bp_sign; |
| 474 | |
| 475 | if (rdev_readat(target_rdev, &cse_bp_sign, 0, CSE_RW_SIGN_SIZE) != CSE_RW_SIGN_SIZE) { |
| 476 | printk(BIOS_ERR, "cse_lite: Failed to read RW boot partition signature\n"); |
| 477 | return false; |
| 478 | } |
| 479 | |
| 480 | return cse_bp_sign == CSE_RW_SIGNATURE; |
| 481 | } |
| 482 | |
| 483 | static bool cse_get_target_rdev(const struct cse_bp_info *cse_bp_info, |
| 484 | struct region_device *target_rdev) |
| 485 | { |
| 486 | struct region_device cse_region_rdev; |
| 487 | size_t size; |
| 488 | uint32_t start_offset; |
| 489 | uint32_t end_offset; |
| 490 | |
| 491 | if (!cse_get_rw_rdev(&cse_region_rdev)) |
| 492 | return false; |
| 493 | |
| 494 | cse_get_bp_entry_range(cse_bp_info, RW, &start_offset, &end_offset); |
| 495 | size = end_offset + 1 - start_offset; |
| 496 | |
| 497 | if (rdev_chain(target_rdev, &cse_region_rdev, start_offset, size)) |
| 498 | return false; |
| 499 | |
| 500 | printk(BIOS_DEBUG, "cse_lite: CSE RW partition: offset = 0x%x, size = 0x%x\n", |
| 501 | (uint32_t)start_offset, (uint32_t) size); |
| 502 | |
| 503 | return true; |
| 504 | } |
| 505 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 506 | static const char *cse_get_source_rdev_fmap(void) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 507 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 508 | struct vb2_context *ctx = vboot_get_context(); |
| 509 | if (ctx == NULL) |
| 510 | return NULL; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 511 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 512 | if (vboot_is_firmware_slot_a(ctx)) |
| 513 | return CONFIG_SOC_INTEL_CSE_RW_A_FMAP_NAME; |
| 514 | |
| 515 | return CONFIG_SOC_INTEL_CSE_RW_B_FMAP_NAME; |
| 516 | } |
| 517 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 518 | /* |
Sridhar Siricilla | b9277ba | 2021-11-27 13:57:40 +0530 | [diff] [blame] | 519 | * Compare versions of CSE CBFS sub-component and CSE sub-component partition |
| 520 | * In case of CSE component comparison: |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 521 | * If ver_cmp_status = 0, no update is required |
| 522 | * If ver_cmp_status < 0, coreboot downgrades CSE RW region |
| 523 | * If ver_cmp_status > 0, coreboot upgrades CSE RW region |
| 524 | */ |
Sridhar Siricilla | b9277ba | 2021-11-27 13:57:40 +0530 | [diff] [blame] | 525 | 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] | 526 | { |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 527 | if (a->major != b->major) |
| 528 | return a->major - b->major; |
| 529 | else if (a->minor != b->minor) |
| 530 | return a->minor - b->minor; |
| 531 | else if (a->hotfix != b->hotfix) |
| 532 | return a->hotfix - b->hotfix; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 533 | else |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 534 | return a->build - b->build; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* The function calculates SHA-256 of CSE RW blob and compares it with the provided SHA value */ |
| 538 | static bool cse_verify_cbfs_rw_sha256(const uint8_t *expected_rw_blob_sha, |
| 539 | const void *rw_blob, const size_t rw_blob_sz) |
| 540 | |
| 541 | { |
| 542 | uint8_t rw_comp_sha[VB2_SHA256_DIGEST_SIZE]; |
| 543 | |
| 544 | if (vb2_digest_buffer(rw_blob, rw_blob_sz, VB2_HASH_SHA256, rw_comp_sha, |
| 545 | VB2_SHA256_DIGEST_SIZE)) { |
| 546 | printk(BIOS_ERR, "cse_lite: CSE CBFS RW's SHA-256 calculation has failed\n"); |
| 547 | return false; |
| 548 | } |
| 549 | |
| 550 | if (memcmp(expected_rw_blob_sha, rw_comp_sha, VB2_SHA256_DIGEST_SIZE)) { |
| 551 | printk(BIOS_ERR, "cse_lite: Computed CBFS RW's SHA-256 does not match with" |
| 552 | "the provided SHA in the metadata\n"); |
| 553 | return false; |
| 554 | } |
| 555 | printk(BIOS_SPEW, "cse_lite: Computed SHA of CSE CBFS RW Image matches the" |
| 556 | " provided hash in the metadata\n"); |
| 557 | return true; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static bool cse_erase_rw_region(const struct region_device *target_rdev) |
| 561 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 562 | if (rdev_eraseat(target_rdev, 0, region_device_sz(target_rdev)) < 0) { |
| 563 | printk(BIOS_ERR, "cse_lite: CSE RW partition could not be erased\n"); |
| 564 | return false; |
| 565 | } |
| 566 | return true; |
| 567 | } |
| 568 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 569 | static bool cse_copy_rw(const struct region_device *target_rdev, const void *buf, |
| 570 | size_t offset, size_t size) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 571 | { |
| 572 | if (rdev_writeat(target_rdev, buf, offset, size) < 0) { |
| 573 | printk(BIOS_ERR, "cse_lite: Failed to update CSE firmware\n"); |
| 574 | return false; |
| 575 | } |
| 576 | |
| 577 | return true; |
| 578 | } |
| 579 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 580 | enum cse_update_status { |
| 581 | CSE_UPDATE_NOT_REQUIRED, |
| 582 | CSE_UPDATE_UPGRADE, |
| 583 | CSE_UPDATE_DOWNGRADE, |
| 584 | CSE_UPDATE_CORRUPTED, |
| 585 | CSE_UPDATE_METADATA_ERROR, |
| 586 | }; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 587 | |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 588 | static bool read_ver_field(const char *start, char **curr, size_t size, uint16_t *ver_field) |
| 589 | { |
| 590 | if ((*curr - start) >= size) { |
| 591 | printk(BIOS_ERR, "cse_lite: Version string read overflow!\n"); |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | *ver_field = skip_atoi(curr); |
| 596 | (*curr)++; |
| 597 | return true; |
| 598 | } |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 599 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 600 | static enum cse_update_status cse_check_update_status(const struct cse_bp_info *cse_bp_info, |
| 601 | struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 602 | { |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 603 | int ret; |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 604 | struct fw_version cbfs_rw_version; |
| 605 | char *version_str, *ptr; |
| 606 | size_t size; |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 607 | |
| 608 | if (!cse_is_rw_bp_sign_valid(target_rdev)) |
| 609 | return CSE_UPDATE_CORRUPTED; |
| 610 | |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 611 | ptr = version_str = cbfs_map(CONFIG_SOC_INTEL_CSE_RW_VERSION_CBFS_NAME, &size); |
| 612 | if (!version_str) { |
| 613 | printk(BIOS_ERR, "cse_lite: Failed to get %s\n", |
| 614 | CONFIG_SOC_INTEL_CSE_RW_VERSION_CBFS_NAME); |
| 615 | return CSE_UPDATE_METADATA_ERROR; |
| 616 | } |
| 617 | |
| 618 | if (!read_ver_field(version_str, &ptr, size, &cbfs_rw_version.major) || |
| 619 | !read_ver_field(version_str, &ptr, size, &cbfs_rw_version.minor) || |
| 620 | !read_ver_field(version_str, &ptr, size, &cbfs_rw_version.hotfix) || |
| 621 | !read_ver_field(version_str, &ptr, size, &cbfs_rw_version.build)) { |
| 622 | cbfs_unmap(version_str); |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 623 | return CSE_UPDATE_METADATA_ERROR; |
| 624 | } |
| 625 | |
| 626 | 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] | 627 | cbfs_rw_version.major, |
| 628 | cbfs_rw_version.minor, |
| 629 | cbfs_rw_version.hotfix, |
| 630 | cbfs_rw_version.build); |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 631 | |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 632 | cbfs_unmap(version_str); |
| 633 | |
Sridhar Siricilla | b9277ba | 2021-11-27 13:57:40 +0530 | [diff] [blame] | 634 | 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] | 635 | if (ret == 0) |
| 636 | return CSE_UPDATE_NOT_REQUIRED; |
| 637 | else if (ret < 0) |
| 638 | return CSE_UPDATE_DOWNGRADE; |
| 639 | else |
| 640 | return CSE_UPDATE_UPGRADE; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static bool cse_write_rw_region(const struct region_device *target_rdev, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 644 | const void *cse_cbfs_rw, const size_t cse_cbfs_rw_sz) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 645 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 646 | /* Points to CSE CBFS RW image after boot partition signature */ |
| 647 | uint8_t *cse_cbfs_rw_wo_sign = (uint8_t *)cse_cbfs_rw + CSE_RW_SIGN_SIZE; |
| 648 | |
| 649 | /* Size of CSE CBFS RW image without boot partition signature */ |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 650 | 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] | 651 | |
| 652 | /* Update except CSE RW signature */ |
| 653 | if (!cse_copy_rw(target_rdev, cse_cbfs_rw_wo_sign, CSE_RW_SIGN_SIZE, |
| 654 | cse_cbfs_rw_wo_sign_sz)) |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 655 | return false; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 656 | |
| 657 | /* Update CSE RW signature to indicate update is complete */ |
| 658 | if (!cse_copy_rw(target_rdev, (void *)cse_cbfs_rw, 0, CSE_RW_SIGN_SIZE)) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 659 | return false; |
| 660 | |
| 661 | printk(BIOS_INFO, "cse_lite: CSE RW Update Successful\n"); |
| 662 | return true; |
| 663 | } |
| 664 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 665 | static enum csme_failure_reason cse_update_rw(const struct cse_bp_info *cse_bp_info, |
| 666 | const void *cse_cbfs_rw, const size_t cse_blob_sz, |
| 667 | struct region_device *target_rdev) |
| 668 | { |
Sridhar Siricilla | abeb688 | 2020-12-07 15:55:10 +0530 | [diff] [blame] | 669 | if (region_device_sz(target_rdev) < cse_blob_sz) { |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 670 | printk(BIOS_ERR, "RW update does not fit. CSE RW flash region size: %zx," |
| 671 | "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] | 672 | return CSE_LITE_SKU_LAYOUT_MISMATCH_ERROR; |
| 673 | } |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 674 | |
| 675 | if (!cse_erase_rw_region(target_rdev)) |
| 676 | return CSE_LITE_SKU_FW_UPDATE_ERROR; |
| 677 | |
| 678 | if (!cse_write_rw_region(target_rdev, cse_cbfs_rw, cse_blob_sz)) |
| 679 | return CSE_LITE_SKU_FW_UPDATE_ERROR; |
| 680 | |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 681 | return CSE_NO_ERROR; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 682 | } |
| 683 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 684 | static bool 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] | 685 | enum cse_update_status status) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 686 | { |
| 687 | /* |
| 688 | * To set CSE's operation mode to HMRFPO mode: |
| 689 | * 1. Ensure CSE to boot from RO(BP1) |
| 690 | * 2. Send HMRFPO_ENABLE command to CSE |
| 691 | */ |
| 692 | if (!cse_boot_to_ro(cse_bp_info)) |
| 693 | return false; |
| 694 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 695 | if ((status == CSE_UPDATE_DOWNGRADE) || (status == CSE_UPDATE_CORRUPTED)) { |
| 696 | if (!cse_data_clear_request(cse_bp_info)) { |
| 697 | printk(BIOS_ERR, "cse_lite: CSE data clear failed!\n"); |
| 698 | return false; |
| 699 | } |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 700 | } |
| 701 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 702 | return cse_hmrfpo_enable(); |
| 703 | } |
| 704 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 705 | 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] | 706 | enum cse_update_status status, |
| 707 | struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 708 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 709 | enum csme_failure_reason rv; |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 710 | uint8_t *cbfs_rw_hash; |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 711 | size_t size; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 712 | |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 713 | const char *area_name = cse_get_source_rdev_fmap(); |
| 714 | if (!area_name) |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 715 | return CSE_LITE_SKU_RW_BLOB_NOT_FOUND; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 716 | |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 717 | void *cse_cbfs_rw = cbfs_unverified_area_map(area_name, |
| 718 | CONFIG_SOC_INTEL_CSE_RW_CBFS_NAME, &size); |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 719 | if (!cse_cbfs_rw) { |
| 720 | printk(BIOS_ERR, "cse_lite: CSE CBFS RW blob could not be mapped\n"); |
| 721 | return CSE_LITE_SKU_RW_BLOB_NOT_FOUND; |
| 722 | } |
| 723 | |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 724 | cbfs_rw_hash = cbfs_map(CONFIG_SOC_INTEL_CSE_RW_HASH_CBFS_NAME, NULL); |
| 725 | if (!cbfs_rw_hash) { |
| 726 | printk(BIOS_ERR, "cse_lite: Failed to get %s\n", |
| 727 | CONFIG_SOC_INTEL_CSE_RW_HASH_CBFS_NAME); |
| 728 | rv = CSE_LITE_SKU_RW_METADATA_NOT_FOUND; |
| 729 | goto error_exit; |
| 730 | } |
| 731 | |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 732 | 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] | 733 | rv = CSE_LITE_SKU_RW_BLOB_SHA256_MISMATCH; |
| 734 | goto error_exit; |
| 735 | } |
| 736 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 737 | if (!cse_prep_for_rw_update(cse_bp_info, status)) { |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 738 | rv = CSE_COMMUNICATION_ERROR; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 739 | goto error_exit; |
| 740 | } |
| 741 | |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 742 | 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] | 743 | |
| 744 | error_exit: |
Furquan Shaikh | d2da870 | 2021-10-07 00:08:59 -0700 | [diff] [blame] | 745 | cbfs_unmap(cbfs_rw_hash); |
Julius Werner | 18881f99 | 2021-04-13 15:28:12 -0700 | [diff] [blame] | 746 | cbfs_unmap(cse_cbfs_rw); |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 747 | return rv; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 748 | } |
| 749 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 750 | 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] | 751 | { |
| 752 | struct region_device target_rdev; |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 753 | enum cse_update_status status; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 754 | |
| 755 | if (!cse_get_target_rdev(cse_bp_info, &target_rdev)) { |
| 756 | printk(BIOS_ERR, "cse_lite: Failed to get CSE RW Partition\n"); |
| 757 | return CSE_LITE_SKU_RW_ACCESS_ERROR; |
| 758 | } |
| 759 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 760 | status = cse_check_update_status(cse_bp_info, &target_rdev); |
| 761 | if (status == CSE_UPDATE_NOT_REQUIRED) |
| 762 | return CSE_NO_ERROR; |
| 763 | if (status == CSE_UPDATE_METADATA_ERROR) |
| 764 | return CSE_LITE_SKU_RW_METADATA_NOT_FOUND; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 765 | |
Furquan Shaikh | c45e0be | 2021-10-06 23:28:03 -0700 | [diff] [blame] | 766 | printk(BIOS_DEBUG, "cse_lite: CSE RW update is initiated\n"); |
| 767 | return cse_trigger_fw_update(cse_bp_info, status, &target_rdev); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 768 | } |
| 769 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 770 | static const char *cse_sub_part_str(enum bpdt_entry_type type) |
| 771 | { |
| 772 | switch (type) { |
| 773 | case IOM_FW: |
| 774 | return "IOM"; |
| 775 | case NPHY_FW: |
| 776 | return "NPHY"; |
| 777 | default: |
| 778 | return "Unknown"; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | static bool cse_sub_part_get_target_rdev(struct region_device *target_rdev, |
| 783 | const char *region_name, enum bpdt_entry_type type) |
| 784 | { |
| 785 | struct bpdt_header bpdt_hdr; |
| 786 | struct region_device cse_rdev; |
| 787 | struct bpdt_entry bpdt_entries[MAX_SUBPARTS]; |
| 788 | uint8_t i; |
| 789 | |
| 790 | if (fmap_locate_area_as_rdev_rw(region_name, &cse_rdev) < 0) { |
| 791 | printk(BIOS_ERR, "cse_lite: Failed to locate %s in the FMAP\n", region_name); |
| 792 | return false; |
| 793 | } |
| 794 | |
| 795 | if ((rdev_readat(&cse_rdev, &bpdt_hdr, 0, BPDT_HEADER_SZ)) != BPDT_HEADER_SZ) { |
| 796 | printk(BIOS_ERR, "cse_lite: Failed to read BPDT header from CSE region\n"); |
| 797 | return false; |
| 798 | } |
| 799 | |
| 800 | if ((rdev_readat(&cse_rdev, bpdt_entries, BPDT_HEADER_SZ, |
| 801 | (bpdt_hdr.descriptor_count * BPDT_ENTRY_SZ))) != |
| 802 | (bpdt_hdr.descriptor_count * BPDT_ENTRY_SZ)) { |
| 803 | printk(BIOS_ERR, "cse_lite: Failed to read BPDT entries from CSE region\n"); |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | /* walk through BPDT entries to identify sub-partition's payload offset and size */ |
| 808 | for (i = 0; i < bpdt_hdr.descriptor_count; i++) { |
| 809 | if (bpdt_entries[i].type == type) { |
| 810 | printk(BIOS_INFO, "cse_lite: Sub-partition %s- offset = 0x%x," |
| 811 | "size = 0x%x\n", cse_sub_part_str(type), bpdt_entries[i].offset, |
| 812 | bpdt_entries[i].size); |
| 813 | |
| 814 | if (rdev_chain(target_rdev, &cse_rdev, bpdt_entries[i].offset, |
| 815 | bpdt_entries[i].size)) |
| 816 | return false; |
| 817 | else |
| 818 | return true; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | printk(BIOS_ERR, "cse_lite: Sub-partition %s is not found\n", cse_sub_part_str(type)); |
| 823 | return false; |
| 824 | } |
| 825 | |
| 826 | static bool cse_get_sub_part_fw_version(enum bpdt_entry_type type, |
| 827 | const struct region_device *rdev, |
| 828 | struct fw_version *fw_ver) |
| 829 | { |
| 830 | struct subpart_entry subpart_entry; |
| 831 | struct subpart_entry_manifest_header man_hdr; |
| 832 | |
| 833 | if ((rdev_readat(rdev, &subpart_entry, SUBPART_HEADER_SZ, SUBPART_ENTRY_SZ)) |
| 834 | != SUBPART_ENTRY_SZ) { |
| 835 | printk(BIOS_ERR, "cse_lite: Failed to read %s sub partition entry\n", |
| 836 | cse_sub_part_str(type)); |
| 837 | return false; |
| 838 | } |
| 839 | |
| 840 | if ((rdev_readat(rdev, &man_hdr, subpart_entry.offset_bytes, SUBPART_MANIFEST_HDR_SZ)) |
| 841 | != SUBPART_MANIFEST_HDR_SZ) { |
| 842 | printk(BIOS_ERR, "cse_lite: Failed to read %s Sub part entry #0 manifest\n", |
| 843 | cse_sub_part_str(type)); |
| 844 | return false; |
| 845 | } |
| 846 | |
| 847 | fw_ver->major = man_hdr.binary_version.major; |
| 848 | fw_ver->minor = man_hdr.binary_version.minor; |
| 849 | fw_ver->hotfix = man_hdr.binary_version.hotfix; |
| 850 | fw_ver->build = man_hdr.binary_version.build; |
| 851 | |
| 852 | return true; |
| 853 | } |
| 854 | |
| 855 | static void cse_sub_part_get_source_fw_version(void *subpart_cbfs_rw, struct fw_version *fw_ver) |
| 856 | { |
| 857 | uint8_t *ptr = (uint8_t *)subpart_cbfs_rw; |
| 858 | struct subpart_entry *subpart_entry; |
| 859 | struct subpart_entry_manifest_header *man_hdr; |
| 860 | |
| 861 | subpart_entry = (struct subpart_entry *) (ptr + SUBPART_HEADER_SZ); |
| 862 | man_hdr = (struct subpart_entry_manifest_header *) (ptr + subpart_entry->offset_bytes); |
| 863 | |
| 864 | fw_ver->major = man_hdr->binary_version.major; |
| 865 | fw_ver->minor = man_hdr->binary_version.minor; |
| 866 | fw_ver->hotfix = man_hdr->binary_version.hotfix; |
| 867 | fw_ver->build = man_hdr->binary_version.build; |
| 868 | } |
| 869 | |
| 870 | static bool cse_prep_for_component_update(const struct cse_bp_info *cse_bp_info) |
| 871 | { |
| 872 | /* |
| 873 | * To set CSE's operation mode to HMRFPO mode: |
| 874 | * 1. Ensure CSE to boot from RO(BP1) |
| 875 | * 2. Send HMRFPO_ENABLE command to CSE |
| 876 | */ |
| 877 | if (!cse_boot_to_ro(cse_bp_info)) |
| 878 | return false; |
| 879 | |
| 880 | return cse_hmrfpo_enable(); |
| 881 | } |
| 882 | |
| 883 | static uint8_t cse_sub_part_trigger_update(enum bpdt_entry_type type, uint8_t bp, |
| 884 | const void *subpart_cbfs_rw, const size_t blob_sz, |
| 885 | struct region_device *target_rdev) |
| 886 | { |
| 887 | if (region_device_sz(target_rdev) < blob_sz) { |
| 888 | printk(BIOS_ERR, "cse_lite: %s Target sub-partition size: %zx, " |
| 889 | "smaller than blob size:%zx, abort update\n", |
| 890 | cse_sub_part_str(type), region_device_sz(target_rdev), blob_sz); |
| 891 | return CSE_LITE_SKU_SUB_PART_LAYOUT_MISMATCH_ERROR; |
| 892 | } |
| 893 | |
| 894 | /* Erase CSE Lite sub-partition */ |
| 895 | if (!cse_erase_rw_region(target_rdev)) |
| 896 | return CSE_LITE_SKU_SUB_PART_UPDATE_FAIL; |
| 897 | |
| 898 | /* Update CSE Lite sub-partition */ |
| 899 | if (!cse_copy_rw(target_rdev, (void *)subpart_cbfs_rw, 0, blob_sz)) |
| 900 | return CSE_LITE_SKU_SUB_PART_UPDATE_FAIL; |
| 901 | |
| 902 | printk(BIOS_INFO, "cse_lite: CSE %s %s Update successful\n", GET_BP_STR(bp), |
| 903 | cse_sub_part_str(type)); |
| 904 | |
| 905 | return CSE_LITE_SKU_PART_UPDATE_SUCCESS; |
| 906 | } |
| 907 | |
| 908 | static uint8_t handle_cse_sub_part_fw_update_rv(uint8_t rv) |
| 909 | { |
| 910 | switch (rv) { |
| 911 | case CSE_LITE_SKU_PART_UPDATE_SUCCESS: |
| 912 | case CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ: |
| 913 | return rv; |
| 914 | default: |
| 915 | cse_trigger_vboot_recovery(rv); |
| 916 | } |
| 917 | /* Control never reaches here */ |
| 918 | return rv; |
| 919 | } |
| 920 | |
| 921 | static enum csme_failure_reason cse_sub_part_fw_component_update(enum bpdt_entry_type type, |
| 922 | const struct cse_bp_info *cse_bp_info, const char *name) |
| 923 | { |
| 924 | struct region_device target_rdev; |
| 925 | struct fw_version target_fw_ver, source_fw_ver; |
| 926 | enum csme_failure_reason rv; |
| 927 | size_t size; |
| 928 | static const char * const cse_regions[] = {"CSE_RO", "CSE_RW"}; |
| 929 | |
| 930 | void *subpart_cbfs_rw = cbfs_map(name, &size); |
| 931 | if (!subpart_cbfs_rw) { |
| 932 | printk(BIOS_ERR, "cse_lite: Not able to map %s CBFS file\n", |
| 933 | cse_sub_part_str(type)); |
| 934 | return CSE_LITE_SKU_SUB_PART_BLOB_ACCESS_ERR; |
| 935 | } |
| 936 | |
| 937 | cse_sub_part_get_source_fw_version(subpart_cbfs_rw, &source_fw_ver); |
| 938 | printk(BIOS_INFO, "cse_lite: CBFS %s FW Version: %x.%x.%x.%x\n", cse_sub_part_str(type), |
| 939 | source_fw_ver.major, source_fw_ver.minor, source_fw_ver.hotfix, |
| 940 | source_fw_ver.build); |
| 941 | |
| 942 | /* Trigger sub-partition update in CSE RO and CSE RW */ |
| 943 | for (size_t bp = 0; bp < ARRAY_SIZE(cse_regions); bp++) { |
| 944 | if (!cse_sub_part_get_target_rdev(&target_rdev, cse_regions[bp], type)) { |
| 945 | rv = CSE_LITE_SKU_SUB_PART_ACCESS_ERR; |
| 946 | goto error_exit; |
| 947 | } |
| 948 | |
| 949 | if (!cse_get_sub_part_fw_version(type, &target_rdev, &target_fw_ver)) { |
| 950 | rv = CSE_LITE_SKU_SUB_PART_ACCESS_ERR; |
| 951 | goto error_exit; |
| 952 | } |
| 953 | |
| 954 | printk(BIOS_INFO, "cse_lite: %s %s FW Version: %x.%x.%x.%x\n", cse_regions[bp], |
| 955 | cse_sub_part_str(type), target_fw_ver.major, |
| 956 | target_fw_ver.minor, target_fw_ver.hotfix, target_fw_ver.build); |
| 957 | |
| 958 | if (!cse_compare_sub_part_version(&target_fw_ver, &source_fw_ver)) { |
| 959 | printk(BIOS_INFO, "cse_lite: %s %s update is not required\n", |
| 960 | cse_regions[bp], cse_sub_part_str(type)); |
| 961 | rv = CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ; |
| 962 | continue; |
| 963 | } |
| 964 | |
| 965 | printk(BIOS_INFO, "CSE %s %s Update initiated\n", GET_BP_STR(bp), |
| 966 | cse_sub_part_str(type)); |
| 967 | |
| 968 | if (!cse_prep_for_component_update(cse_bp_info)) { |
| 969 | rv = CSE_LITE_SKU_SUB_PART_ACCESS_ERR; |
| 970 | goto error_exit; |
| 971 | } |
| 972 | |
| 973 | rv = cse_sub_part_trigger_update(type, bp, subpart_cbfs_rw, |
| 974 | size, &target_rdev); |
| 975 | |
| 976 | if (rv != CSE_LITE_SKU_PART_UPDATE_SUCCESS) |
| 977 | goto error_exit; |
| 978 | } |
| 979 | error_exit: |
| 980 | cbfs_unmap(subpart_cbfs_rw); |
| 981 | return rv; |
| 982 | } |
| 983 | |
| 984 | static uint8_t cse_sub_part_fw_update(const struct cse_bp_info *cse_bp_info) |
| 985 | { |
| 986 | if (skip_cse_sub_part_update()) { |
| 987 | printk(BIOS_INFO, "CSE Sub-partition update not required\n"); |
| 988 | return CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ; |
| 989 | } |
| 990 | |
| 991 | int rv; |
| 992 | rv = cse_sub_part_fw_component_update(IOM_FW, cse_bp_info, |
| 993 | CONFIG_SOC_INTEL_CSE_IOM_CBFS_NAME); |
| 994 | |
| 995 | handle_cse_sub_part_fw_update_rv(rv); |
| 996 | |
| 997 | rv = cse_sub_part_fw_component_update(NPHY_FW, cse_bp_info, |
| 998 | CONFIG_SOC_INTEL_CSE_NPHY_CBFS_NAME); |
| 999 | |
| 1000 | return handle_cse_sub_part_fw_update_rv(rv); |
| 1001 | } |
| 1002 | |
Sridhar Siricilla | 1a2b702 | 2020-12-04 02:22:28 +0530 | [diff] [blame] | 1003 | void cse_fw_sync(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1004 | { |
| 1005 | static struct get_bp_info_rsp cse_bp_info; |
| 1006 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1007 | /* |
| 1008 | * If system is in recovery mode, skip CSE Lite update if CSE sub-partition update |
| 1009 | * is not enabled and continue to update CSE sub-partitions. |
| 1010 | */ |
| 1011 | if (vboot_recovery_mode_enabled() && !CONFIG(SOC_INTEL_CSE_SUB_PART_UPDATE)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1012 | 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] | 1013 | return; |
| 1014 | } |
| 1015 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 1016 | /* If CSE SKU type is not Lite, skip enabling CSE Lite SKU */ |
| 1017 | if (!cse_is_hfs3_fw_sku_lite()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1018 | printk(BIOS_ERR, "cse_lite: Not a CSE Lite SKU\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1019 | return; |
| 1020 | } |
| 1021 | |
| 1022 | if (!cse_get_bp_info(&cse_bp_info)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1023 | 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] | 1024 | |
| 1025 | /* If system is in recovery mode, don't trigger recovery again */ |
| 1026 | if (!vboot_recovery_mode_enabled()) { |
| 1027 | cse_trigger_vboot_recovery(CSE_COMMUNICATION_ERROR); |
| 1028 | } else { |
| 1029 | printk(BIOS_ERR, "cse_lite: System is already in Recovery Mode, " |
| 1030 | "so no action\n"); |
| 1031 | return; |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * If system is in recovery mode, CSE Lite update has to be skipped but CSE |
| 1037 | * sub-partitions like NPHY and IOM have to to be updated. If CSE sub-parition update |
| 1038 | * fails during recovery, just continue to boot. |
| 1039 | */ |
| 1040 | if (CONFIG(SOC_INTEL_CSE_SUB_PART_UPDATE) && vboot_recovery_mode_enabled()) { |
| 1041 | if (cse_sub_part_fw_update(&cse_bp_info.bp_info) == |
| 1042 | CSE_LITE_SKU_PART_UPDATE_SUCCESS) { |
| 1043 | cse_board_reset(); |
| 1044 | do_global_reset(); |
| 1045 | die("ERROR: GLOBAL RESET Failed to reset the system\n"); |
| 1046 | } |
| 1047 | |
| 1048 | return; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1049 | } |
| 1050 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 1051 | if (!cse_fix_data_failure_err(&cse_bp_info.bp_info)) |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 1052 | cse_trigger_vboot_recovery(CSE_LITE_SKU_DATA_WIPE_ERROR); |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 1053 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 1054 | /* |
| 1055 | * If SOC_INTEL_CSE_RW_UPDATE is defined , then trigger CSE firmware update. The driver |
| 1056 | * triggers recovery if CSE CBFS RW metadata or CSE CBFS RW blob is not available. |
| 1057 | */ |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 1058 | if (CONFIG(SOC_INTEL_CSE_RW_UPDATE)) { |
| 1059 | uint8_t rv; |
| 1060 | rv = cse_fw_update(&cse_bp_info.bp_info); |
| 1061 | if (rv) |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 1062 | cse_trigger_vboot_recovery(rv); |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 1063 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1064 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 1065 | if (CONFIG(SOC_INTEL_CSE_SUB_PART_UPDATE)) |
| 1066 | cse_sub_part_fw_update(&cse_bp_info.bp_info); |
| 1067 | |
Sridahr Siricilla | 54b0356 | 2021-06-18 10:59:30 +0530 | [diff] [blame] | 1068 | if (!cse_is_rw_bp_status_valid(&cse_bp_info.bp_info)) |
Tim Wawrzynczak | f2801f4 | 2021-06-22 11:25:14 -0600 | [diff] [blame] | 1069 | cse_trigger_vboot_recovery(CSE_LITE_SKU_RW_JUMP_ERROR); |
Sridahr Siricilla | 54b0356 | 2021-06-18 10:59:30 +0530 | [diff] [blame] | 1070 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1071 | if (!cse_boot_to_rw(&cse_bp_info.bp_info)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 1072 | printk(BIOS_ERR, "cse_lite: Failed to switch to RW\n"); |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 1073 | cse_trigger_vboot_recovery(CSE_LITE_SKU_RW_SWITCH_ERROR); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1074 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 1075 | } |