1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-03 23:13:18 +02:00

probe_flash: Introduce an error code for "other" probing errors

Previously probe_flash had the same return code for the case when
no chips were matched, and when some other error happened during
probing. However these are two different scenarios and it is useful
for the caller to distinguish between them.

In fact, the caller (libflashrom it is) wanted to distinguish
between "no chips found" and "some other probing error" from the
very beginning. libflashrom probe API documented returning special
error code for "other error".
However it was not possible to know when "other error" happened
because probe_flash never returned that back, it could only say
"no matched chips found".

This patch introduces -2 as "other error" code from probe_flash,
while -1 remains as "no chips found".
Both libflashrom probe APIs v1 and v2 are now handling "other error"
from probe_flash and return it to the API callers as was promised in
the documentation.

This also adds a unit test for error code propagation for "no chips
found" error.

Change-Id: I4a271550bea2b36c657c71ce6cb1927082663c3c
Signed-off-by: Anastasia Klimchuk <aklm@flashrom.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/88008
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
This commit is contained in:
Anastasia Klimchuk
2025-06-09 23:06:44 +10:00
parent b41fc17099
commit e5f377c662
8 changed files with 98 additions and 22 deletions

View File

@ -1104,6 +1104,15 @@ static probe_func_t *lookup_probe_func_ptr(const struct flashchip *chip)
return NULL;
}
/*
* Probes the entries in flashchips array one by one, starting from `startchip` index.
* Probing keeps going until first match found or end of array reached.
*
* Returns:
* the position of the matched chip, i.e. index of the entry in flashchips array
* ERROR_FLASHROM_PROBE_NO_CHIPS_FOUND if no matches found
* ERROR_FLASHROM_PROBE_INTERNAL_ERROR if some unexpected error happened during this operation
*/
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force, const char *const chip_to_probe)
{
const struct flashchip *chip;
@ -1130,7 +1139,7 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
flash->chip = calloc(1, sizeof(*flash->chip));
if (!flash->chip) {
msg_gerr("Out of memory!\n");
return -1;
return ERROR_FLASHROM_PROBE_INTERNAL_ERROR;
}
*flash->chip = *chip;
flash->mst = mst;
@ -1188,10 +1197,10 @@ notfound:
}
if (!flash->chip)
return -1;
return ERROR_FLASHROM_PROBE_NO_CHIPS_FOUND;
if (init_default_layout(flash) < 0)
return -1;
return ERROR_FLASHROM_PROBE_INTERNAL_ERROR;
tmp = flashbuses_to_text(flash->chip->bustype);
msg_cinfo("%s %s flash chip \"%s\" (%d kB, %s) ", force ? "Assuming" : "Found",