Re: Loader serial baud rate control

From: Emanuel Strobl <Emanuel.strobl_at_gmx.net>
Date: Sun, 14 Aug 2005 05:09:42 +0200
Am Sonntag, 14. August 2005 03:43 CEST schrieb Ian Dowse:
> Currently the baud rate used by the i386/amd64 loader for a serial
> console is hard-coded as 9600 baud and you need to recompile the
> loader to change it. Below is a patch that adds a "comconsole_speed"
> loader environment variable so that the speed can be changed from
> loader.conf or manually from the loader prompt. It doesn't quite
> do what you want though, since the loader has already printed a
> number of things by the time it reads loader.conf. Any comments?

Yes :)

Thanks a lot for your work!


I recognized that BOOT_COMCONSOLE_SPEED in make.conf doesn't change the 
console behaviour anymore (as with beta2 from last Thursday). I can 
successfully set the speed in /etc/ttys, also the boot bits respect the 
setting, but kernel console is 9600.
Having a loader tunable for serial console speed was really great!!!

Since it seems you're firm with the relevant bits, why doesn't setting 
machdep.conspeed in loader.conf work?

Thanks a lot,

-Harry

>
> Ian
>
> Index: i386/libi386/comconsole.c
> ===================================================================
> RCS file: /dump/FreeBSD-CVS/src/sys/boot/i386/libi386/comconsole.c,v
> retrieving revision 1.10
> diff -u -r1.10 comconsole.c
> --- i386/libi386/comconsole.c	16 Sep 2003 11:24:23 -0000	1.10
> +++ i386/libi386/comconsole.c	14 Aug 2005 01:12:52 -0000
> _at__at_ -48,8 +48,13 _at__at_
>  static void	comc_putchar(int c);
>  static int	comc_getchar(void);
>  static int	comc_ischar(void);
> +static int	comc_parsespeed(const char *string);
> +static void	comc_setup(int speed);
> +static int	comc_speed_set(struct env_var *ev, int flags,
> +		    const void *value);
>
>  static int	comc_started;
> +static int	comc_curspeed;
>
>  struct console comconsole = {
>      "comconsole",
> _at__at_ -72,19 +77,29 _at__at_
>  static int
>  comc_init(int arg)
>  {
> +    char speedbuf[16];
> +    char *speedenv;
> +    int speed;
> +
>      if (comc_started && arg == 0)
>  	return 0;
> -    comc_started = 1;
> +    if (!comc_started) {
> +	comc_curspeed = COMSPEED;
> +	speedenv = getenv("comconsole_speed");
> +	if (speedenv != NULL) {
> +	    speed = comc_parsespeed(speedenv);
> +	    if (speed > 0)
> +		comc_curspeed = speed;
> +	}
>
> -    outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
> -    outb(COMPORT + com_dlbl, COMC_BPS(COMSPEED) & 0xff);
> -    outb(COMPORT + com_dlbh, COMC_BPS(COMSPEED) >> 8);
> -    outb(COMPORT + com_cfcr, COMC_FMT);
> -    outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
> +	sprintf(speedbuf, "%d", comc_curspeed);
> +	unsetenv("comconsole_speed");
> +	env_setenv("comconsole_speed", EV_VOLATILE, speedbuf, comc_speed_set,
> +	    env_nounset);
> +    }
> +    comc_started = 1;
>
> -    do
> -        inb(COMPORT + com_data);
> -    while (inb(COMPORT + com_lsr) & LSR_RXRDY);
> +    comc_setup(comc_curspeed);
>
>      return(0);
>  }
> _at__at_ -112,3 +127,51 _at__at_
>  {
>      return(inb(COMPORT + com_lsr) & LSR_RXRDY);
>  }
> +
> +static int
> +comc_speed_set(struct env_var *ev, int flags, const void *value)
> +{
> +    int speed;
> +
> +    if (value == NULL || (speed = comc_parsespeed(value)) <= 0) {
> +	printf("Invalid speed\n");
> +	return (CMD_ERROR);
> +    }
> +
> +    if (comc_curspeed != speed)
> +	comc_setup(speed);
> +
> +    env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
> +
> +    return (CMD_OK);
> +}
> +
> +static void
> +comc_setup(int speed)
> +{
> +
> +    comc_curspeed = speed;
> +
> +    outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
> +    outb(COMPORT + com_dlbl, COMC_BPS(speed) & 0xff);
> +    outb(COMPORT + com_dlbh, COMC_BPS(speed) >> 8);
> +    outb(COMPORT + com_cfcr, COMC_FMT);
> +    outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
> +
> +    do
> +        inb(COMPORT + com_data);
> +    while (inb(COMPORT + com_lsr) & LSR_RXRDY);
> +}
> +
> +static int
> +comc_parsespeed(const char *speedstr)
> +{
> +    char *p;
> +    int speed;
> +
> +    speed = strtol(speedstr, &p, 0);
> +    if (p == speedstr || *p != '\0' || speed <= 0)
> +	return (-1);
> +
> +    return (speed);
> +}
>
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to
> "freebsd-current-unsubscribe_at_freebsd.org"

Received on Sun Aug 14 2005 - 01:10:01 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:41 UTC