summaryrefslogtreecommitdiff
path: root/util/uut/opr.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/uut/opr.c')
-rw-r--r--util/uut/opr.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/util/uut/opr.c b/util/uut/opr.c
index 5c979afb16..8ad60bd3d4 100644
--- a/util/uut/opr.c
+++ b/util/uut/opr.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -34,7 +34,7 @@ int port_handle = INVALID_HANDLE_VALUE;
*---------------------------------------------------------------------------
*/
#define MAX_PORT_NAME_SIZE 32
-#define OPR_TIMEOUT 10L /* 10 seconds */
+#define OPR_TIMEOUT 10L /* 10 seconds */
#define FLASH_ERASE_TIMEOUT 120L /* 120 seconds */
#define STS_MSG_MIN_SIZE 8
@@ -119,9 +119,8 @@ bool opr_open_port(const char *port_name, struct comport_fields port_cfg)
if (port_handle <= 0) {
display_color_msg(FAIL, "\nERROR: COM Port failed to open.\n");
- DISPLAY_MSG(
- ("Please select the right serial port or check if "
- "other serial\n"));
+ DISPLAY_MSG(("Please select the right serial port or check if "
+ "other serial\n"));
DISPLAY_MSG(("communication applications are opened.\n"));
return false;
}
@@ -150,13 +149,13 @@ bool opr_write_chunk(uint8_t *buffer, uint32_t addr, uint32_t size)
struct command_node wr_cmd_buf;
if (size > MAX_RW_DATA_SIZE) {
- display_color_msg(FAIL,
- "ERROR: Block cannot exceed %d\n", MAX_RW_DATA_SIZE);
+ display_color_msg(FAIL, "ERROR: Block cannot exceed %d\n",
+ MAX_RW_DATA_SIZE);
}
/* Initialize response size */
wr_cmd_buf.resp_size = 1;
- cmd_create_write(addr, size, buffer,
- wr_cmd_buf.cmd, &wr_cmd_buf.cmd_size);
+ cmd_create_write(addr, size, buffer, wr_cmd_buf.cmd,
+ &wr_cmd_buf.cmd_size);
return opr_send_cmds(&wr_cmd_buf, 1);
}
@@ -179,13 +178,13 @@ bool opr_read_chunk(uint8_t *buffer, uint32_t addr, uint32_t size)
struct command_node rd_cmd_buf;
if (size > MAX_RW_DATA_SIZE) {
- display_color_msg(FAIL,
- "ERROR: Block cannot exceed %d\n", MAX_RW_DATA_SIZE);
+ display_color_msg(FAIL, "ERROR: Block cannot exceed %d\n",
+ MAX_RW_DATA_SIZE);
return false;
}
- cmd_create_read(addr, ((uint8_t)size - 1),
- rd_cmd_buf.cmd, &rd_cmd_buf.cmd_size);
+ cmd_create_read(addr, ((uint8_t)size - 1), rd_cmd_buf.cmd,
+ &rd_cmd_buf.cmd_size);
rd_cmd_buf.resp_size = size + 3;
if (opr_send_cmds(&rd_cmd_buf, 1)) {
if (resp_buf[0] == (uint8_t)(UFPP_READ_CMD)) {
@@ -228,7 +227,7 @@ void opr_write_mem(uint8_t *buffer, uint32_t addr, uint32_t size)
wr_cmd_buf.resp_size = 1;
DISPLAY_MSG(("Writing [%d] bytes in [%d] packets\n", size,
- ((size + (block_size - 1)) / block_size)));
+ ((size + (block_size - 1)) / block_size)));
/* Read first token from string */
if (console)
@@ -248,21 +247,21 @@ void opr_write_mem(uint8_t *buffer, uint32_t addr, uint32_t size)
/* Prepare the next iteration */
token = strtok(NULL, seps);
}
- write_size = (size_remain > block_size) ?
- block_size : size_remain;
+ write_size = (size_remain > block_size) ? block_size :
+ size_remain;
if (console) {
cmd_create_write(cur_addr, write_size, data_buf,
- wr_cmd_buf.cmd, &wr_cmd_buf.cmd_size);
+ wr_cmd_buf.cmd, &wr_cmd_buf.cmd_size);
} else {
cmd_create_write(cur_addr, write_size, buffer,
- wr_cmd_buf.cmd, &wr_cmd_buf.cmd_size);
+ wr_cmd_buf.cmd, &wr_cmd_buf.cmd_size);
buffer += write_size;
}
if (opr_send_cmds(&wr_cmd_buf, 1) != true)
break;
cmd_disp_write(resp_buf, write_size, cmd_idx,
- ((size + (block_size - 1)) / block_size));
+ ((size + (block_size - 1)) / block_size));
cur_addr += write_size;
size_remain -= write_size;
cmd_idx++;
@@ -302,7 +301,8 @@ void opr_read_mem(char *output, uint32_t addr, uint32_t size)
output_file_id = fopen(output, "w+b");
if (output_file_id == NULL) {
- display_color_msg(FAIL,
+ display_color_msg(
+ FAIL,
"ERROR: could not open output file [%s]\n",
output);
return;
@@ -310,21 +310,22 @@ void opr_read_mem(char *output, uint32_t addr, uint32_t size)
}
DISPLAY_MSG(("Reading [%d] bytes in [%d] packets\n", size,
- ((size + (MAX_RW_DATA_SIZE - 1)) / MAX_RW_DATA_SIZE)));
+ ((size + (MAX_RW_DATA_SIZE - 1)) / MAX_RW_DATA_SIZE)));
for (cur_addr = addr; cur_addr < (addr + size);
- cur_addr += MAX_RW_DATA_SIZE) {
+ cur_addr += MAX_RW_DATA_SIZE) {
bytes_left = (uint32_t)(addr + size - cur_addr);
read_size = MIN(bytes_left, MAX_RW_DATA_SIZE);
cmd_create_read(cur_addr, ((uint8_t)read_size - 1),
- rd_cmd_buf.cmd, &rd_cmd_buf.cmd_size);
+ rd_cmd_buf.cmd, &rd_cmd_buf.cmd_size);
rd_cmd_buf.resp_size = read_size + 3;
if (opr_send_cmds(&rd_cmd_buf, 1) != true)
break;
- cmd_disp_read(resp_buf, read_size, cmd_idx,
+ cmd_disp_read(
+ resp_buf, read_size, cmd_idx,
((size + (MAX_RW_DATA_SIZE - 1)) / MAX_RW_DATA_SIZE));
if (console)
@@ -386,8 +387,8 @@ bool opr_execute_return(uint32_t addr)
* Check the response command code is UFPP_FCALL_RSLT_CMD and
* the return value from monitor is 0x03. (program finish and verify ok)
*/
- if (resp_buf[1] != (uint8_t)(UFPP_FCALL_RSLT_CMD)
- || resp_buf[2] != 0x03)
+ if (resp_buf[1] != (uint8_t)(UFPP_FCALL_RSLT_CMD) ||
+ resp_buf[2] != 0x03)
return false;
return true;
}
@@ -473,29 +474,31 @@ bool opr_scan_baudrate(void)
sr = opr_check_sync(baud);
step = (baud * BR_BIG_STEP) / 100;
if (sr == SR_OK) {
- printf("SR_OK: Baud rate - %d, resp_buf - 0x%x\n",
- baud, resp_buf[0]);
+ printf("SR_OK: Baud rate - %d, resp_buf - 0x%x\n", baud,
+ resp_buf[0]);
synched = true;
step = (baud * BR_SMALL_STEP) / 100;
} else if (sr == SR_WRONG_DATA) {
printf("SR_WRONG_DATA: Baud rate - %d, resp_buf - "
- "0x%x\n", baud, resp_buf[0]);
+ "0x%x\n",
+ baud, resp_buf[0]);
data_received = true;
step = (baud * BR_MEDIUM_STEP) / 100;
} else if (sr == SR_TIMEOUT) {
printf("SR_TIMEOUT: Baud rate - %d, resp_buf - 0x%x\n",
- baud, resp_buf[0]);
+ baud, resp_buf[0]);
if (synched || data_received)
break;
} else if (sr == SR_ERROR) {
printf("SR_ERROR: Baud rate - %d, resp_buf - 0x%x\n",
- baud, resp_buf[0]);
+ baud, resp_buf[0]);
if (synched || data_received)
break;
} else
printf("Unknown error code: Baud rate - %d, resp_buf - "
- "0x%x\n", baud, resp_buf[0]);
+ "0x%x\n",
+ baud, resp_buf[0]);
}
return true;
@@ -524,7 +527,7 @@ static bool opr_send_cmds(struct command_node *cmd_buf, uint32_t cmd_num)
for (cmd = 0; cmd < cmd_num; cmd++, cur_cmd++) {
if (com_port_write_bin(port_handle, cur_cmd->cmd,
- cur_cmd->cmd_size) == true) {
+ cur_cmd->cmd_size) == true) {
time(&start);
do {
@@ -533,15 +536,17 @@ static bool opr_send_cmds(struct command_node *cmd_buf, uint32_t cmd_num)
} while ((read < cur_cmd->resp_size) &&
(elapsed_time <= OPR_TIMEOUT));
com_port_read_bin(port_handle, resp_buf,
- cur_cmd->resp_size);
+ cur_cmd->resp_size);
if (elapsed_time > OPR_TIMEOUT)
- display_color_msg(FAIL,
+ display_color_msg(
+ FAIL,
"ERROR: [%d] bytes received for read, "
"[%d] bytes are expected\n",
read, cur_cmd->resp_size);
} else {
- display_color_msg(FAIL,
+ display_color_msg(
+ FAIL,
"ERROR: Failed to send Command number %d\n",
cmd);
return false;