Index: sbin/reboot/boot_i386.8 =================================================================== --- sbin/reboot/boot_i386.8 +++ sbin/reboot/boot_i386.8 @@ -257,6 +257,15 @@ combination with the .Fl m option. +.It Fl R +reset the serial terminal if serial console is enabled. This option could +help if prevous boot stages (BIOS, for example) leave the serial terminal +in an unspecified or bogus state. The reset sequence is "\ec" by default +unless it has been overriden by setting +.Va BOOT_COMCONSOLE_RESET_TERM_CMD +in +.Xr make.conf 5 +and recompiling and reinstalling the boot blocks. .It Fl r use the statically configured default for the device containing the root file system Index: stand/common/rbx.h =================================================================== --- stand/common/rbx.h +++ stand/common/rbx.h @@ -43,6 +43,7 @@ #define RBX_NOINTR 0x1c /* -n */ /* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ #define RBX_DUAL 0x1d /* -D */ +#define RBX_RTERM 0x1e /* -R */ /* 0x1f is reserved for log2(RB_BOOTINFO). */ /* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */ Index: stand/defs.mk =================================================================== --- stand/defs.mk +++ stand/defs.mk @@ -177,6 +177,8 @@ # Make sure we use the machine link we're about to create CFLAGS+=-I. +BOOT_COMCONSOLE_RESET_TERM_CMD?= "\ec" + all: ${PROG} .if !defined(NO_OBJ) Index: stand/i386/boot2/Makefile =================================================================== --- stand/i386/boot2/Makefile +++ stand/i386/boot2/Makefile @@ -28,6 +28,7 @@ -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ -DSIOFMT=${B2SIOFMT} \ -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \ + -DSIORST=\"${BOOT_COMCONSOLE_RESET_TERM_CMD}\" \ -I${LDRSRC} \ -Wall -Waggregate-return -Wbad-function-cast -Wno-cast-align \ -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \ Index: stand/i386/boot2/boot2.c =================================================================== --- stand/i386/boot2/boot2.c +++ stand/i386/boot2/boot2.c @@ -55,7 +55,7 @@ #define SECOND 18 /* Circa that many ticks in a second. */ #define ARGS 0x900 -#define NOPT 14 +#define NOPT 15 #define NDEV 3 #define MEM_BASE 0x12 #define MEM_EXT 0x15 @@ -70,7 +70,7 @@ extern uint32_t _end; -static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ +static const char optstr[NOPT] = "DhaCcdgmnpqRrsv"; /* Also 'P', 'S' */ static const unsigned char flags[NOPT] = { RBX_DUAL, RBX_SERIAL, @@ -83,6 +83,7 @@ RBX_NOINTR, RBX_PAUSE, RBX_QUIET, + RBX_RTERM, RBX_DFLTROOT, RBX_SINGLE, RBX_VERBOSE @@ -107,6 +108,7 @@ #if SERIAL static int comspeed = SIOSPD; static uint8_t ioctrl = IO_KEYBOARD; +static const char resettermcmd[] = SIORST; #endif int main(void); @@ -408,8 +410,13 @@ ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) : OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD; if (DO_SIO) { - if (sio_init(115200 / comspeed) != 0) + if (sio_init(115200 / comspeed) != 0) { ioctrl &= ~IO_SERIAL; + } else if (OPT_CHECK(RBX_RTERM)) { + for (i = 0; resettermcmd[i]; i++) + sio_putc(resettermcmd[i]); + sio_flush(); + } } #endif } else { Index: stand/i386/gptboot/Makefile =================================================================== --- stand/i386/gptboot/Makefile +++ stand/i386/gptboot/Makefile @@ -27,6 +27,7 @@ -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ -DSIOFMT=${B2SIOFMT} \ -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \ + -DSIORST=\"${BOOT_COMCONSOLE_RESET_TERM_CMD}\" \ -I${LDRSRC} \ -I${BOOTSRC}/i386/common \ -I${BOOTSRC}/i386/boot2 \ Index: stand/i386/gptboot/gptboot.c =================================================================== --- stand/i386/gptboot/gptboot.c +++ stand/i386/gptboot/gptboot.c @@ -43,7 +43,7 @@ #include "paths.h" #define ARGS 0x900 -#define NOPT 14 +#define NOPT 15 #define NDEV 3 #define MEM_BASE 0x12 #define MEM_EXT 0x15 @@ -59,7 +59,7 @@ extern uint32_t _end; static const uuid_t freebsd_ufs_uuid = GPT_ENT_TYPE_FREEBSD_UFS; -static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ +static const char optstr[NOPT] = "DhaCcdgmnpqRrsv"; /* Also 'P', 'S' */ static const unsigned char flags[NOPT] = { RBX_DUAL, RBX_SERIAL, @@ -72,6 +72,7 @@ RBX_NOINTR, RBX_PAUSE, RBX_QUIET, + RBX_RTERM, RBX_DFLTROOT, RBX_SINGLE, RBX_VERBOSE @@ -83,6 +84,7 @@ static char kname[1024]; static int comspeed = SIOSPD; +static const char resettermcmd[] = SIORST; static struct bootinfo bootinfo; #ifdef LOADER_GELI_SUPPORT static struct geli_boot_args geliargs; @@ -549,8 +551,13 @@ ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) : OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD; if (ioctrl & IO_SERIAL) { - if (sio_init(115200 / comspeed) != 0) + if (sio_init(115200 / comspeed) != 0) { ioctrl &= ~IO_SERIAL; + } else if (OPT_CHECK(RBX_RTERM)) { + for (i = 0; resettermcmd[i]; i++) + sio_putc(resettermcmd[i]); + sio_flush(); + } } } else { for (q = arg--; *q && *q != '('; q++); Index: stand/i386/gptzfsboot/Makefile =================================================================== --- stand/i386/gptzfsboot/Makefile +++ stand/i386/gptzfsboot/Makefile @@ -23,6 +23,7 @@ -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ -DSIOFMT=${B2SIOFMT} \ -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \ + -DSIORST=\"${BOOT_COMCONSOLE_RESET_TERM_CMD}\" \ -I${LDRSRC} \ -I${BOOTSRC}/i386/common \ -I${ZFSSRC} \ Index: stand/i386/isoboot/Makefile =================================================================== --- stand/i386/isoboot/Makefile +++ stand/i386/isoboot/Makefile @@ -23,6 +23,7 @@ -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ -DSIOFMT=${B2SIOFMT} \ -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \ + -DSIORST=\"${BOOT_COMCONSOLE_RESET_TERM_CMD}\" \ -I${LDRSRC} \ -I${BOOTSRC}/i386/common \ -I${BOOTSRC}/i386/boot2 \ Index: stand/i386/isoboot/isoboot.c =================================================================== --- stand/i386/isoboot/isoboot.c +++ stand/i386/isoboot/isoboot.c @@ -43,7 +43,7 @@ #include "paths.h" #define ARGS 0x900 -#define NOPT 14 +#define NOPT 15 #define NDEV 3 #define MEM_BASE 0x12 #define MEM_EXT 0x15 @@ -58,7 +58,7 @@ extern uint32_t _end; -static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ +static const char optstr[NOPT] = "DhaCcdgmnpqRrsv"; /* Also 'P', 'S' */ static const unsigned char flags[NOPT] = { RBX_DUAL, RBX_SERIAL, @@ -71,6 +71,7 @@ RBX_NOINTR, RBX_PAUSE, RBX_QUIET, + RBX_RTERM, RBX_DFLTROOT, RBX_SINGLE, RBX_VERBOSE @@ -83,6 +84,7 @@ static struct dsk dsk; static char kname[1024]; static int comspeed = SIOSPD; +static const char resettermcmd[] = SIORST; static struct bootinfo bootinfo; static vm_offset_t high_heap_base; @@ -472,8 +474,13 @@ ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) : OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD; if (ioctrl & IO_SERIAL) { - if (sio_init(115200 / comspeed) != 0) + if (sio_init(115200 / comspeed) != 0) { ioctrl &= ~IO_SERIAL; + } else if (OPT_CHECK(RBX_RTERM)) { + for (i = 0; resettermcmd[i]; i++) + sio_putc(resettermcmd[i]); + sio_flush(); + } } } else { for (q = arg--; *q && *q != '('; q++); Index: stand/i386/zfsboot/Makefile =================================================================== --- stand/i386/zfsboot/Makefile +++ stand/i386/zfsboot/Makefile @@ -21,6 +21,7 @@ -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ -DSIOFMT=${B2SIOFMT} \ -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \ + -DSIORST=\"${BOOT_COMCONSOLE_RESET_TERM_CMD}\" \ -I${LDRSRC} \ -I${BOOTSRC}/i386/common \ -I${BOOTSRC}/i386 \ Index: stand/i386/zfsboot/zfsboot.c =================================================================== --- stand/i386/zfsboot/zfsboot.c +++ stand/i386/zfsboot/zfsboot.c @@ -49,7 +49,7 @@ #include "libzfs.h" #define ARGS 0x900 -#define NOPT 14 +#define NOPT 15 #define NDEV 3 #define BIOS_NUMDRIVES 0x475 @@ -68,7 +68,7 @@ #ifdef GPT static const uuid_t freebsd_zfs_uuid = GPT_ENT_TYPE_FREEBSD_ZFS; #endif -static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ +static const char optstr[NOPT] = "DhaCcdgmnpqRrsv"; /* Also 'P', 'S' */ static const unsigned char flags[NOPT] = { RBX_DUAL, RBX_SERIAL, @@ -81,6 +81,7 @@ RBX_NOINTR, RBX_PAUSE, RBX_QUIET, + RBX_RTERM, RBX_DFLTROOT, RBX_SINGLE, RBX_VERBOSE @@ -112,6 +113,7 @@ static char kname[1024]; static char rootname[256]; static int comspeed = SIOSPD; +static const char resettermcmd[] = SIORST; static struct bootinfo bootinfo; static uint32_t bootdev; static struct zfs_boot_args zfsargs; @@ -1129,8 +1131,13 @@ ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) : OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD; if (ioctrl & IO_SERIAL) { - if (sio_init(115200 / comspeed) != 0) + if (sio_init(115200 / comspeed) != 0) { ioctrl &= ~IO_SERIAL; + } else if (OPT_CHECK(RBX_RTERM)) { + for (i = 0; resettermcmd[i]; i++) + sio_putc(resettermcmd[i]); + sio_flush(); + } } } if (c == '?') { dnode_phys_t dn;