Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src



Hi,

Your work is attractive for me.
However with this changes and probabley related commits,
bootx64.efi prevents kernel boot for my laptops.
Kernel boot process just stopped after loaded.

Could you please take a look at my problem?

Thank you.

"Emmanuel Dreyfus" <manu%netbsd.org@localhost> writes:

> Module Name:	src
> Committed By:	manu
> Date:		Thu Oct  9 16:10:03 UTC 2025
>
> Modified Files:
> 	src/share/man/man8/man8.x86: boot.8
> 	src/sys/arch/i386/stand/efiboot: boot.c efiboot.h eficons.c
> 	src/sys/arch/i386/stand/lib: libi386.h
>
> Log Message:
> Add support for USB-to-serial adapter in UEFI bootstrap.
>
> This change lets UEFI bootstrap use any UEFI supported serial port.
> com0 to com3 remain used for EISA based serial ports. com4 and over
> are used for serial ports based on something else (USB, PCI or whatever).
>
> Support for non-EISA serial ports may be provided by UEFI. An open
> source UEFI driver exists for FTDI FT232R USB-to-serial adapter.
>
> The change also introduce the kconsdev command, to select the kernel
> console device without altering the bootstrap console device. This
> useful because the device names can differ in bootstrap and kernel.
> For instance an USB-to-serial device could be com4 in boostrap and
> ucom0 for the kernel.
>
> An upcoming change will add console suport to ucom(4).
>
>
> To generate a diff of this commit:
> cvs rdiff -u -r1.35 -r1.36 src/share/man/man8/man8.x86/boot.8
> cvs rdiff -u -r1.33 -r1.34 src/sys/arch/i386/stand/efiboot/boot.c
> cvs rdiff -u -r1.12 -r1.13 src/sys/arch/i386/stand/efiboot/efiboot.h
> cvs rdiff -u -r1.15 -r1.16 src/sys/arch/i386/stand/efiboot/eficons.c
> cvs rdiff -u -r1.55 -r1.56 src/sys/arch/i386/stand/lib/libi386.h
>
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
>
> Modified files:
>
> Index: src/share/man/man8/man8.x86/boot.8
> diff -u src/share/man/man8/man8.x86/boot.8:1.35 src/share/man/man8/man8.x86/boot.8:1.36
> --- src/share/man/man8/man8.x86/boot.8:1.35	Tue May 20 12:26:02 2025
> +++ src/share/man/man8/man8.x86/boot.8	Thu Oct  9 16:10:03 2025
> @@ -1,4 +1,4 @@
> -.\"	$NetBSD: boot.8,v 1.35 2025/05/20 12:26:02 pgoyette Exp $
> +.\"	$NetBSD: boot.8,v 1.36 2025/10/09 16:10:03 manu Exp $
>  .\"
>  .\" Copyright (c) 1991, 1993
>  .\"	The Regents of the University of California.  All rights reserved.
> @@ -414,6 +414,46 @@ Setting the
>  with the
>  .Li pc
>  device is not possible.
> +.Pp
> +UEFI may support some USB and PCI based serial ports. See the 
> +.Sx UEFI serial ports
> +section for details. Using the
> +.Ic consdev
> +command without argument lists the available ports. 
> +.Ar com0
> +to
> +.Ar com3
> +are reserved for standard ISA serial ports, other ports are assigned to
> +.Ar com4
> +and beyond. The generic
> +.Ar com{unit}[,speed]
> +syntax can be used to select any port.
> +.Pp
> +Bootstrap can tell the kernel to use an USB-to-serial adapter for console
> +using the
> +.Ar ucom{unit}[,speed]
> +syntax.
> +No console switch happens in bootstrap, and kernel
> +console initialization will be deferred after USB devices attachment.
> +This means early boot will be silent, and 
> +.Xr userconf 4
> +interactive mode cannot be used. Default
> +.Ar ucom
> +speed is 115200.
> +.It Ic kconsdev Ar dev\| Ns Oo Ns Ic \&, Ns Ar speed Oc
> +Configure the kernel console like
> +.Ic consdev
> +but do not attempt to switch console in bootstrap. This is useful 
> +when using USB-to-serial adapter that is known as a
> +.Ar com
> +device in bootstrap but as
> +.Ar ucom
> +device for the kernel. One may use a syntax like:
> +.Bd -literal -offset indent
> +consdev com4,115200
> +kconsdev ucom0,115200
> +.Ed
> +Note that command ordering matters. 
>  .It Ic dev Op Ar device
>  Set the default drive and partition for subsequent file system
>  operations.
> @@ -870,6 +910,38 @@ device.
>  So you can only boot from unit 0.
>  .El
>  .El
> +.Sh UEFI serial ports
> +Serial ports supported by an UEFI driver can be used in UEFI
> +and in NetBSD bootstrap. UEFI usually supports ISA serial ports,
> +and it may support PCI or USB to serial adapters, depending on
> +vendor-specific implmentations.
> +.Pp
> +An open source UEFI driver is available form Tianocore EDK2,
> +for USB-to-serial adapters using the FTDI FT232R chip. USB 
> +vendor ID and product ID for that devices are
> +.Ar 0x0403
> +and
> +.Ar 0x6001.
> +.Pp
> +To use it, obtain the 
> +.Pa FtdiUsbSerialDxe.efi
> +driver from Tianocore EDK2 and save it in the EFI bootstrap partiton,
> +for instance in
> +.Pa /EFI/EDK2/FtdiUsbSerialDxe.efi 
> +then create a 
> +.Pa /EFI/boot/startup.nsh
> +script containing something like
> +.Bd -literal -offset indent
> +FS0:
> +load \\EFI\\EDK2\\FtdiUsbSerialDxe.efi
> +bootx64.efi
> +.Ed
> +.Pp
> +Then make sure UEFI boots into UEFI shell. If it is not available in the
> +built-in options, 
> +.Pa Shell.efi
> +can be obtained from Tianocore EDK2 and installed in 
> +.Pa /EFI/boot/Shell.efi
>  .Sh FILES
>  .Bl -tag -width /usr/mdec/bootxx_fstype -compact
>  .It Pa /boot
>
> Index: src/sys/arch/i386/stand/efiboot/boot.c
> diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.33 src/sys/arch/i386/stand/efiboot/boot.c:1.34
> --- src/sys/arch/i386/stand/efiboot/boot.c:1.33	Thu Jul 31 02:59:13 2025
> +++ src/sys/arch/i386/stand/efiboot/boot.c	Thu Oct  9 16:10:03 2025
> @@ -1,4 +1,4 @@
> -/*	$NetBSD: boot.c,v 1.33 2025/07/31 02:59:13 pgoyette Exp $	*/
> +/*	$NetBSD: boot.c,v 1.34 2025/10/09 16:10:03 manu Exp $	*/
>  
>  /*-
>   * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
> @@ -71,7 +71,9 @@ void	command_help(char *);
>  void	command_quit(char *);
>  void	command_boot(char *);
>  void	command_pkboot(char *);
> +void	command_consdev_subr(char *, bool);
>  void	command_consdev(char *);
> +void	command_kconsdev(char *);
>  void	command_root(char *);
>  void	command_dev(char *);
>  void	command_devpath(char *);
> @@ -97,6 +99,7 @@ const struct bootblk_command commands[] 
>  	{ "boot",	command_boot },
>  	{ "pkboot",	command_pkboot },
>  	{ "consdev",	command_consdev },
> +	{ "kconsdev",	command_kconsdev },
>  	{ "root",	command_root },
>  	{ "dev",	command_dev },
>  	{ "devpath",	command_devpath },
> @@ -395,9 +398,16 @@ command_help(char *arg)
>  	       "     (ex. \"hd0a:netbsd.old -s\")\n"
>  	       "pkboot [dev:][filename] [-12acdqsvxz]\n"
>  	       "dev [dev:]\n"
> -	       "consdev {pc|com[0123][,{speed}]|com,{ioport}[,{speed}]}\n"
> -	       "root    {spec}\n"
> -	       "     spec can be disk, e.g. wd0, sd0\n"
> +	       "consdev {cons_spec}\n"
> +	       "kconsdev {cons_spec}\n"
> +	       "      cons_spec can be\n"
> +	       "      pc for keyboard and monitor\n"
> +	       "      com[0123][,{speed}\n"
> +	       "      com[,{addr}[,{speed}]] for EISA serial port\n"
> +	       "      com{unit}[,{speed}]] for other serial port\n"
> +	       "      ucom{unit}[,{speed}] for USB-to-serial adapter\n"
> +	       "root    {root_spec}\n"
> +	       "     root_spec can be disk, e.g. wd0, sd0\n"
>  	       "     or string like wedge:name\n"
>  	       "devpath\n"
>  	       "efivar\n"
> @@ -539,27 +549,46 @@ static const struct cons_devs {
>  	const char	*name;
>  	u_int		tag;
>  	int		ioport;
> +	bool		parse_unit;
>  } cons_devs[] = {
> -	{ "pc",		CONSDEV_PC,   0 },
> -	{ "com0",	CONSDEV_COM0, 0 },
> -	{ "com1",	CONSDEV_COM1, 0 },
> -	{ "com2",	CONSDEV_COM2, 0 },
> -	{ "com3",	CONSDEV_COM3, 0 },
> -	{ "com0kbd",	CONSDEV_COM0KBD, 0 },
> -	{ "com1kbd",	CONSDEV_COM1KBD, 0 },
> -	{ "com2kbd",	CONSDEV_COM2KBD, 0 },
> -	{ "com3kbd",	CONSDEV_COM3KBD, 0 },
> -	{ "com",	CONSDEV_COM0, -1 },
> -	{ "auto",	CONSDEV_AUTO, 0 },
> -	{ NULL,		0 }
> +	{ "pc",		CONSDEV_PC,   0, false },
> +	{ "com0",	CONSDEV_COM0, 0, false },
> +	{ "com1",	CONSDEV_COM1, 0, false },
> +	{ "com2",	CONSDEV_COM2, 0, false },
> +	{ "com3",	CONSDEV_COM3, 0, false },
> +	{ "com0kbd",	CONSDEV_COM0KBD, 0, false },
> +	{ "com1kbd",	CONSDEV_COM1KBD, 0, false },
> +	{ "com2kbd",	CONSDEV_COM2KBD, 0, false },
> +	{ "com3kbd",	CONSDEV_COM3KBD, 0, false },
> +	{ "ucom",	CONSDEV_UCOM, 0, true },
> +	{ "com",	CONSDEV_COM0, -1, false }, /* backward compatible */
> +	{ "com",	CONSDEV_COM,  0, true },  /* can match e.g.: com8 */
> +	{ "auto",	CONSDEV_AUTO, 0, false },
> +	{ NULL,		0, 0, false }
>  };
>  
>  void
>  command_consdev(char *arg)
>  {
> +	return command_consdev_subr(arg, true);
> +}
> +
> +void
> +command_kconsdev(char *arg)
> +{
> +	return command_consdev_subr(arg, false);
> +}
> +
> +void
> +command_consdev_subr(char *arg, bool switchcons)
> +{
>  	const struct cons_devs *cdp;
>  	char *sep, *sep2 = NULL;
>  	int ioport, speed = 0;
> +	int unit;
> +	size_t xname_len;
> +	size_t devname_len;
> +	char *cp;
>  
>  	if (*arg == '\0') {
>  		efi_cons_show();
> @@ -574,8 +603,36 @@ command_consdev(char *arg)
>  			*sep2++ = '\0';
>  	}
>  
> +
> +	/*
> +	 * arg is for instance com5 or com5,0x3f8,115200
> +	 * we compute devname_len = strlen("com")
> +	 *            unit = 5
> +	 */
> +	xname_len = strlen(arg);
> +	devname_len = xname_len;
> +	unit = -1;
> +	cp = strchr(arg, (int)',');
> +	if (cp == NULL)
> +		cp = arg + xname_len;
> +	while (--cp >= arg) {
> +		if (!isdigit((int)*cp)) {
> +			if (cp - arg > 1) {
> +				devname_len = cp + 1 - arg;
> +				unit = (int)strtoul(cp + 1, NULL, 10);
> +				break;
> +			}
> +		}
> +	}
> +
>  	for (cdp = cons_devs; cdp->name; cdp++) {
> -		if (strcmp(arg, cdp->name) == 0) {
> +		bool match;
> +
> +		if (cdp->parse_unit)
> +			match = (strncmp(arg, cdp->name, devname_len) == 0);
> +		else
> +			match = (strcmp(arg, cdp->name) == 0);
> +		if (match) {
>  			ioport = cdp->ioport;
>  			if (cdp->tag == CONSDEV_PC || cdp->tag == CONSDEV_AUTO) {
>  				if (sep != NULL || sep2 != NULL)
> @@ -604,9 +661,12 @@ command_consdev(char *arg)
>  						goto error;
>  				}
>  			}
> -			efi_consinit(cdp->tag, ioport, speed);
> -			clearit();
> -			print_bootcfg_banner(bootprog_name, bootprog_rev);
> +			efi_consinit(cdp->tag, ioport, unit, speed, switchcons);
> +			if (switchcons) {
> +				clearit();
> +				print_bootcfg_banner(bootprog_name,
> +				    bootprog_rev);
> +			}
>  			return;
>  		}
>  	}
>
> Index: src/sys/arch/i386/stand/efiboot/efiboot.h
> diff -u src/sys/arch/i386/stand/efiboot/efiboot.h:1.12 src/sys/arch/i386/stand/efiboot/efiboot.h:1.13
> --- src/sys/arch/i386/stand/efiboot/efiboot.h:1.12	Thu Apr 20 00:42:24 2023
> +++ src/sys/arch/i386/stand/efiboot/efiboot.h	Thu Oct  9 16:10:03 2025
> @@ -1,4 +1,4 @@
> -/*	$NetBSD: efiboot.h,v 1.12 2023/04/20 00:42:24 manu Exp $	*/
> +/*	$NetBSD: efiboot.h,v 1.13 2025/10/09 16:10:03 manu Exp $	*/
>  
>  /*-
>   * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
> @@ -70,7 +70,7 @@ int utf8_to_ucs2(const char *, CHAR16 **
>  
>  /* eficons.c */
>  int cninit(void);
> -void efi_consinit(int, int, int);
> +void efi_consinit(int, int, int, int, bool);
>  void efi_cons_show(void);
>  void command_text(char *);
>  void command_gop(char *);
>
> Index: src/sys/arch/i386/stand/efiboot/eficons.c
> diff -u src/sys/arch/i386/stand/efiboot/eficons.c:1.15 src/sys/arch/i386/stand/efiboot/eficons.c:1.16
> --- src/sys/arch/i386/stand/efiboot/eficons.c:1.15	Thu Jun 19 15:00:17 2025
> +++ src/sys/arch/i386/stand/efiboot/eficons.c	Thu Oct  9 16:10:03 2025
> @@ -1,4 +1,4 @@
> -/*	$NetBSD: eficons.c,v 1.15 2025/06/19 15:00:17 manu Exp $	*/
> +/*	$NetBSD: eficons.c,v 1.16 2025/10/09 16:10:03 manu Exp $	*/
>  
>  /*-
>   * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
> @@ -52,7 +52,8 @@ static CHAR16 keybuf[16];
>  static int keybuf_read = 0;
>  static int keybuf_write = 0;
>  
> -static SERIAL_IO_INTERFACE *serios[4];
> +#define EISA_COM_COUNT 4
> +static SERIAL_IO_INTERFACE *serios[12]; /* 4 EISA com slots, 8 others */
>  static int default_comspeed =
>  #if defined(CONSPEED)
>      CONSPEED;
> @@ -73,6 +74,7 @@ static int efi_cons_putc(int);
>  static int efi_cons_iskey(int);
>  static int efi_cons_waitforinputevent(uint64_t);
>  
> +static int efi_com_consdev2unit(int); 
>  static void efi_com_probe(void);
>  static bool efi_valid_com(int);
>  static int efi_com_init(int, int);
> @@ -89,7 +91,7 @@ static int raw_com_waitforinputevent(uin
>  
>  static int efi_find_gop_mode(char *);
>  
> -static int iodev;
> +static int com_unit = -1;
>  static int (*internal_getchar)(void) = efi_cons_getc;
>  static int (*internal_putchar)(int) = efi_cons_putc;
>  static int (*internal_iskey)(int) = efi_cons_iskey;
> @@ -109,20 +111,24 @@ getcomaddr(int idx)
>   * XXX only pass console parameters to kernel.
>   */
>  void
> -efi_consinit(int dev, int ioport, int speed)
> +efi_consinit(int dev, int ioport, int unit, int speed, bool switchcons)
>  {
>  	int i;
> +	char *consname = NULL;
>  
>  	btinfo_console.speed = default_comspeed;
>  
>  	switch (dev) {
>  	case CONSDEV_AUTO:
>  		for (i = 0; i < __arraycount(serios); i++) {
> -			iodev = CONSDEV_COM0 + i;
> -			if (!efi_valid_com(iodev))
> +			if (!efi_valid_com(i))
>  				continue;
> +			consname = "com";
>  			btinfo_console.addr = getcomaddr(i);
>  
> +			/* switch to com for the test, regardless switchcons */
> +			com_unit = i;
> +
>  			efi_cons_putc('0' + i);
>  			efi_com_init(btinfo_console.addr, btinfo_console.speed);
>  			/* check for:
> @@ -135,7 +141,6 @@ efi_consinit(int dev, int ioport, int sp
>  			    awaitkey(7, 0))
>  				goto ok;
>  		}
> -		goto nocom;
>  ok:
>  		break;
>  
> @@ -143,23 +148,33 @@ ok:
>  	case CONSDEV_COM1:
>  	case CONSDEV_COM2:
>  	case CONSDEV_COM3:
> -		iodev = dev;
> +	case CONSDEV_COM:
> +		consname = "com";
>  		btinfo_console.addr = ioport;
>  		if (btinfo_console.addr == 0)
> -			btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0);
> +			btinfo_console.addr = getcomaddr(unit);
>  		if (speed != 0)
>  			btinfo_console.speed = speed;
> -		efi_com_init(btinfo_console.addr, btinfo_console.speed);
> +
> +		if (switchcons) {
> +			com_unit = unit;
> +			efi_com_init(btinfo_console.addr, btinfo_console.speed);
> +		}
>  		break;
>  
>  	case CONSDEV_COM0KBD:
>  	case CONSDEV_COM1KBD:
>  	case CONSDEV_COM2KBD:
> -	case CONSDEV_COM3KBD:
> -		iodev = dev - CONSDEV_COM0KBD + CONSDEV_COM0;
> -		btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0);
> +	case CONSDEV_COM3KBD: /* XXXmanu */
> +		consname = "com";
> +		btinfo_console.addr = getcomaddr(unit);
>  
> -		efi_cons_putc('0' + iodev - CONSDEV_COM0);
> +		if (!switchcons) 
> +			goto kbd;
> +
> +		com_unit = unit;
> +
> +		efi_cons_putc('0' + unit); /* XXX if unit>=10 ?  */
>  		efi_com_init(btinfo_console.addr, btinfo_console.speed);
>  		/* check for:
>  		 *  1. successful output
> @@ -172,11 +187,24 @@ ok:
>  			goto kbd;
>  		/*FALLTHROUGH*/
>  	case CONSDEV_PC:
> +		goto nocom;
> +	case CONSDEV_UCOM:
> +		consname = "ucom";
> +		btinfo_console.addr = unit; /* Used for unit number */
> +		if (speed != 0)
> +			btinfo_console.speed = speed;
> +		break;
>  	default:
>  nocom:
> -		iodev = CONSDEV_PC;
> +		consname = "pc";
> +		if (!switchcons)
> +			break;
>  		internal_putchar = efi_cons_putc;
>  kbd:
> +		consname = "com";
> +		if (!switchcons)
> +			break;
> +		com_unit = unit;
>  		internal_getchar = efi_cons_getc;
>  		internal_iskey = efi_cons_iskey;
>  		internal_waitforinputevent = efi_cons_waitforinputevent;
> @@ -185,19 +213,24 @@ kbd:
>  		break;
>  	}
>  
> -	strlcpy(btinfo_console.devname, iodev == CONSDEV_PC ? "pc" : "com", 16);
> +	if (consname != NULL)
> +		strlcpy(btinfo_console.devname, consname, 16);
>  }
>  
>  int
>  cninit(void)
>  {
> -
> +	int unit;
>  	efi_switch_video_to_text_mode();
>  	eficons_init_video();
> +
> +	/* console output is now possible */
> +
>  	efi_com_probe();
>  
> -	efi_consinit(boot_params.bp_consdev, boot_params.bp_consaddr,
> -	    boot_params.bp_conspeed);
> +	unit = efi_com_consdev2unit(boot_params.bp_consdev);
> +	efi_consinit(boot_params.bp_consdev, boot_params.bp_consaddr, unit,
> +	    boot_params.bp_conspeed, true);
>  
>  	return 0;
>  }
> @@ -801,6 +834,27 @@ efi_switch_video_to_text_mode(void)
>  	}
>  }
>  
> +static int
> +efi_com_consdev2unit(int dev) 
> +{
> +	int unit = -1;
> +
> +	if (dev >= CONSDEV_COM0 && unit <= CONSDEV_COM3)
> +		unit = dev - CONSDEV_COM0;
> +
> +	if (dev >= CONSDEV_COM0KBD && unit <= CONSDEV_COM3KBD)
> +		unit = dev - CONSDEV_COM0KBD;
> +
> +	if (dev == CONSDEV_COM)
> +		unit = 0;
> +
> +	if (dev == CONSDEV_UCOM)
> +		unit = 0;
> +
> +	return unit;
> +}
> +
> +
>  /*
>   * serial port
>   */
> @@ -813,7 +867,20 @@ efi_com_probe(void)
>  	EFI_DEVICE_PATH	*dp, *dp0;
>  	EFI_DEV_PATH_PTR dpp;
>  	SERIAL_IO_INTERFACE *serio;
> -	int uid = -1;
> +	int unit = -1;
> +	int high_unit = EISA_COM_COUNT;
> +
> +	/*
> +	 * We could want to dynamically allocate serios[] to cope
> +	 * with an aritrary count of serial ports, but we cannot yet
> +	 * call alloc(), because efi_heap_init() was not yet called.
> +	 * We could swap cninit() and efi_heap_init() order in 
> +	 * efi_main(), but then efi_heap_init() could not display
> +	 * a failure message. Let us keep static it for now for the
> +	 * sake of reliability.
> +	 */
> +	for (i = 0; i < __arraycount(serios); i++)
> +		serios[i] = NULL;
>  
>  	status = LibLocateHandle(ByProtocol, &SerialIoProtocol, NULL,
>  	    &nhandles, &handles);
> @@ -831,20 +898,24 @@ efi_com_probe(void)
>  		if (EFI_ERROR(status))
>  			continue;
>  
> -		for (uid = -1, dp = dp0;
> -		     !IsDevicePathEnd(dp);
> +		unit = -1;
> +		for (dp = dp0; !IsDevicePathEnd(dp);
>  		     dp = NextDevicePathNode(dp)) {
>  
>  			if (DevicePathType(dp) == ACPI_DEVICE_PATH &&
>  			    DevicePathSubType(dp) == ACPI_DP) {
>  				dpp = (EFI_DEV_PATH_PTR)dp;
>  				if (dpp.Acpi->HID == EISA_PNP_ID(0x0501)) {
> -					uid = dpp.Acpi->UID;
> +					unit = dpp.Acpi->UID;
>  					break;
>  				}
>  			}
>  		}
> -		if (uid < 0 || __arraycount(serios) <= uid)
> +
> +		if (unit == -1)
> +			unit = high_unit++;
> +
> +		if (unit < 0 || __arraycount(serios) <= unit)
>  			continue;
>  
>  		/* Prepare SERIAL_IO_INTERFACE */
> @@ -853,7 +924,7 @@ efi_com_probe(void)
>  		if (EFI_ERROR(status))
>  			continue;
>  
> -		serios[uid] = serio;
> +		serios[unit] = serio;
>  	}
>  
>  	FreePool(handles);
> @@ -861,26 +932,10 @@ efi_com_probe(void)
>  }
>  
>  static bool
> -efi_valid_com(int dev)
> +efi_valid_com(int unit)
>  {
> -	int idx;
> -
> -	switch (dev) {
> -	default:
> -	case CONSDEV_PC:
> -		return false;
> -
> -	case CONSDEV_COM0:
> -	case CONSDEV_COM1:
> -	case CONSDEV_COM2:
> -	case CONSDEV_COM3:
> -		idx = dev - CONSDEV_COM0;
> -		break;
> -	}
> -
> -	return idx < __arraycount(serios) &&
> -	    serios[idx] != NULL &&
> -	    getcomaddr(idx) != 0;
> +	return (unit >= 0 &&unit < __arraycount(serios) &&
> +	    serios[unit] != NULL);
>  }
>  
>  static int
> @@ -892,10 +947,10 @@ efi_com_init(int addr, int speed)
>  	if (speed <= 0)
>  		return 0;
>  
> -	if (!efi_valid_com(iodev))
> +	if (!efi_valid_com(com_unit))
>  		return raw_com_init(addr, speed);
>  
> -	serio = serios[iodev - CONSDEV_COM0];
> +	serio = serios[com_unit];
>  
>  	if (serio->Mode->BaudRate != btinfo_console.speed) {
>  		status = uefi_call_wrapper(serio->SetAttributes, 7, serio,
> @@ -904,7 +959,7 @@ efi_com_init(int addr, int speed)
>  		    serio->Mode->DataBits, serio->Mode->StopBits);
>  		if (EFI_ERROR(status)) {
>  			printf("com%d: SetAttribute() failed with status=%" PRIxMAX
> -			    "\n", iodev - CONSDEV_COM0, (uintmax_t)status);
> +			    "\n", com_unit, (uintmax_t)status);
>  			return 0;
>  		}
>  	}
> @@ -929,8 +984,8 @@ efi_com_getc(void)
>  	UINTN sz;
>  	u_char c;
>  
> -	if (!efi_valid_com(iodev))
> -		panic("Invalid serial port: iodev=%d", iodev);
> +	if (!efi_valid_com(com_unit))
> +		panic("Invalid serial port: unit=%d", com_unit);
>  
>  	if (serbuf_read != serbuf_write) {
>  		c = serbuf[serbuf_read];
> @@ -938,7 +993,7 @@ efi_com_getc(void)
>  		return c;
>  	}
>  
> -	serio = serios[iodev - CONSDEV_COM0];
> +	serio = serios[com_unit];
>  
>  	for (;;) {
>  		sz = 1;
> @@ -960,10 +1015,10 @@ efi_com_putc(int c)
>  	UINTN sz = 1;
>  	u_char buf;
>  
> -	if (!efi_valid_com(iodev))
> +	if (!efi_valid_com(com_unit))
>  		return 0;
>  
> -	serio = serios[iodev - CONSDEV_COM0];
> +	serio = serios[com_unit];
>  	buf = c;
>  	status = uefi_call_wrapper(serio->Write, 3, serio, &sz, &buf);
>  	if (EFI_ERROR(status) || sz < 1)
> @@ -980,13 +1035,13 @@ efi_com_status(int intr)
>  	UINTN sz;
>  	u_char c;
>  
> -	if (!efi_valid_com(iodev))
> -		panic("Invalid serial port: iodev=%d", iodev);
> +	if (!efi_valid_com(com_unit))
> +		panic("Invalid serial port: unit = %d", com_unit);
>  
>  	if (serbuf_read != serbuf_write)
>  		return 1;
>  
> -	serio = serios[iodev - CONSDEV_COM0];
> +	serio = serios[com_unit];
>  	sz = 1;
>  	status = uefi_call_wrapper(serio->Read, 3, serio, &sz, &c);
>  	if (EFI_ERROR(status) || sz < 1)
>
> Index: src/sys/arch/i386/stand/lib/libi386.h
> diff -u src/sys/arch/i386/stand/lib/libi386.h:1.55 src/sys/arch/i386/stand/lib/libi386.h:1.56
> --- src/sys/arch/i386/stand/lib/libi386.h:1.55	Tue May  6 18:16:12 2025
> +++ src/sys/arch/i386/stand/lib/libi386.h	Thu Oct  9 16:10:03 2025
> @@ -1,4 +1,4 @@
> -/*	$NetBSD: libi386.h,v 1.55 2025/05/06 18:16:12 pgoyette Exp $	*/
> +/*	$NetBSD: libi386.h,v 1.56 2025/10/09 16:10:03 manu Exp $	*/
>  
>  /*
>   * Copyright (c) 1996
> @@ -68,6 +68,8 @@ void initio(int);
>  #define CONSDEV_COM1KBD 6
>  #define CONSDEV_COM2KBD 7
>  #define CONSDEV_COM3KBD 8
> +#define CONSDEV_COM 9
> +#define CONSDEV_UCOM 10
>  #define CONSDEV_AUTO (-1)
>  int iskey(int);
>  char awaitkey(int, int);
>

-- 
Ryo ONODERA // ryo%tetera.org@localhost
PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3


Home | Main Index | Thread Index | Old Index