summaryrefslogtreecommitdiff
path: root/util/uut/com_port.h
diff options
context:
space:
mode:
authorCHLin <CHLIN56@nuvoton.com>2018-03-07 14:33:43 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-04-18 02:07:59 -0700
commitdcaf8edc47c1703a760eff4d9ea12f68f8af492c (patch)
tree45cd1ce7771fb3f3305da88d097cf7ae51e6174e /util/uut/com_port.h
parentb21f335c40568060cbd0b671d138f0ff69a47a05 (diff)
downloadchrome-ec-dcaf8edc47c1703a760eff4d9ea12f68f8af492c.tar.gz
util: uartupdatetool (UUT): Add tool to flash firmware by UART
When the FLPRG# strap pin is set to active low, and npcx7 chip is reset, it will enter uut mode. This CL adds the host tool to communicate with npcx chip in uut mode to flash ec firmware via UART port. BRANCH=none BUG=none TEST=No build errors for make buildall. TEST= ------------------------------------------------------------------------ 1. Connect the servo connector (J24) on npcx7 EVB to servo board v2 via flex cable. 2. Manually turn the switch SW1.6 to "ON" on npcx7 EVB. 3. Reset ec by issuing Power-Up or VCC1_RST reset. 4. Manually turn the switch SW1.6 to "OFF" on npcx7 EVB. 5. Move npcx7_evb from array BOARDS_NPCX_7M7X_JTAG to BOARDS_NPCX_UUT in flash_ec. 6. "./util/flash_ec --board=npcx7_evb." Change-Id: I2c588418e809e59f97ef4c3ad7ad13a3fef42f11 Signed-off-by: Dror Goldstein <dror.goldstein@nuvoton.com> Signed-off-by: CHLin <CHLIN56@nuvoton.com> Reviewed-on: https://chromium-review.googlesource.com/952037 Commit-Ready: CH Lin <chlin56@nuvoton.com> Tested-by: Alexandru M Stan <amstan@chromium.org> Tested-by: CH Lin <chlin56@nuvoton.com> Tested-by: Raul E Rangel <rrangel@chromium.org> Reviewed-by: Raul E Rangel <rrangel@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'util/uut/com_port.h')
-rw-r--r--util/uut/com_port.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/util/uut/com_port.h b/util/uut/com_port.h
new file mode 100644
index 0000000000..36331f2fb6
--- /dev/null
+++ b/util/uut/com_port.h
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* This file defines the ComPort interface header file. */
+
+#ifndef __UTIL_UUT_COM_PORT_H
+#define __UTIL_UUT_COM_PORT_H
+
+#include <stdbool.h>
+#include <termios.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*---------------------------------------------------------------------------
+ * ComPort INTERFACE
+ *---------------------------------------------------------------------------
+ */
+
+/*---------------------------------------------------------------------------
+ * Constant definitions
+ *---------------------------------------------------------------------------
+ */
+#define INVALID_HANDLE_VALUE -1
+
+/*---------------------------------------------------------------------------
+ * Type definitions
+ *---------------------------------------------------------------------------
+ */
+#define COMP_PORT_PREFIX_1 "ttyS"
+#define COMP_PORT_PREFIX_2 "ttyUSB"
+#define COMP_PORT_PREFIX_3 "pts"
+
+struct comport_fields {
+ uint32_t baudrate; /* Baudrate at which running */
+ tcflag_t byte_size; /* Number of bits/byte, 4-8 */
+ tcflag_t parity; /* 0-4=None,Odd,Even,Mark,Space */
+ uint8_t stop_bits; /* 0,1,2 = 1, 1.5, 2 */
+ uint8_t flow_control; /* 0-none, 1-SwFlowControl,2-HwFlowControl */
+};
+
+/*---------------------------------------------------------------------------
+ * Function: int com_port_open()
+ *
+ * Purpose: Open the specified ComPort device.
+ *
+ * Params: com_port_dev_name - The name of the device to open
+ * com_port_fields - a struct filled with Comport settings, see
+ * definition above.
+ *
+ * Returns: INVALID_HANDLE_VALUE (-1) - invalid handle.
+ * Other value - Handle to be used in other Comport APIs
+ *
+ * Comments: The returned handle can be used for other Win32 API communication
+ * function by casting it to HANDLE.
+ *
+ *---------------------------------------------------------------------------
+ */
+int com_port_open(const char *com_port_dev_name,
+ struct comport_fields com_port_fields);
+
+/*---------------------------------------------------------------------------
+ * Function: int com_config_uart()
+ *
+ * Purpose: Configures the Uart port properties.
+ *
+ * Params: h_dev_drv - the opened handle returned by com_port_open()
+ * com_port_fields - a struct filled with Comport settings, see
+ * definition above.
+ *
+ * Returns: 1 if successful
+ * 0 in the case of an error.
+ *
+ *---------------------------------------------------------------------------
+ */
+bool com_config_uart(int h_dev_drv, struct comport_fields com_port_fields);
+
+/*---------------------------------------------------------------------------
+ * Function: bool ComPortClose()
+ *
+ * Purpose: Close the ComPort device specified by Handle
+ *
+ * Params: device_id - the opened handle returned by com_port_open()
+ *
+ * Returns: 1 if successful
+ * 0 in the case of an error.
+ *
+ *---------------------------------------------------------------------------
+ */
+bool com_port_close(int device_id);
+
+/*---------------------------------------------------------------------------
+ * Function: bool com_port_write_bin()
+ *
+ * Purpose: Send binary data through Comport
+ *
+ * Params: device_id - the opened handle returned by com_port_open()
+ * buffer - contains the binary data to send
+ * buf_size - the size of data to send
+ *
+ * Returns: 1 if successful
+ * 0 in the case of an error.
+ *
+ * Comments: The caller must ensure that buf_size is not bigger than
+ * Buffer size.
+ *
+ *---------------------------------------------------------------------------
+ */
+bool com_port_write_bin(int device_id, const uint8_t *buffer,
+ uint32_t buf_size);
+
+/*---------------------------------------------------------------------------
+ * Function: uint32_t com_port_read_bin()
+ *
+ * Purpose: Read a binary data from Comport
+ *
+ * Params: device_id - the opened handle returned by com_port_open()
+ * buffer - this buffer will contain the arrived data
+ * buf_size - maximum data size to read
+ *
+ * Returns: The number of bytes read.
+ *
+ * Comments: The caller must ensure that Size is not bigger than Buffer size.
+ *
+ *---------------------------------------------------------------------------
+ */
+uint32_t com_port_read_bin(int device_id, uint8_t *buffer, uint32_t buf_size);
+
+/*---------------------------------------------------------------------------
+ * Function: uint32_t com_port_wait_read()
+ *
+ * Purpose: Wait until a byte is received for read
+ *
+ * Params: device_id - the opened handle returned by com_port_open()
+ *
+ * Returns: The number of bytes that are waiting in RX queue.
+ *
+ *---------------------------------------------------------------------------
+ */
+uint32_t com_port_wait_read(int device_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UTIL_UUT_COM_PORT_H */