diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-09-21 14:08:36 -0700 |
---|---|---|
committer | Tom Hughes <tomhughes@chromium.org> | 2022-09-22 12:59:38 -0700 |
commit | c453fd704268ef72de871b0c5ac7a989de662334 (patch) | |
tree | fcf6ce5810f9ff9e3c8cce434812dd75492269ed /util/iteflash.c | |
parent | 6c1587ca70f558b4f96b3f0b18ad8b027d3ba99d (diff) | |
parent | 28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff) | |
download | chrome-ec-c453fd704268ef72de871b0c5ac7a989de662334.tar.gz |
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-releasefirmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file
./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release
Relevant changes:
git log --oneline 6c1587ca70..28712dae9d -- board/nocturne_fp
board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint
util/getversion.sh
ded9307b79 util/getversion.sh: Fix version when not in a git repo
956055e692 board: change Google USB vendor info
71b2ef709d Update license boilerplate text in source code files
33e11afda0 Revert "fpsensor: Build fpsensor source file with C++"
c8d0360723 fpsensor: Build fpsensor source file with C++
bc113abd53 fpsensor: Fix g++ compiler error
150a58a0dc fpsensor: Fix fp_set_sensor_mode return type
b33b5ce85b fpsensor: Remove nested designators for C++ compatibility
2e864b2539 tree-wide: const-ify argv for console commands
56d8b360f9 test: Add test for get ikm failure when seed not set
3a3d6c3690 test: Add test for fpsensor trivial key failure
233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256
0a041b285b docs/fingerprint: Typo correction
c03fab67e2 docs/fingerprint: Fix the path of fputils.py
0b5d4baf5a util/getversion.sh: Fix empty file list handling
6e128fe760 FPMCU dev board environment with Satlab
3eb29b6aa5 builtin: Move ssize_t to sys/types.h
345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release
c25ffdb316 common: Conditionally support printf %l and %i modifiers
9a3c514b45 test: Add a test to check if the debugger is connected
54e603413f Move standard library tests to their own file
43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release
25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format
4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format
738de2b575 trng: Rename rand to trng_rand
14b8270edd docs/fingerprint: Update dragonclaw power numbers
0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format
f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format
a0751778f4 board/nocturne_fp/ro_workarounds.c: Format with clang-format
5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format
c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format
eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format
6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format
e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format
58f0246dbe board/nocturne_fp/board_ro.c: Format with clang-format
7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format
21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format
98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format
a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format
84e53a65da board/nocturne_fp/board.h: Format with clang-format
73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format
0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format
1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format
dca9d74321 Revert "trng: Rename rand to trng_rand"
a6b0b3554f trng: Rename rand to trng_rand
28d0b75b70 third_party/boringssl: Remove unused header
BRANCH=None
BUG=b:244387210 b:242720240 b:215613183 b:242720910 b:236386294
BUG=b:234181908 b:244781166 b:234781655 b:234143158 b:234181908
BUG=b:237344361 b:236025198 b:234181908 b:180945056 chromium:1098010
BUG=b:246424843 b:234181908 b:131913998
TEST=`make -j buildall`
TEST=./util/run_device_tests.py --board dartmonkey
Test "aes": PASSED
Test "cec": PASSED
Test "cortexm_fpu": PASSED
Test "crc": PASSED
Test "flash_physical": PASSED
Test "flash_write_protect": PASSED
Test "fpsensor_hw": PASSED
Test "fpsensor_spi_ro": PASSED
Test "fpsensor_spi_rw": PASSED
Test "fpsensor_uart_ro": PASSED
Test "fpsensor_uart_rw": PASSED
Test "mpu_ro": PASSED
Test "mpu_rw": PASSED
Test "mutex": PASSED
Test "pingpong": PASSED
Test "printf": PASSED
Test "queue": PASSED
Test "rollback_region0": PASSED
Test "rollback_region1": PASSED
Test "rollback_entropy": PASSED
Test "rtc": PASSED
Test "sha256": PASSED
Test "sha256_unrolled": PASSED
Test "static_if": PASSED
Test "stdlib": PASSED
Test "system_is_locked_wp_on": PASSED
Test "system_is_locked_wp_off": PASSED
Test "timer_dos": PASSED
Test "utils": PASSED
Test "utils_str": PASSED
Test "panic_data_dartmonkey_v2.0.2887": PASSED
Test "panic_data_nocturne_fp_v2.2.64": PASSED
Test "panic_data_nami_fp_v2.2.144": PASSED
Force-Relevant-Builds: all
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I2c312583a709fedae8fe11d92c22328c3b634bc7
Diffstat (limited to 'util/iteflash.c')
-rw-r--r-- | util/iteflash.c | 530 |
1 files changed, 274 insertions, 256 deletions
diff --git a/util/iteflash.c b/util/iteflash.c index a4a166d3d8..9085365135 100644 --- a/util/iteflash.c +++ b/util/iteflash.c @@ -1,4 +1,4 @@ -/* Copyright 2013 The Chromium OS Authors. All rights reserved. +/* Copyright 2013 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * @@ -38,65 +38,65 @@ #define CR50_USB_PID 0x5014 /* Cr50 exposed properties of the USB I2C endpoint. */ -#define CR50_I2C_SUBCLASS 82 -#define CR50_I2C_PROTOCOL 1 +#define CR50_I2C_SUBCLASS 82 +#define CR50_I2C_PROTOCOL 1 -#define CROS_CMD_ADDR 0x78 /* USB_I2C_CMD_ADDR 0xF0 >> 1 */ -#define CROS_CMD_ITE_SYNC 0 +#define CROS_CMD_ADDR 0x78 /* USB_I2C_CMD_ADDR 0xF0 >> 1 */ +#define CROS_CMD_ITE_SYNC 0 /* DBGR I2C addresses */ -#define I2C_CMD_ADDR 0x5A -#define I2C_DATA_ADDR 0x35 +#define I2C_CMD_ADDR 0x5A +#define I2C_DATA_ADDR 0x35 #define I2C_BLOCK_ADDR 0x79 #define FTDI_I2C_FREQ 400000 /* I2C pins on the FTDI interface */ -#define SCL_BIT BIT(0) -#define SDA_BIT BIT(1) +#define SCL_BIT BIT(0) +#define SDA_BIT BIT(1) /* Chip ID register value */ #define CHIP_ID 0x8380 /* Embedded flash page size */ -#define PAGE_SIZE (1<<8) +#define PAGE_SIZE (1 << 8) /* Embedded flash block write size for different programming modes. */ -#define FTDI_BLOCK_WRITE_SIZE (1<<16) +#define FTDI_BLOCK_WRITE_SIZE (1 << 16) /* JEDEC SPI Flash commands */ -#define SPI_CMD_PAGE_PROGRAM 0x02 -#define SPI_CMD_WRITE_DISABLE 0x04 -#define SPI_CMD_READ_STATUS 0x05 -#define SPI_CMD_WRITE_ENABLE 0x06 -#define SPI_CMD_FAST_READ 0x0B -#define SPI_CMD_CHIP_ERASE 0x60 -#define SPI_CMD_SECTOR_ERASE_1K 0xD7 -#define SPI_CMD_SECTOR_ERASE_4K 0x20 -#define SPI_CMD_WORD_PROGRAM 0xAD -#define SPI_CMD_EWSR 0x50 /* Enable Write Status Register */ -#define SPI_CMD_WRSR 0x01 /* Write Status Register */ -#define SPI_CMD_RDID 0x9F /* Read Flash ID */ +#define SPI_CMD_PAGE_PROGRAM 0x02 +#define SPI_CMD_WRITE_DISABLE 0x04 +#define SPI_CMD_READ_STATUS 0x05 +#define SPI_CMD_WRITE_ENABLE 0x06 +#define SPI_CMD_FAST_READ 0x0B +#define SPI_CMD_CHIP_ERASE 0x60 +#define SPI_CMD_SECTOR_ERASE_1K 0xD7 +#define SPI_CMD_SECTOR_ERASE_4K 0x20 +#define SPI_CMD_WORD_PROGRAM 0xAD +#define SPI_CMD_EWSR 0x50 /* Enable Write Status Register */ +#define SPI_CMD_WRSR 0x01 /* Write Status Register */ +#define SPI_CMD_RDID 0x9F /* Read Flash ID */ /* Size for FTDI outgoing buffer */ -#define FTDI_CMD_BUF_SIZE (1<<12) +#define FTDI_CMD_BUF_SIZE (1 << 12) /* Reset Status */ -#define RSTS_VCCDO_PW_ON 0x40 -#define RSTS_VFSPIPG 0x20 -#define RSTS_HGRST 0x08 -#define RSTS_GRST 0x04 +#define RSTS_VCCDO_PW_ON 0x40 +#define RSTS_VFSPIPG 0x20 +#define RSTS_HGRST 0x08 +#define RSTS_GRST 0x04 /* I2C MUX Configuration: TCA9543 or PCA9546 */ -#define I2C_MUX_CMD_ADDR 0x70 -#define I2C_MUX_CMD_NONE 0x00 -#define I2C_MUX_CMD_INAS 0x01 -#define I2C_MUX_CMD_EC 0x02 +#define I2C_MUX_CMD_ADDR 0x70 +#define I2C_MUX_CMD_NONE 0x00 +#define I2C_MUX_CMD_INAS 0x01 +#define I2C_MUX_CMD_EC 0x02 /* Eflash Type*/ -#define EFLASH_TYPE_8315 0x01 -#define EFLASH_TYPE_KGD 0x02 -#define EFLASH_TYPE_NONE 0xFF +#define EFLASH_TYPE_8315 0x01 +#define EFLASH_TYPE_KGD 0x02 +#define EFLASH_TYPE_NONE 0xFF uint8_t eflash_type; uint8_t spi_cmd_sector_erase; @@ -104,7 +104,6 @@ uint8_t spi_cmd_sector_erase; /* Embedded flash number of pages in a sector erase */ uint8_t sector_erase_pages; - static volatile sig_atomic_t exit_requested; struct i2c_interface; @@ -113,17 +112,17 @@ struct i2c_interface; struct iteflash_config { char *input_filename; char *output_filename; - int send_waveform; /* boolean */ - int erase; /* boolean */ + int send_waveform; /* boolean */ + int erase; /* boolean */ int i2c_mux; /* boolean */ - int debug; /* boolean */ - int disable_watchdog; /* boolean */ - int disable_protect_path; /* boolean */ + int debug; /* boolean */ + int disable_watchdog; /* boolean */ + int disable_protect_path; /* boolean */ int block_write_size; int usb_interface; int usb_vid; int usb_pid; - int verify; /* boolean */ + int verify; /* boolean */ char *usb_serial; char *i2c_dev_path; const struct i2c_interface *i2c_if; @@ -134,8 +133,8 @@ struct iteflash_config { struct common_hnd { struct iteflash_config conf; int flash_size; - int flash_cmd_v2; /* boolean */ - int dbgr_addr_3bytes; /* boolean */ + int flash_cmd_v2; /* boolean */ + int dbgr_addr_3bytes; /* boolean */ union { int i2c_dev_fd; struct usb_endpoint uep; @@ -162,13 +161,13 @@ struct i2c_interface { int (*send_special_waveform)(struct common_hnd *chnd); /* Required, must not be NULL. */ int (*byte_transfer)(struct common_hnd *chnd, uint8_t addr, - uint8_t *data, int write, int numbytes); + uint8_t *data, int write, int numbytes); /* Required, must be positive. */ int default_block_write_size; }; -static int spi_flash_command_short(struct common_hnd *chnd, - uint8_t cmd, char *desc); +static int spi_flash_command_short(struct common_hnd *chnd, uint8_t cmd, + char *desc); static void null_and_free(void **ptr) { @@ -192,7 +191,7 @@ static void config_release(struct iteflash_config *conf) } /* number of bytes to send consecutively before checking for ACKs */ -#define FTDI_TX_BUFFER_LIMIT 32 +#define FTDI_TX_BUFFER_LIMIT 32 static inline int i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, uint8_t *data, int write, int numbytes) @@ -202,7 +201,7 @@ static inline int i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, return -1; return chnd->conf.i2c_if->byte_transfer(chnd, addr, data, write, - numbytes); + numbytes); } static int linux_i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, @@ -225,8 +224,10 @@ static int linux_i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, ret = ioctl(chnd->i2c_dev_fd, I2C_RDWR, &msgset); if (ret < 0) { extra_int = errno; - fprintf(stderr, "%s: ioctl() failed with return value %d and " - "errno %d\n", __func__, ret, extra_int); + fprintf(stderr, + "%s: ioctl() failed with return value %d and " + "errno %d\n", + __func__, ret, extra_int); if (ret == -1 && extra_int) ret = -abs(extra_int); } else if (ret < nmsgs) { @@ -250,12 +251,17 @@ static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, for (i = 0; i < tcnt; i++) { /* WORKAROUND: force SDA before sending the next byte */ - *b++ = SET_BITS_LOW; *b++ = SDA_BIT; *b++ = SCL_BIT | SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = SDA_BIT; + *b++ = SCL_BIT | SDA_BIT; /* write byte */ *b++ = MPSSE_DO_WRITE | MPSSE_BITMODE | MPSSE_WRITE_NEG; - *b++ = 0x07; *b++ = *tbuf++; + *b++ = 0x07; + *b++ = *tbuf++; /* prepare for ACK */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SCL_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SCL_BIT; /* read ACK */ *b++ = MPSSE_DO_READ | MPSSE_BITMODE | MPSSE_LSB; *b++ = 0; @@ -267,7 +273,7 @@ static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, * On the last byte, or every FTDI_TX_BUFFER_LIMIT bytes, read * the ACK bits. */ - if (i == tcnt-1 || (tx_buffered == FTDI_TX_BUFFER_LIMIT)) { + if (i == tcnt - 1 || (tx_buffered == FTDI_TX_BUFFER_LIMIT)) { /* write data */ ret = ftdi_write_data(ftdi, buf, b - buf); if (ret < 0) { @@ -280,7 +286,7 @@ static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, ack_idx = 0; do { ret = ftdi_read_data(ftdi, &ack[ack_idx], - remaining_data); + remaining_data); if (ret < 0) { fprintf(stderr, "read ACK failed\n"); return ret; @@ -299,7 +305,7 @@ static int i2c_add_send_byte(struct ftdi_context *ftdi, uint8_t *buf, fprintf(stderr, "write ACK fail: %d, 0x%02x\n", ret, failed_ack); - return -ENXIO; + return -ENXIO; } /* reset for next set of transactions */ @@ -318,20 +324,32 @@ static int i2c_add_recv_bytes(struct ftdi_context *ftdi, uint8_t *buf, for (i = 0; i < rcnt; i++) { /* set SCL low */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SCL_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SCL_BIT; /* read the byte on the wire */ - *b++ = MPSSE_DO_READ; *b++ = 0; *b++ = 0; + *b++ = MPSSE_DO_READ; + *b++ = 0; + *b++ = 0; if (i == rcnt - 1) { /* NACK last byte */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SCL_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SCL_BIT; *b++ = MPSSE_DO_WRITE | MPSSE_BITMODE | MPSSE_WRITE_NEG; - *b++ = 0; *b++ = 0xff; *b++ = SEND_IMMEDIATE; + *b++ = 0; + *b++ = 0xff; + *b++ = SEND_IMMEDIATE; } else { /* ACK all other bytes */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SCL_BIT | SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SCL_BIT | SDA_BIT; *b++ = MPSSE_DO_WRITE | MPSSE_BITMODE | MPSSE_WRITE_NEG; - *b++ = 0; *b++ = 0; *b++ = SEND_IMMEDIATE; + *b++ = 0; + *b++ = 0; + *b++ = SEND_IMMEDIATE; } } @@ -401,7 +419,7 @@ static int ccd_i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, write ? sizeof(usb_buffer) : USB_I2C_HEADER_SIZE + extra, usb_buffer, sizeof(usb_buffer), 1, &response_size); - if (response_size < (USB_I2C_HEADER_SIZE + (write ? 0 : numbytes))) { + if (response_size < (USB_I2C_HEADER_SIZE + (write ? 0 : numbytes))) { fprintf(stderr, "%s: got too few bytes (%zd) in response\n", __func__, response_size); return -1; @@ -417,8 +435,7 @@ static int ccd_i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, rv = usb_buffer[1]; rv = (rv << 8) + usb_buffer[0]; - fprintf(stderr, "%s: usb i2c error %d\n", - __func__, + fprintf(stderr, "%s: usb i2c error %d\n", __func__, (((uint16_t)usb_buffer[1]) << 8) + usb_buffer[0]); return -rv; @@ -445,14 +462,26 @@ static int ftdi_i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, /* START condition */ /* SCL & SDA high */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = 0; - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = 0; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = 0; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = 0; /* SCL high, SDA low */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SDA_BIT; - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SDA_BIT; /* SCL low, SDA low */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SCL_BIT | SDA_BIT; - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SCL_BIT | SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SCL_BIT | SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SCL_BIT | SDA_BIT; /* send address */ slave_addr = (addr << 1) | (write ? 0 : 1); @@ -467,7 +496,7 @@ static int ftdi_i2c_byte_transfer(struct common_hnd *chnd, uint8_t addr, b = buf; if (write) /* write data */ ret = i2c_add_send_byte(ftdi, buf, b, data, numbytes, - chnd->conf.debug); + chnd->conf.debug); else /* read data */ ret = i2c_add_recv_bytes(ftdi, buf, b, data, numbytes); @@ -475,11 +504,19 @@ exit_xfer: b = buf; /* STOP condition */ /* SCL high, SDA low */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SDA_BIT; - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SDA_BIT; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = SDA_BIT; /* SCL high, SDA high */ - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = 0; - *b++ = SET_BITS_LOW; *b++ = 0; *b++ = 0; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = 0; + *b++ = SET_BITS_LOW; + *b++ = 0; + *b++ = 0; rets = ftdi_write_data(ftdi, buf, b - buf); if (rets < 0) @@ -549,21 +586,16 @@ static int check_flashid(struct common_hnd *chnd) { int ret = 0; uint8_t id[16], i; - struct cmds commands[] = { - {0x07, 0x7f}, - {0x06, 0xff}, - {0x04, 0x00}, - {0x05, 0xfe}, - {0x08, 0x00}, - {0x05, 0xfd}, - {0x08, 0x9f} - }; + struct cmds commands[] = { { 0x07, 0x7f }, { 0x06, 0xff }, + { 0x04, 0x00 }, { 0x05, 0xfe }, + { 0x08, 0x00 }, { 0x05, 0xfd }, + { 0x08, 0x9f } }; for (i = 0; i < ARRAY_SIZE(commands); i++) { ret = i2c_write_byte(chnd, commands[i].addr, commands[i].cmd); if (ret) { fprintf(stderr, "Flash ID Failed : cmd %x ,data %x\n", - commands[i].addr, commands[i].cmd); + commands[i].addr, commands[i].cmd); return ret; } } @@ -595,7 +627,7 @@ static int check_chipid(struct common_hnd *chnd) int ret; uint8_t ver = 0xff; uint32_t id = 0xffff; - uint16_t v2[7] = {128, 192, 256, 384, 512, 0, 1024}; + uint16_t v2[7] = { 128, 192, 256, 384, 512, 0, 1024 }; /* * Chip Version is mapping from bit 3-0 * Flash size is mapping from bit 7-4 @@ -637,7 +669,7 @@ static int check_chipid(struct common_hnd *chnd) if ((id & 0xff00) != (CHIP_ID & 0xff00)) { id |= 0xff0000; - ret = get_3rd_chip_id_byte(chnd, (uint8_t *)&id+2); + ret = get_3rd_chip_id_byte(chnd, (uint8_t *)&id + 2); if (ret < 0) return ret; @@ -657,7 +689,7 @@ static int check_chipid(struct common_hnd *chnd) } /* compute embedded flash size from CHIPVER field */ if (chnd->flash_cmd_v2) - chnd->flash_size = v2[(ver & 0xF0)>>5] * 1024; + chnd->flash_size = v2[(ver & 0xF0) >> 5] * 1024; else chnd->flash_size = (128 + (ver & 0xF0)) * 1024; @@ -667,29 +699,7 @@ static int check_chipid(struct common_hnd *chnd) } printf("CHIPID %05x, CHIPVER %02x, Flash size %d kB\n", id, ver, - chnd->flash_size / 1024); - - return 0; -} - -/* DBGR Reset */ -static int dbgr_reset(struct common_hnd *chnd, unsigned char val) -{ - int ret = 0; - - /* Reset CPU only, and we keep power state until flashing is done. */ - if (chnd->dbgr_addr_3bytes) - ret |= i2c_write_byte(chnd, 0x80, 0xf0); - - ret |= i2c_write_byte(chnd, 0x2f, 0x20); - ret |= i2c_write_byte(chnd, 0x2e, 0x06); - - /* Enable the Reset Status by val */ - ret |= i2c_write_byte(chnd, 0x30, val); - - ret |= i2c_write_byte(chnd, 0x27, 0x80); - if (ret < 0) - fprintf(stderr, "DBGR RESET FAILED\n"); + chnd->flash_size / 1024); return 0; } @@ -761,7 +771,7 @@ static int dbgr_disable_protect_path(struct common_hnd *chnd) ret |= i2c_write_byte(chnd, 0x2f, 0x20); for (i = 0; i < 32; i++) { - ret |= i2c_write_byte(chnd, 0x2e, 0xa0+i); + ret |= i2c_write_byte(chnd, 0x2e, 0xa0 + i); ret |= i2c_write_byte(chnd, 0x30, 0); } @@ -800,8 +810,8 @@ static int spi_flash_follow_mode_exit(struct common_hnd *chnd, char *desc) ret = (ret ? -EIO : 0); if (ret < 0) - fprintf(stderr, "Flash %s exit follow mode FAILED (%d)\n", - desc, ret); + fprintf(stderr, "Flash %s exit follow mode FAILED (%d)\n", desc, + ret); return ret; } @@ -821,8 +831,8 @@ static int dbgr_stop_ec(struct common_hnd *chnd) } /* SPI Flash generic command, short version */ -static int spi_flash_command_short(struct common_hnd *chnd, - uint8_t cmd, char *desc) +static int spi_flash_command_short(struct common_hnd *chnd, uint8_t cmd, + char *desc) { int ret = 0; @@ -839,8 +849,8 @@ static int spi_flash_command_short(struct common_hnd *chnd, } /* SPI Flash set erase page */ -static int spi_flash_set_erase_page(struct common_hnd *chnd, - int page, char *desc) +static int spi_flash_set_erase_page(struct common_hnd *chnd, int page, + char *desc) { int ret = 0; @@ -862,7 +872,7 @@ static int spi_poll_busy(struct common_hnd *chnd, char *desc) int ret = -EIO; if (spi_flash_command_short(chnd, SPI_CMD_READ_STATUS, - "read status for busy bit") < 0) { + "read status for busy bit") < 0) { fprintf(stderr, "Flash %s wait busy cleared FAILED\n", desc); goto failed_read_status; } @@ -889,7 +899,7 @@ static int spi_check_write_enable(struct common_hnd *chnd, char *desc) int ret = -EIO; if (spi_flash_command_short(chnd, SPI_CMD_READ_STATUS, - "read status for write enable bit") < 0) { + "read status for write enable bit") < 0) { fprintf(stderr, "Flash %s wait WE FAILED\n", desc); goto failed_read_status; } @@ -915,12 +925,8 @@ static int ftdi_config_i2c(struct ftdi_context *ftdi) int ret; static const uint16_t divisor = 60000000 / (2 * FTDI_I2C_FREQ * 3 / 2 /* 3-phase CLK */) - 1; - uint8_t clock_buf[] = { - EN_3_PHASE, - DIS_DIV_5, - TCK_DIVISOR, - divisor & 0xff, - divisor >> 8}; + uint8_t clock_buf[] = { EN_3_PHASE, DIS_DIV_5, TCK_DIVISOR, + divisor & 0xff, divisor >> 8 }; ret = ftdi_set_latency_timer(ftdi, 16 /* ms */); if (ret < 0) @@ -951,7 +957,7 @@ static int ftdi_config_i2c(struct ftdi_context *ftdi) /* Special waveform definition */ #define SPECIAL_LEN_USEC 50000ULL /* us */ -#define SPECIAL_FREQ 400000ULL +#define SPECIAL_FREQ 400000ULL #define SPECIAL_PATTERN 0x0000020301010302ULL #define SPECIAL_PATTERN_SDA_L_SCL_L 0x0000000000000000ULL @@ -960,7 +966,7 @@ static int ftdi_config_i2c(struct ftdi_context *ftdi) #define SPECIAL_PATTERN_SDA_H_SCL_H 0x0303030303030303ULL #define TICK_COUNT 24 -#define MSEC 1000 +#define MSEC 1000 #define USEC 1000000 #define SPECIAL_BUFFER_SIZE \ @@ -975,8 +981,8 @@ static int connect_to_ccd_i2c_bridge(struct common_hnd *chnd) CR50_I2C_PROTOCOL, &chnd->uep); if (rv) { - fprintf(stderr, "%s: usb_findit returned error %d\n", - __func__, rv); + fprintf(stderr, "%s: usb_findit returned error %d\n", __func__, + rv); } return rv; @@ -986,13 +992,11 @@ static int ccd_trigger_special_waveform(struct common_hnd *chnd) { uint8_t response[20]; size_t rsize; - uint8_t req[] = { - 0, /* Port 0. Might be necessary to modify. */ - CROS_CMD_ADDR, /* Chrome OS dedicated address. */ - 1, /* Will send a single byte command. */ - 0, /* No need to read back anything. */ - CROS_CMD_ITE_SYNC - }; + uint8_t req[] = { 0, /* Port 0. Might be necessary to modify. */ + CROS_CMD_ADDR, /* Chrome OS dedicated address. */ + 1, /* Will send a single byte command. */ + 0, /* No need to read back anything. */ + CROS_CMD_ITE_SYNC }; usb_trx(&chnd->uep, req, sizeof(req), response, sizeof(response), 1, &rsize); @@ -1019,7 +1023,7 @@ static int ftdi_send_special_waveform(struct common_hnd *chnd) int i; uint64_t *wave; struct ftdi_context *ftdi = chnd->ftdi_hnd; - uint8_t release_lines[] = {SET_BITS_LOW, 0, 0}; + uint8_t release_lines[] = { SET_BITS_LOW, 0, 0 }; wave = malloc(SPECIAL_BUFFER_SIZE); if (!wave) { @@ -1058,7 +1062,7 @@ static int ftdi_send_special_waveform(struct common_hnd *chnd) usleep(5000); /* program each special tick */ - for (i = 0; i < TICK_COUNT; ) { + for (i = 0; i < TICK_COUNT;) { wave[i++] = SPECIAL_PATTERN_SDA_L_SCL_L; wave[i++] = SPECIAL_PATTERN_SDA_H_SCL_L; wave[i++] = SPECIAL_PATTERN_SDA_L_SCL_L; @@ -1082,7 +1086,7 @@ static int ftdi_send_special_waveform(struct common_hnd *chnd) ftdi_config_i2c(ftdi); ftdi_write_data(ftdi, release_lines, sizeof(release_lines)); - free_and_return: +free_and_return: free(wave); return ret; } @@ -1094,7 +1098,8 @@ static int send_special_waveform(struct common_hnd *chnd) int iterations; if (!chnd->conf.i2c_if->send_special_waveform) { - fprintf(stderr, "This binary does not support sending the ITE " + fprintf(stderr, + "This binary does not support sending the ITE " "special waveform with the chosen I2C interface.\n"); return -1; } @@ -1120,7 +1125,7 @@ static int send_special_waveform(struct common_hnd *chnd) ret = -1; if (!(iterations % max_iterations)) fprintf(stderr, "!please reset EC if flashing" - " sequence is not starting!\n"); + " sequence is not starting!\n"); } } while (ret && (iterations++ < max_iterations)); @@ -1133,10 +1138,10 @@ static int send_special_waveform(struct common_hnd *chnd) } static int windex; -static const char wheel[] = {'|', '/', '-', '\\' }; +static const char wheel[] = { '|', '/', '-', '\\' }; static void draw_spinner(uint32_t remaining, uint32_t size) { - int percent = (size - remaining)*100/size; + int percent = (size - remaining) * 100 / size; fprintf(stderr, "\r%c%3d%%", wheel[windex++], percent); windex %= sizeof(wheel); } @@ -1151,8 +1156,8 @@ static int spi_send_cmd_fast_read(struct common_hnd *chnd, uint32_t addr) ret = spi_flash_command_short(chnd, SPI_CMD_FAST_READ, "fast read"); /* Send address */ ret |= i2c_write_byte(chnd, 0x08, ((addr >> 16) & 0xff)); /* addr_h */ - ret |= i2c_write_byte(chnd, 0x08, ((addr >> 8) & 0xff)); /* addr_m */ - ret |= i2c_write_byte(chnd, 0x08, (addr & 0xff)); /* addr_l */ + ret |= i2c_write_byte(chnd, 0x08, ((addr >> 8) & 0xff)); /* addr_m */ + ret |= i2c_write_byte(chnd, 0x08, (addr & 0xff)); /* addr_l */ /* fake byte */ ret |= i2c_write_byte(chnd, 0x08, 0x00); /* use i2c block read command */ @@ -1171,8 +1176,10 @@ static int command_read_pages(struct common_hnd *chnd, uint32_t address, int cnt; if (address & 0xFF) { - fprintf(stderr, "page read requested at non-page boundary: " - "0x%X\n", address); + fprintf(stderr, + "page read requested at non-page boundary: " + "0x%X\n", + address); return -EINVAL; } @@ -1238,8 +1245,8 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address, goto failed_write; while (remaining) { - cnt = (remaining > block_write_size) ? - block_write_size : remaining; + cnt = (remaining > block_write_size) ? block_write_size : + remaining; addr_H = (address >> 16) & 0xFF; addr_M = (address >> 8) & 0xFF; addr_L = address & 0xFF; @@ -1248,7 +1255,7 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address, /* Write enable */ if (spi_flash_command_short(chnd, SPI_CMD_WRITE_ENABLE, - "write enable for AAI write") < 0) + "write enable for AAI write") < 0) goto failed_write; /* Check write enable bit */ @@ -1257,7 +1264,7 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address, /* Setup write */ if (spi_flash_command_short(chnd, SPI_CMD_WORD_PROGRAM, - "AAI write") < 0) + "AAI write") < 0) goto failed_write; /* Set eflash page address */ @@ -1266,7 +1273,7 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address, res |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &addr_L, 1, 1); if (res < 0) { fprintf(stderr, "Flash write set page FAILED (%d)\n", - res); + res); goto failed_write; } @@ -1289,13 +1296,13 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address, res |= i2c_write_byte(chnd, 0x10, 0x00); if (res < 0) { fprintf(stderr, "Flash end data write FAILED (%d)\n", - res); + res); goto failed_write; } /* Write disable */ if (spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "write disable for AAI write") < 0) + "write disable for AAI write") < 0) goto failed_write; /* Wait until available */ @@ -1310,7 +1317,7 @@ static int command_write_pages(struct common_hnd *chnd, uint32_t address, res = size; failed_write: if (spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "write disable exit AAI write") < 0) + "write disable exit AAI write") < 0) res = -EIO; if (spi_flash_follow_mode_exit(chnd, "AAI write") < 0) @@ -1330,13 +1337,13 @@ static int command_write_pages3(struct common_hnd *chnd, uint32_t address, /* SMB_SPI_Flash_Write_Enable */ if (spi_flash_command_short(chnd, SPI_CMD_WRITE_ENABLE, - "SPI Command Write Enable") < 0) { + "SPI Command Write Enable") < 0) { ret = -EIO; goto failed_write; } if (spi_flash_command_short(chnd, SPI_CMD_PAGE_PROGRAM, - "SPI_CMD_PAGE_PROGRAM") < 0) { + "SPI_CMD_PAGE_PROGRAM") < 0) { ret = -EIO; goto failed_write; } @@ -1361,8 +1368,6 @@ failed_write: return ret; } - - static int command_erase(struct common_hnd *chnd, uint32_t len, uint32_t off) { int res = -EIO; @@ -1383,7 +1388,7 @@ static int command_erase(struct common_hnd *chnd, uint32_t len, uint32_t off) draw_spinner(remaining, len); if (spi_flash_command_short(chnd, SPI_CMD_WRITE_ENABLE, - "write enable for erase") < 0) + "write enable for erase") < 0) goto failed_erase; if (spi_check_write_enable(chnd, "erase") < 0) @@ -1392,28 +1397,28 @@ static int command_erase(struct common_hnd *chnd, uint32_t len, uint32_t off) /* do chip erase */ if (remaining == chnd->flash_size) { if (spi_flash_command_short(chnd, SPI_CMD_CHIP_ERASE, - "chip erase") < 0) + "chip erase") < 0) goto failed_erase; goto wait_busy_cleared; } /* do sector erase */ if (spi_flash_command_short(chnd, spi_cmd_sector_erase, - "sector erase") < 0) + "sector erase") < 0) goto failed_erase; if (spi_flash_set_erase_page(chnd, page, "sector erase") < 0) goto failed_erase; -wait_busy_cleared: + wait_busy_cleared: if (spi_poll_busy(chnd, "erase") < 0) goto failed_erase; if (spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "write disable for erase") < 0) + "write disable for erase") < 0) goto failed_erase; - if (remaining == chnd->flash_size) { + if (remaining == chnd->flash_size) { remaining = 0; draw_spinner(remaining, len); } else { @@ -1428,7 +1433,7 @@ wait_busy_cleared: failed_erase: if (spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "write disable exit erase") < 0) + "write disable exit erase") < 0) res = -EIO; if (spi_flash_follow_mode_exit(chnd, "erase") < 0) @@ -1443,8 +1448,8 @@ failed_erase: * reset issue while flash. * Add such function to prevent the reset issue. */ -static int command_erase2(struct common_hnd *chnd, uint32_t len, - uint32_t off, uint32_t reset) +static int command_erase2(struct common_hnd *chnd, uint32_t len, uint32_t off, + uint32_t reset) { int res = -EIO; int page = 0; @@ -1468,11 +1473,10 @@ static int command_erase2(struct common_hnd *chnd, uint32_t len, goto failed_erase; while (remaining) { - draw_spinner(remaining, len); if (spi_flash_command_short(chnd, SPI_CMD_WRITE_ENABLE, - "write enable for erase") < 0) + "write enable for erase") < 0) goto failed_erase; if (spi_check_write_enable(chnd, "erase") < 0) @@ -1480,7 +1484,7 @@ static int command_erase2(struct common_hnd *chnd, uint32_t len, /* do sector erase */ if (spi_flash_command_short(chnd, spi_cmd_sector_erase, - "sector erase") < 0) + "sector erase") < 0) goto failed_erase; if (spi_flash_set_erase_page(chnd, page, "sector erase") < 0) @@ -1490,7 +1494,7 @@ static int command_erase2(struct common_hnd *chnd, uint32_t len, goto failed_erase; if (spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "write disable for erase") < 0) + "write disable for erase") < 0) goto failed_erase; if (reset) { @@ -1501,7 +1505,6 @@ static int command_erase2(struct common_hnd *chnd, uint32_t len, page += sector_erase_pages; remaining -= sector_erase_pages * PAGE_SIZE; draw_spinner(remaining, len); - } /* No error so far */ @@ -1510,7 +1513,7 @@ static int command_erase2(struct common_hnd *chnd, uint32_t len, failed_erase: if (spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "write disable exit erase") < 0) + "write disable exit erase") < 0) res = -EIO; if (spi_flash_follow_mode_exit(chnd, "erase") < 0) @@ -1604,8 +1607,10 @@ static int write_flash(struct common_hnd *chnd, const char *filename, } res = fread(buffer, 1, size, hnd); if (res <= 0) { - fprintf(stderr, "%s: Failed to read %d bytes from %s with " - "ferror() %d\n", __func__, size, filename, ferror(hnd)); + fprintf(stderr, + "%s: Failed to read %d bytes from %s with " + "ferror() %d\n", + __func__, size, filename, ferror(hnd)); free(buffer); fclose(hnd); return -EIO; @@ -1658,8 +1663,10 @@ static int write_flash2(struct common_hnd *chnd, const char *filename, } res = fread(buffer, 1, size, hnd); if (res <= 0) { - fprintf(stderr, "%s: Failed to read %d bytes from %s with " - "ferror() %d\n", __func__, size, filename, ferror(hnd)); + fprintf(stderr, + "%s: Failed to read %d bytes from %s with " + "ferror() %d\n", + __func__, size, filename, ferror(hnd)); fclose(hnd); free(buffer); return -EIO; @@ -1689,7 +1696,8 @@ __send_aai_cmd: ret |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &addr_l, 1, 1); /* Send first two bytes of buffe */ ret |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &buffer[offset], 1, 1); - ret |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &buffer[offset+1], 1, 1); + ret |= i2c_byte_transfer(chnd, I2C_DATA_ADDR, &buffer[offset + 1], 1, + 1); /* we had sent two bytes */ offset += 2; res -= 2; @@ -1711,8 +1719,8 @@ __send_aai_cmd: two_bytes_sent = 0; cnt -= 2; } - if (i2c_byte_transfer(chnd, I2C_BLOCK_ADDR, &buffer[offset], - 1, cnt) < 0) { + if (i2c_byte_transfer(chnd, I2C_BLOCK_ADDR, &buffer[offset], 1, + cnt) < 0) { ret = -EIO; goto failed_write; } @@ -1728,7 +1736,7 @@ __send_aai_cmd: i2c_write_byte(chnd, 0x10, 0x00); /* write disable command */ spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "SPI write disable"); + "SPI write disable"); goto __send_aai_cmd; } } @@ -1739,7 +1747,7 @@ failed_write: i2c_write_byte(chnd, 0x10, 0x00); /* write disable command */ spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "SPI write disable"); + "SPI write disable"); failed_enter_mode: /* exit follow mode */ spi_flash_follow_mode_exit(chnd, "AAI write"); @@ -1786,8 +1794,10 @@ static int write_flash3(struct common_hnd *chnd, const char *filename, } res = fread(buf, 1, size, hnd); if (res <= 0) { - fprintf(stderr, "%s: Failed to read %d bytes from %s with " - "ferror() %d\n", __func__, size, filename, ferror(hnd)); + fprintf(stderr, + "%s: Failed to read %d bytes from %s with " + "ferror() %d\n", + __func__, size, filename, ferror(hnd)); fclose(hnd); free(buf); return -EIO; @@ -1809,8 +1819,8 @@ static int write_flash3(struct common_hnd *chnd, const char *filename, cnt = (res > block_write_size) ? block_write_size : res; if (chnd->conf.erase && is_empty_page(&buf[offset], cnt)) { /* do nothing */ - } else if (command_write_pages3(chnd, offset, cnt, &buf[offset]) - < 0) { + } else if (command_write_pages3(chnd, offset, cnt, + &buf[offset]) < 0) { ret = -EIO; goto failed_write; } @@ -1823,7 +1833,7 @@ static int write_flash3(struct common_hnd *chnd, const char *filename, failed_write: free(buf); spi_flash_command_short(chnd, SPI_CMD_WRITE_DISABLE, - "SPI write disable"); + "SPI write disable"); spi_flash_follow_mode_exit(chnd, "Page program"); if (ret < 0) fprintf(stderr, "%s: Error writing to flash\n", __func__); @@ -1833,8 +1843,6 @@ failed_write: return ret; } - - /* Return zero on success, a non-zero value on failures. */ static int verify_flash(struct common_hnd *chnd, const char *filename, uint32_t offset) @@ -1842,7 +1850,7 @@ static int verify_flash(struct common_hnd *chnd, const char *filename, int res; int file_size; FILE *hnd; - uint8_t *buffer = malloc(chnd->flash_size); + uint8_t *buffer = malloc(chnd->flash_size); uint8_t *buffer2 = malloc(chnd->flash_size); if (!buffer || !buffer2) { @@ -1863,9 +1871,10 @@ static int verify_flash(struct common_hnd *chnd, const char *filename, file_size = fread(buffer, 1, chnd->flash_size, hnd); if (file_size <= 0) { - fprintf(stderr, "%s: Failed to read %d bytes from %s with " - "ferror() %d\n", __func__, chnd->flash_size, filename, - ferror(hnd)); + fprintf(stderr, + "%s: Failed to read %d bytes from %s with " + "ferror() %d\n", + __func__, chnd->flash_size, filename, ferror(hnd)); fclose(hnd); res = -EIO; goto exit; @@ -1885,8 +1894,8 @@ exit: return res; } -static struct ftdi_context *open_ftdi_device(int vid, int pid, - int interface, const char *serial) +static struct ftdi_context *open_ftdi_device(int vid, int pid, int interface, + const char *serial) { struct ftdi_context *ftdi; int ret; @@ -1926,17 +1935,19 @@ static int linux_i2c_interface_init(struct common_hnd *chnd) return -1; } printf("Attempting to open Linux i2c-dev path %s\n", - chnd->conf.i2c_dev_path); + chnd->conf.i2c_dev_path); chnd->i2c_dev_fd = open(chnd->conf.i2c_dev_path, O_RDWR); if (chnd->i2c_dev_fd < 0) { err = errno; perror("Failed to open Linux i2c-dev file path with error"); - fprintf(stderr, "Linux i2c-dev file path from --i2c_dev_path " - "is: %s\n", chnd->conf.i2c_dev_path); + fprintf(stderr, + "Linux i2c-dev file path from --i2c_dev_path " + "is: %s\n", + chnd->conf.i2c_dev_path); return err ? err : -1; } printf("Successfully opened Linux i2c-dev path %s\n", - chnd->conf.i2c_dev_path); + chnd->conf.i2c_dev_path); return 0; } @@ -1945,15 +1956,15 @@ static int linux_i2c_interface_shutdown(struct common_hnd *chnd) int err; printf("Attempting to close Linux i2c-dev file descriptor %d\n", - chnd->i2c_dev_fd); + chnd->i2c_dev_fd); if (close(chnd->i2c_dev_fd)) { err = errno; perror("Failed to close Linux i2c-dev file descriptor with " - "error"); + "error"); return err ? err : -1; } printf("Successfully closed Linux i2c-dev file descriptor %d\n", - chnd->i2c_dev_fd); + chnd->i2c_dev_fd); return 0; } @@ -1973,8 +1984,9 @@ static int ccd_i2c_interface_shutdown(struct common_hnd *chnd) static int ftdi_i2c_interface_init(struct common_hnd *chnd) { chnd->ftdi_hnd = open_ftdi_device(chnd->conf.usb_vid, - chnd->conf.usb_pid, chnd->conf.usb_interface, - chnd->conf.usb_serial); + chnd->conf.usb_pid, + chnd->conf.usb_interface, + chnd->conf.usb_serial); if (chnd->ftdi_hnd == NULL) return -1; return 0; @@ -2067,31 +2079,31 @@ static int strdup_with_errmsg(const char *source, char **dest, const char *name) return ret; } -static const struct option longopts[] = { - {"block-write-size", 1, 0, 'b'}, - {"debug", 0, 0, 'd'}, - {"erase", 0, 0, 'e'}, - {"help", 0, 0, 'h'}, - {"i2c-dev-path", 1, 0, 'D'}, - {"i2c-interface", 1, 0, 'c'}, - {"i2c-mux", 0, 0, 'm'}, - {"interface", 1, 0, 'i'}, - {"nodisable-protect-path", 0, 0, 'Z'}, - {"nodisable-watchdog", 0, 0, 'z'}, - {"noverify", 0, 0, 'n'}, - {"product", 1, 0, 'p'}, - {"range", 1, 0, 'R'}, - {"read", 1, 0, 'r'}, - {"send-waveform", 1, 0, 'W'}, - {"serial", 1, 0, 's'}, - {"vendor", 1, 0, 'v'}, - {"write", 1, 0, 'w'}, - {NULL, 0, 0, 0} -}; +static const struct option longopts[] = { { "block-write-size", 1, 0, 'b' }, + { "debug", 0, 0, 'd' }, + { "erase", 0, 0, 'e' }, + { "help", 0, 0, 'h' }, + { "i2c-dev-path", 1, 0, 'D' }, + { "i2c-interface", 1, 0, 'c' }, + { "i2c-mux", 0, 0, 'm' }, + { "interface", 1, 0, 'i' }, + { "nodisable-protect-path", 0, 0, + 'Z' }, + { "nodisable-watchdog", 0, 0, 'z' }, + { "noverify", 0, 0, 'n' }, + { "product", 1, 0, 'p' }, + { "range", 1, 0, 'R' }, + { "read", 1, 0, 'r' }, + { "send-waveform", 1, 0, 'W' }, + { "serial", 1, 0, 's' }, + { "vendor", 1, 0, 'v' }, + { "write", 1, 0, 'w' }, + { NULL, 0, 0, 0 } }; static void display_usage(const char *program) { - fprintf(stderr, "Usage: %s [-d] [-v <VID>] [-p <PID>] \\\n" + fprintf(stderr, + "Usage: %s [-d] [-v <VID>] [-p <PID>] \\\n" "\t[-c <linux|ccd|ftdi>] [-D /dev/i2c-<N>] [-i <1|2>] [-S] \\\n" "\t[-s <serial>] [-e] [-r <file>] [-W <0|1|false|true>] \\\n" "\t[-w <file>] [-R base[:size]] [-m] [-b <size>]\n", @@ -2105,14 +2117,16 @@ static void display_usage(const char *program) "\tonly applicable with --i2c-interface=linux\n"); fprintf(stderr, "-i, --interface <1> : FTDI interface: A=1, B=2," " ...\n"); - fprintf(stderr, "-m, --i2c-mux : Enable i2c-mux (to EC).\n" + fprintf(stderr, + "-m, --i2c-mux : Enable i2c-mux (to EC).\n" "\tSpecify this flag only if the board has an I2C MUX and\n" "\tyou are not using servod.\n"); fprintf(stderr, "-n, --noverify : Don't auto verify.\n"); fprintf(stderr, "-b, --block-write-size <size> : Perform writes in\n" - "\tblocks of this many bytes.\n"); + "\tblocks of this many bytes.\n"); fprintf(stderr, "-p, --product <0x1234> : USB product ID\n"); - fprintf(stderr, "-R, --range base[:size] : Allow to read or write" + fprintf(stderr, + "-R, --range base[:size] : Allow to read or write" " just a slice\n" "\tof the file, starting at <base>:<size> bytes, or til\n" "\tthe end of the file if <size> is not specified, expressed\n" @@ -2121,15 +2135,16 @@ static void display_usage(const char *program) " write it into <file>.\n"); fprintf(stderr, "-s, --serial <serialname> : USB serial string\n"); fprintf(stderr, "-v, --vendor <0x1234> : USB vendor ID\n"); - fprintf(stderr, "-W, --send-waveform <0|1|false|true> : Send the" + fprintf(stderr, + "-W, --send-waveform <0|1|false|true> : Send the" " special waveform.\n" "\tDefault is true. Set to false if ITE direct firmware\n" "\tupdate mode has already been enabled.\n"); fprintf(stderr, "-w, --write <file> : Write <file> to flash.\n"); fprintf(stderr, "-z, --nodisable-watchdog : Do *not* disable EC " - "watchdog.\n"); + "watchdog.\n"); fprintf(stderr, "-Z, --nodisable-protect-path : Do *not* disable EC " - "protect path.\n"); + "protect path.\n"); } /* @@ -2141,7 +2156,7 @@ static int parse_range_options(char *str, struct iteflash_config *conf) char *size; if (!str) { - fprintf(stderr, "missing range base address specification\n"); + fprintf(stderr, "missing range base address specification\n"); return -1; } @@ -2187,14 +2202,16 @@ static int parse_parameters(int argc, char **argv, struct iteflash_config *conf) } else if (!strcasecmp(optarg, "ftdi")) { conf->i2c_if = &ftdi_i2c_interface; } else { - fprintf(stderr, "Unexpected -c / " - "--i2c-interface value: %s\n", optarg); + fprintf(stderr, + "Unexpected -c / " + "--i2c-interface value: %s\n", + optarg); ret = -1; } break; case 'D': ret = strdup_with_errmsg(optarg, &conf->i2c_dev_path, - "-D / --i2c-dev-path"); + "-D / --i2c-dev-path"); break; case 'd': conf->debug = 1; @@ -2224,11 +2241,11 @@ static int parse_parameters(int argc, char **argv, struct iteflash_config *conf) break; case 'r': ret = strdup_with_errmsg(optarg, &conf->input_filename, - "-r / --read"); + "-r / --read"); break; case 's': ret = strdup_with_errmsg(optarg, &conf->usb_serial, - "-s / --serial"); + "-s / --serial"); break; case 'v': conf->usb_vid = strtol(optarg, NULL, 16); @@ -2244,13 +2261,15 @@ static int parse_parameters(int argc, char **argv, struct iteflash_config *conf) conf->send_waveform = 1; break; } - fprintf(stderr, "Unexpected -W / --special-waveform " - "value: %s\n", optarg); + fprintf(stderr, + "Unexpected -W / --special-waveform " + "value: %s\n", + optarg); ret = -1; break; case 'w': ret = strdup_with_errmsg(optarg, &conf->output_filename, - "-w / --write"); + "-w / --write"); break; case 'z': conf->disable_watchdog = 0; @@ -2269,8 +2288,8 @@ static int parse_parameters(int argc, char **argv, struct iteflash_config *conf) static void sighandler(int signum) { int status; - printf("\nCaught signal %d: %s\nExiting...\n", - signum, strsignal(signum)); + printf("\nCaught signal %d: %s\nExiting...\n", signum, + strsignal(signum)); wait(&status); exit_requested = status; } @@ -2340,7 +2359,8 @@ int main(int argc, char **argv) ret = check_chipid(&chnd); if (ret) { - fprintf(stderr, "Failed to get ITE chip ID. This " + fprintf(stderr, + "Failed to get ITE chip ID. This " "could be because the ITE direct firmware " "update (DFU) mode is not enabled.\n"); goto return_after_init; @@ -2386,20 +2406,18 @@ int main(int argc, char **argv) command_erase2(&chnd, chnd.flash_size, 0, 0); else command_erase(&chnd, chnd.flash_size, 0); - /* Call DBGR Rest to clear the EC lock status after erasing */ - dbgr_reset(&chnd, RSTS_VCCDO_PW_ON|RSTS_HGRST|RSTS_GRST); } if (chnd.conf.output_filename) { if (chnd.flash_cmd_v2) switch (eflash_type) { case EFLASH_TYPE_8315: - ret = write_flash2(&chnd, - chnd.conf.output_filename, 0); + ret = write_flash2( + &chnd, chnd.conf.output_filename, 0); break; case EFLASH_TYPE_KGD: - ret = write_flash3(&chnd, - chnd.conf.output_filename, 0); + ret = write_flash3( + &chnd, chnd.conf.output_filename, 0); break; default: printf("Invalid EFLASH TYPE!"); @@ -2420,7 +2438,7 @@ int main(int argc, char **argv) /* Normal exit */ ret = 0; - return_after_init: +return_after_init: /* * Exit DBGR mode. This ensures EC won't hold clock/data pins of I2C. * Avoid resetting EC here because flash_ec will after iteflash exits. @@ -2439,7 +2457,7 @@ int main(int argc, char **argv) ret = other_ret; } - return_after_parse: +return_after_parse: config_release(&chnd.conf); return ret; } |