mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-26 14:42:36 +02:00
flashrom.c: Make 'chip_to_probe' a param to probe_flash()
Apart from the very bespoke case of 'probe_w29ee011()' the override 'chip_to_probe' name is a nature parameter to 'probe_flash()'. However we can deal with w29ee011 by providing a probe specific validation function to check if the chip can indeed be overriden. TEST=`./flashrom -p internal --flash-name`. Change-Id: Ifcdace07ea2135d83dea92cfa5c6bec8d7ddf05d Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/67091 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <felixsinger@posteo.net> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
parent
39b1890773
commit
af76e44752
@ -646,6 +646,7 @@ int main(int argc, char *argv[])
|
||||
char *pparam = NULL;
|
||||
struct layout_include_args *include_args = NULL;
|
||||
char *wp_region = NULL;
|
||||
const char *chip_to_probe = NULL;
|
||||
|
||||
/*
|
||||
* Safety-guard against a user who has (mistakenly) closed
|
||||
@ -977,7 +978,7 @@ int main(int argc, char *argv[])
|
||||
for (j = 0; j < registered_master_count; j++) {
|
||||
startchip = 0;
|
||||
while (chipcount < (int)ARRAY_SIZE(flashes)) {
|
||||
startchip = probe_flash(®istered_masters[j], startchip, &flashes[chipcount], 0);
|
||||
startchip = probe_flash(®istered_masters[j], startchip, &flashes[chipcount], 0, chip_to_probe);
|
||||
if (startchip == -1)
|
||||
break;
|
||||
chipcount++;
|
||||
@ -1020,7 +1021,7 @@ int main(int argc, char *argv[])
|
||||
"chip, using the first one.\n");
|
||||
for (j = 0; j < registered_master_count; j++) {
|
||||
mst = ®istered_masters[j];
|
||||
startchip = probe_flash(mst, 0, &flashes[0], 1);
|
||||
startchip = probe_flash(mst, 0, &flashes[0], 1, chip_to_probe);
|
||||
if (startchip != -1)
|
||||
break;
|
||||
}
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "chipdrivers.h"
|
||||
|
||||
const char flashrom_version[] = FLASHROM_VERSION;
|
||||
const char *chip_to_probe = NULL;
|
||||
|
||||
static const struct programmer_entry *programmer = NULL;
|
||||
|
||||
@ -824,7 +823,7 @@ static probe_func_t *lookup_probe_func_ptr(const struct flashchip *chip)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force)
|
||||
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force, const char *const chip_to_probe)
|
||||
{
|
||||
const struct flashchip *chip;
|
||||
enum chipbustype buses_common;
|
||||
@ -864,6 +863,10 @@ int probe_flash(struct registered_master *mst, int startchip, struct flashctx *f
|
||||
if (force)
|
||||
break;
|
||||
|
||||
if (probe_func == &probe_w29ee011)
|
||||
if (!w29ee011_can_override(flash->chip->name, chip_to_probe))
|
||||
goto notfound;
|
||||
|
||||
if (probe_func(flash) != 1)
|
||||
goto notfound;
|
||||
|
||||
|
@ -195,6 +195,7 @@ int printlock_at49f(struct flashctx *flash);
|
||||
|
||||
/* w29ee011.c */
|
||||
int probe_w29ee011(struct flashctx *flash);
|
||||
bool w29ee011_can_override(const char *const chip_name, const char *const override_chip);
|
||||
|
||||
/* stm50.c */
|
||||
int erase_sector_stm50(struct flashctx *flash, unsigned int block, unsigned int blocksize);
|
||||
|
@ -475,13 +475,12 @@ size_t strnlen(const char *str, size_t n);
|
||||
|
||||
/* flashrom.c */
|
||||
extern const char flashrom_version[];
|
||||
extern const char *chip_to_probe;
|
||||
char *flashbuses_to_text(enum chipbustype bustype);
|
||||
int map_flash(struct flashctx *flash);
|
||||
void unmap_flash(struct flashctx *flash);
|
||||
int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
|
||||
int erase_flash(struct flashctx *flash);
|
||||
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *fill_flash, int force);
|
||||
int probe_flash(struct registered_master *mst, int startchip, struct flashctx *flash, int force, const char *const chip_to_probe);
|
||||
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len);
|
||||
void emergency_help_message(void);
|
||||
void print_version(void);
|
||||
|
@ -221,8 +221,6 @@ int flashrom_flash_probe(struct flashrom_flashctx **const flashctx,
|
||||
int i, ret = 2;
|
||||
struct flashrom_flashctx second_flashctx = { 0, };
|
||||
|
||||
chip_to_probe = chip_name; /* chip_to_probe is global in flashrom.c */
|
||||
|
||||
*flashctx = malloc(sizeof(**flashctx));
|
||||
if (!*flashctx)
|
||||
return 1;
|
||||
@ -230,10 +228,10 @@ int flashrom_flash_probe(struct flashrom_flashctx **const flashctx,
|
||||
|
||||
for (i = 0; i < registered_master_count; ++i) {
|
||||
int flash_idx = -1;
|
||||
if (!ret || (flash_idx = probe_flash(®istered_masters[i], 0, *flashctx, 0)) != -1) {
|
||||
if (!ret || (flash_idx = probe_flash(®istered_masters[i], 0, *flashctx, 0, chip_name)) != -1) {
|
||||
ret = 0;
|
||||
/* We found one chip, now check that there is no second match. */
|
||||
if (probe_flash(®istered_masters[i], flash_idx + 1, &second_flashctx, 0) != -1) {
|
||||
if (probe_flash(®istered_masters[i], flash_idx + 1, &second_flashctx, 0, chip_name) != -1) {
|
||||
flashrom_layout_release(second_flashctx.default_layout);
|
||||
free(second_flashctx.chip);
|
||||
ret = 3;
|
||||
|
23
w29ee011.c
23
w29ee011.c
@ -15,9 +15,24 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "flash.h"
|
||||
#include "chipdrivers.h"
|
||||
|
||||
bool w29ee011_can_override(const char *const chip_name, const char *const override_chip)
|
||||
{
|
||||
if (!override_chip || strcmp(override_chip, chip_name)) {
|
||||
msg_cdbg("Old Winbond W29* probe method disabled because "
|
||||
"the probing sequence puts the AMIC A49LF040A in "
|
||||
"a funky state. Use 'flashrom -c %s' if you "
|
||||
"have a board with such a chip.\n", chip_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* According to the Winbond W29EE011, W29EE012, W29C010M, W29C011A
|
||||
* datasheets this is the only valid probe function for those chips.
|
||||
*/
|
||||
@ -26,14 +41,6 @@ int probe_w29ee011(struct flashctx *flash)
|
||||
chipaddr bios = flash->virtual_memory;
|
||||
uint8_t id1, id2;
|
||||
|
||||
if (!chip_to_probe || strcmp(chip_to_probe, flash->chip->name)) {
|
||||
msg_cdbg("Old Winbond W29* probe method disabled because "
|
||||
"the probing sequence puts the AMIC A49LF040A in "
|
||||
"a funky state. Use 'flashrom -c %s' if you "
|
||||
"have a board with such a chip.\n", flash->chip->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Issue JEDEC Product ID Entry command */
|
||||
chip_writeb(flash, 0xAA, bios + 0x5555);
|
||||
programmer_delay(flash, 10);
|
||||
|
Loading…
x
Reference in New Issue
Block a user