* The logic for updating an EC firmware image. */
| 320 | * The logic for updating an EC firmware image. |
| 321 | */ |
| 322 | static vb2_error_t ec_update_image(enum vb2_firmware_selection select) |
| 323 | { |
| 324 | uint32_t region_offset, region_size; |
| 325 | enum ec_flash_region region; |
| 326 | vb2_error_t rv; |
| 327 | void *image; |
| 328 | size_t image_size; |
| 329 | |
| 330 | /* Un-protect the flash region */ |
| 331 | rv = ec_protect_flash(0); |
| 332 | if (rv != VB2_SUCCESS) |
| 333 | return rv; |
| 334 | |
| 335 | /* Convert vboot region into an EC region */ |
| 336 | region = vboot_to_ec_region(select); |
| 337 | |
| 338 | /* Get information about the flash region */ |
| 339 | if (google_chromeec_flash_region_info(region, ®ion_offset, |
| 340 | ®ion_size)) |
| 341 | return VB2_ERROR_UNKNOWN; |
| 342 | |
| 343 | /* Map the CBFS file */ |
| 344 | image = cbfs_map(EC_IMAGE_FILENAME(select), &image_size); |
| 345 | if (!image) |
| 346 | return VB2_ERROR_UNKNOWN; |
| 347 | |
| 348 | rv = VB2_ERROR_UNKNOWN; |
| 349 | |
| 350 | /* Bail if the image is too large */ |
| 351 | if (image_size > region_size) |
| 352 | goto unmap; |
| 353 | |
| 354 | /* Erase the region */ |
| 355 | if (google_chromeec_flash_erase(region_offset, region_size)) |
| 356 | goto unmap; |
| 357 | |
| 358 | /* Write the image into the region */ |
| 359 | if (ec_flash_write(image, region_offset, image_size)) |
| 360 | goto unmap; |
| 361 | |
| 362 | /* Verify the image */ |
| 363 | if (google_chromeec_efs_verify(region)) |
| 364 | goto unmap; |
| 365 | |
| 366 | rv = VB2_SUCCESS; |
| 367 | |
| 368 | unmap: |
| 369 | cbfs_unmap(image); |
| 370 | return rv; |
| 371 | } |
| 372 | |
| 373 | static vb2_error_t ec_get_expected_hash(enum vb2_firmware_selection select, |
| 374 | const uint8_t **hash, |
no test coverage detected