On Sun, Apr 16, 2023 at 11:39:33PM +0200, Patrick Wildt wrote:
> You can also simply dd the image to /dev/sda and reboot, but that still
> doesn't solve the problem.  The bootup is hard to debug because the
> console is KVM and uses viogpu.  As soon as we exit the EFI bootservices
> the framebuffer is shut down for whatever reason.  Means we can only get
> access to it again through viogpu, which happens pretty late.  I wish we
> had a serial console, because Qemu/edk2 can do it, they just don't make
> it available.  This is gonna be "fun" to debug without serial.

i dont think the problem here is booting openbsd, but if it were the
diff below might help.

this diff teaches BOOTAA64.EFI to load files from the EFI System
Partition that the boot loader was run from. this means you can go
"boot esp0a:bsd.rd" at the boot> prompt and get into the installer.

i wrote this cos i wanted another option for getting openbsd installed
on machines where the boot loader and driver support arent that
great yet. i can imagine it being useful for upgrading the OS on a
system where it's difficult to plug install media in, or repartitioning
or overwriting the disk is risky. especially if you also just want to
check how well the hardware is supported in openbsd before making
changes.

> 
> On Sat, Apr 15, 2023 at 11:33:39AM +0100, Chris Narkiewicz wrote:
> > 
> > I asked Hetzner to import install73.img and mounted it as VM CD-ROM,
> > but it doesn't boot. I'm not sure if this is a bug either.
> > 
> > Cheers,
> > Chris Narkiewic
> > 
> > On Thu, 2023-04-13 at 16:16 +0000, Mikolaj Kucharski wrote:
> > > Hi,
> > > 
> > > I'm not sure does this belong to bugs@
> > > 
> > > However what I used in the past was Yaifo and I still use it every
> > > few
> > > years, but it takes too much effort to rebase it to -current, so I
> > > didn't touch it for few years now, but for me it worked really
> > > nicely.
> > > 
> > > https://github.com/jedisct1/yaifo
> > > 
> > > 
> > > On Thu, Apr 13, 2023 at 09:00:23AM +0200, Peter J. Philipp wrote:
> > > > Hi,
> > > > 
> > > > Yesterday hetzner.com came out with arm64 cloud instances, I tried
> > > > one out.
> > > > Here is what I found.? The images they give you a choice of does
> > > > not include
> > > > OpenBSD, so I had to get a ubuntu OS.? That's fine the EFI
> > > > partition was
> > > > already mounted.? Through trialing this I found the best way of
> > > > getting the
> > > > OpenBSD loader to boot was the following way:
> > > > 
> > > > 1. place miniroot73.img on the EFI partition root (/boot/efi/)
> > > > 2. reboot
> > > > 3. press escape to get to the BIOS, there is 3 options one is a
> > > > configuration
> > > > ?? option under 1, enter it.? I'm working off memory here I didn't
> > > > save 
> > > > ?? anything so take it with a grain of salt on exactness.? In this
> > > > option is
> > > > ?? an option to create a RAM drive from a file, go there and enter
> > > > the
> > > > ?? miniroot73.img (45MB).? The down arrows didn't work in this BIOS
> > > > so it was
> > > > ?? great that it wrapped around going up.
> > > > 4. next go back into the main bios screen by pressing escape.?
> > > > There is option
> > > > ?? 3 for boot options, enter it.? There is a boot from file option
> > > > enter it.
> > > > ?? Select the RAM drive and manouver your way to the bootaa64.efi
> > > > file.? Press
> > > > ?? enter.
> > > > 5. OpenBSD loader now loads.? ls displays bsd and bsd.rd, the
> > > > console is on
> > > > ?? comcons0 or something like that.? Switching to fb0 works too.?
> > > > Then when
> > > > ?? pressing boot a blank screen happens.? Waiting a while no
> > > > prompts and I
> > > > ?? didn't try to blind type anything.? Doing this again with fb0
> > > > doesn't
> > > > ?? work either.
> > > > 6. Full stop, I didn't get further.
> > > > 
> > > > I then deleted my instance as ubuntu is not good enough for me.? I
> > > > guess we'll
> > > > have to wait until the pros get to it.? Thanks!
> > > > 
> > > > Best Regards,
> > > > -peter
> > > > 
> > > 
> > 
> > -- 
> > +44 7502 415 180 (Phone, Signal, WhatsApp)
> > @ezaquarii:etacassiopeiae.net (Matrix)

Index: conf.c
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/conf.c,v
retrieving revision 1.44
diff -u -p -r1.44 conf.c
--- conf.c      15 Feb 2023 14:13:38 -0000      1.44
+++ conf.c      15 Apr 2023 02:22:34 -0000
@@ -58,10 +58,13 @@ struct fs_ops file_system[] = {
          ufs_stat,    ufs_readdir,  ufs_fchmod },
        { ufs2_open,   ufs2_close,   ufs2_read,   ufs2_write,   ufs2_seek,
          ufs2_stat,   ufs2_readdir, ufs2_fchmod },
+       { esp_open,    esp_close,    esp_read,    esp_write,    esp_seek,
+         esp_stat,    esp_readdir,  }
 };
 int nfsys = nitems(file_system);
 
 struct devsw   devsw[] = {
+       { "esp", espstrategy, espopen, espclose, espioctl },
        { "tftp", tftpstrategy, tftpopen, tftpclose, tftpioctl },
        { "sd", efistrategy, efiopen, eficlose, efiioctl },
        { "sr", srstrategy, sropen, srclose, srioctl },
Index: efidev.c
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/efidev.c,v
retrieving revision 1.11
diff -u -p -r1.11 efidev.c
--- efidev.c    1 Sep 2022 13:45:26 -0000       1.11
+++ efidev.c    15 Apr 2023 02:22:34 -0000
@@ -565,3 +565,213 @@ efiioctl(struct open_file *f, u_long cmd
 {
        return 0;
 }
+
+/*
+ * load a file from the EFI System Partition
+ */
+
+static EFI_GUID lip_guid = LOADED_IMAGE_PROTOCOL;
+static EFI_GUID sfsp_guid = SIMPLE_FILE_SYSTEM_PROTOCOL;
+static EFI_GUID fi_guid = EFI_FILE_INFO_ID;
+
+int
+esp_open(char *path, struct open_file *f)
+{
+       extern EFI_HANDLE IH;
+       extern EFI_BOOT_SERVICES *BS;
+
+       EFI_LOADED_IMAGE *li = NULL;
+       EFI_FILE_IO_INTERFACE *ESPVolume;
+       CHAR16 *fname;
+       EFI_FILE_HANDLE VH, FH;
+       UINTN pathlen, i;
+       EFI_STATUS status;
+
+       if (strcmp("esp", f->f_dev->dv_name) != 0)
+               return ENXIO;
+
+       if (IH == NULL)
+               return ENXIO;
+
+       /* get the loaded image protocol interface */
+       status = BS->HandleProtocol(IH, &lip_guid, (void **)&li);
+       if (status != EFI_SUCCESS)
+               return ENXIO;
+
+       /* get a fs handle */
+       status = BS->HandleProtocol(li->DeviceHandle, &sfsp_guid,
+           (void *)&ESPVolume);
+       if (status != EFI_SUCCESS)
+               return ENXIO;
+
+       status = ESPVolume->OpenVolume(ESPVolume, &VH);
+       if (status != EFI_SUCCESS)
+               return ENOENT;
+
+       pathlen = strlen(path) + 1;
+       fname = alloc(pathlen * sizeof(*fname));
+       if (fname == NULL)
+               return ENOMEM;
+
+       /* No AsciiStrToUnicodeStrS */
+       for (i = 0; i < pathlen; i++)
+               fname[i] = path[i];
+
+       status = VH->Open(VH, &FH, fname, EFI_FILE_MODE_READ,
+           EFI_FILE_READ_ONLY /*| EFI_FILE_HIDDEN*/ | EFI_FILE_SYSTEM);
+       free(fname, pathlen * sizeof(*fname));
+       if (status != EFI_SUCCESS)
+               return ENOENT;
+
+       f->f_fsdata = FH;
+       return (0);
+}
+
+int
+esp_close(struct open_file *f)
+{
+       EFI_FILE_HANDLE FH = f->f_fsdata;
+       FH->Close(FH);
+       return 0;
+}
+
+int
+esp_read(struct open_file *f, void *addr, size_t size, size_t *resid)
+{
+       EFI_FILE_HANDLE FH = f->f_fsdata;
+       UINT64 readlen = size;
+       EFI_STATUS status;
+
+       status = FH->Read(FH, &readlen, addr);
+       if (status != EFI_SUCCESS)
+               return (EIO);
+
+       *resid = size - readlen;
+       return (0);
+}
+
+int
+esp_write(struct open_file *f, void *start, size_t size, size_t *resid)
+{
+       return (EROFS);
+}
+
+off_t
+esp_seek(struct open_file *f, off_t offset, int where)
+{
+       EFI_FILE_HANDLE FH = f->f_fsdata;
+       UINT64 position;
+       EFI_STATUS status;
+
+       switch(where) {
+       case SEEK_CUR:
+               status = FH->GetPosition(FH, &position);
+               if (status != EFI_SUCCESS) {
+                       errno = EIO;
+                       return ((off_t)-1);
+               }
+
+               position += offset;
+               break;
+       case SEEK_SET:
+               position = offset;
+               break;
+       case SEEK_END:
+               position = 0xFFFFFFFFFFFFFFFF;
+               break;
+       default:
+               errno = EINVAL;
+               return ((off_t)-1);
+       }
+
+       status = FH->SetPosition(FH, position);
+       if (status != EFI_SUCCESS) {
+               errno = EIO;
+               return ((off_t)-1);
+       }
+
+       return (0);
+}
+
+int
+esp_stat(struct open_file *f, struct stat *sb)
+{
+
+       EFI_FILE_HANDLE FH = f->f_fsdata;
+       EFI_FILE_INFO fi;
+       EFI_FILE_INFO *fip = &fi;
+       UINTN filen = sizeof(fi);
+       EFI_STATUS status;
+       ssize_t rv = -1;
+
+       sb->st_mode = 0444;
+       sb->st_nlink = 1;
+       sb->st_uid = 0;
+       sb->st_gid = 0;
+
+       status = FH->GetInfo(FH, &fi_guid, &filen, fip);
+       switch (status) {
+       case EFI_SUCCESS:
+               sb->st_size = fip->FileSize;
+               return (0);
+       case EFI_BUFFER_TOO_SMALL:
+               break;
+       default:
+               return (EIO);
+       }
+
+       fip = alloc(filen);
+       if (fip == NULL)
+               return (ENOMEM);
+
+       status = FH->GetInfo(FH, &fi_guid, &filen, fip);
+       if (status != EFI_SUCCESS)
+               goto done;
+
+       sb->st_size = fip->FileSize;
+
+done:
+       free(fip, filen);
+       return (rv);
+}
+
+int
+esp_readdir(struct open_file *f, char *name)
+{
+       return EOPNOTSUPP;
+}
+
+int
+espopen(struct open_file *f, ...)
+{
+        u_int unit;
+        va_list ap;
+
+        va_start(ap, f);
+        unit = va_arg(ap, u_int);
+        va_end(ap);
+
+        if (unit != 0)
+                return 1;
+
+        return 0;
+}
+
+int
+espclose(struct open_file *f)
+{
+       return 0;
+}
+
+int
+espioctl(struct open_file *f, u_long cmd, void *data)
+{
+        return EOPNOTSUPP;
+}
+
+int
+espstrategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
+    size_t *rsize)
+{
+       return EOPNOTSUPP;
+}
Index: efidev.h
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/efidev.h,v
retrieving revision 1.3
diff -u -p -r1.3 efidev.h
--- efidev.h    9 Dec 2020 18:10:18 -0000       1.3
+++ efidev.h    15 Apr 2023 02:22:34 -0000
@@ -34,3 +34,16 @@ int           efiopen(struct open_file *, ...);
 int             efistrategy(void *, int, daddr_t, size_t, void *, size_t *);
 int             eficlose(struct open_file *);
 int             efiioctl(struct open_file *, u_long, void *);
+
+int             esp_open(char *, struct open_file *);
+int             esp_close(struct open_file *);
+int             esp_read(struct open_file *, void *, size_t, size_t *);
+int             esp_write(struct open_file *, void *, size_t, size_t *);
+off_t           esp_seek(struct open_file *, off_t, int);
+int             esp_stat(struct open_file *, struct stat *);
+int             esp_readdir(struct open_file *, char *);
+
+int             espopen(struct open_file *, ...);
+int             espclose(struct open_file *);
+int             espioctl(struct open_file *, u_long, void *);
+int             espstrategy(void *, int, daddr_t, size_t, void *, size_t *);

Reply via email to