[PATCH 2/4] barebox remote control
Sascha Hauer
s.hauer at pengutronix.de
Sun Jun 14 21:51:39 PDT 2015
Hi Peter,
On Fri, Jun 12, 2015 at 12:36:48PM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:
>
> Hi,
>
> > This adds the ability to control barebox over serial lines. The regular
> > console is designed for human input and is unsuitable for controlling
> > barebox from scripts since characters can be lost on both ends, the data
> > stream contains escape sequences and the prompt cannot be easily matched
> > upon.
> > This approach is based on the RATP protocol. RATP packages start with a
> > binary 0x01 which does not occur in normal console data. Whenever a
> > 0x01 character is detected in the console barebox goes into RATP mode.
> > The RATP packets contain a simple structure with a command/respone
> > type and data for that type. Currently defined types are:
>
>
> > +int barebox_ratp(struct console_device *cdev)
> > +{
> > + void *buf = xmalloc(512);
> > + int ret;
> > + size_t len;
> > + struct ratp_ctx *ctx;
> > + struct ratp *ratp;
> > +
> > + ctx = xzalloc(sizeof(*ctx));
> > + ratp = &ctx->ratp;
> > +
> > + ratp->send = ratp_send;
> > + ratp->recv = ratp_recv;
> > + ctx->cdev = cdev;
> > +
> > + ret = ratp_establish(ratp, false, 0);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = ratp_console_register(ctx);
> > + if (ret)
> > + return ret;
>
> You're leaking ctx and buf here (and buf below as well).
Thanks, will fix.
>
> > +
> > + while (1) {
> > + ret = ratp_poll(ratp);
> > + if (ret == -EINTR)
> > + goto out;
> > + if (ratp_closed(ratp))
> > + goto out;
> > +
> > + len = 512;
> > + ret = ratp_recv_data(ratp, buf, &len);
> > + if (ret == -EAGAIN)
> > + continue;
> > +
> > + if (ret < 0)
> > + goto out;
> > +
> > + ret = ratp_bb_dispatch(ctx, buf, len);
> > + if (ret)
> > + break;
> > + }
> > +out:
> > +
> > + console_unregister(&ctx->ratp_console);
> > +
> > + free(ctx);
> > +
> > + return ret;
> > +}
>
>
> > +++ b/crypto/Kconfig
> > @@ -2,6 +2,7 @@ config CRC32
> > bool
>
> > config CRC16
> > + default y
>
> Why?
This is not necessary, it's a leftover from development.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list