summaryrefslogtreecommitdiffstats
path: root/commands/loadb.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-11-11 12:29:22 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-11-17 12:00:29 +0100
commitfa6b6145d1cfb8fc8610478513f5b398f8869343 (patch)
treee968e2fd29cd97472a73fae224e198b5c3d0efcd /commands/loadb.c
parentedc1bfa1fe475031a9b652e0500393cad7f15eae (diff)
downloadbarebox-fa6b6145d1cfb8fc8610478513f5b398f8869343.tar.gz
barebox-fa6b6145d1cfb8fc8610478513f5b398f8869343.tar.xz
loadb: Use local cdev
We already retrieve a console_device using console_get_first_active(). Use this one also to send/receive characters instead of the combined input/output of all console devices with putc/getc. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/loadb.c')
-rw-r--r--commands/loadb.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/commands/loadb.c b/commands/loadb.c
index aabb00ab20..bdf1710fdf 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,7 +617,6 @@ 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;
while ((opt = getopt(argc, argv, "f:b:o:c")) > 0) {
switch (opt) {