vboot_hash: Abort hash calculation on flash write

If flash is being written, any pending hash calculation is likely to
be invalid.

BRANCH=None
BUG=chrome-os-partner:38103
TEST=on Cyan, run hundreds of flashrom cycles to make sure there are no
read, erase or write errors

Change-Id: I915f8db7998c56fc12e7d85173232882fb7ed80d
Signed-off-by: Divya Jyothi <divya.jyothi@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/282211
Reviewed-by: Shawn N <shawnn@chromium.org>
Commit-Queue: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
This commit is contained in:
Divya Jyothi
2015-06-25 20:19:37 -07:00
committed by ChromeOS Commit Bot
parent d2dabdae5d
commit b4c205bf51
3 changed files with 36 additions and 3 deletions

View File

@@ -313,7 +313,15 @@ int flash_write(int offset, int size, const char *data)
return EC_ERROR_INVAL; /* Invalid range */
#ifdef CONFIG_VBOOT_HASH
vboot_hash_invalidate(offset, size);
/*
* Abort hash calculations when flashrom flash updates
* are in progress.Otherwise invalidate the pre-computed hash,
* since it's likely to change after flash write
*/
if (vboot_hash_in_progress())
vboot_hash_abort();
else
vboot_hash_invalidate(offset, size);
#endif
return flash_physical_write(offset, size, data);
@@ -325,7 +333,15 @@ int flash_erase(int offset, int size)
return EC_ERROR_INVAL; /* Invalid range */
#ifdef CONFIG_VBOOT_HASH
vboot_hash_invalidate(offset, size);
/*
* Abort hash calculations when flashrom flash updates
* are in progress.Otherwise invalidate the pre-computed hash,
* since it's likely to be wrong after erase.
*/
if (vboot_hash_in_progress())
vboot_hash_abort();
else
vboot_hash_invalidate(offset, size);
#endif
return flash_physical_erase(offset, size);

View File

@@ -43,10 +43,15 @@ static int in_progress;
static struct sha256_ctx ctx;
int vboot_hash_in_progress(void)
{
return in_progress;
}
/**
* Abort hash currently in progress, and invalidate any completed hash.
*/
static void vboot_hash_abort(void)
void vboot_hash_abort(void)
{
if (in_progress) {
want_abort = 1;

View File

@@ -20,4 +20,16 @@
*/
int vboot_hash_invalidate(int offset, int size);
/**
* Get vboot progress status.
*
* @return 1 if vboot hashing is in progress, 0 otherwise.
*/
int vboot_hash_in_progress(void);
/**
* Abort hash currently in progress, and invalidate any completed hash.
*/
void vboot_hash_abort(void);
#endif /* __CROS_EC_VBOOT_HASH_H */