summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-05-18 16:59:26 -0700
committerRandall Spangler <rspangler@chromium.org>2012-05-21 09:17:51 -0700
commit01e94792e7436e89e55f043982e9446e0759bf25 (patch)
tree8e8dc705a825391449041b81ec061d767231fb91
parentb1bb8314bd852dea40bc7514486ce4e781e14f88 (diff)
downloadchrome-ec-01e94792e7436e89e55f043982e9446e0759bf25.tar.gz
Clean up debug commands to use less space
BUG=none TEST=(run the commands) Change-Id: I6ed4aee169311825190bcc386b86cdc32ba0866a Signed-off-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/lm4/adc.c2
-rw-r--r--chip/lm4/clock.c2
-rw-r--r--chip/lm4/eeprom.c80
-rw-r--r--chip/lm4/i2c.c25
-rw-r--r--chip/lm4/peci.c5
-rw-r--r--common/console.c38
-rw-r--r--common/flash_commands.c63
-rw-r--r--include/util.h2
8 files changed, 79 insertions, 138 deletions
diff --git a/chip/lm4/adc.c b/chip/lm4/adc.c
index d265d0f283..fa1d06e2b8 100644
--- a/chip/lm4/adc.c
+++ b/chip/lm4/adc.c
@@ -177,6 +177,7 @@ DECLARE_IRQ(LM4_IRQ_ADC0_SS3, ss3_interrupt, 2);
/*****************************************************************************/
/* Console commands */
+#ifdef CONSOLE_COMMAND_ECTEMP
static int command_ectemp(int argc, char **argv)
{
int t = adc_read_channel(ADC_CH_EC_TEMP);
@@ -184,6 +185,7 @@ static int command_ectemp(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(ectemp, command_ectemp);
+#endif
static int command_adc(int argc, char **argv)
diff --git a/chip/lm4/clock.c b/chip/lm4/clock.c
index aaa2e9403c..e709fa0b62 100644
--- a/chip/lm4/clock.c
+++ b/chip/lm4/clock.c
@@ -214,7 +214,7 @@ static int command_pll(int argc, char **argv)
/* Disable PLL and set extra divider */
char *e;
div = strtoi(argv[1], &e, 10);
- if (e && *e)
+ if (*e)
return EC_ERROR_INVAL;
LM4_SYSTEM_RCC = LM4_SYSTEM_RCC_SYSDIV(div - 1) |
diff --git a/chip/lm4/eeprom.c b/chip/lm4/eeprom.c
index f5783ad664..3490e6d183 100644
--- a/chip/lm4/eeprom.c
+++ b/chip/lm4/eeprom.c
@@ -119,9 +119,9 @@ int eeprom_hide(int block)
static int command_eeprom_info(int argc, char **argv)
{
- ccprintf("EEPROM: %d blocks of %d bytes\n",
- eeprom_get_block_count(), eeprom_get_block_size());
- ccprintf(" Block-hide flags: 0x%08x\n", LM4_EEPROM_EEHIDE);
+ ccprintf("%d blocks @ %d bytes, hide=0x%08x\n",
+ eeprom_get_block_count(), eeprom_get_block_size(),
+ LM4_EEPROM_EEHIDE);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(eeinfo, command_eeprom_info);
@@ -135,28 +135,22 @@ static int command_eeprom_read(int argc, char **argv)
int rv;
uint32_t d;
- if (argc < 2) {
- ccputs("Usage: eeread <block> [offset]\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 2)
+ return EC_ERROR_INVAL;
block = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid block\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
if (argc > 2) {
offset = strtoi(argv[2], &e, 0);
- if (*e) {
- ccputs("Invalid offset\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
}
rv = eeprom_read(block, offset, sizeof(d), (char *)&d);
if (rv == EC_SUCCESS)
- ccprintf("Block %d offset %d = 0x%08x\n", block, offset, d);
+ ccprintf("%d:%d = 0x%08x\n", block, offset, d);
return rv;
}
DECLARE_CONSOLE_COMMAND(eeread, command_eeprom_read);
@@ -167,63 +161,45 @@ static int command_eeprom_write(int argc, char **argv)
int block = 0;
int offset = 0;
char *e;
- int rv;
uint32_t d;
- if (argc < 4) {
- ccputs("Usage: eeread <block> <offset> <data>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 4)
+ return EC_ERROR_INVAL;
block = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid block\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
offset = strtoi(argv[2], &e, 0);
- if (*e) {
- ccputs("Invalid offset\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
d = strtoi(argv[3], &e, 0);
- if (*e) {
- ccputs("Invalid data\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
- ccprintf("Writing 0x%08x to block %d offset %d...\n", d, block, offset);
- rv = eeprom_write(block, offset, sizeof(d), (char *)&d);
- if (rv == EC_SUCCESS)
- ccputs("done.\n");
- return rv;
+ ccprintf("Writing 0x%08x to %d:%d...\n", d, block, offset);
+ return eeprom_write(block, offset, sizeof(d), (char *)&d);
}
DECLARE_CONSOLE_COMMAND(eewrite, command_eeprom_write);
+#ifdef CONSOLE_COMMAND_EEHIDE
static int command_eeprom_hide(int argc, char **argv)
{
int block = 0;
char *e;
- int rv;
- if (argc < 2) {
- ccputs("Usage: eehide <block>\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 2)
+ return EC_ERROR_INVAL;
block = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid block\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (*e)
+ return EC_ERROR_INVAL;
- ccprintf("Hiding EEPROM block %d...\n", block);
- rv = eeprom_hide(block);
- if (rv == EC_SUCCESS)
- ccprintf("Done.\n");
- return rv;
+ ccprintf("Hiding block %d\n", block);
+ return eeprom_hide(block);
}
DECLARE_CONSOLE_COMMAND(eehide, command_eeprom_hide);
+#endif
/*****************************************************************************/
diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c
index 06ccb07f59..1ebab481e8 100644
--- a/chip/lm4/i2c.c
+++ b/chip/lm4/i2c.c
@@ -34,6 +34,7 @@ static task_id_t task_waiting_on_port[NUM_PORTS];
static struct mutex port_mutex[NUM_PORTS];
extern const struct i2c_port_t i2c_ports[I2C_PORTS_USED];
+
static int wait_idle(int port)
{
int i;
@@ -241,10 +242,9 @@ int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
reg = offset;
/* Send device reg space offset, and read back block length.
- * Keep this session open without a stop
- */
+ * Keep this session open without a stop */
rv = i2c_transmit_receive(port, slave_addr, &reg, 1, &block_length, 1,
- START, NO_STOP);
+ START, NO_STOP);
if (rv)
goto exit;
@@ -252,7 +252,7 @@ int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
block_length = len - 1;
rv = i2c_transmit_receive(port, slave_addr, 0, 0, data, block_length,
- NO_START, STOP);
+ NO_START, STOP);
data[block_length] = 0;
exit:
@@ -313,7 +313,7 @@ static void scan_bus(int port, const char *desc)
int rv;
int a;
- ccprintf("Scanning %s I2C bus (%d)...\n", desc, port);
+ ccprintf("Scanning %d %s\n", desc, port);
mutex_lock(port_mutex + port);
@@ -325,11 +325,10 @@ static void scan_bus(int port, const char *desc)
LM4_I2C_MCS(port) = 0x07;
rv = wait_idle(port);
if (rv == EC_SUCCESS)
- ccprintf("\nFound device at 8-bit addr 0x%02x\n", a);
-}
+ ccprintf("0x%02x\n", a);
+ }
mutex_unlock(port_mutex + port);
-
ccputs("\n");
}
@@ -341,16 +340,12 @@ static int command_i2cread(int argc, char **argv)
int rv;
int d, i;
- if (argc < 3) {
- ccputs("Usage: i2cread <port> <addr> [count]\n");
- return EC_ERROR_UNKNOWN;
- }
+ if (argc < 3)
+ return EC_ERROR_INVAL;
port = strtoi(argv[1], &e, 0);
- if (*e) {
- ccputs("Invalid port\n");
+ if (*e)
return EC_ERROR_INVAL;
- }
for (i = 0; i < I2C_PORTS_USED && port != i2c_ports[i].port; i++)
;
diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c
index 6bbdaa832c..88f3f95b6e 100644
--- a/chip/lm4/peci.c
+++ b/chip/lm4/peci.c
@@ -101,11 +101,10 @@ static int command_peci_temp(int argc, char **argv)
{
int t = peci_get_cpu_temp();
if (t == -1) {
- ccputs("Error reading CPU temperature via PECI\n");
- ccprintf("Error code = 0x%04x\n", LM4_PECI_M0D0 & 0xffff);
+ ccprintf("PECI error 0x%04x\n", LM4_PECI_M0D0 & 0xffff);
return EC_ERROR_UNKNOWN;
}
- ccprintf("Current CPU temperature = %d K = %d C\n", t, t - 273);
+ ccprintf("CPU temp = %d K = %d C\n", t, t - 273);
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp);
diff --git a/common/console.c b/common/console.c
index cebfd573c9..8f21418f43 100644
--- a/common/console.c
+++ b/common/console.c
@@ -163,7 +163,7 @@ static int handle_command(char *input)
if (cmd)
return cmd->handler(argc, argv);
- ccprintf("Command '%s' either not found or ambiguous.\n", argv[0]);
+ ccprintf("Command '%s' not found or ambiguous.\n", argv[0]);
return EC_ERROR_UNKNOWN;
}
@@ -253,30 +253,15 @@ DECLARE_CONSOLE_COMMAND(help, command_help);
/* Set active channels */
static int command_ch(int argc, char **argv)
{
- int m;
+ int i;
char *e;
- /* If no args, print the list of channels */
- if (argc == 1) {
- int i;
- ccputs(" # Mask Enabled Channel\n");
- for (i = 0; i < CC_CHANNEL_COUNT; i++) {
- ccprintf("%2d %08x %c %s\n",
- i, CC_MASK(i),
- (channel_mask & CC_MASK(i)) ? '*' : ' ',
- channel_names[i]);
- cflush();
- }
- return EC_SUCCESS;
- }
-
/* If one arg, set the mask */
if (argc == 2) {
- m = strtoi(argv[1], &e, 0);
- if (e && *e) {
- ccputs("Invalid mask\n");
+ int m = strtoi(argv[1], &e, 0);
+ if (*e)
return EC_ERROR_INVAL;
- }
+
/* No disabling the command output channel */
channel_mask = m | CC_MASK(CC_COMMAND);
@@ -285,8 +270,15 @@ static int command_ch(int argc, char **argv)
return EC_SUCCESS;
}
- /* Otherwise, print help */
- ccputs("Usage: chan [newmask]\n");
- return EC_ERROR_INVAL;
+ /* Print the list of channels */
+ ccputs(" # Mask E Channel\n");
+ for (i = 0; i < CC_CHANNEL_COUNT; i++) {
+ ccprintf("%2d %08x %c %s\n",
+ i, CC_MASK(i),
+ (channel_mask & CC_MASK(i)) ? '*' : ' ',
+ channel_names[i]);
+ cflush();
+ }
+ return EC_SUCCESS;
};
DECLARE_CONSOLE_COMMAND(chan, command_ch);
diff --git a/common/flash_commands.c b/common/flash_commands.c
index 239a57661f..ade35b15c9 100644
--- a/common/flash_commands.c
+++ b/common/flash_commands.c
@@ -24,27 +24,19 @@ static int parse_offset_size(int argc, char **argv, int *offset, int *size)
if (argc >= 1) {
i = (uint32_t)strtoi(argv[0], &e, 0);
- if (e && *e) {
- ccprintf("Invalid offset \"%s\"\n", argv[0]);
+ if (*e)
return EC_ERROR_INVAL;
- }
*offset = i;
- } else if (*offset < 0) {
- ccputs("Must specify offset.\n");
+ } else if (*offset < 0)
return EC_ERROR_INVAL;
- }
if (argc >= 2) {
i = (uint32_t)strtoi(argv[1], &e, 0);
- if (e && *e) {
- ccprintf("Invalid size \"%s\"\n", argv[1]);
+ if (*e)
return EC_ERROR_INVAL;
- }
*size = i;
- } else if (*size < 0) {
- ccputs("Must specify offset and size.\n");
+ } else if (*size < 0)
return EC_ERROR_INVAL;
- }
return EC_SUCCESS;
}
@@ -59,18 +51,18 @@ static int command_flash_info(int argc, char **argv)
int banks = flash_get_size() / flash_get_protect_block_size();
int i;
- ccprintf("Physical size: %4d KB\n", flash_physical_size() / 1024);
- ccprintf("Usable size: %4d KB\n", flash_get_size() / 1024);
- ccprintf("Write block: %4d B\n", flash_get_write_block_size());
- ccprintf("Erase block: %4d B\n", flash_get_erase_block_size());
- ccprintf("Protect block: %4d B\n", flash_get_protect_block_size());
+ ccprintf("Physical:%4d KB\n", flash_physical_size() / 1024);
+ ccprintf("Usable: %4d KB\n", flash_get_size() / 1024);
+ ccprintf("Write: %4d B\n", flash_get_write_block_size());
+ ccprintf("Erase: %4d B\n", flash_get_erase_block_size());
+ ccprintf("Protect: %4d B\n", flash_get_protect_block_size());
i = flash_get_protect_lock();
- ccprintf("Protect lock: %s%s\n",
+ ccprintf("Lock: %s%s\n",
(i & FLASH_PROTECT_LOCK_SET) ? "LOCKED" : "unlocked",
- (i & FLASH_PROTECT_LOCK_APPLIED) ? " AND APPLIED" : "");
- ccprintf("WP pin: %s\n", (i & FLASH_PROTECT_PIN_ASSERTED) ?
- "ASSERTED" : "deasserted");
+ (i & FLASH_PROTECT_LOCK_APPLIED) ? ",APPLIED" : "");
+ ccprintf("WP pin: %sasserted\n",
+ (i & FLASH_PROTECT_PIN_ASSERTED) ? "" : "de");
wp = flash_get_protect_array();
@@ -103,8 +95,7 @@ static int command_flash_erase(int argc, char **argv)
if (rv)
return rv;
- ccprintf("Erasing %d bytes at offset 0x%x (%d)...\n",
- size, offset, offset);
+ ccprintf("Erasing %d bytes at 0x%x...\n", size, offset, offset);
return flash_erase(offset, size);
}
DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase);
@@ -123,15 +114,13 @@ static int command_flash_write(int argc, char **argv)
if (rv)
return rv;
- if (size > shared_mem_size()) {
- ccputs("Truncating size\n");
+ if (size > shared_mem_size())
size = shared_mem_size();
- }
/* Acquire the shared memory buffer */
rv = shared_mem_acquire(size, 0, &data);
if (rv) {
- ccprintf("Unable to acquire %d byte buffer\n", size);
+ ccputs("Can't get shared mem\n");
return rv;
}
@@ -139,13 +128,9 @@ static int command_flash_write(int argc, char **argv)
for (i = 0; i < size; i++)
data[i] = i;
- ccprintf("Writing %d bytes to offset 0x%x (%d)...\n",
+ ccprintf("Writing %d bytes to 0x%x...\n",
size, offset, offset);
rv = flash_write(offset, size, data);
- if (rv == EC_SUCCESS)
- ccputs("done.\n");
- else
- ccprintf("failed. (error %d)\n", rv);
/* Free the buffer */
shared_mem_release(data);
@@ -155,21 +140,14 @@ static int command_flash_write(int argc, char **argv)
DECLARE_CONSOLE_COMMAND(flashwrite, command_flash_write);
-static const char flash_wp_help[] =
- "Usage: flashwp <now | set | clear> <offset> [size]\n"
- " or: flashwp <lock | unlock>\n";
-
-
static int command_flash_wp(int argc, char **argv)
{
int offset = -1;
int size = flash_get_protect_block_size();
int rv;
- if (argc < 2) {
- ccputs(flash_wp_help);
+ if (argc < 2)
return EC_ERROR_INVAL;
- }
/* Commands that don't need offset and size */
if (!strcasecmp(argv[1], "lock"))
@@ -188,11 +166,8 @@ static int command_flash_wp(int argc, char **argv)
return flash_set_protect(offset, size, 1);
else if (!strcasecmp(argv[1], "clear"))
return flash_set_protect(offset, size, 0);
- else {
- ccputs(flash_wp_help);
+ else
return EC_ERROR_INVAL;
- }
-
}
DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp);
diff --git a/include/util.h b/include/util.h
index 6bbb8dd7df..68e4668f03 100644
--- a/include/util.h
+++ b/include/util.h
@@ -68,6 +68,8 @@ void *memmove(void *dest, const void *src, int len);
int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, int size);
int strlen(const char *s);
+
+/* Like strtol(), but for integers. */
int strtoi(const char *nptr, char **endptr, int base);
/* Like strncpy(), but guarantees null termination. */