On Wed, Dec 22, 2021 at 12:34:34PM -0500, Dave Voutila wrote:
> 
> Claudio Jeker <cje...@diehard.n-r-g.com> writes:
> 
> > On Wed, Dec 22, 2021 at 10:14:40AM -0500, Dave Voutila wrote:
> >>
> >> Claudio Jeker <cje...@diehard.n-r-g.com> writes:
> >>
> >> > I added support for vmctl -cL -B net -b bsd.rd -d disk.img to run the
> >> > autoinstall by emulating a PXE boot. In the commit
> >> > https://github.com/openbsd/src/commit/a13de4d12a4c9ba0edc05aab2ad635f782449229
> >> > the feature got removed over eagerly.
> >> >
> >> > This diff adds this back because I find this super practical.
> >>
> >> Seems to add back more than that...see below.
> >>
> >
> > Those are becasue of warnings from the compiler and I do not like to send
> > out diffs for files that compile with a bunch of warnings.
> > I can split this out into an extra commit if people prefer that.
> >
> 
> Yes please. :) Understand the warnings concern, though.
> 

So here is the diff just fixing -B net -b bsd.rd
Somebody else can look into all the clang 13 errors in vmd.

-- 
:wq Claudio

Index: loadfile.h
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/loadfile.h,v
retrieving revision 1.15
diff -u -p -r1.15 loadfile.h
--- loadfile.h  16 Jun 2021 16:55:02 -0000      1.15
+++ loadfile.h  22 Dec 2021 14:34:06 -0000
@@ -80,7 +80,8 @@
 #define PML2_PAGE 0x13000
 #define NPTE_PG (PAGE_SIZE / sizeof(uint64_t))
 
-int loadfile_elf(gzFile, struct vm_create_params *, struct vcpu_reg_state *);
+int    loadfile_elf(gzFile, struct vm_create_params *, struct vcpu_reg_state *,
+           unsigned int);
 
 size_t mread(gzFile, paddr_t, size_t);
 
Index: loadfile_elf.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/loadfile_elf.c,v
retrieving revision 1.39
diff -u -p -r1.39 loadfile_elf.c
--- loadfile_elf.c      4 May 2021 10:48:51 -0000       1.39
+++ loadfile_elf.c      29 Dec 2021 13:14:04 -0000
@@ -118,7 +118,7 @@ static void setsegment(struct mem_segmen
 static int elf32_exec(gzFile, Elf32_Ehdr *, u_long *, int);
 static int elf64_exec(gzFile, Elf64_Ehdr *, u_long *, int);
 static size_t create_bios_memmap(struct vm_create_params *, bios_memmap_t *);
-static uint32_t push_bootargs(bios_memmap_t *, size_t);
+static uint32_t push_bootargs(bios_memmap_t *, size_t, bios_bootmac_t *);
 static size_t push_stack(uint32_t, uint32_t);
 static void push_gdt(void);
 static void push_pt_32(void);
@@ -264,13 +264,14 @@ push_pt_64(void)
  */
 int
 loadfile_elf(gzFile fp, struct vm_create_params *vcp,
-    struct vcpu_reg_state *vrs)
+    struct vcpu_reg_state *vrs, unsigned int bootdevice)
 {
        int r, is_i386 = 0;
        uint32_t bootargsz;
        size_t n, stacksize;
        u_long marks[MARK_MAX];
        bios_memmap_t memmap[VMM_MAX_MEM_RANGES + 1];
+       bios_bootmac_t bm, *bootmac = NULL;
 
        if ((r = gzread(fp, &hdr, sizeof(hdr))) != sizeof(hdr))
                return 1;
@@ -301,8 +302,12 @@ loadfile_elf(gzFile fp, struct vm_create
        else
                push_pt_64();
 
+       if (bootdevice & VMBOOTDEV_NET) {
+               bootmac = &bm;
+               memcpy(bootmac, vcp->vcp_macs[0], ETHER_ADDR_LEN);
+       }
        n = create_bios_memmap(vcp, memmap);
-       bootargsz = push_bootargs(memmap, n);
+       bootargsz = push_bootargs(memmap, n, bootmac);
        stacksize = push_stack(bootargsz, marks[MARK_END]);
 
        vrs->vrs_gprs[VCPU_REGS_RIP] = (uint64_t)marks[MARK_ENTRY];
@@ -382,9 +387,9 @@ create_bios_memmap(struct vm_create_para
  *  The size of the bootargs
  */
 static uint32_t
-push_bootargs(bios_memmap_t *memmap, size_t n)
+push_bootargs(bios_memmap_t *memmap, size_t n, bios_bootmac_t *bootmac)
 {
-       uint32_t memmap_sz, consdev_sz, i;
+       uint32_t memmap_sz, consdev_sz, bootmac_sz, i;
        bios_consdev_t consdev;
        uint32_t ba[1024];
 
@@ -407,6 +412,15 @@ push_bootargs(bios_memmap_t *memmap, siz
        ba[i + 2] = consdev_sz;
        memcpy(&ba[i + 3], &consdev, sizeof(bios_consdev_t));
        i += consdev_sz / sizeof(int);
+
+       if (bootmac) {
+               bootmac_sz = 3 * sizeof(int) + (sizeof(bios_bootmac_t) + 3) & 
~3;
+               ba[i] = 0x7;   /* bootmac */
+               ba[i + 1] = bootmac_sz;
+               ba[i + 2] = bootmac_sz;
+               memcpy(&ba[i + 3], bootmac, sizeof(bios_bootmac_t));
+               i += bootmac_sz / sizeof(int);
+       } 
 
        ba[i++] = 0xFFFFFFFF; /* BOOTARG_END */
 
Index: vm.c
===================================================================
RCS file: /cvs/src/usr.sbin/vmd/vm.c,v
retrieving revision 1.66
diff -u -p -r1.66 vm.c
--- vm.c        29 Nov 2021 05:17:35 -0000      1.66
+++ vm.c        22 Dec 2021 14:33:55 -0000
@@ -336,7 +336,7 @@ start_vm(struct vmd_vm *vm, int fd)
                        fatalx("failed to open kernel - exiting");
 
                /* Load kernel image */
-               ret = loadfile_elf(fp, vcp, &vrs);
+               ret = loadfile_elf(fp, vcp, &vrs, vmc->vmc_bootdevice);
 
                /*
                 * Try BIOS as a fallback (only if it was provided as an image

Reply via email to