Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/56415 )
Change subject: dediprog.c: Drop dediprog_ prefix for spi data struct members ......................................................................
dediprog.c: Drop dediprog_ prefix for spi data struct members
The name of the struct type already contains dp_ prefix, so prefix doesn't need to be repeated in members name.
BUG=b:185191942 TEST=builds and ninja test
Change-Id: I688d50926b78a6c3f1c5a8ba4ef88a0d5b495bd0 Signed-off-by: Anastasia Klimchuk aklm@chromium.org --- M dediprog.c 1 file changed, 56 insertions(+), 59 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/15/56415/1
diff --git a/dediprog.c b/dediprog.c index b51f760..4097766 100644 --- a/dediprog.c +++ b/dediprog.c @@ -156,11 +156,11 @@
struct dediprog_data { struct libusb_context *usb_ctx; - libusb_device_handle *dediprog_handle; - int dediprog_in_endpoint; - int dediprog_out_endpoint; - int dediprog_firmwareversion; - enum dediprog_devtype dediprog_devicetype; + libusb_device_handle *handle; + int in_endpoint; + int out_endpoint; + int firmwareversion; + enum dediprog_devtype devicetype; };
#if defined(LIBUSB_MAJOR) && defined(LIBUSB_MINOR) && defined(LIBUSB_MICRO) && \ @@ -182,17 +182,17 @@ static enum protocol protocol(const struct dediprog_data *dp_data) { /* Firmware version < 5.0.0 is handled explicitly in some cases. */ - switch (dp_data->dediprog_devicetype) { + switch (dp_data->devicetype) { case DEV_SF100: case DEV_SF200: - if (dp_data->dediprog_firmwareversion < FIRMWARE_VERSION(5, 5, 0)) + if (dp_data->firmwareversion < FIRMWARE_VERSION(5, 5, 0)) return PROTOCOL_V1; else return PROTOCOL_V2; case DEV_SF600: - if (dp_data->dediprog_firmwareversion < FIRMWARE_VERSION(6, 9, 0)) + if (dp_data->firmwareversion < FIRMWARE_VERSION(6, 9, 0)) return PROTOCOL_V1; - else if (dp_data->dediprog_firmwareversion <= FIRMWARE_VERSION(7, 2, 21)) + else if (dp_data->firmwareversion <= FIRMWARE_VERSION(7, 2, 21)) return PROTOCOL_V2; else return PROTOCOL_V3; @@ -276,16 +276,16 @@ int target_leds, ret; if (protocol(dp_data) >= PROTOCOL_V2) { target_leds = (leds ^ 7) << 8; - ret = dediprog_write(CMD_SET_IO_LED, target_leds, 0, NULL, 0, dp_data->dediprog_handle); + ret = dediprog_write(CMD_SET_IO_LED, target_leds, 0, NULL, 0, dp_data->handle); } else { - if (dp_data->dediprog_firmwareversion < FIRMWARE_VERSION(5, 0, 0)) { + if (dp_data->firmwareversion < FIRMWARE_VERSION(5, 0, 0)) { target_leds = ((leds & LED_ERROR) >> 2) | ((leds & LED_PASS) << 2); } else { target_leds = leds; } target_leds ^= 7;
- ret = dediprog_write(CMD_SET_IO_LED, 0x9, target_leds, NULL, 0, dp_data->dediprog_handle); + ret = dediprog_write(CMD_SET_IO_LED, 0x9, target_leds, NULL, 0, dp_data->handle); }
if (ret != 0x0) { @@ -358,7 +358,7 @@
static int dediprog_set_spi_speed(unsigned int spispeed_idx, const struct dediprog_data *dp_data) { - if (dp_data->dediprog_firmwareversion < FIRMWARE_VERSION(5, 0, 0)) { + if (dp_data->firmwareversion < FIRMWARE_VERSION(5, 0, 0)) { msg_pwarn("Skipping to set SPI speed because firmware is too old.\n"); return 0; } @@ -366,7 +366,7 @@ const struct dediprog_spispeeds *spispeed = &spispeeds[spispeed_idx]; msg_pdbg("SPI speed is %sHz\n", spispeed->name);
- int ret = dediprog_write(CMD_SET_SPI_CLK, spispeed->speed, 0, NULL, 0, dp_data->dediprog_handle); + int ret = dediprog_write(CMD_SET_SPI_CLK, spispeed->speed, 0, NULL, 0, dp_data->handle); if (ret != 0x0) { msg_perr("Command Set SPI Speed 0x%x failed!\n", spispeed->speed); return 1; @@ -491,7 +491,7 @@ return 1;
int ret = dediprog_write(CMD_READ, value, idx, data_packet, sizeof(data_packet), - dp_data->dediprog_handle); + dp_data->handle); if (ret != (int)sizeof(data_packet)) { msg_perr("Command Read SPI Bulk failed, %i %s!\n", ret, libusb_error_name(ret)); return 1; @@ -520,7 +520,7 @@ { transfer = transfers[status.queued_idx % DEDIPROG_ASYNC_TRANSFERS]; libusb_fill_bulk_transfer(transfer, - dp_data->dediprog_handle, 0x80 | dp_data->dediprog_in_endpoint, + dp_data->handle, 0x80 | dp_data->in_endpoint, (unsigned char *)buf + status.queued_idx * chunksize, chunksize, dediprog_bulk_read_cb, &status, DEFAULT_TIMEOUT); transfer->flags |= LIBUSB_TRANSFER_SHORT_NOT_OK; @@ -650,8 +650,7 @@ unsigned int value, idx; if (prepare_rw_cmd(flash, data_packet, count, dedi_spi_cmd, &value, &idx, start, 0)) return 1; - int ret = dediprog_write(CMD_WRITE, value, idx, data_packet, sizeof(data_packet), - dp_data->dediprog_handle); + int ret = dediprog_write(CMD_WRITE, value, idx, data_packet, sizeof(data_packet), dp_data->handle); if (ret != (int)sizeof(data_packet)) { msg_perr("Command Write SPI Bulk failed, %s!\n", libusb_error_name(ret)); return 1; @@ -663,9 +662,8 @@ memcpy(usbbuf, buf + i * chunksize, chunksize); memset(usbbuf + chunksize, 0xff, sizeof(usbbuf) - chunksize); // fill up with 0xFF int transferred; - ret = libusb_bulk_transfer(dp_data->dediprog_handle, - dp_data->dediprog_out_endpoint, - usbbuf, 512, &transferred, DEFAULT_TIMEOUT); + ret = libusb_bulk_transfer(dp_data->handle, dp_data->out_endpoint, usbbuf, 512, &transferred, + DEFAULT_TIMEOUT); if ((ret < 0) || (transferred != 512)) { msg_perr("SPI bulk write failed, expected %i, got %s!\n", 512, libusb_error_name(ret)); return 1; @@ -767,7 +765,7 @@ idx = readcnt ? 0x1 : 0x0; // Indicate if we require a read value = 0; } - ret = dediprog_write(CMD_TRANSCEIVE, value, idx, writearr, writecnt, dp_data->dediprog_handle); + ret = dediprog_write(CMD_TRANSCEIVE, value, idx, writearr, writecnt, dp_data->handle); if (ret != (int)writecnt) { msg_perr("Send SPI failed, expected %i, got %i %s!\n", writecnt, ret, libusb_error_name(ret)); @@ -794,7 +792,7 @@ } ret = dediprog_read(CMD_TRANSCEIVE, value, idx, readarr, readcnt); */ - ret = dediprog_read(CMD_TRANSCEIVE, 0, 0, readarr, readcnt, dp_data->dediprog_handle); + ret = dediprog_read(CMD_TRANSCEIVE, 0, 0, readarr, readcnt, dp_data->handle); if (ret != (int)readcnt) { msg_perr("Receive SPI failed, expected %i, got %i %s!\n", readcnt, ret, libusb_error_name(ret)); return 1; @@ -808,7 +806,7 @@ char buf[0x11];
/* Command Receive Device String. */ - ret = dediprog_read(CMD_READ_PROG_INFO, 0, 0, (uint8_t *)buf, 0x10, dp_data->dediprog_handle); + ret = dediprog_read(CMD_READ_PROG_INFO, 0, 0, (uint8_t *)buf, 0x10, dp_data->handle); if (ret != 0x10) { msg_perr("Incomplete/failed Command Receive Device String!\n"); return 1; @@ -816,11 +814,11 @@ buf[0x10] = '\0'; msg_pdbg("Found a %s\n", buf); if (memcmp(buf, "SF100", 0x5) == 0) - dp_data->dediprog_devicetype = DEV_SF100; + dp_data->devicetype = DEV_SF100; else if (memcmp(buf, "SF200", 0x5) == 0) - dp_data->dediprog_devicetype = DEV_SF200; + dp_data->devicetype = DEV_SF200; else if (memcmp(buf, "SF600", 0x5) == 0) - dp_data->dediprog_devicetype = DEV_SF600; + dp_data->devicetype = DEV_SF600; else { msg_perr("Device not a SF100, SF200, or SF600!\n"); return 1; @@ -829,7 +827,7 @@ int sfnum; int fw[3]; if (sscanf(buf, "SF%d V:%d.%d.%d ", &sfnum, &fw[0], &fw[1], &fw[2]) != 4 || - sfnum != (int)dp_data->dediprog_devicetype) { + sfnum != (int)dp_data->devicetype) { msg_perr("Unexpected firmware version string '%s'\n", buf); return 1; } @@ -839,7 +837,7 @@ return 1; }
- dp_data->dediprog_firmwareversion = FIRMWARE_VERSION(fw[0], fw[1], fw[2]); + dp_data->firmwareversion = FIRMWARE_VERSION(fw[0], fw[1], fw[2]); if (protocol(dp_data) == PROTOCOL_UNKNOWN) { msg_perr("Internal error: Unable to determine protocol version.\n"); return 1; @@ -905,12 +903,11 @@ { int ret;
- if (dp_data->dediprog_devicetype != DEV_SF600) + if (dp_data->devicetype != DEV_SF600) return 0;
msg_pdbg2("Disabling standalone mode.\n"); - ret = dediprog_write(CMD_SET_STANDALONE, LEAVE_STANDALONE_MODE, 0, NULL, 0, - dp_data->dediprog_handle); + ret = dediprog_write(CMD_SET_STANDALONE, LEAVE_STANDALONE_MODE, 0, NULL, 0, dp_data->handle); if (ret) { msg_perr("Failed to disable standalone mode: %s\n", libusb_error_name(ret)); return 1; @@ -1040,25 +1037,25 @@ const uint16_t pid = devs_dediprog[0].device_id; int ret;
- dp_data->dediprog_handle = usb_dev_get_by_vid_pid_number(dp_data->usb_ctx, + dp_data->handle = usb_dev_get_by_vid_pid_number(dp_data->usb_ctx, vid, pid, (unsigned int) index); - if (!dp_data->dediprog_handle) { + if (!dp_data->handle) { msg_perr("Could not find a Dediprog programmer on USB.\n"); libusb_exit(dp_data->usb_ctx); return -1; } - ret = libusb_set_configuration(dp_data->dediprog_handle, 1); + ret = libusb_set_configuration(dp_data->handle, 1); if (ret != 0) { msg_perr("Could not set USB device configuration: %i %s\n", ret, libusb_error_name(ret)); - libusb_close(dp_data->dediprog_handle); + libusb_close(dp_data->handle); return -2; } - ret = libusb_claim_interface(dp_data->dediprog_handle, 0); + ret = libusb_claim_interface(dp_data->handle, 0); if (ret < 0) { msg_perr("Could not claim USB device interface %i: %i %s\n", 0, ret, libusb_error_name(ret)); - libusb_close(dp_data->dediprog_handle); + libusb_close(dp_data->handle); return -2; } return 0; @@ -1068,20 +1065,20 @@ { int ret = 0; struct dediprog_data *dp_data = data; - dp_data->dediprog_devicetype = DEV_UNKNOWN; + dp_data->devicetype = DEV_UNKNOWN;
/* URB 28. Command Set SPI Voltage to 0. */ - if (dediprog_set_spi_voltage(0x0, dp_data->dediprog_handle)) { + if (dediprog_set_spi_voltage(0x0, dp_data->handle)) { ret = 1; goto out; }
- if (libusb_release_interface(dp_data->dediprog_handle, 0)) { + if (libusb_release_interface(dp_data->handle, 0)) { msg_perr("Could not release USB interface!\n"); ret = 1; goto out; } - libusb_close(dp_data->dediprog_handle); + libusb_close(dp_data->handle); libusb_exit(dp_data->usb_ctx); out: free(data); @@ -1214,8 +1211,8 @@ msg_perr("Unable to allocate space for SPI master data\n"); return 1; } - dp_data->dediprog_firmwareversion = FIRMWARE_VERSION(0, 0, 0); - dp_data->dediprog_devicetype = DEV_UNKNOWN; + dp_data->firmwareversion = FIRMWARE_VERSION(0, 0, 0); + dp_data->devicetype = DEV_UNKNOWN;
/* Here comes the USB stuff. */ libusb_init(&dp_data->usb_ctx); @@ -1242,17 +1239,17 @@ * device is in use by another instance of flashrom), * the device is skipped and the next device is tried. */ - found_id = dediprog_read_id(dp_data->dediprog_handle); + found_id = dediprog_read_id(dp_data->handle); if (found_id < 0) { msg_perr("Could not read id.\n"); - libusb_release_interface(dp_data->dediprog_handle, 0); - libusb_close(dp_data->dediprog_handle); + libusb_release_interface(dp_data->handle, 0); + libusb_close(dp_data->handle); continue; } msg_pinfo("Found dediprog id SF%06d.\n", found_id); if (found_id != id) { - libusb_release_interface(dp_data->dediprog_handle, 0); - libusb_close(dp_data->dediprog_handle); + libusb_release_interface(dp_data->handle, 0); + libusb_close(dp_data->handle); continue; } break; @@ -1261,7 +1258,7 @@ if (dediprog_open(usedevice, dp_data)) { return 1; } - found_id = dediprog_read_id(dp_data->dediprog_handle); + found_id = dediprog_read_id(dp_data->handle); }
if (found_id >= 0) { @@ -1271,21 +1268,21 @@ /* Try reading the devicestring. If that fails and the device is old (FW < 6.0.0, which we can not know) * then we need to try the "set voltage" command and then attempt to read the devicestring again. */ if (dediprog_check_devicestring(dp_data)) { - if (dediprog_set_voltage(dp_data->dediprog_handle)) + if (dediprog_set_voltage(dp_data->handle)) goto init_err_cleanup_exit; if (dediprog_check_devicestring(dp_data)) goto init_err_cleanup_exit; }
/* SF100/SF200 uses one in/out endpoint, SF600 uses separate in/out endpoints */ - dp_data->dediprog_in_endpoint = 2; - switch (dp_data->dediprog_devicetype) { + dp_data->in_endpoint = 2; + switch (dp_data->devicetype) { case DEV_SF100: case DEV_SF200: - dp_data->dediprog_out_endpoint = 2; + dp_data->out_endpoint = 2; break; default: - dp_data->dediprog_out_endpoint = 1; + dp_data->out_endpoint = 1; break; }
@@ -1295,9 +1292,9 @@ dediprog_set_leds(LED_ALL, dp_data);
/* Select target/socket, frequency and VCC. */ - if (set_target_flash(target, dp_data->dediprog_handle) || + if (set_target_flash(target, dp_data->handle) || dediprog_set_spi_speed(spispeed_idx, dp_data) || - dediprog_set_spi_voltage(millivolt, dp_data->dediprog_handle)) { + dediprog_set_spi_voltage(millivolt, dp_data->handle)) { dediprog_set_leds(LED_ERROR, dp_data); goto init_err_cleanup_exit; } @@ -1305,8 +1302,8 @@ if (dediprog_standalone_mode(dp_data)) goto init_err_cleanup_exit;
- if ((dp_data->dediprog_devicetype == DEV_SF100) || - (dp_data->dediprog_devicetype == DEV_SF600 && protocol(dp_data) == PROTOCOL_V3)) + if ((dp_data->devicetype == DEV_SF100) || + (dp_data->devicetype == DEV_SF600 && protocol(dp_data) == PROTOCOL_V3)) spi_master_dediprog.features &= ~SPI_MASTER_NO_4BA_MODES;
if (protocol(dp_data) >= PROTOCOL_V2)