summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei-Han Chen <stimim@google.com>2018-10-08 11:21:00 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-15 23:28:42 -0700
commite89911e940dc94ebf3765e785716d4431a9d646e (patch)
tree1fa8a6f65865fff46e97d1b4544f99af112a6393
parent582dfdbe15bbd9118fc2b53cf423544f16cc2d19 (diff)
downloadchrome-ec-e89911e940dc94ebf3765e785716d4431a9d646e.tar.gz
touchpad_st: embed FTB header in unpacked TP FW
To make it easier to decide if full panel initialization is required, we put the original FTB header in the beginning of unpacked TP FW. touchpad_update_write will clear CX data if CX version will be different. CQ-DEPEND=CL:*697971 BRANCH=nocturne BUG=b:117203130 TEST=manual on whiskers Signed-off-by: Wei-Han Chen <stimim@chromium.org> Change-Id: I60351783b8c015fcb23431811c156bfca8d15b67 Reviewed-on: https://chromium-review.googlesource.com/1267876 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r--board/hammer/board.h2
-rw-r--r--driver/touchpad_st.c60
-rw-r--r--driver/touchpad_st.h14
-rwxr-xr-xutil/unpack_ftb.py15
4 files changed, 59 insertions, 32 deletions
diff --git a/board/hammer/board.h b/board/hammer/board.h
index d797e198cd..3f0385daab 100644
--- a/board/hammer/board.h
+++ b/board/hammer/board.h
@@ -224,7 +224,7 @@
#define CONFIG_USB_HID_TOUCHPAD_LOGICAL_MAX_PRESSURE 255
#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_X 1030 /* tenth of mm */
#define CONFIG_USB_HID_TOUCHPAD_PHYSICAL_MAX_Y 750 /* tenth of mm */
-#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (128*1024)
+#define CONFIG_TOUCHPAD_VIRTUAL_SIZE (CONFIG_UPDATE_PDU_SIZE + 128*1024)
#else
#error "No touchpad information for board."
#endif
diff --git a/driver/touchpad_st.c b/driver/touchpad_st.c
index 9cfb461d47..d4c7aaa22b 100644
--- a/driver/touchpad_st.c
+++ b/driver/touchpad_st.c
@@ -898,12 +898,15 @@ static int wait_for_flash_ready(uint8_t type)
return retry >= 0 ? ret : EC_ERROR_TIMEOUT;
}
-static int erase_flash(void)
+static int erase_flash(int full_init_required)
{
int ret;
- /* Erase everything, except CX */
- ret = write_hwreg_cmd32(0x20000128, 0xFFFFFF83);
+ if (full_init_required)
+ ret = write_hwreg_cmd32(0x20000128, 0xFFFFFFFF);
+ else
+ /* Erase everything, except CX */
+ ret = write_hwreg_cmd32(0x20000128, 0xFFFFFF83);
if (ret)
return ret;
ret = write_hwreg_cmd8(0x2000006B, 0x00);
@@ -915,7 +918,7 @@ static int erase_flash(void)
return wait_for_flash_ready(0x6A);
}
-static int st_tp_prepare_for_update(void)
+static int st_tp_prepare_for_update(int full_init_required)
{
/* hold m3 */
write_hwreg_cmd8(0x20000024, 0x01);
@@ -923,7 +926,7 @@ static int st_tp_prepare_for_update(void)
write_hwreg_cmd8(0x20000025, 0x20);
/* unlock flash erase */
write_hwreg_cmd8(0x200000DE, 0x03);
- erase_flash();
+ erase_flash(full_init_required);
return EC_SUCCESS;
}
@@ -1079,32 +1082,15 @@ static int st_tp_panel_init(int full)
ST_TP_CMD_WRITE_SYSTEM_COMMAND, 0x00, 0x02
};
int ret, retry;
- uint8_t old_cx_version;
- uint8_t new_cx_version;
if (tp_control & (TP_CONTROL_INIT | TP_CONTROL_INIT_FULL))
return EC_ERROR_BUSY;
- if (full == -1) /* not specified */
- old_cx_version = get_cx_version(
- system_info.release_info & 0xFF);
-
st_tp_stop_scan();
ret = st_tp_reset();
if (ret)
return ret;
- if (full == -1) { /* not specified */
- /*
- * On boot, ST firmware will load system info to host data
- * memory, So we don't need to reload it.
- */
- st_tp_read_system_info(0);
- new_cx_version = get_cx_version(
- system_info.release_info & 0xFF);
- full = old_cx_version != new_cx_version;
- }
-
if (full) { /* should perform full panel initialization */
tx_buf[2] = 0x3;
tp_control = TP_CONTROL_INIT_FULL;
@@ -1144,34 +1130,50 @@ static int st_tp_panel_init(int full)
*/
int touchpad_update_write(int offset, int size, const uint8_t *data)
{
- int ret;
+ static int full_init_required;
+ int ret, flash_offset;
CPRINTS("%s %08x %d", __func__, offset, size);
if (offset == 0) {
+ const struct st_tp_fw_header_t *header;
+ uint8_t old_cx_version;
+ uint8_t new_cx_version;
+
+ header = (const struct st_tp_fw_header_t *)data;
+ if (header->signature != 0xAA55AA55)
+ return EC_ERROR_INVAL;
+
+ old_cx_version = get_cx_version(system_info.release_info);
+ new_cx_version = get_cx_version(header->release_info);
+
+ full_init_required = old_cx_version != new_cx_version;
+
/* stop scanning, interrupt, etc... */
st_tp_stop_scan();
- ret = st_tp_prepare_for_update();
+ ret = st_tp_prepare_for_update(full_init_required);
if (ret)
return ret;
+ return EC_SUCCESS;
}
- if (offset % ST_TP_DMA_CHUNK_SIZE)
+ flash_offset = offset - CONFIG_UPDATE_PDU_SIZE;
+ if (flash_offset % ST_TP_DMA_CHUNK_SIZE)
return EC_ERROR_INVAL;
- if (offset >= ST_TP_FLASH_OFFSET_CX &&
- offset < ST_TP_FLASH_OFFSET_CONFIG)
+ if (flash_offset >= ST_TP_FLASH_OFFSET_CX &&
+ flash_offset < ST_TP_FLASH_OFFSET_CONFIG)
/* don't update CX section */
return EC_SUCCESS;
- ret = st_tp_write_flash(offset, size, data);
+ ret = st_tp_write_flash(flash_offset, size, data);
if (ret)
return ret;
if (offset + size == CONFIG_TOUCHPAD_VIRTUAL_SIZE) {
CPRINTS("%s: End update, wait for reset.", __func__);
- return st_tp_panel_init(-1);
+ return st_tp_panel_init(full_init_required);
}
return EC_SUCCESS;
diff --git a/driver/touchpad_st.h b/driver/touchpad_st.h
index e8662a52fd..506cf49ae6 100644
--- a/driver/touchpad_st.h
+++ b/driver/touchpad_st.h
@@ -238,6 +238,20 @@ struct st_tp_event_t {
unsigned evt_left:5;
} __packed;
+struct st_tp_fw_header_t {
+ uint32_t signature;
+ uint32_t ftb_ver;
+ uint32_t chip_id;
+ uint32_t svn_ver;
+ uint32_t fw_ver;
+ uint32_t config_id;
+ uint32_t config_ver;
+ uint8_t reserved[8];
+ uint64_t release_info;
+ uint32_t sec_size[4];
+ uint32_t crc;
+} __packed;
+
enum ST_TP_MODE {
X_Y_MODE = 0,
HEAT_MAP_MODE,
diff --git a/util/unpack_ftb.py b/util/unpack_ftb.py
index 49f4d0ab5b..1777d5eec6 100755
--- a/util/unpack_ftb.py
+++ b/util/unpack_ftb.py
@@ -41,7 +41,15 @@ FLASH_SEC_ADDR = [
None # This section shouldn't exist
]
-OUTPUT_FILE_SIZE = 128 * 1024 # 128KB
+UPDATE_PDU_SIZE = 4096
+
+# Bin file format:
+# FTB header (padded to `UPDATE_PDU_SIZE`)
+# Flash sections
+# CODE
+# CX
+# CONFIG
+OUTPUT_FILE_SIZE = UPDATE_PDU_SIZE + 128 * 1024
def main():
@@ -85,6 +93,9 @@ def main():
f.seek(OUTPUT_FILE_SIZE - 1, os.SEEK_SET)
f.write('\x00')
+ f.seek(0, os.SEEK_SET)
+ f.write(bs[0 : ctypes.sizeof(header)])
+
offset = 0
# write each sections
for i, addr in enumerate(FLASH_SEC_ADDR):
@@ -94,7 +105,7 @@ def main():
if size == 0:
continue
- f.seek(addr, os.SEEK_SET)
+ f.seek(UPDATE_PDU_SIZE + addr, os.SEEK_SET)
f.write(data[offset : offset + size])
offset += size