summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/go.c5
-rw-r--r--commands/i2c.c56
-rw-r--r--commands/loadb.c78
-rw-r--r--commands/loads.c6
4 files changed, 94 insertions, 51 deletions
diff --git a/commands/go.c b/commands/go.c
index f25db48ca2..fb319b320c 100644
--- a/commands/go.c
+++ b/commands/go.c
@@ -60,10 +60,7 @@ static int do_go(int argc, char *argv[])
shutdown_barebox();
- if (do_execute)
- do_execute(func, argc - 1, &argv[1]);
- else
- func(argc - 1, &argv[1]);
+ func(argc - 1, &argv[1]);
/*
* The application returned. Since we have shutdown barebox and
diff --git a/commands/i2c.c b/commands/i2c.c
index d6c5412762..f4ffc99827 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -22,30 +22,16 @@
#include <getopt.h>
#include <i2c/i2c.h>
-static int do_i2c_probe(int argc, char *argv[])
+static void i2c_probe_range(struct i2c_adapter *adapter, int startaddr, int stopaddr)
{
- struct i2c_adapter *adapter;
- struct i2c_client client;
- int startaddr = -1, stopaddr = -1, addr, ret;
+ struct i2c_client client = {};
+ int addr;
+ int ret;
u8 reg;
- if (argc < 4)
- return COMMAND_ERROR_USAGE;
-
- adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
- if (!adapter)
- return -ENODEV;
client.adapter = adapter;
- startaddr = simple_strtol(argv[2], NULL, 0);
- stopaddr = simple_strtol(argv[3], NULL, 0);
- if ((startaddr == -1) || (stopaddr == -1) || (startaddr > stopaddr))
- return COMMAND_ERROR_USAGE;
-
- if (stopaddr > 0x7F)
- stopaddr = 0x7F;
-
- printf("probing i2c range 0x%02x - 0x%02x :\n", startaddr, stopaddr);
+ printf("probing i2c%d range 0x%02x-0x%02x: ", adapter->nr, startaddr, stopaddr);
for (addr = startaddr; addr <= stopaddr; addr++) {
client.addr = addr;
ret = i2c_write_reg(&client, 0x00, &reg, 0);
@@ -53,6 +39,38 @@ static int do_i2c_probe(int argc, char *argv[])
printf("0x%02x ", addr);
}
printf("\n");
+}
+
+static int do_i2c_probe(int argc, char *argv[])
+{
+ struct i2c_adapter *adapter = NULL;
+ int startaddr = 0, stopaddr = 0x7f;
+
+ if (argc > 1) {
+ adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0));
+ if (!adapter)
+ return -ENODEV;
+ }
+
+ if (argc > 2)
+ startaddr = simple_strtol(argv[2], NULL, 0);
+ if (argc > 3)
+ startaddr = simple_strtol(argv[3], NULL, 0);
+
+
+ if (startaddr > stopaddr)
+ return COMMAND_ERROR_USAGE;
+
+ if (stopaddr > 0x7F)
+ stopaddr = 0x7F;
+
+ if (adapter) {
+ i2c_probe_range(adapter, startaddr, stopaddr);
+ } else {
+ for_each_i2c_adapter(adapter)
+ i2c_probe_range(adapter, startaddr, stopaddr);
+ }
+
return 0;
}
diff --git a/commands/loadb.c b/commands/loadb.c
index aabb00ab20..6223512477 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -67,13 +67,24 @@ static char his_eol; /* character he needs at end of packet */
static int his_pad_count; /* number of pad chars he needs */
static char his_pad_char; /* pad chars he needs */
static char his_quote; /* quote chars he'll use */
+static struct console_device *cdev; /* The console device we are using */
+
+static void sendchar(char c)
+{
+ cdev->putc(cdev, c);
+}
+
+static int receivechar(void)
+{
+ return cdev->getc(cdev);
+}
static void send_pad(void)
{
int count = his_pad_count;
while (count-- > 0)
- console_putc(CONSOLE_STDOUT, his_pad_char);
+ sendchar(his_pad_char);
}
/* converts escaped kermit char to binary char */
@@ -100,9 +111,8 @@ static int chk1(char *buffer)
static void s1_sendpacket(char *packet)
{
send_pad();
- while (*packet) {
- console_putc(CONSOLE_STDOUT, *packet++);
- }
+ while (*packet)
+ sendchar(*packet++);
}
static char a_b[24];
@@ -397,7 +407,7 @@ static int k_recv(void)
/* get a packet */
/* wait for the starting character or ^C */
for (;;) {
- switch (getc()) {
+ switch (receivechar()) {
case START_CHAR: /* start packet */
goto START;
case ETX_CHAR: /* ^C waiting for packet */
@@ -411,13 +421,13 @@ static int k_recv(void)
START:
/* get length of packet */
sum = 0;
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
length = untochar(new_char);
/* get sequence number */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -447,7 +457,7 @@ START:
/* END NEW CODE */
/* get packet type */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -457,19 +467,19 @@ START:
if (length == -2) {
/* (length byte was 0, decremented twice) */
/* get the two length bytes */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_hi = untochar(new_char);
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_lo = untochar(new_char);
length = len_hi * 95 + len_lo;
/* check header checksum */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char !=
@@ -488,7 +498,7 @@ START:
}
}
while (length > 1) {
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -505,13 +515,13 @@ START:
}
}
/* get and validate checksum character */
- new_char = getc();
+ new_char = receivechar();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
goto packet_error;
/* get END_CHAR */
- new_char = getc();
+ new_char = receivechar();
if (new_char != END_CHAR) {
packet_error:
/* restore state machines */
@@ -566,8 +576,8 @@ static ulong load_serial_bin(void)
* box some time (100 * 1 ms)
*/
for (i = 0; i < 100; ++i) {
- if (tstc())
- (void)getc();
+ if (cdev->tstc(cdev))
+ (void)receivechar();;
udelay(1000);
}
@@ -607,9 +617,10 @@ static int do_load_serial_bin(int argc, char *argv[])
int rcode = 0, ret;
int opt;
char *output_file = NULL;
- struct console_device *cdev = NULL;
+ int current_active;
+ char *console_dev_name = NULL;
- while ((opt = getopt(argc, argv, "f:b:o:c")) > 0) {
+ while ((opt = getopt(argc, argv, "f:b:o:c:")) > 0) {
switch (opt) {
case 'f':
output_file = optarg;
@@ -620,18 +631,30 @@ static int do_load_serial_bin(int argc, char *argv[])
case 'o':
offset = (int)simple_strtoul(optarg, NULL, 10);
break;
+ case 'c':
+ console_dev_name = optarg;
+ break;
default:
perror(argv[0]);
return 1;
}
}
- cdev = console_get_first_active();
- if (NULL == cdev) {
- printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
- return -ENODEV;
+ if (console_dev_name) {
+ cdev = console_get_by_name(console_dev_name);
+ if (!cdev) {
+ printf("Console %s not found\n", console_dev_name);
+ return -ENODEV;
+ }
+ } else {
+ cdev = console_get_first_active();
+ if (!cdev) {
+ printf("No console device with STDIN and STDOUT\n");
+ return -ENODEV;
+ }
}
current_baudrate = console_get_baudrate(cdev);
+ current_active = console_get_active(cdev);
/* Load Defaults */
if (load_baudrate == 0)
@@ -656,13 +679,15 @@ static int do_load_serial_bin(int argc, char *argv[])
}
}
+ printf("## Ready for binary (kermit) download "
+ "to 0x%08lX offset on %s device at %d bps...\n", offset,
+ output_file, load_baudrate);
+
+ console_set_active(cdev, 0);
ret = console_set_baudrate(cdev, load_baudrate);
if (ret)
return ret;
- printf("## Ready for binary (kermit) download "
- "to 0x%08lX offset on %s device at %d bps...\n", offset,
- output_file, load_baudrate);
addr = load_serial_bin();
if (addr == 0) {
printf("## Binary (kermit) download aborted\n");
@@ -673,6 +698,8 @@ static int do_load_serial_bin(int argc, char *argv[])
if (ret)
return ret;
+ console_set_active(cdev, current_active);
+
close(ofd);
ofd = 0;
return rcode;
@@ -684,6 +711,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin)")
BAREBOX_CMD_HELP_OPT("-o OFFS", "destination file OFFSet (default 0)")
BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate)")
+BAREBOX_CMD_HELP_OPT("-c CONSOLE", "Specify console (default: first active console")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(loadb)
diff --git a/commands/loads.c b/commands/loads.c
index 24093e191f..aa3095ee8c 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -127,7 +127,7 @@ static ulong load_serial(ulong offset)
}
if (!do_echo) { /* print a '.' every 100 lines */
if ((++line_count % 100) == 0)
- console_putc(CONSOLE_STDOUT, '.');
+ putchar('.');
}
}
@@ -144,7 +144,7 @@ static int read_record(char *buf, ulong len)
for (p=buf; p < buf+len; ++p) {
c = getc(); /* read character */
if (do_echo)
- console_putc(CONSOLE_STDOUT, c);
+ putchar(c);
switch (c) {
case '\r':
@@ -259,7 +259,7 @@ static int write_record(char *buf)
char c;
while ((c = *buf++))
- console_putc(CONSOLE_STDOUT, c);
+ putchar(c);
/* Check for the console hangup (if any different from serial) */