mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-28 15:33:42 +02:00
dummyflasher.c: Upstream ChromiumOS 'freq' param feature
This allows the dummyflasher to emulate a bus/chip frequency by passing a delay parameter. BUG=b:140394053 BRANCH=none TEST=builds and ran with freq passed, ``` └──╼ dd if=/dev/urandom of=/tmp/bar bs=2K count=1 1+0 records in 1+0 records out 2048 bytes (2.0 kB, 2.0 KiB) copied, 0.000583308 s, 3.5 MB/s └──╼ ./flashrom -p dummy:image=/tmp/foo,bus=spi,freq=100Hz,size=2048,emulate=VARIABLE_SIZE -w /tmp/bar flashrom v1.2-105-g702c58a-dirty on Linux 5.7.10-1rodete2-amd64 (x86_64) flashrom is free software, get the source code at https://flashrom.org Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns). Found Generic flash chip "Variable Size SPI chip" (2 kB, SPI) on dummy. Reading old flash chip contents... done. Erasing and writing flash chip... Erase/write done. Verifying flash... VERIFIED. ``` Change-Id: I1c2702b9e0cae860f5f03114e307707d4d3219af Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/45461 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Sam McNally <sammc@google.com>
This commit is contained in:
parent
702c58a321
commit
cb9f3cd0a7
@ -54,6 +54,9 @@ struct emu_data {
|
||||
unsigned int emu_chip_size;
|
||||
int emu_modified; /* is the image modified since reading it? */
|
||||
uint8_t emu_status;
|
||||
/* If "freq" parameter is passed in from command line, commands will delay
|
||||
* for this period before returning. */
|
||||
unsigned long int delay_us;
|
||||
unsigned int emu_max_byteprogram_size;
|
||||
unsigned int emu_max_aai_size;
|
||||
unsigned int emu_jedec_se_size;
|
||||
@ -175,6 +178,7 @@ int dummy_init(void)
|
||||
return 1;
|
||||
}
|
||||
data->emu_chip = EMULATE_NONE;
|
||||
data->delay_us = 0;
|
||||
spi_master_dummyflasher.data = data;
|
||||
|
||||
msg_pspew("%s\n", __func__);
|
||||
@ -289,6 +293,52 @@ int dummy_init(void)
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
/* frequency to emulate in Hz (default), KHz, or MHz */
|
||||
tmp = extract_programmer_param("freq");
|
||||
if (tmp) {
|
||||
unsigned long int freq;
|
||||
char *units = tmp;
|
||||
char *end = tmp + strlen(tmp);
|
||||
|
||||
errno = 0;
|
||||
freq = strtoul(tmp, &units, 0);
|
||||
if (errno) {
|
||||
msg_perr("Invalid frequency \"%s\", %s\n",
|
||||
tmp, strerror(errno));
|
||||
free(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((units > tmp) && (units < end)) {
|
||||
int units_valid = 0;
|
||||
|
||||
if (units < end - 3) {
|
||||
;
|
||||
} else if (units == end - 2) {
|
||||
if (!strcasecmp(units, "hz"))
|
||||
units_valid = 1;
|
||||
} else if (units == end - 3) {
|
||||
if (!strcasecmp(units, "khz")) {
|
||||
freq *= 1000;
|
||||
units_valid = 1;
|
||||
} else if (!strcasecmp(units, "mhz")) {
|
||||
freq *= 1000000;
|
||||
units_valid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!units_valid) {
|
||||
msg_perr("Invalid units: %s\n", units);
|
||||
free(tmp);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Assume we only work with bytes and transfer at 1 bit/Hz */
|
||||
data->delay_us = (1000000 * 8) / freq;
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
#if EMULATE_CHIP
|
||||
#if EMULATE_SPI_CHIP
|
||||
tmp = extract_programmer_param("size");
|
||||
@ -963,6 +1013,8 @@ static int dummy_spi_send_command(const struct flashctx *flash, unsigned int wri
|
||||
for (i = 0; i < readcnt; i++)
|
||||
msg_pspew(" 0x%02x", readarr[i]);
|
||||
msg_pspew("\n");
|
||||
|
||||
programmer_delay((writecnt + readcnt) * emu_data->delay_us);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user