summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2023-01-16 15:36:07 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-01-16 11:18:49 +0000
commite36a0bf504f7e091e964a66d20d30b27e01fae57 (patch)
treef560046b944912f39f1ad1ec6b116fb32826230e /common
parent2821042a63da8310dcad5a2cdf2082fa56a4b25c (diff)
downloadchrome-ec-e36a0bf504f7e091e964a66d20d30b27e01fae57.tar.gz
flash: allow zero num_banks_desc in flash_info request
Some external tools (e.g. flashrom) sends EC_CMD_FLASH_INFO with num_banks_desc=0 to get the total number of banks. EC should allow this type of request. Also add a test to cover this use case. BUG=b:265472751 TEST=1) `flashrom -p ec -w <ec.bin>` on tentacruel 2) ./twister -T zephyr/test/drivers/ \ --sub-test drivers.flash.page_layout 3) ./twister -T zephyr/test/drivers/ --sub-test drivers.flash BRANCH=none Change-Id: Iab97ac754bac87067f949cf9435156be91b07ebc Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4167539 Tested-by: Chen-Tsung Hsieh <chentsung@chromium.org> Reviewed-by: Patryk Duda <patrykd@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Patryk Duda <patrykd@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/flash.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/common/flash.c b/common/flash.c
index f2469cca32..c68f47a368 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -227,12 +227,11 @@ int crec_flash_response_fill_banks(struct ec_response_flash_info_2 *r,
const struct ec_flash_bank *banks = flash_bank_array;
int banks_to_copy = MIN(ARRAY_SIZE(flash_bank_array), num_banks);
- if (num_banks < 1)
- return EC_RES_INVALID_PARAM;
-
- memcpy(r->banks, banks, banks_to_copy * sizeof(struct ec_flash_bank));
r->num_banks_desc = banks_to_copy;
r->num_banks_total = ARRAY_SIZE(flash_bank_array);
+ if (banks_to_copy > 0)
+ memcpy(r->banks, banks,
+ banks_to_copy * sizeof(struct ec_flash_bank));
return EC_RES_SUCCESS;
}
@@ -243,16 +242,19 @@ int crec_flash_response_fill_banks(struct ec_response_flash_info_2 *r,
int crec_flash_response_fill_banks(struct ec_response_flash_info_2 *r,
int num_banks)
{
- if (num_banks < 1)
- return EC_RES_INVALID_PARAM;
-
- r->banks[0].count = crec_flash_total_banks();
- r->banks[0].size_exp = __fls(CONFIG_FLASH_BANK_SIZE);
- r->banks[0].write_size_exp = __fls(CONFIG_FLASH_WRITE_SIZE);
- r->banks[0].erase_size_exp = __fls(CONFIG_FLASH_ERASE_SIZE);
- r->banks[0].protect_size_exp = __fls(CONFIG_FLASH_BANK_SIZE);
+ if (num_banks >= 1) {
+ r->banks[0].count = crec_flash_total_banks();
+ r->banks[0].size_exp = __fls(CONFIG_FLASH_BANK_SIZE);
+ r->banks[0].write_size_exp = __fls(CONFIG_FLASH_WRITE_SIZE);
+ r->banks[0].erase_size_exp = __fls(CONFIG_FLASH_ERASE_SIZE);
+ r->banks[0].protect_size_exp = __fls(CONFIG_FLASH_BANK_SIZE);
+
+ r->num_banks_desc = 1;
+ } else {
+ /* num_banks == 0, don't fill the banks array */
+ r->num_banks_desc = 0;
+ }
- r->num_banks_desc = 1;
r->num_banks_total = 1;
return EC_RES_SUCCESS;