extra/touchpad_updater: Various fixups (cross-compile, new chip)

This fixes a few issues in touchpad_updater, that is used only for
early bringup by Elan:
 - Fix Makefile to correctly cross-compile
 - Add support for 0x10 IC
 - Improve debugging
 - Remove manual fragmentation of USB bulk packets (this is not
   required and actually breaks large transactions)
 - Add timeout to libusb_bulk_transfer calls.

BRANCH=kukui
BUG=b:142333653
TEST=emerge-kukui -v ec-devutils && \
    scp /build/kukui/usr/sbin/ec_touchpad_updater $IP:/usr/local/sbin
    Ping-pong between 2 images:
    ec_touchpad_updater -p 0x503c -f S8648A-15H0_FW01.bin
    ec_touchpad_updater -p 0x503c -f S8648A-15H0_FWB1.bin

Change-Id: I78a8064002504ba4db15e202e516e7a2399bf648
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1906393
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
This commit is contained in:
Nicolas Boichat 2019-11-11 09:26:56 +08:00
parent 2e228e9890
commit fe55d00fbc
2 changed files with 22 additions and 12 deletions

View File

@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
CC ?= gcc
PKG_CONFIG ?= pkg-config
PROGRAM := touchpad_updater
SOURCE := $(PROGRAM).c
LIBS :=
@ -22,11 +24,11 @@ CFLAGS := -std=gnu99 \
#
# Add libusb-1.0 required flags
#
LIBS += $(shell pkg-config --libs libusb-1.0)
CFLAGS += $(shell pkg-config --cflags libusb-1.0)
LIBS += $(shell $(PKG_CONFIG) --libs libusb-1.0)
CFLAGS += $(shell $(PKG_CONFIG) --cflags libusb-1.0)
$(PROGRAM): $(SOURCE) Makefile
gcc $(CFLAGS) $(SOURCE) $(LFLAGS) $(LIBS) -o $@
$(CC) $(CFLAGS) $(SOURCE) $(LFLAGS) $(LIBS) -o $@
.PHONY: clean

View File

@ -321,20 +321,22 @@ static int libusb_single_write_and_read(
tx_buf[3] = read_length;
}
/*
* TODO: This loop is probably not required as we write the whole block
* in one transaction.
*/
while (sent_bytes < (offset + write_length)) {
tx_ready = remains = (offset + write_length) - sent_bytes;
if (tx_ready > MAX_USB_PACKET_SIZE)
tx_ready = MAX_USB_PACKET_SIZE;
r = libusb_bulk_transfer(devh,
(ep_num | LIBUSB_ENDPOINT_OUT),
tx_buf + sent_bytes, tx_ready,
&actual_length, 0);
&actual_length, 5000);
if (r == 0 && actual_length == tx_ready) {
r = libusb_bulk_transfer(devh,
(ep_num | LIBUSB_ENDPOINT_IN),
rx_buf, sizeof(rx_buf),
&actual_length, 0);
&actual_length, 5000);
}
r = check_read_status(
r, (remains == tx_ready) ? read_length : 0,
@ -400,9 +402,10 @@ static int elan_get_ic_page_count(void)
case 0x0D:
return 896;
case 0x00:
case 0x10:
return 1024;
default:
request_exit("The IC type is not supported .\n");
request_exit("The IC type is not supported.\n");
}
return -1;
}
@ -456,6 +459,8 @@ static int elan_in_main_mode(void)
static void elan_prepare_for_update(void)
{
printf("%s\n", __func__);
int initial_mode = elan_in_main_mode();
if (!initial_mode) {
printf("In IAP mode, reset IC.\n");
@ -535,15 +540,18 @@ static uint16_t elan_update_firmware(void)
uint16_t checksum = 0, block_checksum;
int rv;
printf("%s\n", __func__);
for (int i = elan_get_iap_addr(); i < fw_size; i += FW_PAGE_SIZE) {
printf("\rUpdating page %3d...", i / FW_PAGE_SIZE);
fflush(stdout);
block_checksum = elan_calc_checksum(fw_data + i, FW_PAGE_SIZE);
rv = elan_write_fw_block(fw_data + i, block_checksum);
checksum += block_checksum;
printf("\rPage %3d is updated, checksum: %d",
i / FW_PAGE_SIZE, checksum);
fflush(stdout);
if (rv)
request_exit("Failed to update.");
checksum += block_checksum;
printf(" Updated, checksum: %d", checksum);
fflush(stdout);
}
return checksum;
}