Edward O'Callaghan has uploaded this change for review.

View Change

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>
---
M dummyflasher.c
1 file changed, 49 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/61/45461/1
diff --git a/dummyflasher.c b/dummyflasher.c
index 89e8ba4..8af982d 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -54,6 +54,9 @@
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 @@
return 1;
}
data->emu_chip = EMULATE_NONE;
+ data->delay_us = 0;
spi_master_dummyflasher.data = data;

msg_pspew("%s\n", __func__);
@@ -289,6 +293,49 @@
}
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));
+ goto dummy_init_out;
+ }
+
+ 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);
+ return 1;
+ }
+ }
+
+ /* Assume we only work with bytes and transfer at 1 bit/Hz */
+ data->delay_us = (1000000 * 8) / freq;
+ }
+
#if EMULATE_CHIP
#if EMULATE_SPI_CHIP
tmp = extract_programmer_param("size");
@@ -963,6 +1010,8 @@
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;
}


To view, visit change 45461. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I1c2702b9e0cae860f5f03114e307707d4d3219af
Gerrit-Change-Number: 45461
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange