* Asks the EC to calculate a hash of the specified firmware image, and * returns the information in **hash and *hash_size. */
| 105 | * returns the information in **hash and *hash_size. |
| 106 | */ |
| 107 | static vb2_error_t ec_hash_image(enum vb2_firmware_selection select, |
| 108 | const uint8_t **hash, int *hash_size) |
| 109 | { |
| 110 | static struct ec_response_vboot_hash resp; |
| 111 | uint32_t hash_offset; |
| 112 | int recalc_requested = 0; |
| 113 | struct stopwatch sw; |
| 114 | |
| 115 | hash_offset = get_vboot_hash_offset(select); |
| 116 | |
| 117 | stopwatch_init_msecs_expire(&sw, CROS_EC_HASH_TIMEOUT_MS); |
| 118 | do { |
| 119 | if (google_chromeec_get_vboot_hash(hash_offset, &resp)) |
| 120 | return VB2_ERROR_UNKNOWN; |
| 121 | |
| 122 | switch (resp.status) { |
| 123 | case EC_VBOOT_HASH_STATUS_NONE: |
| 124 | /* |
| 125 | * There is no hash available right now. |
| 126 | * Request a recalc if it hasn't been done yet. |
| 127 | */ |
| 128 | if (recalc_requested) |
| 129 | break; |
| 130 | |
| 131 | printk(BIOS_WARNING, |
| 132 | "%s: No valid hash (status=%d size=%d). " |
| 133 | "Computing...\n", __func__, resp.status, |
| 134 | resp.size); |
| 135 | |
| 136 | if (google_chromeec_start_vboot_hash( |
| 137 | EC_VBOOT_HASH_TYPE_SHA256, hash_offset, &resp)) |
| 138 | return VB2_ERROR_UNKNOWN; |
| 139 | |
| 140 | recalc_requested = 1; |
| 141 | |
| 142 | /* |
| 143 | * Expect status to be busy since we just sent |
| 144 | * a recalc request. |
| 145 | */ |
| 146 | resp.status = EC_VBOOT_HASH_STATUS_BUSY; |
| 147 | |
| 148 | /* Hash just started calculating, let it go for a bit */ |
| 149 | mdelay(CROS_EC_HASH_CHECK_DELAY_MS); |
| 150 | break; |
| 151 | |
| 152 | case EC_VBOOT_HASH_STATUS_BUSY: |
| 153 | /* Hash is still calculating. */ |
| 154 | mdelay(CROS_EC_HASH_CHECK_DELAY_MS); |
| 155 | break; |
| 156 | |
| 157 | case EC_VBOOT_HASH_STATUS_DONE: /* intentional fallthrough */ |
| 158 | default: |
| 159 | /* Hash is ready! */ |
| 160 | break; |
| 161 | } |
| 162 | } while (resp.status == EC_VBOOT_HASH_STATUS_BUSY && |
| 163 | !stopwatch_expired(&sw)); |
| 164 |
no test coverage detected