NetBSD Problem Report #59207

From paul@whooppee.com  Sun Mar 23 10:56:45 2025
Return-Path: <paul@whooppee.com>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D30551A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 23 Mar 2025 10:56:45 +0000 (UTC)
Message-Id: <20250323105613.BF9B449A95C@speedy.whooppee.com>
Date: Sun, 23 Mar 2025 03:56:13 -0700 (PDT)
From: paul@whooppee.com
Reply-To: paul@whooppee.com
To: gnats-bugs@NetBSD.org
Subject: unexpected behavior of dev command in bootstrap code
X-Send-Pr-Version: 3.95

>Number:         59207
>Category:       port-amd64
>Synopsis:       unexpected behavior of dev command in bootstrap code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pgoyette
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 23 11:00:00 +0000 2025
>Closed-Date:    Tue May 06 18:22:17 +0000 2025
>Last-Modified:  Wed May 07 06:10:01 +0000 2025
>Originator:     Paul Goyette
>Release:        NetBSD 10.99.12
>Organization:
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint:     | E-mail addresses:    |
| (Retired)           | 1B11 1849 721C 56C8 F63A | paul@whooppee.com    |
| Software Developer  | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org  |
| & Network Engineer  |                          | pgoyette99@gmail.com |
+---------------------+--------------------------+----------------------+
>Environment:


System: NetBSD speedy.whooppee.com 10.99.12 NetBSD 10.99.12 (GENERIC) #0: Wed Mar 19 03:32:11 UTC 2025 paul@speedy.whooppee.com:/build/netbsd-local/obj/amd64/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
In the final stage bootstrap code (where the menu of boot selections
is presented, the dev command does not appear to work when included
in the boot.cfg file; the default device does not get updated.  When
entered interactively (from the ``boot prompt'') it works as one would
expect.

The problem occurs in both "standard" and "efi" bootstrap code (files
/usr/mdec/boot and /usr/mdec/bootx64.efi) so probably lives in common
shared code.

>How-To-Repeat:
1. Install a base VM system - the system created by sysutils/anita works
   fine for this step.

2. Boot the resulting VM, login as root, and edit the /boot.cfg file to
	a) add a failsafe menu entry #4, just in case it works!
	b) add an invocation of the ``dev'' command to select a different
	   default device

   The following boot.cfg is useful here:

	# more /boot.cfg
	menu=Boot normally:rndseed /var/db/entropy-file;boot
	menu=Boot single user:rndseed /var/db/entropy-file;boot -s
	menu=Drop to boot prompt:prompt
	menu=Boot normally:rndseed /var/db/entropy-file;boot hd0a:/netbsd
	default=1
	timeout=5
	clear=1
	dev=fd0a:

3. Boot the VM, drop to the boot prompt, and observe that the default
   device has not been set:

	<Banner removed for brevity>

	     1. Boot normally
	     2. Boot single user
	     3. Drop to boot prompt
	     4. Boot normally

	Choose an option; RETURN for default; SPACE to stop countdown.
	Option 1 will be chosen in 0 seconds.     

	Option: [1]:3
	type "?" or "help" for help.
	> dev
	disk hd0 size 25 GB
	  hd0a(NetBSD FFS) hd0b(NetBSD Swap)
	disk fd0
	  fd0a
	disk fd1
	  fd1a
	default hd0a
	> 

4. Enter the dev command manually and note the default device updates:

	> dev fd0a:
	> dev
	disk hd0 size 25 GB
	  hd0a(NetBSD FFS) hd0b(NetBSD Swap)
	disk fd0
	  fd0a
	disk fd1
	  fd1a
	default fd0a
	>

>Fix:
Please

>Release-Note:

>Audit-Trail:
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amd64/59207: unexpected behavior of dev command in bootstrap
 code
Date: Sun, 23 Mar 2025 08:05:55 -0700 (PDT)

 It seems that the rndseed command behaves similarly, although it is
 more difficult to demonstrate - you cannot ask the boot loader to
 display the value of rndseed.  Instead you have to observe if the
 ``entropy ready'' message is displayed.

 ...
 [   1.0000000] WARNING: system needs entropy for security; see entropy(7)
 [   1.0000000] entropy: entering seed from bootloader with 256 bits of entropy
 [   1.0000000] entropy: ready
 [   1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
 ...

 Edit the boot.cfg file to include the following line (at the end)

  	rndseed=/var/db/entropy-file

 Reboot the vm, drop to the boot prompt (option 3 in the previous
 example) and enter ``boot''.  When the system comes up, note that
 the ``entropy ready'' message is not displayed, and verify that the
 file exists:

 > boot
 20919416+760104+1337048 [840369+1265856+940213]=0x18e8728
 Loading /stand/amd64/10.99.12/modules/wapbl/wapbl.kmod
 Loading /stand/amd64/10.99.12/modules/ufs/ufs.kmod
 Loading /stand/amd64/10.99.12/modules/ffs/ffs.kmod
 [   1.0000000] WARNING: system needs entropy for security; see entropy(7)
 [   1.0000000] Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
 ...
 # ls -l /var/db
 total 24126
 drwxr-x---  2 root     wheel         512 Mar 21 21:34 dhcpcd
 -rw-------  1 root     wheel         536 Mar 21 01:20 entropy-file
 ...
 # cat /boot.cfg
 menu=Boot normally:boot
 menu=Boot single user:rndseed /var/db/entropy-file;boot -s
 menu=Drop to boot prompt:prompt
 menu=Boot normally:rndseed /var/db/entropy-file;boot hd0a:/netbsd
 default=1
 timeout=5
 clear=1
 dev=fd0a:
 rndseed=/var/db/entropy-file
 #


 +---------------------+--------------------------+----------------------+
 | Paul Goyette (.sig) | PGP Key fingerprint:     | E-mail addresses:    |
 | (Retired)           | 1B11 1849 721C 56C8 F63A | paul@whooppee.com    |
 | Software Developer  | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org  |
 | & Network Engineer  |                          | pgoyette99@gmail.com |
 +---------------------+--------------------------+----------------------+

From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amd64/59207: unexpected behavior of dev command in bootstrap
 code
Date: Wed, 26 Mar 2025 07:44:21 +0000 (UTC)

 On Sun, 23 Mar 2025, Paul Goyette via gnats wrote:

 > It seems that the rndseed command behaves similarly, [...]
 >

 Yeah, the set of commands recognized in /boot.cfg differ from those
 understood at the bootloader prompt.

 For EFI on amd64, following the call sequence:

 sys/arch/i386/stand/efiboot/efiboot.c:efi_main()	->
 sys/arch/i386/stand/efiboot/boot.c:boot()		->
 sys/arch/i386/stand/lib/bootmenu.c:parsebootconf()	->
 sys/lib/libsa/bootcfg.c:perform_bootcfg()

 we see that only these commands are recognized in /boot.cfg:

 menu, banner, timeout, default, consdev, root, format, clear &
 fs, load, userconf via the call-back function.

 At the bootloader prompt, the `commands[]' array has the commands you can
 type in:

 sys/arch/i386/stand/efiboot/efiboot.c:efi_main()	->
 sys/arch/i386/stand/efiboot/boot.c:boot()		->
 sys/arch/i386/stand/lib/menuutils.c:bootmenu()	-> docommand() ->
 sys/arch/i386/stand/efiboot/boot.c:			->

 struct bootblk_command commands[] = { ... };

 There're probably good reasons for this...

 Anyway, Paul, can you please try this patch?

 Thx,

 -RVP

 ---START patch---
 diff -urN a/src/sys/arch/i386/stand/boot/boot2.c b/src/sys/arch/i386/stand/boot/boot2.c
 --- a/src/sys/arch/i386/stand/boot/boot2.c	2022-06-08 21:43:45.000000000 +0000
 +++ b/src/sys/arch/i386/stand/boot/boot2.c	2025-03-26 06:42:31.883704627 +0000
 @@ -130,7 +130,6 @@
   void	command_quit(char *);
   void	command_boot(char *);
   void	command_pkboot(char *);
 -void	command_dev(char *);
   void	command_consdev(char *);
   void	command_root(char *);
   #ifndef SMALL
 diff -urN a/src/sys/arch/i386/stand/dosboot/main.c b/src/sys/arch/i386/stand/dosboot/main.c
 --- a/src/sys/arch/i386/stand/dosboot/main.c	2024-09-12 05:58:29.835738814 +0000
 +++ b/src/sys/arch/i386/stand/dosboot/main.c	2025-03-26 06:42:31.883704627 +0000
 @@ -65,7 +65,6 @@
   void	command_quit(char *);
   void	command_boot(char *);
   void	command_mode(char *);
 -void	command_dev(char *);

   const struct bootblk_command commands[] = {
   	{ "help",	command_help },
 diff -urN a/src/sys/arch/i386/stand/lib/bootmenu.c b/src/sys/arch/i386/stand/lib/bootmenu.c
 --- a/src/sys/arch/i386/stand/lib/bootmenu.c	2024-11-28 01:49:47.366302337 +0000
 +++ b/src/sys/arch/i386/stand/lib/bootmenu.c	2025-03-26 07:04:54.920298651 +0000
 @@ -57,10 +57,14 @@
   static void
   do_bootcfg_command(const char *cmd, char *arg)
   {
 -	if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 -		module_add(arg);
 -	else if (strcmp(cmd, "fs") == 0)
 +	if (strcmp(cmd, BOOTCFG_CMD_DEV) == 0)
 +		command_dev(arg);
 +	else if (strcmp(cmd, BOOTCFG_CMD_FS) == 0)
   		fs_add(arg);
 +	else if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 +		module_add(arg);
 +	else if (strcmp(cmd, BOOTCFG_CMD_RNDSEED) == 0)
 +		rnd_add(arg);
   	else if (strcmp(cmd, BOOTCFG_CMD_USERCONF) == 0)
   		userconf_add(arg);
   }
 diff -urN a/src/sys/arch/i386/stand/lib/libi386.h b/src/sys/arch/i386/stand/lib/libi386.h
 --- a/src/sys/arch/i386/stand/lib/libi386.h	2024-09-18 04:04:46.535251031 +0000
 +++ b/src/sys/arch/i386/stand/lib/libi386.h	2025-03-26 06:42:31.883704627 +0000
 @@ -150,6 +150,9 @@
   void userconf_add(char *);
   void module_add_split(const char *, uint8_t);

 +/* Note: implementations differ in boot2, dosboot & efiboot */
 +void command_dev(char *);
 +
   struct btinfo_framebuffer;
   void framebuffer_configure(struct btinfo_framebuffer *);

 diff -urN a/src/sys/lib/libsa/bootcfg.c b/src/sys/lib/libsa/bootcfg.c
 --- a/src/sys/lib/libsa/bootcfg.c	2022-01-05 16:01:54.000000000 +0000
 +++ b/src/sys/lib/libsa/bootcfg.c	2025-03-26 07:03:58.367307984 +0000
 @@ -227,8 +227,6 @@
   			bootcfg_info.consdev = value;
   		} else if (!strncmp(key, "root", 4)) {
   			bootcfg_info.root = value;
 -		} else if (!strncmp(key, BOOTCFG_CMD_LOAD, 4)) {
 -			command(BOOTCFG_CMD_LOAD, value);
   		} else if (!strncmp(key, "format", 6)) {
   			printf("value:%c\n", *value);
   			switch (*value) {
 @@ -251,8 +249,6 @@
   			}
   		} else if (!strncmp(key, "clear", 5)) {
   			bootcfg_info.clear = !!atoi(value);
 -		} else if (!strncmp(key, BOOTCFG_CMD_USERCONF, 8)) {
 -			command(BOOTCFG_CMD_USERCONF, value);
   		} else {
   			command(key, value);
   		}
 diff -urN a/src/sys/lib/libsa/bootcfg.h b/src/sys/lib/libsa/bootcfg.h
 --- a/src/sys/lib/libsa/bootcfg.h	2021-09-07 11:41:31.000000000 +0000
 +++ b/src/sys/lib/libsa/bootcfg.h	2025-03-26 07:12:00.103744727 +0000
 @@ -29,12 +29,15 @@
   #ifndef _BOOTCFG_H
   #define _BOOTCFG_H

 -#define BOOTCFG_FILENAME "boot.cfg"
 -#define BOOTCFG_MAXMENU	 20
 -#define BOOTCFG_MAXBANNER 12
 +#define BOOTCFG_FILENAME	"boot.cfg"
 +#define BOOTCFG_MAXMENU		20
 +#define BOOTCFG_MAXBANNER	12

 -#define BOOTCFG_CMD_LOAD	  "load"
 -#define BOOTCFG_CMD_USERCONF	  "userconf"
 +#define BOOTCFG_CMD_DEV		"dev"
 +#define BOOTCFG_CMD_FS		"fs"
 +#define BOOTCFG_CMD_LOAD	"load"
 +#define BOOTCFG_CMD_RNDSEED	"rndseed"
 +#define BOOTCFG_CMD_USERCONF	"userconf"

   typedef void (*bootcfg_command)(const char *cmd, char *arg);

 ---END patch---

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amd64/59207: unexpected behavior of dev command in bootstrap
 code
Date: Wed, 26 Mar 2025 06:23:48 -0700 (PDT)

 With the patches below, PLUS the pxeboot patch you sent offline, it
 (bootx64.efi) works as desired.  I have removed all of the NAME=xxx
 from the kernel filenames and set DEV=NAME=xxx (to override the initial
 value of DEV=NAME-yyy.  It boots correctly from the specified kernel
 file.

 A qemu VM installed with these patches still seems to ignore the DEV
 command within boot.cfg (but I have not cacrefully verified this.)  I
 was not able to test any other non-efi boots...

 Here is the pxeboot patch that you originally sent off-list:

 ```
 diff -urN a/src/sys/arch/i386/stand/pxeboot/main.c
 b/src/sys/arch/i386/stand/pxeboot/main.c
 --- a/src/sys/arch/i386/stand/pxeboot/main.c    2024-11-10
 04:31:15.013906675 +0000
 +++ b/src/sys/arch/i386/stand/pxeboot/main.c    2025-03-26
 11:07:28.331263167 +0000
 @@ -180,6 +180,18 @@
          return (1);
   }

 +/*
 + * dummy function to satisfy link against call in
 + * sys/arch/i386/stand/lib/bootmenu.c:do_bootcfg_command()
 + */ +/* ARGSUSED */
 +void
 +command_dev(char *arg)
 +{
 +       (void)arg;
 +       return;
 +}
 +
   /* ARGSUSED */
   void
   command_help(char *arg)
 ```



 On Wed, 26 Mar 2025, RVP via gnats wrote:

 > The following reply was made to PR port-amd64/59207; it has been noted by GNATS.
 >
 > From: RVP <rvp@SDF.ORG>
 > To: gnats-bugs@netbsd.org
 > Cc:
 > Subject: Re: port-amd64/59207: unexpected behavior of dev command in bootstrap
 > code
 > Date: Wed, 26 Mar 2025 07:44:21 +0000 (UTC)
 >
 > On Sun, 23 Mar 2025, Paul Goyette via gnats wrote:
 >
 > > It seems that the rndseed command behaves similarly, [...]
 > >
 >
 > Yeah, the set of commands recognized in /boot.cfg differ from those
 > understood at the bootloader prompt.
 >
 > For EFI on amd64, following the call sequence:
 >
 > sys/arch/i386/stand/efiboot/efiboot.c:efi_main()	->
 > sys/arch/i386/stand/efiboot/boot.c:boot()		->
 > sys/arch/i386/stand/lib/bootmenu.c:parsebootconf()	->
 > sys/lib/libsa/bootcfg.c:perform_bootcfg()
 >
 > we see that only these commands are recognized in /boot.cfg:
 >
 > menu, banner, timeout, default, consdev, root, format, clear &
 > fs, load, userconf via the call-back function.
 >
 > At the bootloader prompt, the `commands[]' array has the commands you can
 > type in:
 >
 > sys/arch/i386/stand/efiboot/efiboot.c:efi_main()	->
 > sys/arch/i386/stand/efiboot/boot.c:boot()		->
 > sys/arch/i386/stand/lib/menuutils.c:bootmenu()	-> docommand() ->
 > sys/arch/i386/stand/efiboot/boot.c:			->
 >
 > struct bootblk_command commands[] = { ... };
 >
 > There're probably good reasons for this...
 >
 > Anyway, Paul, can you please try this patch?
 >
 > Thx,
 >
 > -RVP
 >
 > ---START patch---
 > diff -urN a/src/sys/arch/i386/stand/boot/boot2.c b/src/sys/arch/i386/stand/boot/boot2.c
 > --- a/src/sys/arch/i386/stand/boot/boot2.c	2022-06-08 21:43:45.000000000 +0000
 > +++ b/src/sys/arch/i386/stand/boot/boot2.c	2025-03-26 06:42:31.883704627 +0000
 > @@ -130,7 +130,6 @@
 >   void	command_quit(char *);
 >   void	command_boot(char *);
 >   void	command_pkboot(char *);
 > -void	command_dev(char *);
 >   void	command_consdev(char *);
 >   void	command_root(char *);
 >   #ifndef SMALL
 > diff -urN a/src/sys/arch/i386/stand/dosboot/main.c b/src/sys/arch/i386/stand/dosboot/main.c
 > --- a/src/sys/arch/i386/stand/dosboot/main.c	2024-09-12 05:58:29.835738814 +0000
 > +++ b/src/sys/arch/i386/stand/dosboot/main.c	2025-03-26 06:42:31.883704627 +0000
 > @@ -65,7 +65,6 @@
 >   void	command_quit(char *);
 >   void	command_boot(char *);
 >   void	command_mode(char *);
 > -void	command_dev(char *);
 >
 >   const struct bootblk_command commands[] = {
 >   	{ "help",	command_help },
 > diff -urN a/src/sys/arch/i386/stand/lib/bootmenu.c b/src/sys/arch/i386/stand/lib/bootmenu.c
 > --- a/src/sys/arch/i386/stand/lib/bootmenu.c	2024-11-28 01:49:47.366302337 +0000
 > +++ b/src/sys/arch/i386/stand/lib/bootmenu.c	2025-03-26 07:04:54.920298651 +0000
 > @@ -57,10 +57,14 @@
 >   static void
 >   do_bootcfg_command(const char *cmd, char *arg)
 >   {
 > -	if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 > -		module_add(arg);
 > -	else if (strcmp(cmd, "fs") == 0)
 > +	if (strcmp(cmd, BOOTCFG_CMD_DEV) == 0)
 > +		command_dev(arg);
 > +	else if (strcmp(cmd, BOOTCFG_CMD_FS) == 0)
 >   		fs_add(arg);
 > +	else if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 > +		module_add(arg);
 > +	else if (strcmp(cmd, BOOTCFG_CMD_RNDSEED) == 0)
 > +		rnd_add(arg);
 >   	else if (strcmp(cmd, BOOTCFG_CMD_USERCONF) == 0)
 >   		userconf_add(arg);
 >   }
 > diff -urN a/src/sys/arch/i386/stand/lib/libi386.h b/src/sys/arch/i386/stand/lib/libi386.h
 > --- a/src/sys/arch/i386/stand/lib/libi386.h	2024-09-18 04:04:46.535251031 +0000
 > +++ b/src/sys/arch/i386/stand/lib/libi386.h	2025-03-26 06:42:31.883704627 +0000
 > @@ -150,6 +150,9 @@
 >   void userconf_add(char *);
 >   void module_add_split(const char *, uint8_t);
 >
 > +/* Note: implementations differ in boot2, dosboot & efiboot */
 > +void command_dev(char *);
 > +
 >   struct btinfo_framebuffer;
 >   void framebuffer_configure(struct btinfo_framebuffer *);
 >
 > diff -urN a/src/sys/lib/libsa/bootcfg.c b/src/sys/lib/libsa/bootcfg.c
 > --- a/src/sys/lib/libsa/bootcfg.c	2022-01-05 16:01:54.000000000 +0000
 > +++ b/src/sys/lib/libsa/bootcfg.c	2025-03-26 07:03:58.367307984 +0000
 > @@ -227,8 +227,6 @@
 >   			bootcfg_info.consdev = value;
 >   		} else if (!strncmp(key, "root", 4)) {
 >   			bootcfg_info.root = value;
 > -		} else if (!strncmp(key, BOOTCFG_CMD_LOAD, 4)) {
 > -			command(BOOTCFG_CMD_LOAD, value);
 >   		} else if (!strncmp(key, "format", 6)) {
 >   			printf("value:%c\n", *value);
 >   			switch (*value) {
 > @@ -251,8 +249,6 @@
 >   			}
 >   		} else if (!strncmp(key, "clear", 5)) {
 >   			bootcfg_info.clear = !!atoi(value);
 > -		} else if (!strncmp(key, BOOTCFG_CMD_USERCONF, 8)) {
 > -			command(BOOTCFG_CMD_USERCONF, value);
 >   		} else {
 >   			command(key, value);
 >   		}
 > diff -urN a/src/sys/lib/libsa/bootcfg.h b/src/sys/lib/libsa/bootcfg.h
 > --- a/src/sys/lib/libsa/bootcfg.h	2021-09-07 11:41:31.000000000 +0000
 > +++ b/src/sys/lib/libsa/bootcfg.h	2025-03-26 07:12:00.103744727 +0000
 > @@ -29,12 +29,15 @@
 >   #ifndef _BOOTCFG_H
 >   #define _BOOTCFG_H
 >
 > -#define BOOTCFG_FILENAME "boot.cfg"
 > -#define BOOTCFG_MAXMENU	 20
 > -#define BOOTCFG_MAXBANNER 12
 > +#define BOOTCFG_FILENAME	"boot.cfg"
 > +#define BOOTCFG_MAXMENU		20
 > +#define BOOTCFG_MAXBANNER	12
 >
 > -#define BOOTCFG_CMD_LOAD	  "load"
 > -#define BOOTCFG_CMD_USERCONF	  "userconf"
 > +#define BOOTCFG_CMD_DEV		"dev"
 > +#define BOOTCFG_CMD_FS		"fs"
 > +#define BOOTCFG_CMD_LOAD	"load"
 > +#define BOOTCFG_CMD_RNDSEED	"rndseed"
 > +#define BOOTCFG_CMD_USERCONF	"userconf"
 >
 >   typedef void (*bootcfg_command)(const char *cmd, char *arg);
 >
 > ---END patch---
 >
 >
 > !DSPAM:67e3b09e68781226255623!
 >
 >

 +---------------------+--------------------------+----------------------+
 | Paul Goyette (.sig) | PGP Key fingerprint:     | E-mail addresses:    |
 | (Retired)           | 1B11 1849 721C 56C8 F63A | paul@whooppee.com    |
 | Software Developer  | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org  |
 | & Network Engineer  |                          | pgoyette99@gmail.com |
 +---------------------+--------------------------+----------------------+

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: rvp@sdf.org
Subject: Re: port-amd64/59207: unexpected behavior of dev command in bootstrap
 code
Date: Sat, 3 May 2025 18:06:10 -0700 (PDT)

 Is there any chance we can get these patches committed soon?

 they work just fine on my machine...


 On Wed, 26 Mar 2025, Paul Goyette wrote:

 > With the patches below, PLUS the pxeboot patch you sent offline, it
 > (bootx64.efi) works as desired.  I have removed all of the NAME=xxx
 > from the kernel filenames and set DEV=NAME=xxx (to override the initial
 > value of DEV=NAME-yyy.  It boots correctly from the specified kernel
 > file.
 >
 > A qemu VM installed with these patches still seems to ignore the DEV
 > command within boot.cfg (but I have not cacrefully verified this.)  I
 > was not able to test any other non-efi boots...
 >
 > Here is the pxeboot patch that you originally sent off-list:
 >
 > ```
 > diff -urN a/src/sys/arch/i386/stand/pxeboot/main.c
 > b/src/sys/arch/i386/stand/pxeboot/main.c
 > --- a/src/sys/arch/i386/stand/pxeboot/main.c    2024-11-10
 > 04:31:15.013906675 +0000
 > +++ b/src/sys/arch/i386/stand/pxeboot/main.c    2025-03-26
 > 11:07:28.331263167 +0000
 > @@ -180,6 +180,18 @@
 >        return (1);
 > }
 >
 > +/*
 > + * dummy function to satisfy link against call in
 > + * sys/arch/i386/stand/lib/bootmenu.c:do_bootcfg_command()
 > + */ +/* ARGSUSED */
 > +void
 > +command_dev(char *arg)
 > +{
 > +       (void)arg;
 > +       return;
 > +}
 > +
 > /* ARGSUSED */
 > void
 > command_help(char *arg)
 > ```
 >
 >
 >
 > On Wed, 26 Mar 2025, RVP via gnats wrote:
 >
 >> The following reply was made to PR port-amd64/59207; it has been noted by 
 >> GNATS.
 >> 
 >> From: RVP <rvp@SDF.ORG>
 >> To: gnats-bugs@netbsd.org
 >> Cc:
 >> Subject: Re: port-amd64/59207: unexpected behavior of dev command in 
 >> bootstrap
 >> code
 >> Date: Wed, 26 Mar 2025 07:44:21 +0000 (UTC)
 >> 
 >> On Sun, 23 Mar 2025, Paul Goyette via gnats wrote:
 >> 
 >> > It seems that the rndseed command behaves similarly, [...]
 >> >
 >> 
 >> Yeah, the set of commands recognized in /boot.cfg differ from those
 >> understood at the bootloader prompt.
 >> 
 >> For EFI on amd64, following the call sequence:
 >> 
 >> sys/arch/i386/stand/efiboot/efiboot.c:efi_main()	->
 >> sys/arch/i386/stand/efiboot/boot.c:boot()		->
 >> sys/arch/i386/stand/lib/bootmenu.c:parsebootconf()	->
 >> sys/lib/libsa/bootcfg.c:perform_bootcfg()
 >> 
 >> we see that only these commands are recognized in /boot.cfg:
 >> 
 >> menu, banner, timeout, default, consdev, root, format, clear &
 >> fs, load, userconf via the call-back function.
 >> 
 >> At the bootloader prompt, the `commands[]' array has the commands you can
 >> type in:
 >> 
 >> sys/arch/i386/stand/efiboot/efiboot.c:efi_main()	->
 >> sys/arch/i386/stand/efiboot/boot.c:boot()		->
 >> sys/arch/i386/stand/lib/menuutils.c:bootmenu()	-> docommand() ->
 >> sys/arch/i386/stand/efiboot/boot.c:			->
 >> 
 >> struct bootblk_command commands[] = { ... };
 >> 
 >> There're probably good reasons for this...
 >> 
 >> Anyway, Paul, can you please try this patch?
 >> 
 >> Thx,
 >> 
 >> -RVP
 >> 
 >> ---START patch---
 >> diff -urN a/src/sys/arch/i386/stand/boot/boot2.c 
 >> b/src/sys/arch/i386/stand/boot/boot2.c
 >> --- a/src/sys/arch/i386/stand/boot/boot2.c	2022-06-08 21:43:45.000000000 
 >> +0000
 >> +++ b/src/sys/arch/i386/stand/boot/boot2.c	2025-03-26 06:42:31.883704627 
 >> +0000
 >> @@ -130,7 +130,6 @@
 >>   void	command_quit(char *);
 >>   void	command_boot(char *);
 >>   void	command_pkboot(char *);
 >> -void	command_dev(char *);
 >>   void	command_consdev(char *);
 >>   void	command_root(char *);
 >>   #ifndef SMALL
 >> diff -urN a/src/sys/arch/i386/stand/dosboot/main.c 
 >> b/src/sys/arch/i386/stand/dosboot/main.c
 >> --- a/src/sys/arch/i386/stand/dosboot/main.c	2024-09-12 05:58:29.835738814 
 >> +0000
 >> +++ b/src/sys/arch/i386/stand/dosboot/main.c	2025-03-26 06:42:31.883704627 
 >> +0000
 >> @@ -65,7 +65,6 @@
 >>   void	command_quit(char *);
 >>   void	command_boot(char *);
 >>   void	command_mode(char *);
 >> -void	command_dev(char *);
 >>
 >>   const struct bootblk_command commands[] = {
 >>   	{ "help",	command_help },
 >> diff -urN a/src/sys/arch/i386/stand/lib/bootmenu.c 
 >> b/src/sys/arch/i386/stand/lib/bootmenu.c
 >> --- a/src/sys/arch/i386/stand/lib/bootmenu.c	2024-11-28 01:49:47.366302337 
 >> +0000
 >> +++ b/src/sys/arch/i386/stand/lib/bootmenu.c	2025-03-26 07:04:54.920298651 
 >> +0000
 >> @@ -57,10 +57,14 @@
 >>   static void
 >>   do_bootcfg_command(const char *cmd, char *arg)
 >>   {
 >> -	if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 >> -		module_add(arg);
 >> -	else if (strcmp(cmd, "fs") == 0)
 >> +	if (strcmp(cmd, BOOTCFG_CMD_DEV) == 0)
 >> +		command_dev(arg);
 >> +	else if (strcmp(cmd, BOOTCFG_CMD_FS) == 0)
 >>   		fs_add(arg);
 >> +	else if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 >> +		module_add(arg);
 >> +	else if (strcmp(cmd, BOOTCFG_CMD_RNDSEED) == 0)
 >> +		rnd_add(arg);
 >>   	else if (strcmp(cmd, BOOTCFG_CMD_USERCONF) == 0)
 >>   		userconf_add(arg);
 >>   }
 >> diff -urN a/src/sys/arch/i386/stand/lib/libi386.h 
 >> b/src/sys/arch/i386/stand/lib/libi386.h
 >> --- a/src/sys/arch/i386/stand/lib/libi386.h	2024-09-18 04:04:46.535251031 
 >> +0000
 >> +++ b/src/sys/arch/i386/stand/lib/libi386.h	2025-03-26 06:42:31.883704627 
 >> +0000
 >> @@ -150,6 +150,9 @@
 >>   void userconf_add(char *);
 >>   void module_add_split(const char *, uint8_t);
 >> 
 >> +/* Note: implementations differ in boot2, dosboot & efiboot */
 >> +void command_dev(char *);
 >> +
 >>   struct btinfo_framebuffer;
 >>   void framebuffer_configure(struct btinfo_framebuffer *);
 >> 
 >> diff -urN a/src/sys/lib/libsa/bootcfg.c b/src/sys/lib/libsa/bootcfg.c
 >> --- a/src/sys/lib/libsa/bootcfg.c	2022-01-05 16:01:54.000000000 +0000
 >> +++ b/src/sys/lib/libsa/bootcfg.c	2025-03-26 07:03:58.367307984 +0000
 >> @@ -227,8 +227,6 @@
 >>   			bootcfg_info.consdev = value;
 >>   		} else if (!strncmp(key, "root", 4)) {
 >>   			bootcfg_info.root = value;
 >> -		} else if (!strncmp(key, BOOTCFG_CMD_LOAD, 4)) {
 >> -			command(BOOTCFG_CMD_LOAD, value);
 >>   		} else if (!strncmp(key, "format", 6)) {
 >>   			printf("value:%c\n", *value);
 >>   			switch (*value) {
 >> @@ -251,8 +249,6 @@
 >>   			}
 >>   		} else if (!strncmp(key, "clear", 5)) {
 >>   			bootcfg_info.clear = !!atoi(value);
 >> -		} else if (!strncmp(key, BOOTCFG_CMD_USERCONF, 8)) {
 >> -			command(BOOTCFG_CMD_USERCONF, value);
 >>   		} else {
 >>   			command(key, value);
 >>   		}
 >> diff -urN a/src/sys/lib/libsa/bootcfg.h b/src/sys/lib/libsa/bootcfg.h
 >> --- a/src/sys/lib/libsa/bootcfg.h	2021-09-07 11:41:31.000000000 +0000
 >> +++ b/src/sys/lib/libsa/bootcfg.h	2025-03-26 07:12:00.103744727 +0000
 >> @@ -29,12 +29,15 @@
 >>   #ifndef _BOOTCFG_H
 >>   #define _BOOTCFG_H
 >> 
 >> -#define BOOTCFG_FILENAME "boot.cfg"
 >> -#define BOOTCFG_MAXMENU	 20
 >> -#define BOOTCFG_MAXBANNER 12
 >> +#define BOOTCFG_FILENAME	"boot.cfg"
 >> +#define BOOTCFG_MAXMENU		20
 >> +#define BOOTCFG_MAXBANNER	12
 >> 
 >> -#define BOOTCFG_CMD_LOAD	  "load"
 >> -#define BOOTCFG_CMD_USERCONF	  "userconf"
 >> +#define BOOTCFG_CMD_DEV		"dev"
 >> +#define BOOTCFG_CMD_FS		"fs"
 >> +#define BOOTCFG_CMD_LOAD	"load"
 >> +#define BOOTCFG_CMD_RNDSEED	"rndseed"
 >> +#define BOOTCFG_CMD_USERCONF	"userconf"
 >>
 >>   typedef void (*bootcfg_command)(const char *cmd, char *arg);
 >> 
 >> ---END patch---
 >> 
 >> 
 >> !DSPAM:67e3b09e68781226255623!
 >> 
 >> 
 >
 > +---------------------+--------------------------+----------------------+
 > | Paul Goyette (.sig) | PGP Key fingerprint:     | E-mail addresses:    |
 > | (Retired)           | 1B11 1849 721C 56C8 F63A | paul@whooppee.com    |
 > | Software Developer  | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org  |
 > | & Network Engineer  |                          | pgoyette99@gmail.com |
 > +---------------------+--------------------------+----------------------+
 >

 +---------------------+--------------------------+----------------------+
 | Paul Goyette (.sig) | PGP Key fingerprint:     | E-mail addresses:    |
 | (Retired)           | 1B11 1849 721C 56C8 F63A | paul@whooppee.com    |
 | Software Developer  | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org  |
 | & Network Engineer  |                          | pgoyette99@gmail.com |
 +---------------------+--------------------------+----------------------+

Responsible-Changed-From-To: port-amd64-maintainer->pgoyette
Responsible-Changed-By: pgoyette@NetBSD.org
Responsible-Changed-When: Tue, 06 May 2025 18:22:17 +0000
Responsible-Changed-Why:
it's mine


State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Tue, 06 May 2025 18:22:17 +0000
State-Changed-Why:
fix committed

Module Name:    src
Committed By:   pgoyette
Date:           Tue May  6 18:16:12 UTC 2025

Modified Files:
        src/sys/arch/i386/stand/boot: boot2.c
        src/sys/arch/i386/stand/lib: bootmenu.c libi386.h
        src/sys/arch/i386/stand/pxeboot: main.c
        src/sys/lib/libsa: bootcfg.c bootcfg.h

Log Message:
Allow the dev= command when processing /boot.cfg file.  This
addresses kern/59207


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/i386/stand/boot/boot2.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/i386/stand/lib/bootmenu.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/i386/stand/lib/libi386.h
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/i386/stand/pxeboot/main.c
cvs rdiff -u -r1.9 -r1.10 src/sys/lib/libsa/bootcfg.c
cvs rdiff -u -r1.5 -r1.6 src/sys/lib/libsa/bootcfg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-amd64/59207: unexpected behavior of dev command in bootstrap
 code
Date: Wed, 7 May 2025 06:05:05 +0000 (UTC)

 On Sun, 4 May 2025, Paul Goyette via gnats wrote:

 > Is there any chance we can get these patches committed soon?
 >
 > they work just fine on my machine...
 >

 I see that you've committed it. Great!

 I wanted to change all the strncmp()s in sys/lib/libsa/bootcfg.c:perform_bootcfg()
 to plain strcmp()s too, but, that's a minor thing... :)

 -RVP

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.