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> |
| 5 | #include <commonlib/cbfs.h> |
| 6 | #include <commonlib/region.h> |
| 7 | #include <fmap.h> |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 8 | #include <intelblocks/cse.h> |
| 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> |
| 12 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 13 | /* Converts bp index to boot partition string */ |
| 14 | #define GET_BP_STR(bp_index) (bp_index ? "RW" : "RO") |
| 15 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 16 | /* CSE RW boot partition signature */ |
| 17 | #define CSE_RW_SIGNATURE 0x000055aa |
| 18 | |
| 19 | /* CSE RW boot partition signature size */ |
| 20 | #define CSE_RW_SIGN_SIZE sizeof(uint32_t) |
| 21 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 22 | /* |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 23 | * 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] | 24 | * 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] | 25 | * CSE Lite SKU Image Layout: |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 26 | * ------------- ------------------- --------------------- |
| 27 | * |CSE REGION | => | RO | RW | DATA | => | BP1 | BP2 | DATA | |
| 28 | * ------------- ------------------- --------------------- |
| 29 | */ |
| 30 | #define CSE_MAX_BOOT_PARTITIONS 3 |
| 31 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 32 | /* CSE Lite SKU's valid bootable partition identifiers */ |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 33 | enum boot_partition_id { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 34 | /* RO(BP1) contains recovery/minimal boot firmware */ |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 35 | RO = 0, |
| 36 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 37 | /* RW(BP2) contains fully functional CSE firmware */ |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 38 | RW = 1 |
| 39 | }; |
| 40 | |
| 41 | /* |
| 42 | * Boot partition status. |
| 43 | * The status is returned in response to MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO cmd. |
| 44 | */ |
| 45 | enum bp_status { |
| 46 | /* This value is returned when a partition has no errors */ |
| 47 | BP_STATUS_SUCCESS = 0, |
| 48 | |
| 49 | /* |
| 50 | * This value is returned when a partition should be present based on layout, but it is |
| 51 | * not valid. |
| 52 | */ |
| 53 | BP_STATUS_GENERAL_FAILURE = 1, |
| 54 | |
| 55 | /* This value is returned when a partition is not present per initial image layout */ |
| 56 | BP_STATUS_PARTITION_NOT_PRESENT = 2, |
| 57 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 58 | /* |
| 59 | * This value is returned when unexpected issues are detected in CSE Data area |
| 60 | * and CSE TCB-SVN downgrade scenario. |
| 61 | */ |
| 62 | BP_STATUS_DATA_FAILURE = 3, |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * Boot Partition Info Flags |
| 67 | * The flags are returned in response to MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO cmd. |
| 68 | */ |
| 69 | enum bp_info_flags { |
| 70 | |
| 71 | /* Redundancy Enabled: It indicates CSE supports RO(BP1) and RW(BP2) regions */ |
| 72 | BP_INFO_REDUNDANCY_EN = 1 << 0, |
| 73 | |
| 74 | /* It indicates RO(BP1) supports Minimal Recovery Mode */ |
| 75 | BP_INFO_MIN_RECOV_MODE_EN = 1 << 1, |
| 76 | |
| 77 | /* |
| 78 | * Read-only Config Enabled: It indicates HW protection to CSE RO region is enabled. |
| 79 | * The option is relevant only if the BP_INFO_MIN_RECOV_MODE_EN flag is enabled. |
| 80 | */ |
| 81 | BP_INFO_READ_ONLY_CFG = 1 << 2, |
| 82 | }; |
| 83 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 84 | /* CSE boot partition entry info */ |
| 85 | struct cse_bp_entry { |
| 86 | /* Boot partition version */ |
| 87 | struct fw_version fw_ver; |
| 88 | |
| 89 | /* Boot partition status */ |
| 90 | uint32_t status; |
| 91 | |
| 92 | /* Starting offset of the partition within CSE region */ |
| 93 | uint32_t start_offset; |
| 94 | |
| 95 | /* Ending offset of the partition within CSE region */ |
| 96 | uint32_t end_offset; |
| 97 | uint8_t reserved[12]; |
| 98 | } __packed; |
| 99 | |
| 100 | /* CSE boot partition info */ |
| 101 | struct cse_bp_info { |
| 102 | /* Number of boot partitions */ |
| 103 | uint8_t total_number_of_bp; |
| 104 | |
| 105 | /* Current boot partition */ |
| 106 | uint8_t current_bp; |
| 107 | |
| 108 | /* Next boot partition */ |
| 109 | uint8_t next_bp; |
| 110 | |
| 111 | /* Boot Partition Info Flags */ |
| 112 | uint8_t flags; |
| 113 | |
| 114 | /* Boot Partition Entry Info */ |
| 115 | struct cse_bp_entry bp_entries[CSE_MAX_BOOT_PARTITIONS]; |
| 116 | } __packed; |
| 117 | |
| 118 | struct get_bp_info_rsp { |
| 119 | struct mkhi_hdr hdr; |
| 120 | struct cse_bp_info bp_info; |
| 121 | } __packed; |
| 122 | |
| 123 | static uint8_t cse_get_current_bp(const struct cse_bp_info *cse_bp_info) |
| 124 | { |
| 125 | return cse_bp_info->current_bp; |
| 126 | } |
| 127 | |
| 128 | static const struct cse_bp_entry *cse_get_bp_entry(enum boot_partition_id bp, |
| 129 | const struct cse_bp_info *cse_bp_info) |
| 130 | { |
| 131 | return &cse_bp_info->bp_entries[bp]; |
| 132 | } |
| 133 | |
| 134 | static void cse_print_boot_partition_info(const struct cse_bp_info *cse_bp_info) |
| 135 | { |
| 136 | const struct cse_bp_entry *cse_bp; |
| 137 | |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 138 | printk(BIOS_DEBUG, "cse_lite: Number of partitions = %d\n", |
| 139 | cse_bp_info->total_number_of_bp); |
| 140 | printk(BIOS_DEBUG, "cse_lite: Current partition = %s\n", |
| 141 | GET_BP_STR(cse_bp_info->current_bp)); |
| 142 | printk(BIOS_DEBUG, "cse_lite: Next partition = %s\n", GET_BP_STR(cse_bp_info->next_bp)); |
| 143 | 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] | 144 | |
| 145 | /* Log version info of RO & RW partitions */ |
| 146 | cse_bp = cse_get_bp_entry(RO, cse_bp_info); |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 147 | 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] | 148 | GET_BP_STR(RO), cse_bp->fw_ver.major, cse_bp->fw_ver.minor, |
| 149 | cse_bp->fw_ver.hotfix, cse_bp->fw_ver.build, |
| 150 | cse_bp->status, cse_bp->start_offset, |
| 151 | cse_bp->end_offset); |
| 152 | |
| 153 | cse_bp = cse_get_bp_entry(RW, cse_bp_info); |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 154 | 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] | 155 | GET_BP_STR(RW), cse_bp->fw_ver.major, cse_bp->fw_ver.minor, |
| 156 | cse_bp->fw_ver.hotfix, cse_bp->fw_ver.build, |
| 157 | cse_bp->status, cse_bp->start_offset, |
| 158 | cse_bp->end_offset); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Checks prerequisites for MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO and |
| 163 | * MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO HECI commands. |
| 164 | * It allows execution of the Boot Partition commands in below scenarios: |
| 165 | * - When CSE boots from RW partition (COM: Normal and CWS: Normal) |
| 166 | * - When CSE boots from RO partition (COM: Soft Temp Disable and CWS: Normal) |
| 167 | * - 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] | 168 | * The prerequisite check should be handled in cse_get_bp_info() and |
| 169 | * cse_set_next_boot_partition() since the CSE's current operation mode is changed between these |
| 170 | * cmd handler calls. |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 171 | */ |
| 172 | static bool cse_is_bp_cmd_info_possible(void) |
| 173 | { |
| 174 | if (cse_is_hfs1_cws_normal()) { |
| 175 | if (cse_is_hfs1_com_normal()) |
| 176 | return true; |
| 177 | if (cse_is_hfs1_com_secover_mei_msg()) |
| 178 | return true; |
| 179 | if (cse_is_hfs1_com_soft_temp_disable()) |
| 180 | return true; |
| 181 | } |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | static bool cse_get_bp_info(struct get_bp_info_rsp *bp_info_rsp) |
| 186 | { |
| 187 | struct get_bp_info_req { |
| 188 | struct mkhi_hdr hdr; |
| 189 | uint8_t reserved[4]; |
| 190 | } __packed; |
| 191 | |
| 192 | struct get_bp_info_req info_req = { |
| 193 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 194 | .hdr.command = MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO, |
| 195 | .reserved = {0}, |
| 196 | }; |
| 197 | |
| 198 | if (!cse_is_bp_cmd_info_possible()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 199 | printk(BIOS_ERR, "cse_lite: CSE does not meet prerequisites\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | |
| 203 | size_t resp_size = sizeof(struct get_bp_info_rsp); |
| 204 | |
| 205 | if (!heci_send_receive(&info_req, sizeof(info_req), bp_info_rsp, &resp_size)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 206 | printk(BIOS_ERR, "cse_lite: Could not get partition info\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 207 | return false; |
| 208 | } |
| 209 | |
| 210 | if (bp_info_rsp->hdr.result) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 211 | printk(BIOS_ERR, "cse_lite: Get partition info resp failed: %d\n", |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 212 | bp_info_rsp->hdr.result); |
| 213 | return false; |
| 214 | } |
| 215 | |
| 216 | cse_print_boot_partition_info(&bp_info_rsp->bp_info); |
| 217 | |
| 218 | return true; |
| 219 | } |
| 220 | /* |
| 221 | * It sends HECI command to notify CSE about its next boot partition. When coreboot wants |
| 222 | * CSE to boot from certain partition (BP1 <RO> or BP2 <RW>), then this command can be used. |
| 223 | * The CSE's valid bootable partitions are BP1(RO) and BP2(RW). |
| 224 | * This function must be used before EOP. |
| 225 | * Returns false on failure and true on success. |
| 226 | */ |
| 227 | static bool cse_set_next_boot_partition(enum boot_partition_id bp) |
| 228 | { |
| 229 | struct set_boot_partition_info_req { |
| 230 | struct mkhi_hdr hdr; |
| 231 | uint8_t next_bp; |
| 232 | uint8_t reserved[3]; |
| 233 | } __packed; |
| 234 | |
| 235 | struct set_boot_partition_info_req switch_req = { |
| 236 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 237 | .hdr.command = MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO, |
| 238 | .next_bp = bp, |
| 239 | .reserved = {0}, |
| 240 | }; |
| 241 | |
| 242 | if (bp != RO && bp != RW) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 243 | printk(BIOS_ERR, "cse_lite: Incorrect partition id(%d) is provided", bp); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 244 | return false; |
| 245 | } |
| 246 | |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 247 | 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] | 248 | |
| 249 | if (!cse_is_bp_cmd_info_possible()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 250 | printk(BIOS_ERR, "cse_lite: CSE does not meet prerequisites\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 251 | return false; |
| 252 | } |
| 253 | |
| 254 | struct mkhi_hdr switch_resp; |
| 255 | size_t sw_resp_sz = sizeof(struct mkhi_hdr); |
| 256 | |
| 257 | if (!heci_send_receive(&switch_req, sizeof(switch_req), &switch_resp, &sw_resp_sz)) |
| 258 | return false; |
| 259 | |
| 260 | if (switch_resp.result) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 261 | 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] | 262 | switch_resp.result); |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | return true; |
| 267 | } |
| 268 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 269 | static bool cse_data_clear_request(const struct cse_bp_info *cse_bp_info) |
| 270 | { |
| 271 | struct data_clr_request { |
| 272 | struct mkhi_hdr hdr; |
| 273 | uint8_t reserved[4]; |
| 274 | } __packed; |
| 275 | |
| 276 | struct data_clr_request data_clr_rq = { |
| 277 | .hdr.group_id = MKHI_GROUP_ID_BUP_COMMON, |
| 278 | .hdr.command = MKHI_BUP_COMMON_DATA_CLEAR, |
| 279 | .reserved = {0}, |
| 280 | }; |
| 281 | |
| 282 | if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_soft_temp_disable() || |
| 283 | cse_get_current_bp(cse_bp_info) != RO) { |
| 284 | printk(BIOS_ERR, "cse_lite: CSE doesn't meet DATA CLEAR cmd prerequisites\n"); |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | printk(BIOS_DEBUG, "cse_lite: Sending DATA CLEAR HECI command\n"); |
| 289 | |
| 290 | struct mkhi_hdr data_clr_rsp; |
| 291 | size_t data_clr_rsp_sz = sizeof(data_clr_rsp); |
| 292 | |
| 293 | if (!heci_send_receive(&data_clr_rq, sizeof(data_clr_rq), &data_clr_rsp, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 294 | &data_clr_rsp_sz)) { |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 295 | return false; |
| 296 | } |
| 297 | |
| 298 | if (data_clr_rsp.result) { |
| 299 | printk(BIOS_ERR, "cse_lite: CSE DATA CLEAR command response failed: %d\n", |
| 300 | data_clr_rsp.result); |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | return true; |
| 305 | } |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 306 | |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 307 | __weak void cse_board_reset(void) |
| 308 | { |
| 309 | /* Default weak implementation, does nothing. */ |
| 310 | } |
| 311 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 312 | /* Set the CSE's next boot partition and issues system reset */ |
| 313 | 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] | 314 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 315 | if (!cse_set_next_boot_partition(bp)) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 316 | return false; |
| 317 | |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 318 | /* Allow the board to perform a reset for CSE RO<->RW jump */ |
| 319 | cse_board_reset(); |
| 320 | |
| 321 | /* If board does not perform the reset, then perform global_reset */ |
Furquan Shaikh | b13bd1e | 2020-09-21 22:44:27 +0000 | [diff] [blame] | 322 | do_global_reset(); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 323 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 324 | die("cse_lite: Failed to reset the system\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 325 | |
| 326 | /* Control never reaches here */ |
| 327 | return false; |
| 328 | } |
| 329 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 330 | 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] | 331 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 332 | if (cse_get_current_bp(cse_bp_info) == RW) |
| 333 | return true; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 334 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 335 | return cse_set_and_boot_from_next_bp(RW); |
| 336 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 337 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 338 | /* Check if CSE RW data partition is valid or not */ |
| 339 | static bool cse_is_rw_dp_valid(const struct cse_bp_info *cse_bp_info) |
| 340 | { |
| 341 | const struct cse_bp_entry *rw_bp; |
| 342 | |
| 343 | rw_bp = cse_get_bp_entry(RW, cse_bp_info); |
| 344 | return rw_bp->status != BP_STATUS_DATA_FAILURE; |
| 345 | } |
| 346 | |
| 347 | /* |
| 348 | * It returns true if RW partition doesn't indicate BP_STATUS_DATA_FAILURE |
| 349 | * otherwise false if any operation fails. |
| 350 | */ |
| 351 | static bool cse_fix_data_failure_err(const struct cse_bp_info *cse_bp_info) |
| 352 | { |
| 353 | /* |
| 354 | * If RW partition status indicates BP_STATUS_DATA_FAILURE, |
| 355 | * - Send DATA CLEAR HECI command to CSE |
| 356 | * - Send SET BOOT PARTITION INFO(RW) command to set CSE's next partition |
| 357 | * - Issue GLOBAL RESET HECI command. |
| 358 | */ |
| 359 | if (cse_is_rw_dp_valid(cse_bp_info)) |
| 360 | return true; |
| 361 | |
| 362 | if (!cse_data_clear_request(cse_bp_info)) |
| 363 | return false; |
| 364 | |
| 365 | return cse_boot_to_rw(cse_bp_info); |
| 366 | } |
| 367 | |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 368 | 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] | 369 | const struct cse_bp_info *bp_info) |
V Sowmya | f990552 | 2020-11-12 20:19:04 +0530 | [diff] [blame] | 370 | { |
| 371 | const struct cse_bp_entry *cse_bp; |
| 372 | |
| 373 | cse_bp = cse_get_bp_entry(bp, bp_info); |
| 374 | return &cse_bp->fw_ver; |
| 375 | } |
| 376 | |
| 377 | static const struct fw_version *cse_get_rw_version(const struct cse_bp_info *cse_bp_info) |
| 378 | { |
| 379 | return cse_get_bp_entry_version(RW, cse_bp_info); |
| 380 | } |
| 381 | |
| 382 | 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] | 383 | 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] | 384 | { |
| 385 | const struct cse_bp_entry *cse_bp; |
| 386 | |
| 387 | cse_bp = cse_get_bp_entry(bp, cse_bp_info); |
| 388 | |
| 389 | if (start_offset) |
| 390 | *start_offset = cse_bp->start_offset; |
| 391 | |
| 392 | if (end_offset) |
| 393 | *end_offset = cse_bp->end_offset; |
| 394 | |
| 395 | } |
| 396 | |
| 397 | static bool cse_is_rw_bp_status_valid(const struct cse_bp_info *cse_bp_info) |
| 398 | { |
| 399 | const struct cse_bp_entry *rw_bp; |
| 400 | |
| 401 | rw_bp = cse_get_bp_entry(RW, cse_bp_info); |
| 402 | |
| 403 | if (rw_bp->status == BP_STATUS_PARTITION_NOT_PRESENT || |
| 404 | rw_bp->status == BP_STATUS_GENERAL_FAILURE) { |
| 405 | printk(BIOS_ERR, "cse_lite: RW BP (status:%u) is not valid\n", rw_bp->status); |
| 406 | return false; |
| 407 | } |
| 408 | return true; |
| 409 | } |
| 410 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 411 | static bool cse_boot_to_ro(const struct cse_bp_info *cse_bp_info) |
| 412 | { |
| 413 | if (cse_get_current_bp(cse_bp_info) == RO) |
| 414 | return true; |
| 415 | |
| 416 | return cse_set_and_boot_from_next_bp(RO); |
| 417 | } |
| 418 | |
| 419 | static bool cse_get_rw_rdev(struct region_device *rdev) |
| 420 | { |
| 421 | if (fmap_locate_area_as_rdev_rw(CONFIG_SOC_INTEL_CSE_FMAP_NAME, rdev) < 0) { |
| 422 | printk(BIOS_ERR, "cse_lite: Failed to locate %s in FMAP\n", |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 423 | CONFIG_SOC_INTEL_CSE_FMAP_NAME); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 424 | return false; |
| 425 | } |
| 426 | |
| 427 | return true; |
| 428 | } |
| 429 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 430 | static bool cse_is_rw_bp_sign_valid(const struct region_device *target_rdev) |
| 431 | { |
| 432 | uint32_t cse_bp_sign; |
| 433 | |
| 434 | if (rdev_readat(target_rdev, &cse_bp_sign, 0, CSE_RW_SIGN_SIZE) != CSE_RW_SIGN_SIZE) { |
| 435 | printk(BIOS_ERR, "cse_lite: Failed to read RW boot partition signature\n"); |
| 436 | return false; |
| 437 | } |
| 438 | |
| 439 | return cse_bp_sign == CSE_RW_SIGNATURE; |
| 440 | } |
| 441 | |
| 442 | static bool cse_get_target_rdev(const struct cse_bp_info *cse_bp_info, |
| 443 | struct region_device *target_rdev) |
| 444 | { |
| 445 | struct region_device cse_region_rdev; |
| 446 | size_t size; |
| 447 | uint32_t start_offset; |
| 448 | uint32_t end_offset; |
| 449 | |
| 450 | if (!cse_get_rw_rdev(&cse_region_rdev)) |
| 451 | return false; |
| 452 | |
| 453 | cse_get_bp_entry_range(cse_bp_info, RW, &start_offset, &end_offset); |
| 454 | size = end_offset + 1 - start_offset; |
| 455 | |
| 456 | if (rdev_chain(target_rdev, &cse_region_rdev, start_offset, size)) |
| 457 | return false; |
| 458 | |
| 459 | printk(BIOS_DEBUG, "cse_lite: CSE RW partition: offset = 0x%x, size = 0x%x\n", |
| 460 | (uint32_t)start_offset, (uint32_t) size); |
| 461 | |
| 462 | return true; |
| 463 | } |
| 464 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 465 | static const char *cse_get_source_rdev_fmap(void) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 466 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 467 | struct vb2_context *ctx = vboot_get_context(); |
| 468 | if (ctx == NULL) |
| 469 | return NULL; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 470 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 471 | if (vboot_is_firmware_slot_a(ctx)) |
| 472 | return CONFIG_SOC_INTEL_CSE_RW_A_FMAP_NAME; |
| 473 | |
| 474 | return CONFIG_SOC_INTEL_CSE_RW_B_FMAP_NAME; |
| 475 | } |
| 476 | |
| 477 | static bool cse_get_source_rdev(struct region_device *rdev) |
| 478 | { |
| 479 | const char *reg_name; |
| 480 | uint32_t cbfs_type = CBFS_TYPE_RAW; |
| 481 | struct cbfsf fh; |
| 482 | |
| 483 | reg_name = cse_get_source_rdev_fmap(); |
| 484 | |
| 485 | if (reg_name == NULL) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 486 | return false; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 487 | |
| 488 | if (cbfs_locate_file_in_region(&fh, reg_name, CONFIG_SOC_INTEL_CSE_RW_CBFS_NAME, |
| 489 | &cbfs_type) < 0) |
| 490 | return false; |
| 491 | |
| 492 | cbfs_file_data(rdev, &fh); |
| 493 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 497 | /* |
| 498 | * Compare versions of CSE CBFS RW and CSE RW partition |
| 499 | * If ver_cmp_status = 0, no update is required |
| 500 | * If ver_cmp_status < 0, coreboot downgrades CSE RW region |
| 501 | * If ver_cmp_status > 0, coreboot upgrades CSE RW region |
| 502 | */ |
| 503 | static int cse_check_version_mismatch(const struct cse_bp_info *cse_bp_info, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 504 | const struct cse_rw_metadata *source_metadata) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 505 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 506 | const struct fw_version *cse_rw_ver; |
| 507 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 508 | printk(BIOS_DEBUG, "cse_lite: CSE CBFS RW version : %d.%d.%d.%d\n", |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 509 | source_metadata->version.major, |
| 510 | source_metadata->version.minor, |
| 511 | source_metadata->version.hotfix, |
| 512 | source_metadata->version.build); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 513 | |
| 514 | cse_rw_ver = cse_get_rw_version(cse_bp_info); |
| 515 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 516 | if (source_metadata->version.major != cse_rw_ver->major) |
| 517 | return source_metadata->version.major - cse_rw_ver->major; |
| 518 | else if (source_metadata->version.minor != cse_rw_ver->minor) |
| 519 | return source_metadata->version.minor - cse_rw_ver->minor; |
| 520 | else if (source_metadata->version.hotfix != cse_rw_ver->hotfix) |
| 521 | return source_metadata->version.hotfix - cse_rw_ver->hotfix; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 522 | else |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 523 | return source_metadata->version.build - cse_rw_ver->build; |
| 524 | } |
| 525 | |
| 526 | /* The function calculates SHA-256 of CSE RW blob and compares it with the provided SHA value */ |
| 527 | static bool cse_verify_cbfs_rw_sha256(const uint8_t *expected_rw_blob_sha, |
| 528 | const void *rw_blob, const size_t rw_blob_sz) |
| 529 | |
| 530 | { |
| 531 | uint8_t rw_comp_sha[VB2_SHA256_DIGEST_SIZE]; |
| 532 | |
| 533 | if (vb2_digest_buffer(rw_blob, rw_blob_sz, VB2_HASH_SHA256, rw_comp_sha, |
| 534 | VB2_SHA256_DIGEST_SIZE)) { |
| 535 | printk(BIOS_ERR, "cse_lite: CSE CBFS RW's SHA-256 calculation has failed\n"); |
| 536 | return false; |
| 537 | } |
| 538 | |
| 539 | if (memcmp(expected_rw_blob_sha, rw_comp_sha, VB2_SHA256_DIGEST_SIZE)) { |
| 540 | printk(BIOS_ERR, "cse_lite: Computed CBFS RW's SHA-256 does not match with" |
| 541 | "the provided SHA in the metadata\n"); |
| 542 | return false; |
| 543 | } |
| 544 | printk(BIOS_SPEW, "cse_lite: Computed SHA of CSE CBFS RW Image matches the" |
| 545 | " provided hash in the metadata\n"); |
| 546 | return true; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static bool cse_erase_rw_region(const struct region_device *target_rdev) |
| 550 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 551 | if (rdev_eraseat(target_rdev, 0, region_device_sz(target_rdev)) < 0) { |
| 552 | printk(BIOS_ERR, "cse_lite: CSE RW partition could not be erased\n"); |
| 553 | return false; |
| 554 | } |
| 555 | return true; |
| 556 | } |
| 557 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 558 | static bool cse_copy_rw(const struct region_device *target_rdev, const void *buf, |
| 559 | size_t offset, size_t size) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 560 | { |
| 561 | if (rdev_writeat(target_rdev, buf, offset, size) < 0) { |
| 562 | printk(BIOS_ERR, "cse_lite: Failed to update CSE firmware\n"); |
| 563 | return false; |
| 564 | } |
| 565 | |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | static bool cse_is_rw_version_latest(const struct cse_bp_info *cse_bp_info, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 570 | const struct cse_rw_metadata *source_metadata) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 571 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 572 | return !cse_check_version_mismatch(cse_bp_info, source_metadata); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 573 | } |
| 574 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 575 | static bool cse_is_downgrade_instance(const struct cse_bp_info *cse_bp_info, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 576 | const struct cse_rw_metadata *source_metadata) |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 577 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 578 | return cse_check_version_mismatch(cse_bp_info, source_metadata) < 0; |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 579 | } |
| 580 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 581 | static bool cse_is_update_required(const struct cse_bp_info *cse_bp_info, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 582 | const struct cse_rw_metadata *source_metadata, |
| 583 | struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 584 | { |
| 585 | return (!cse_is_rw_bp_sign_valid(target_rdev) || |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 586 | !cse_is_rw_version_latest(cse_bp_info, source_metadata)); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | static bool cse_write_rw_region(const struct region_device *target_rdev, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 590 | const void *cse_cbfs_rw, const size_t cse_cbfs_rw_sz) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 591 | { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 592 | /* Points to CSE CBFS RW image after boot partition signature */ |
| 593 | uint8_t *cse_cbfs_rw_wo_sign = (uint8_t *)cse_cbfs_rw + CSE_RW_SIGN_SIZE; |
| 594 | |
| 595 | /* Size of CSE CBFS RW image without boot partition signature */ |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 596 | 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] | 597 | |
| 598 | /* Update except CSE RW signature */ |
| 599 | if (!cse_copy_rw(target_rdev, cse_cbfs_rw_wo_sign, CSE_RW_SIGN_SIZE, |
| 600 | cse_cbfs_rw_wo_sign_sz)) |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 601 | return false; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 602 | |
| 603 | /* Update CSE RW signature to indicate update is complete */ |
| 604 | 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] | 605 | return false; |
| 606 | |
| 607 | printk(BIOS_INFO, "cse_lite: CSE RW Update Successful\n"); |
| 608 | return true; |
| 609 | } |
| 610 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 611 | static enum csme_failure_reason cse_update_rw(const struct cse_bp_info *cse_bp_info, |
| 612 | const void *cse_cbfs_rw, const size_t cse_blob_sz, |
| 613 | struct region_device *target_rdev) |
| 614 | { |
Sridhar Siricilla | abeb688 | 2020-12-07 15:55:10 +0530 | [diff] [blame] | 615 | if (region_device_sz(target_rdev) < cse_blob_sz) { |
| 616 | printk(BIOS_ERR, "RW update does not fit. CSE RW flash region size: %zx, Update blob size:%zx\n", |
| 617 | region_device_sz(target_rdev), cse_blob_sz); |
| 618 | return CSE_LITE_SKU_LAYOUT_MISMATCH_ERROR; |
| 619 | } |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 620 | |
| 621 | if (!cse_erase_rw_region(target_rdev)) |
| 622 | return CSE_LITE_SKU_FW_UPDATE_ERROR; |
| 623 | |
| 624 | if (!cse_write_rw_region(target_rdev, cse_cbfs_rw, cse_blob_sz)) |
| 625 | return CSE_LITE_SKU_FW_UPDATE_ERROR; |
| 626 | |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 627 | return CSE_NO_ERROR; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 628 | } |
| 629 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 630 | static bool cse_prep_for_rw_update(const struct cse_bp_info *cse_bp_info, |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 631 | const struct cse_rw_metadata *source_metadata) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 632 | { |
| 633 | /* |
| 634 | * To set CSE's operation mode to HMRFPO mode: |
| 635 | * 1. Ensure CSE to boot from RO(BP1) |
| 636 | * 2. Send HMRFPO_ENABLE command to CSE |
| 637 | */ |
| 638 | if (!cse_boot_to_ro(cse_bp_info)) |
| 639 | return false; |
| 640 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 641 | if (cse_is_downgrade_instance(cse_bp_info, source_metadata) && |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 642 | !cse_data_clear_request(cse_bp_info)) { |
| 643 | printk(BIOS_ERR, "cse_lite: CSE FW downgrade is aborted\n"); |
| 644 | return false; |
| 645 | } |
| 646 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 647 | return cse_hmrfpo_enable(); |
| 648 | } |
| 649 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 650 | static enum csme_failure_reason cse_trigger_fw_update(const struct cse_bp_info *cse_bp_info, |
| 651 | const struct cse_rw_metadata *source_metadata, |
| 652 | struct region_device *target_rdev) |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 653 | { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 654 | struct region_device source_rdev; |
| 655 | enum csme_failure_reason rv; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 656 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 657 | if (!cse_get_source_rdev(&source_rdev)) |
| 658 | return CSE_LITE_SKU_RW_BLOB_NOT_FOUND; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 659 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 660 | void *cse_cbfs_rw = rdev_mmap_full(&source_rdev); |
| 661 | |
| 662 | if (!cse_cbfs_rw) { |
| 663 | printk(BIOS_ERR, "cse_lite: CSE CBFS RW blob could not be mapped\n"); |
| 664 | return CSE_LITE_SKU_RW_BLOB_NOT_FOUND; |
| 665 | } |
| 666 | |
| 667 | if (!cse_verify_cbfs_rw_sha256(source_metadata->sha256, cse_cbfs_rw, |
| 668 | region_device_sz(&source_rdev))) { |
| 669 | rv = CSE_LITE_SKU_RW_BLOB_SHA256_MISMATCH; |
| 670 | goto error_exit; |
| 671 | } |
| 672 | |
| 673 | if (!cse_prep_for_rw_update(cse_bp_info, source_metadata)) { |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 674 | rv = CSE_COMMUNICATION_ERROR; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 675 | goto error_exit; |
| 676 | } |
| 677 | |
| 678 | rv = cse_update_rw(cse_bp_info, cse_cbfs_rw, region_device_sz(&source_rdev), |
| 679 | target_rdev); |
| 680 | |
| 681 | error_exit: |
| 682 | rdev_munmap(&source_rdev, cse_cbfs_rw); |
| 683 | return rv; |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 684 | } |
| 685 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 686 | 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] | 687 | { |
| 688 | struct region_device target_rdev; |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 689 | struct cse_rw_metadata source_metadata; |
| 690 | |
| 691 | /* Read CSE CBFS RW metadata */ |
V Sowmya | 1369516 | 2020-12-04 09:40:12 +0530 | [diff] [blame] | 692 | if (cbfs_load(CONFIG_SOC_INTEL_CSE_RW_METADATA_CBFS_NAME, &source_metadata, |
| 693 | sizeof(source_metadata)) != sizeof(source_metadata)) { |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 694 | printk(BIOS_ERR, "cse_lite: Failed to get CSE CBFS RW metadata\n"); |
| 695 | return CSE_LITE_SKU_RW_METADATA_NOT_FOUND; |
| 696 | } |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 697 | |
| 698 | if (!cse_get_target_rdev(cse_bp_info, &target_rdev)) { |
| 699 | printk(BIOS_ERR, "cse_lite: Failed to get CSE RW Partition\n"); |
| 700 | return CSE_LITE_SKU_RW_ACCESS_ERROR; |
| 701 | } |
| 702 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 703 | if (cse_is_update_required(cse_bp_info, &source_metadata, &target_rdev)) { |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 704 | printk(BIOS_DEBUG, "cse_lite: CSE RW update is initiated\n"); |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 705 | return cse_trigger_fw_update(cse_bp_info, &source_metadata, &target_rdev); |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 706 | } |
| 707 | |
Rizwan Qureshi | ec32109 | 2019-09-06 20:28:43 +0530 | [diff] [blame] | 708 | return 0; |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 709 | } |
| 710 | |
Sridhar Siricilla | 1a2b702 | 2020-12-04 02:22:28 +0530 | [diff] [blame] | 711 | void cse_fw_sync(void) |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 712 | { |
| 713 | static struct get_bp_info_rsp cse_bp_info; |
| 714 | |
| 715 | if (vboot_recovery_mode_enabled()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 716 | 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] | 717 | return; |
| 718 | } |
| 719 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 720 | /* If CSE SKU type is not Lite, skip enabling CSE Lite SKU */ |
| 721 | if (!cse_is_hfs3_fw_sku_lite()) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 722 | printk(BIOS_ERR, "cse_lite: Not a CSE Lite SKU\n"); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 723 | return; |
| 724 | } |
| 725 | |
| 726 | if (!cse_get_bp_info(&cse_bp_info)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 727 | printk(BIOS_ERR, "cse_lite: Failed to get CSE boot partition info\n"); |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame^] | 728 | cse_trigger_vboot_recovery(CSE_COMMUNICATION_ERROR); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 729 | } |
| 730 | |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 731 | if (!cse_fix_data_failure_err(&cse_bp_info.bp_info)) |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame^] | 732 | cse_trigger_vboot_recovery(CSE_LITE_SKU_DATA_WIPE_ERROR); |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 733 | |
Sridhar Siricilla | 361e364 | 2020-10-18 20:14:07 +0530 | [diff] [blame] | 734 | /* |
| 735 | * If SOC_INTEL_CSE_RW_UPDATE is defined , then trigger CSE firmware update. The driver |
| 736 | * triggers recovery if CSE CBFS RW metadata or CSE CBFS RW blob is not available. |
| 737 | */ |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 738 | if (CONFIG(SOC_INTEL_CSE_RW_UPDATE)) { |
| 739 | uint8_t rv; |
| 740 | rv = cse_fw_update(&cse_bp_info.bp_info); |
| 741 | if (rv) |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame^] | 742 | cse_trigger_vboot_recovery(rv); |
Sridhar Siricilla | 4c2890d | 2020-12-09 00:28:30 +0530 | [diff] [blame] | 743 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 744 | |
Sridahr Siricilla | 54b0356 | 2021-06-18 10:59:30 +0530 | [diff] [blame] | 745 | if (!cse_is_rw_bp_status_valid(&cse_bp_info.bp_info)) |
| 746 | cse_trigger_recovery(CSE_LITE_SKU_RW_JUMP_ERROR); |
| 747 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 748 | if (!cse_boot_to_rw(&cse_bp_info.bp_info)) { |
Sridhar Siricilla | 9f71b17 | 2020-06-01 14:50:52 +0530 | [diff] [blame] | 749 | printk(BIOS_ERR, "cse_lite: Failed to switch to RW\n"); |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame^] | 750 | cse_trigger_vboot_recovery(CSE_LITE_SKU_RW_SWITCH_ERROR); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 751 | } |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 752 | } |