Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved Namyoon Woo: Looks good to me, but someone else must approve Edward O'Callaghan: Looks good to me, approved
dummyflasher.c: Drop useless macros

The `EMULATE_CHIP` and `EMULATE_SPI_CHIP` macros are unconditionally
defined as `1`, with no way to change their values. Since this means
that the code never gets build-tested using other values, drop these
noisy macros.

TEST=Build with `make distclean && make VERSION=none -j` with and
without this patch, the flashrom executable does not change.

Change-Id: If46e1c37c3b04b28b4ba1f82c9b3def1e549368f
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55265
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Namyoon Woo <namyoon@google.com>
---
M dummyflasher.c
1 file changed, 1 insertion(+), 37 deletions(-)

diff --git a/dummyflasher.c b/dummyflasher.c
index e2f38f5..ba06e7c 100644
--- a/dummyflasher.c
+++ b/dummyflasher.c
@@ -22,21 +22,11 @@
#include "chipdrivers.h"
#include "programmer.h"
#include "flashchips.h"
-
-/* Remove the #define below if you don't want SPI flash chip emulation. */
-#define EMULATE_SPI_CHIP 1
-
-#if EMULATE_SPI_CHIP
-#define EMULATE_CHIP 1
#include "spi.h"
-#endif

-#if EMULATE_CHIP
#include <sys/types.h>
#include <sys/stat.h>
-#endif

-#if EMULATE_CHIP
enum emu_chip {
EMULATE_NONE,
EMULATE_ST_M25P10_RES,
@@ -73,7 +63,6 @@
uint8_t *flashchip_contents;
};

-#if EMULATE_SPI_CHIP
/* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */
static const uint8_t sfdp_table[] = {
0x53, 0x46, 0x44, 0x50, // @0x00: SFDP signature
@@ -100,9 +89,6 @@
0xFF, 0xFF, 0xFF, 0xFF, // @0x54: Macronix parameter table end
};

-#endif
-#endif
-
void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
{
msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
@@ -173,7 +159,6 @@
return;
}

-#if EMULATE_SPI_CHIP
static int emulate_spi_chip_response(unsigned int writecnt,
unsigned int readcnt,
const unsigned char *writearr,
@@ -550,7 +535,6 @@
data->emu_status &= ~SPI_SR_WEL;
return 0;
}
-#endif

static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt,
@@ -572,7 +556,6 @@

/* Response for unknown commands and missing chip is 0xff. */
memset(readarr, 0xff, readcnt);
-#if EMULATE_SPI_CHIP
switch (emu_data->emu_chip) {
case EMULATE_ST_M25P10_RES:
case EMULATE_SST_SST25VF040_REMS:
@@ -589,7 +572,6 @@
default:
break;
}
-#endif
msg_pspew(" reading %u bytes:", readcnt);
for (i = 0; i < readcnt; i++)
msg_pspew(" 0x%02x", readarr[i]);
@@ -626,7 +608,6 @@
static int dummy_shutdown(void *data)
{
msg_pspew("%s\n", __func__);
-#if EMULATE_CHIP
struct emu_data *emu_data = (struct emu_data *)data;
if (emu_data->emu_chip != EMULATE_NONE) {
if (emu_data->emu_persistent_image && emu_data->emu_modified) {
@@ -638,7 +619,6 @@
free(emu_data->emu_persistent_image);
free(emu_data->flashchip_contents);
}
-#endif
free(data);
return 0;
}
@@ -650,10 +630,8 @@
char *tmp = NULL;
unsigned int i;
char *endptr;
-#if EMULATE_SPI_CHIP
char *status = NULL;
int size = -1; /* size for VARIABLE_SIZE chip device */
-#endif

bustext = extract_programmer_param("bus");
msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
@@ -812,8 +790,6 @@
}
free(tmp);

-#if EMULATE_CHIP
-#if EMULATE_SPI_CHIP
tmp = extract_programmer_param("size");
if (tmp) {
size = strtol(tmp, NULL, 10);
@@ -825,7 +801,6 @@
}
free(tmp);
}
-#endif /* EMULATE_SPI_CHIP */

tmp = extract_programmer_param("emulate");
if (!tmp) {
@@ -834,7 +809,6 @@
return 0;
}

-#if EMULATE_SPI_CHIP
if (!strcmp(tmp, "M25P10.RES")) {
data->emu_chip = EMULATE_ST_M25P10_RES;
data->emu_chip_size = 128 * 1024;
@@ -921,7 +895,7 @@
msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
data->emu_chip_size);
}
-#endif /* EMULATE_SPI_CHIP */
+
if (data->emu_chip == EMULATE_NONE) {
msg_perr("Invalid chip specified for emulation: %s\n", tmp);
free(tmp);
@@ -945,7 +919,6 @@
}
free(tmp);

-#ifdef EMULATE_SPI_CHIP
status = extract_programmer_param("spi_status");
if (status) {
errno = 0;
@@ -960,7 +933,6 @@
msg_pdbg("Initial status register is set to 0x%02x.\n",
data->emu_status);
}
-#endif /* EMULATE_SPI_CHIP */

data->flashchip_contents = malloc(data->emu_chip_size);
if (!data->flashchip_contents) {
@@ -968,16 +940,12 @@
return 1;
}

-#endif /* EMULATE_CHIP */
-
return 0;
}

int dummy_init(void)
{
-#if EMULATE_CHIP
struct stat image_stat;
-#endif

struct emu_data *data = calloc(1, sizeof(struct emu_data));
if (!data) {
@@ -996,7 +964,6 @@
return 1;
}

-#if EMULATE_CHIP
if (data->emu_chip == EMULATE_NONE) {
msg_pdbg("Not emulating any flash chip.\n");
/* Nothing else to do. */
@@ -1033,7 +1000,6 @@
msg_pdbg("doesn't match.\n");
}
}
-#endif /* EMULATE_CHIP */

dummy_init_out:
if (register_shutdown(dummy_shutdown, data)) {
@@ -1052,7 +1018,6 @@
return 0;
}

-#if EMULATE_CHIP && EMULATE_SPI_CHIP
int probe_variable_size(struct flashctx *flash)
{
unsigned int i;
@@ -1095,4 +1060,3 @@

return 1;
}
-#endif

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If46e1c37c3b04b28b4ba1f82c9b3def1e549368f
Gerrit-Change-Number: 55265
Gerrit-PatchSet: 3
Gerrit-Owner: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Namyoon Woo <namyoon@google.com>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged