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