1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

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>
This commit is contained in:
Angel Pons 2021-06-07 12:08:27 +02:00 committed by Nico Huber
parent cedf7bd385
commit 14c916d380

View File

@ -22,21 +22,11 @@
#include "chipdrivers.h" #include "chipdrivers.h"
#include "programmer.h" #include "programmer.h"
#include "flashchips.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" #include "spi.h"
#endif
#if EMULATE_CHIP
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#endif
#if EMULATE_CHIP
enum emu_chip { enum emu_chip {
EMULATE_NONE, EMULATE_NONE,
EMULATE_ST_M25P10_RES, EMULATE_ST_M25P10_RES,
@ -73,7 +63,6 @@ struct emu_data {
uint8_t *flashchip_contents; uint8_t *flashchip_contents;
}; };
#if EMULATE_SPI_CHIP
/* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */ /* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */
static const uint8_t sfdp_table[] = { static const uint8_t sfdp_table[] = {
0x53, 0x46, 0x44, 0x50, // @0x00: SFDP signature 0x53, 0x46, 0x44, 0x50, // @0x00: SFDP signature
@ -100,9 +89,6 @@ static const uint8_t sfdp_table[] = {
0xFF, 0xFF, 0xFF, 0xFF, // @0x54: Macronix parameter table end 0xFF, 0xFF, 0xFF, 0xFF, // @0x54: Macronix parameter table end
}; };
#endif
#endif
void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len) 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", msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
@ -173,7 +159,6 @@ static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const c
return; return;
} }
#if EMULATE_SPI_CHIP
static int emulate_spi_chip_response(unsigned int writecnt, static int emulate_spi_chip_response(unsigned int writecnt,
unsigned int readcnt, unsigned int readcnt,
const unsigned char *writearr, const unsigned char *writearr,
@ -550,7 +535,6 @@ static int emulate_spi_chip_response(unsigned int writecnt,
data->emu_status &= ~SPI_SR_WEL; data->emu_status &= ~SPI_SR_WEL;
return 0; return 0;
} }
#endif
static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
unsigned int readcnt, unsigned int readcnt,
@ -572,7 +556,6 @@ static int dummy_spi_send_command(const struct flashctx *flash, unsigned int wri
/* Response for unknown commands and missing chip is 0xff. */ /* Response for unknown commands and missing chip is 0xff. */
memset(readarr, 0xff, readcnt); memset(readarr, 0xff, readcnt);
#if EMULATE_SPI_CHIP
switch (emu_data->emu_chip) { switch (emu_data->emu_chip) {
case EMULATE_ST_M25P10_RES: case EMULATE_ST_M25P10_RES:
case EMULATE_SST_SST25VF040_REMS: case EMULATE_SST_SST25VF040_REMS:
@ -589,7 +572,6 @@ static int dummy_spi_send_command(const struct flashctx *flash, unsigned int wri
default: default:
break; break;
} }
#endif
msg_pspew(" reading %u bytes:", readcnt); msg_pspew(" reading %u bytes:", readcnt);
for (i = 0; i < readcnt; i++) for (i = 0; i < readcnt; i++)
msg_pspew(" 0x%02x", readarr[i]); msg_pspew(" 0x%02x", readarr[i]);
@ -626,7 +608,6 @@ static const struct par_master par_master_dummyflasher = {
static int dummy_shutdown(void *data) static int dummy_shutdown(void *data)
{ {
msg_pspew("%s\n", __func__); msg_pspew("%s\n", __func__);
#if EMULATE_CHIP
struct emu_data *emu_data = (struct emu_data *)data; struct emu_data *emu_data = (struct emu_data *)data;
if (emu_data->emu_chip != EMULATE_NONE) { if (emu_data->emu_chip != EMULATE_NONE) {
if (emu_data->emu_persistent_image && emu_data->emu_modified) { if (emu_data->emu_persistent_image && emu_data->emu_modified) {
@ -638,7 +619,6 @@ static int dummy_shutdown(void *data)
free(emu_data->emu_persistent_image); free(emu_data->emu_persistent_image);
free(emu_data->flashchip_contents); free(emu_data->flashchip_contents);
} }
#endif
free(data); free(data);
return 0; return 0;
} }
@ -650,10 +630,8 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
char *tmp = NULL; char *tmp = NULL;
unsigned int i; unsigned int i;
char *endptr; char *endptr;
#if EMULATE_SPI_CHIP
char *status = NULL; char *status = NULL;
int size = -1; /* size for VARIABLE_SIZE chip device */ int size = -1; /* size for VARIABLE_SIZE chip device */
#endif
bustext = extract_programmer_param("bus"); bustext = extract_programmer_param("bus");
msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default"); msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
@ -812,8 +790,6 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
} }
free(tmp); free(tmp);
#if EMULATE_CHIP
#if EMULATE_SPI_CHIP
tmp = extract_programmer_param("size"); tmp = extract_programmer_param("size");
if (tmp) { if (tmp) {
size = strtol(tmp, NULL, 10); size = strtol(tmp, NULL, 10);
@ -825,7 +801,6 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
} }
free(tmp); free(tmp);
} }
#endif /* EMULATE_SPI_CHIP */
tmp = extract_programmer_param("emulate"); tmp = extract_programmer_param("emulate");
if (!tmp) { if (!tmp) {
@ -834,7 +809,6 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
return 0; return 0;
} }
#if EMULATE_SPI_CHIP
if (!strcmp(tmp, "M25P10.RES")) { if (!strcmp(tmp, "M25P10.RES")) {
data->emu_chip = EMULATE_ST_M25P10_RES; data->emu_chip = EMULATE_ST_M25P10_RES;
data->emu_chip_size = 128 * 1024; data->emu_chip_size = 128 * 1024;
@ -921,7 +895,7 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n", msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
data->emu_chip_size); data->emu_chip_size);
} }
#endif /* EMULATE_SPI_CHIP */
if (data->emu_chip == EMULATE_NONE) { if (data->emu_chip == EMULATE_NONE) {
msg_perr("Invalid chip specified for emulation: %s\n", tmp); msg_perr("Invalid chip specified for emulation: %s\n", tmp);
free(tmp); free(tmp);
@ -945,7 +919,6 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
} }
free(tmp); free(tmp);
#ifdef EMULATE_SPI_CHIP
status = extract_programmer_param("spi_status"); status = extract_programmer_param("spi_status");
if (status) { if (status) {
errno = 0; errno = 0;
@ -960,7 +933,6 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
msg_pdbg("Initial status register is set to 0x%02x.\n", msg_pdbg("Initial status register is set to 0x%02x.\n",
data->emu_status); data->emu_status);
} }
#endif /* EMULATE_SPI_CHIP */
data->flashchip_contents = malloc(data->emu_chip_size); data->flashchip_contents = malloc(data->emu_chip_size);
if (!data->flashchip_contents) { if (!data->flashchip_contents) {
@ -968,16 +940,12 @@ static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_suppor
return 1; return 1;
} }
#endif /* EMULATE_CHIP */
return 0; return 0;
} }
int dummy_init(void) int dummy_init(void)
{ {
#if EMULATE_CHIP
struct stat image_stat; struct stat image_stat;
#endif
struct emu_data *data = calloc(1, sizeof(struct emu_data)); struct emu_data *data = calloc(1, sizeof(struct emu_data));
if (!data) { if (!data) {
@ -996,7 +964,6 @@ int dummy_init(void)
return 1; return 1;
} }
#if EMULATE_CHIP
if (data->emu_chip == EMULATE_NONE) { if (data->emu_chip == EMULATE_NONE) {
msg_pdbg("Not emulating any flash chip.\n"); msg_pdbg("Not emulating any flash chip.\n");
/* Nothing else to do. */ /* Nothing else to do. */
@ -1033,7 +1000,6 @@ int dummy_init(void)
msg_pdbg("doesn't match.\n"); msg_pdbg("doesn't match.\n");
} }
} }
#endif /* EMULATE_CHIP */
dummy_init_out: dummy_init_out:
if (register_shutdown(dummy_shutdown, data)) { if (register_shutdown(dummy_shutdown, data)) {
@ -1052,7 +1018,6 @@ dummy_init_out:
return 0; return 0;
} }
#if EMULATE_CHIP && EMULATE_SPI_CHIP
int probe_variable_size(struct flashctx *flash) int probe_variable_size(struct flashctx *flash)
{ {
unsigned int i; unsigned int i;
@ -1095,4 +1060,3 @@ int probe_variable_size(struct flashctx *flash)
return 1; return 1;
} }
#endif