On Sun, Aug 28, 2022 at 10:22:23AM +0000, Klemens Nanni wrote:
> Every platform ought to set `stages', `stage1' and optionally `stage2'
> in md_init(), otherwise passing explicit files results won't work as
> `stages' is zero-initialised and no default path is set:
> 
>       # installboot -v sd0 /root/BOOTAA64.EFI
>       usage: installboot [-npv] [-r root] disk [stage1]
> 
> This is correct synopsis and ought to work, but efi_installboot.c has
> an empty md_init().
> 
> Set stage bits for EFI platforms (armv7, arm64 and riscv64) to fix this:
> 
>       # ./obj/installboot -nv sd0 /root/BOOTAA64.EFI
>       Using / as root
>       would install bootstrap on /dev/rsd0c
>       using first-stage /root/BOOTAA64.EFI
>       would copy /root/BOOTAA64.EFI to 
> /tmp/installboot.2bGhLGT1eF/efi/boot/bootaa64.efi
>       would write /tmp/installboot.2bGhLGT1eF/efi/boot/startup.nsh
> 
> /usr/src/distrib/ uses `-r /mnt' without explicit stage files, which is
> install media work despite this bug.
> 
> These usages keep working with this diff (/mnt is another root install):
>       # ./obj/installboot sd4 /usr/mdec/BOOTAA64.EFI
>       # ./obj/installboot -r /mnt sd4 /usr/mdec/BOOTAA64.EFI
>       # ./obj/installboot -r /mnt sd4
> 
> And arm64 miniroot keeps booting and installs/ugprades fine with this.
> 
> I've only tested this on arm64 but it should be the same for other EFIs
> (armv7 and riscv64);  this just looks like an oversight.
> 
> Feedback? OK?

macppc suffers the same problem:

        # installboot -nv wd0 ./ofwboot
        usage:  installboot [-nv] [-r root] disk [stage1]
                installboot [-nv] -p disk
        # ./obj/installboot -nv wd0 ./ofwboot
        Using / as root
        would install bootstrap on /dev/rwd0c
        using first-stage ./ofwboot
        would copy ./ofwboot to /tmp/installboot.Ymmm6QU8OJ/ofwboot

The same fix leads to a bit more cleanup since using `stage1' means
that installboot.c's main() already handles -r, i.e. write_filesystem()
no longer has needs to do the fileprefix() dance itself.

Feedback? OK?


Index: macppc_installboot.c
===================================================================
RCS file: /mount/openbsd/cvs/src/usr.sbin/installboot/macppc_installboot.c,v
retrieving revision 1.4
diff -u -p -r1.4 macppc_installboot.c
--- macppc_installboot.c        20 Jul 2021 14:51:56 -0000      1.4
+++ macppc_installboot.c        31 Aug 2022 19:28:10 -0000
@@ -60,6 +60,8 @@ static int    findmbrfat(int, struct diskla
 void
 md_init(void)
 {
+       stages = 1;
+       stage1 = "/usr/mdec/boot";
 }
 
 void
@@ -161,12 +163,9 @@ write_filesystem(struct disklabel *dl, c
        struct msdosfs_args args;
        char cmd[60];
        char dst[PATH_MAX];
-       char *src;
-       size_t mntlen, pathlen, srclen;
+       size_t mntlen, pathlen;
        int rslt;
 
-       src = NULL;
-
        /* Create directory for temporary mount point. */
        strlcpy(dst, "/tmp/installboot.XXXXXXXXXX", sizeof(dst));
        if (mkdtemp(dst) == NULL)
@@ -224,17 +223,11 @@ write_filesystem(struct disklabel *dl, c
                warn("unable to build /ofwboot path");
                goto umount;
        }
-       src = fileprefix(root, "/usr/mdec/ofwboot");
-       if (src == NULL) {
-               rslt = -1;
-               goto umount;
-       }
-       srclen = strlen(src);
        if (verbose)
                fprintf(stderr, "%s %s to %s\n",
-                   (nowrite ? "would copy" : "copying"), src, dst);
+                   (nowrite ? "would copy" : "copying"), stage1, dst);
        if (!nowrite) {
-               rslt = filecopy(src, dst);
+               rslt = filecopy(stage1, dst);
                if (rslt == -1)
                        goto umount;
        }
@@ -251,8 +244,6 @@ rmdir:
        dst[mntlen] = '\0';
        if (rmdir(dst) == -1)
                err(1, "rmdir('%s') failed", dst);
-
-       free(src);
 
        if (rslt == -1)
                exit(1);

Reply via email to