mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
flash: Call lock function prior to mapped external read
Mapped read access to external flash may conflict with direct access through SPI commands, so call a chip-level function to lock access prior to doing such reads. BUG=chrome-os-partner:55781 BRANCH=Gru TEST=Verify 'ver' still works fine on kevin, and vboot hashing completes successfully. Change-Id: I009d6d5ee61c83260fb49ad4ee137fa3f4cd625a Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/385165 Tested-by: Mulin Chao <mlchao@nuvoton.com> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Mulin Chao <mlchao@nuvoton.com> (cherry picked from commit a7f3e3fa376731709f4823a0c1d464b4d1deae14) Reviewed-on: https://chromium-review.googlesource.com/386446 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
258bc48bac
commit
fd41823595
@@ -777,6 +777,13 @@ int flash_pre_init(void)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
void flash_lock_mapped_storage(int lock)
|
||||
{
|
||||
/*
|
||||
* TODO(crosbug.com/p/55781): Add mutex to ensure no conflict between
|
||||
* mapped read and regular flash ops.
|
||||
*/
|
||||
}
|
||||
/*****************************************************************************/
|
||||
/* Console commands */
|
||||
|
||||
|
||||
@@ -370,9 +370,14 @@ int flash_is_erased(uint32_t offset, int size)
|
||||
(const char **)&ptr) < 0)
|
||||
return 0;
|
||||
|
||||
flash_lock_mapped_storage(1);
|
||||
for (size /= sizeof(uint32_t); size > 0; size--, ptr++)
|
||||
if (*ptr != CONFIG_FLASH_ERASED_VALUE32)
|
||||
if (*ptr != CONFIG_FLASH_ERASED_VALUE32) {
|
||||
flash_lock_mapped_storage(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
flash_lock_mapped_storage(0);
|
||||
#else
|
||||
/* Read flash a chunk at a time */
|
||||
uint32_t buf[8];
|
||||
@@ -406,7 +411,9 @@ int flash_read(int offset, int size, char *data)
|
||||
if (flash_dataptr(offset, size, 1, &src) < 0)
|
||||
return EC_ERROR_INVAL;
|
||||
|
||||
flash_lock_mapped_storage(1);
|
||||
memcpy(data, src, size);
|
||||
flash_lock_mapped_storage(0);
|
||||
return EC_SUCCESS;
|
||||
#else
|
||||
return flash_physical_read(offset, size, data);
|
||||
|
||||
@@ -407,8 +407,10 @@ int system_get_image_used(enum system_image_copy_t copy)
|
||||
} while (*image != 0xea);
|
||||
#else
|
||||
image = (const uint8_t *)(image_offset + CONFIG_MAPPED_STORAGE_BASE);
|
||||
flash_lock_mapped_storage(1);
|
||||
for (size--; size > 0 && image[size] != 0xea; size--)
|
||||
;
|
||||
flash_lock_mapped_storage(0);
|
||||
#endif
|
||||
|
||||
return size ? size + 1 : 0; /* 0xea byte IS part of the image */
|
||||
@@ -613,12 +615,9 @@ int system_run_image_copy(enum system_image_copy_t copy)
|
||||
__attribute__((weak)) /* Weird chips may need their own implementations */
|
||||
const char *system_get_version(enum system_image_copy_t copy)
|
||||
{
|
||||
#ifndef CONFIG_MAPPED_STORAGE
|
||||
static struct version_struct vdata;
|
||||
#endif
|
||||
static struct version_struct v;
|
||||
|
||||
uintptr_t addr;
|
||||
const struct version_struct *v;
|
||||
enum system_image_copy_t active_copy = system_get_image_copy();
|
||||
|
||||
/* Handle version of current image */
|
||||
@@ -645,21 +644,20 @@ const char *system_get_version(enum system_image_copy_t copy)
|
||||
|
||||
#ifdef CONFIG_MAPPED_STORAGE
|
||||
addr += CONFIG_MAPPED_STORAGE_BASE;
|
||||
v = (const struct version_struct *)addr;
|
||||
flash_lock_mapped_storage(1);
|
||||
memcpy(&v, (const void *)addr, sizeof(v));
|
||||
flash_lock_mapped_storage(0);
|
||||
#else
|
||||
|
||||
/* Read the version struct from flash into a buffer. */
|
||||
if (flash_read(addr, sizeof(vdata), (char *)&vdata))
|
||||
if (flash_read(addr, sizeof(v), (char *)&v))
|
||||
return "";
|
||||
|
||||
v = &vdata;
|
||||
#endif
|
||||
|
||||
/* Make sure the version struct cookies match before returning the
|
||||
* version string. */
|
||||
if (v->cookie1 == version_data.cookie1 &&
|
||||
v->cookie2 == version_data.cookie2)
|
||||
return v->version;
|
||||
if (v.cookie1 == version_data.cookie1 &&
|
||||
v.cookie2 == version_data.cookie2)
|
||||
return v.version;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -117,8 +117,10 @@ static void vboot_hash_next_chunk(void)
|
||||
size = MIN(CHUNK_SIZE, data_size - curr_pos);
|
||||
|
||||
#ifdef CONFIG_MAPPED_STORAGE
|
||||
flash_lock_mapped_storage(1);
|
||||
SHA256_update(&ctx, (const uint8_t *)(CONFIG_MAPPED_STORAGE_BASE +
|
||||
data_offset + curr_pos), size);
|
||||
flash_lock_mapped_storage(0);
|
||||
#else
|
||||
if (read_and_hash_chunk(data_offset + curr_pos, size) != EC_SUCCESS)
|
||||
return;
|
||||
|
||||
@@ -261,4 +261,14 @@ const char *flash_read_serial(void);
|
||||
*/
|
||||
int flash_write_serial(const char *serialno);
|
||||
|
||||
/**
|
||||
* Lock or unlock HW necessary for mapped storage read.
|
||||
*
|
||||
* @param lock 1 to lock, 0 to unlock.
|
||||
*/
|
||||
#ifdef CONFIG_EXTERNAL_STORAGE
|
||||
void flash_lock_mapped_storage(int lock);
|
||||
#else
|
||||
static inline void flash_lock_mapped_storage(int lock) { };
|
||||
#endif /* CONFIG_EXTERNAL_STORAGE */
|
||||
#endif /* __CROS_EC_FLASH_H */
|
||||
|
||||
Reference in New Issue
Block a user