Stefan Reinauer has uploaded this change for review. ( https://review.coreboot.org/c/em100/+/47730 )
Change subject: Make em100 a (struct em100 *) ......................................................................
Make em100 a (struct em100 *)
Make em100 a pointer to struct em100 in main, to make the code more consistent with all other functions.
Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org Change-Id: I51ccfd3047140e40814de4df2adb8446e6408f20 --- M em100.c 1 file changed, 49 insertions(+), 48 deletions(-)
git pull ssh://review.coreboot.org:29418/em100 refs/changes/30/47730/1
diff --git a/em100.c b/em100.c index e0b145a..09cc490 100644 --- a/em100.c +++ b/em100.c @@ -30,6 +30,7 @@ int debug = 0;
static volatile int do_exit_flag = 0; +static struct em100 em100_state;
static void exit_handler(int sig __unused) { @@ -841,6 +842,7 @@ unsigned int spi_start_address = 0; const char *voltage = NULL; struct sigaction signal_action; + struct em100 *em100 = &em100_state;
while ((opt = getopt_long(argc, argv, "c:d:a:m:u:rsvtO:F:f:g:S:V:p:DCx:lUhT", longopts, &idx)) != -1) { @@ -928,8 +930,7 @@ } }
- struct em100 em100; - if (!em100_attach(&em100, bus, device, serial_number)) { + if (!em100_attach(em100, bus, device, serial_number)) { return 1; }
@@ -950,8 +951,8 @@ sigemptyset(&signal_action.sa_mask); sigaction(SIGINT, &signal_action, NULL);
- if (em100.hwversion == HWVERSION_EM100PRO || em100.hwversion == HWVERSION_EM100PRO_EARLY) { - printf("MCU version: %d.%02d\n", em100.mcu >> 8, em100.mcu & 0xff); + if (em100->hwversion == HWVERSION_EM100PRO || em100->hwversion == HWVERSION_EM100PRO_EARLY) { + printf("MCU version: %d.%02d\n", em100->mcu >> 8, em100->mcu & 0xff); /* While the Dediprog software for Windows will refuse to work * with 1.8V chips on older FPGA versions, it does not * specifically output a voltage when reporting the FPGA @@ -959,43 +960,43 @@ * known to behave the old way, 0.75 is behaving the new * way. */ - if (em100.fpga > 0x0033) /* 0.51 */ + if (em100->fpga > 0x0033) /* 0.51 */ printf("FPGA version: %d.%02d (%s)\n", - em100.fpga >> 8 & 0x7f, em100.fpga & 0xff, - em100.fpga & 0x8000 ? "1.8V" : "3.3V"); + em100->fpga >> 8 & 0x7f, em100->fpga & 0xff, + em100->fpga & 0x8000 ? "1.8V" : "3.3V"); else - printf("FPGA version: %d.%02d\n", em100.fpga >> 8, - em100.fpga & 0xff); + printf("FPGA version: %d.%02d\n", em100->fpga >> 8, + em100->fpga & 0xff); } else {/* EM100Pro-G2 */ - printf("MCU version: %d.%d\n", em100.mcu >> 8, em100.mcu & 0xff); + printf("MCU version: %d.%d\n", em100->mcu >> 8, em100->mcu & 0xff); printf("FPGA version: %d.%03d\n", - em100.fpga >> 8 & 0x7f, em100.fpga & 0xff); + em100->fpga >> 8 & 0x7f, em100->fpga & 0xff); }
- printf("Hardware version: %u\n", em100.hwversion); + printf("Hardware version: %u\n", em100->hwversion);
- if (em100.serialno != 0xffffffff) + if (em100->serialno != 0xffffffff) printf("Serial number: %s%06d\n", - em100.hwversion == HWVERSION_EM100PRO_EARLY ? "DP" : "EM", em100.serialno); + em100->hwversion == HWVERSION_EM100PRO_EARLY ? "DP" : "EM", em100->serialno); else printf("Serial number: N.A.\n"); printf("SPI flash database: %s\n", database_version); - get_current_state(&em100); - get_current_pin_state(&em100); + get_current_state(em100); + get_current_pin_state(em100); printf("\n");
if (debug) { - em100_debug(&em100); + em100_debug(em100); }
if (firmware_in) { - firmware_update(&em100, firmware_in, verify); - return em100_detach(&em100); + firmware_update(em100, firmware_in, verify); + return em100_detach(em100); }
if (firmware_out) { - firmware_dump(&em100, firmware_out, firmware_is_dpfw); - return em100_detach(&em100); + firmware_dump(em100, firmware_out, firmware_is_dpfw); + return em100_detach(em100); }
if (serialno) { @@ -1013,17 +1014,17 @@ printf("Error: Can't parse serial number '%s'\n", serialno); else - set_serialno(&em100, serial_number); + set_serialno(em100, serial_number);
- return em100_detach(&em100); + return em100_detach(em100); }
if (do_stop) { - set_state(&em100, 0); + set_state(em100, 0); }
if (desiredchip) { - if (!set_chip_type(&em100, chip)) { + if (!set_chip_type(em100, chip)) { printf("Failed configuring chip type.\n"); return 0; } @@ -1033,25 +1034,25 @@ * unless specified by the user on the command line. */ if (!address_mode && chip->size > (16 * 1024 * 1024)) { - set_address_mode(&em100, 4); + set_address_mode(em100, 4); } }
if (address_mode) { - if (set_address_mode(&em100, address_mode) < 0) { + if (set_address_mode(em100, address_mode) < 0) { return 1; } }
if (voltage) { - if (!set_fpga_voltage_from_str(&em100, voltage)) { + if (!set_fpga_voltage_from_str(em100, voltage)) { printf("Failed configuring FPGA voltage.\n"); return 1; } }
if (holdpin) { - if (!set_hold_pin_state_from_str(&em100, holdpin)) { + if (!set_hold_pin_state_from_str(em100, holdpin)) { printf("Failed configuring hold pin state.\n"); return 0; } @@ -1064,7 +1065,7 @@ /* Read configured SPI emulation from EM100 */ chipdesc emulated_chip;
- if (!get_chip_type(&em100, &emulated_chip)) { + if (!get_chip_type(em100, &emulated_chip)) { printf("Configured to emulate %dkB chip\n", emulated_chip.size / 1024); maxlen = emulated_chip.size; } @@ -1084,7 +1085,7 @@ return 1; }
- read_sdram(&em100, data, 0x00000000, maxlen); + read_sdram(em100, data, 0x00000000, maxlen);
int length = fwrite(data, maxlen, 1, fdata); fclose(fdata); @@ -1141,7 +1142,7 @@ }
if (compatibility) - autocorrect_image(&em100, data, length); + autocorrect_image(em100, data, length);
if (spi_start_address) { readback = malloc(maxlen); @@ -1150,16 +1151,16 @@ free(data); return 1; } - done = read_sdram(&em100, readback, 0, maxlen); + done = read_sdram(em100, readback, 0, maxlen); if (done) { memcpy((unsigned char*)readback + spi_start_address, data, length); - write_sdram(&em100, (unsigned char*)readback, 0x00000000, maxlen); + write_sdram(em100, (unsigned char*)readback, 0x00000000, maxlen); } else { printf("Error: sdram readback failed\n"); } free(readback); } else { - write_sdram(&em100, (unsigned char*)data, 0x00000000, length); + write_sdram(em100, (unsigned char*)data, 0x00000000, length); }
if (verify) { @@ -1169,14 +1170,14 @@ free(data); return 1; } - done = read_sdram(&em100, readback, spi_start_address, length); + done = read_sdram(em100, readback, spi_start_address, length); if (done && (memcmp(data, readback, length) == 0)) printf("Verify: PASS\n"); else { printf("Verify: FAIL\n"); free(readback); free(data); - em100_detach(&em100); + em100_detach(em100); return 1; } free(readback); @@ -1186,27 +1187,27 @@ }
if (do_start) { - set_state(&em100, 1); + set_state(em100, 1); }
if (trace || terminal) { - if ((holdpin == NULL) && (!set_hold_pin_state(&em100, 3))) { + if ((holdpin == NULL) && (!set_hold_pin_state(em100, 3))) { printf("Error: Failed to set EM100 to input\n"); return 1; }
if (!do_start && !do_stop) - set_state(&em100, 1); + set_state(em100, 1);
printf ("Starting ");
if (trace) { - reset_spi_trace(&em100); + reset_spi_trace(em100); printf("trace%s", terminal ? " & " : ""); }
if (terminal) { - init_spi_terminal(&em100); + init_spi_terminal(em100); printf("terminal"); }
@@ -1214,22 +1215,22 @@
while (!do_exit_flag) { if (trace) - read_spi_trace(&em100, terminal, + read_spi_trace(em100, terminal, address_offset); else - read_spi_terminal(&em100, 0); + read_spi_terminal(em100, 0); }
if (!do_start && !do_stop) - set_state(&em100, 0); + set_state(em100, 0); if (trace) - reset_spi_trace(&em100); + reset_spi_trace(em100);
- if ((holdpin == NULL) && (!set_hold_pin_state(&em100, 2))) { + if ((holdpin == NULL) && (!set_hold_pin_state(em100, 2))) { printf("Error: Failed to set EM100 to float\n"); return 1; } }
- return em100_detach(&em100); + return em100_detach(em100); }