BOOT_ARG from <machine/boot_flag.h> is a NetBSDism which did not make
its way to OpenBSD, where parsing kernel commandline options is done
inline.

It is no surprise then, that it is only used by the sparc64 boot blocks;
but boot blocks really only care about one option, -a, so there is no
need to check for more letters.

The following diff removes BOOT_ARG and simplifies boot blocks logic.
Moreover, since the kernel will pick its options from Open Firmware and
not from the boot blocks, it makes absolutely no sense for the boot
blocks to try and rebuild a commandline with the various options, so
let's get rid of this as well while changing the boot blocks.

Note that, after this diff is applied, none of the original contents of
<machine/boot_flag.h> remain, and the licence block ought to be updated.
This is left as an exercize for the appropriate developer.

Index: include/boot_flag.h
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc64/include/boot_flag.h,v
retrieving revision 1.5
diff -u -p -r1.5 boot_flag.h
--- include/boot_flag.h 26 Nov 2014 20:06:53 -0000      1.5
+++ include/boot_flag.h 3 Jan 2020 18:27:05 -0000
@@ -30,39 +30,6 @@
 #ifndef _MACHINE_BOOT_FLAG_H_
 #define _MACHINE_BOOT_FLAG_H_
 
-#include <sys/reboot.h>
-
-/*
- * Recognize standard boot arguments. If the flag is known, appropriate
- * value is or'ed to retval, otherwise retval is left intact.
- * Note that not all ports use all flags recognized here. This list is mere
- * concatenation of all non-conflicting standard boot flags. Individual ports
- * might use also other flags (see e.g. alpha).
- */
-#define        BOOT_FLAG(arg, retval) do {                             \
-       switch (arg) {                                          \
-       case 'a': /* ask for file name to boot from */          \
-               (retval) |= RB_ASKNAME;                         \
-               break;                                          \
-       case 'b': /* always halt, never reboot */               \
-               (retval) |= RB_HALT;                            \
-               break;                                          \
-       case 'c': /* userconf */                                \
-               (retval) |= RB_CONFIG;                  \
-               break;                                          \
-       case 'd': /* break into the kernel debugger ASAP (if compiled in) */ \
-               (retval) |= RB_KDB;                             \
-               break;                                          \
-       case 's': /* boot to single user */                     \
-               (retval) |= RB_SINGLE;                          \
-               break;                                          \
-       default:  /* something else, do nothing */              \
-               break;                                          \
-       } /* switch */                                          \
-                                                               \
-       } while (/* CONSTCOND */ 0)
-
-
 /* softraid boot information */
 #define BOOTSR_UUID_MAX 16
 #define BOOTSR_CRYPTO_MAXKEYBYTES 32
Index: stand/ofwboot/boot.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc64/stand/ofwboot/boot.c,v
retrieving revision 1.32
diff -u -p -r1.32 boot.c
--- stand/ofwboot/boot.c        29 Oct 2019 02:55:52 -0000      1.32
+++ stand/ofwboot/boot.c        3 Jan 2020 18:27:05 -0000
@@ -53,7 +53,6 @@
 #include <sys/exec_elf.h>
 #include <sys/reboot.h>
 #include <sys/disklabel.h>
-#include <machine/boot_flag.h>
 
 #include <machine/cpu.h>
 #include <lib/libsa/arc4.h>
@@ -124,10 +123,18 @@ parseargs(char *str, int *howtop)
                while (*cp == ' ')
                        ++cp;
        }
+       /*
+        * Note that, if only options have been passed, without a kernel
+        * name, str == cp and options will be ignored at the boot blocks
+        * level.
+        * This a feature intended to make `boot -a' behave as intended.
+        * If you want the bootblocks to handle arguments explicitly, a
+        * kernel filename needs to be provided (as in `boot bsd -a').
+        */
        *str = 0;
-       switch(*cp) {
+       switch (*cp) {
        default:
-               printf ("boot options string <%s> must start with -\n", cp);
+               printf("boot options string <%s> must start with -\n", cp);
                return -1;
        case 0:
                return 0;
@@ -137,9 +144,10 @@ parseargs(char *str, int *howtop)
 
        ++cp;
        while (*cp) {
-               BOOT_FLAG(*cp, *howtop);
-               /* handle specialties */
                switch (*cp++) {
+               case 'a':
+                       *howtop |= RB_ASKNAME;
+                       break;
                case 'd':
                        if (!debug) debug = 1;
                        break;
@@ -379,7 +387,7 @@ main(void)
        int chosen;
        char bootline[512];             /* Should check size? */
        char *cp;
-       int i, fd, len;
+       int i, fd;
 #ifdef SOFTRAID
        int err;
 #endif
@@ -464,7 +472,7 @@ main(void)
                        }
                }
                if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)))
-                       printf("open %s: %s\n", opened_name, strerror(errno));
+                       printf("open %s: %s\n", BOOTRANDOM, strerror(errno));
 
                rc4_keysetup(&randomctx, rnddata, sizeof rnddata);
                rc4_skip(&randomctx, 1536);
@@ -473,21 +481,12 @@ main(void)
                        printf("open %s: %s\n", opened_name, strerror(errno));
                        continue;
                }
-               len = snprintf(bootline, sizeof bootline, "%s%s%s%s",
-                   opened_name,
-                   (boothowto & RB_ASKNAME) ? " -a" : "",
-                   (boothowto & RB_SINGLE) ? " -s" : "",
-                   (boothowto & RB_KDB) ? " -d" : "");
-               if (len >= sizeof bootline) {
-                       printf("bootargs too long: %s\n", bootline);
-                       _rtt();
-               }
                /* XXX void, for now */
 #ifdef DEBUG
                if (debug)
-                       printf("main: Calling loadfile(fd, %s)\n", bootline);
+                       printf("main: Calling loadfile(fd, %s)\n", opened_name);
 #endif
-               (void)loadfile(fd, bootline);
+               (void)loadfile(fd, opened_name);
        }
        return 0;
 }
Index: stand/ofwboot/vers.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc64/stand/ofwboot/vers.c,v
retrieving revision 1.16
diff -u -p -r1.16 vers.c
--- stand/ofwboot/vers.c        29 Oct 2019 02:55:52 -0000      1.16
+++ stand/ofwboot/vers.c        3 Jan 2020 18:27:05 -0000
@@ -1 +1 @@
-const char version[] = "1.15";
+const char version[] = "1.16";

Reply via email to