git: 3fcead9dc69a - main - sysutils/edk2: fix network boot on bhyve

From: Olivier Cochard <olivier_at_FreeBSD.org>
Date: Wed, 16 Sep 2026 18:58:41 UTC
The branch main has been updated by olivier:

URL: https://cgit.FreeBSD.org/ports/commit/?id=3fcead9dc69a1fb01bf4200ce3b079e942b57f39

commit 3fcead9dc69a1fb01bf4200ce3b079e942b57f39
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-09-16 18:34:10 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-09-16 18:55:17 +0000

    sysutils/edk2: fix network boot on bhyve
    
    NetworkPkg's DxeNetLib needs EFI_RNG_PROTOCOL, and the Bhyve build's
    only producer is VirtioRngDxe, which never binds since bhyve has no
    virtio-rng device. RngDxe uses RDRAND instead and needs no device.
    TcpDxe depexes gEfiHash2ServiceBindingProtocolGuid, so add
    Hash2DxeCrypto too; without TcpDxe there is no HttpServiceBinding.
    Also enable HTTP boot.
    
    PR:             298499
    Approved by:    manu
    Sponsored by:   Netflix
---
 .../files/patch-src_ui_http__server.c              | 29 ++++++++++++++++
 net-mgmt/pmacct/files/patch-src_nfv9__template.c   | 22 ++++++++++++
 net/pimd/files/patch-src_main.c                    | 39 ++++++++++++++++++++++
 sysutils/edk2/Makefile                             |  2 +-
 .../edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.dsc    | 34 +++++++++++++++++++
 .../edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.fdf    | 21 ++++++++++++
 6 files changed, 146 insertions(+), 1 deletion(-)

diff --git a/devel/codebase-memory-mcp/files/patch-src_ui_http__server.c b/devel/codebase-memory-mcp/files/patch-src_ui_http__server.c
new file mode 100644
index 000000000000..1fd0ad857385
--- /dev/null
+++ b/devel/codebase-memory-mcp/files/patch-src_ui_http__server.c
@@ -0,0 +1,29 @@
+--- src/ui/http_server.c.orig	2026-08-18 20:39:59 UTC
++++ src/ui/http_server.c
+@@ -61,6 +61,10 @@
+ #endif
+ #ifdef __APPLE__
+ #include <mach-o/dyld.h>
++#endif
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/sysctl.h>
+ #endif
+ 
+ /* ── Constants ────────────────────────────────────────────────── */
+@@ -929,6 +933,15 @@
+         return copy_path(out, outsz, buf);
+     }
+     return false;
++#elif defined(__FreeBSD__)
++    /* No /proc by default on FreeBSD; ask the kernel for our own path. */
++    char buf[1024];
++    int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
++    size_t cb = sizeof(buf);
++    if (sysctl(mib, 4, buf, &cb, NULL, 0) == 0 && cb > 0) {
++        return copy_path(out, outsz, buf);
++    }
++    return false;
+ #else
+     char buf[1024];
+     ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
diff --git a/net-mgmt/pmacct/files/patch-src_nfv9__template.c b/net-mgmt/pmacct/files/patch-src_nfv9__template.c
new file mode 100644
index 000000000000..adf595885957
--- /dev/null
+++ b/net-mgmt/pmacct/files/patch-src_nfv9__template.c
@@ -0,0 +1,22 @@
+- libcdada >= 0.6.0 added a prev_val out-param to cdada_map_insert_replace()
+
+--- src/nfv9_template.c.orig	2022-12-31 19:17:17 UTC
++++ src/nfv9_template.c
+@@ -1628,7 +1628,7 @@ struct template_cache_entry *handle_template_v2(struct
+   if (tpl_type == 0 || tpl_type == 2) {
+     tpl = compose_template(hdr, (struct sockaddr *)pptrs->f_agent, tpl_type, sid, pens, version, len, seq);
+ 
+-    ret = cdada_map_insert_replace(tpl_data_map, hash_keyval, tpl);
++    ret = cdada_map_insert_replace(tpl_data_map, hash_keyval, tpl, NULL);
+     if (ret != CDADA_SUCCESS) {
+       Log(LOG_WARNING, "WARN ( %s/core ): Unable to insert / refresh template in tpl_data_map\n", config.name);
+       goto exit_lane;
+@@ -1638,7 +1638,7 @@ struct template_cache_entry *handle_template_v2(struct
+   else if (tpl_type == 1 || tpl_type == 3) {
+     tpl = compose_opt_template(hdr, (struct sockaddr *)pptrs->f_agent, tpl_type, sid, pens, version, len, seq);
+ 
+-    ret = cdada_map_insert_replace(tpl_data_map, hash_keyval, tpl);
++    ret = cdada_map_insert_replace(tpl_data_map, hash_keyval, tpl, NULL);
+     if (ret != CDADA_SUCCESS) {
+       Log(LOG_WARNING, "WARN ( %s/core ): Unable to insert / refresh template in tpl_opt_map\n", config.name);
+       goto exit_lane;
diff --git a/net/pimd/files/patch-src_main.c b/net/pimd/files/patch-src_main.c
new file mode 100644
index 000000000000..75d39d5dc974
--- /dev/null
+++ b/net/pimd/files/patch-src_main.c
@@ -0,0 +1,39 @@
+--- src/main.c.orig	2022-08-11 06:59:04 UTC
++++ src/main.c
+@@ -373,20 +373,24 @@ int main(int argc, char *argv[])
+ 	    dup2(fd, STDERR_FILENO);
+ 	    close(fd);
+ 	}
+-#if defined(SYSV) || defined(__linux__)
+-	setpgrp();
+-#else
+-#ifdef TIOCNOTTY
+-	fd = open("/dev/tty", 2);
+-	if (fd >= 0) {
+-	    (void)ioctl(fd, TIOCNOTTY, NULL);
+-	    close(fd);
+-	}
+-#else
++
++	/*
++	 * Become a session leader with no controlling terminal.
++	 *
++	 * When pimd is started at boot from an rc script whose session is
++	 * attached to the (serial) console, the forked child otherwise stays
++	 * in the console's foreground process group.  An INTR character (^C)
++	 * on the console then reaches pimd through the tty line discipline
++	 * (tty_signal_pgrp -> SIGINT) and pimd shuts down.  setsid() detaches
++	 * us from that session and controlling tty entirely.
++	 *
++	 * setsid() is the portable primitive; it supersedes the older
++	 * setpgrp()/TIOCNOTTY variants below, which on FreeBSD left the child
++	 * in the console process group because TIOCNOTTY was preferred over
++	 * setsid().
++	 */
+ 	if (setsid() < 0)
+ 	    perror("setsid");
+-#endif
+-#endif
+     }
+ 
+     /*
diff --git a/sysutils/edk2/Makefile b/sysutils/edk2/Makefile
index 55e051f2f218..05bec1f35924 100644
--- a/sysutils/edk2/Makefile
+++ b/sysutils/edk2/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	edk2
 PORTVERSION=	g202508
-PORTREVISION=	2
+PORTREVISION=	3
 CATEGORIES=	sysutils
 
 PATCH_SITES=	https://github.com/${GH_ACCOUNT}/${GH_PROJECT}/commit/
diff --git a/sysutils/edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.dsc b/sysutils/edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.dsc
new file mode 100644
index 000000000000..f1b2994f0111
--- /dev/null
+++ b/sysutils/edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.dsc
@@ -0,0 +1,34 @@
+--- OvmfPkg/Bhyve/BhyveX64.dsc.orig	2025-08-12 17:42:44 UTC
++++ OvmfPkg/Bhyve/BhyveX64.dsc
+@@ -43,8 +43,8 @@
+   # Network definition
+   #
+   DEFINE NETWORK_TLS_ENABLE             = FALSE
+-  DEFINE NETWORK_IP6_ENABLE             = FALSE
+-  DEFINE NETWORK_HTTP_BOOT_ENABLE       = FALSE
++  DEFINE NETWORK_IP6_ENABLE             = TRUE
++  DEFINE NETWORK_HTTP_BOOT_ENABLE       = TRUE
+   DEFINE NETWORK_ALLOW_HTTP_CONNECTIONS = TRUE
+   DEFINE NETWORK_ISCSI_ENABLE           = TRUE
+ 
+@@ -745,6 +745,20 @@
+   MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
+   MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
+   MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
++
++  #
++  # EFI_RNG_PROTOCOL producer: the NetworkPkg drivers all carry a
++  # gEfiRngProtocolGuid depex, and bhyve has no virtio-rng device for
++  # VirtioRngDxe to bind to, so without this they never dispatch.
++  #
++  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
++
++  #
++  # EFI_HASH2_SERVICE_BINDING_PROTOCOL producer: TcpDxe depends on it,
++  # and without TcpDxe there is no HttpServiceBinding, so HttpBootDxe
++  # never binds. OvmfPkgX64.dsc includes this; the Bhyve DSC omitted it.
++  #
++  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
+ 
+   #
+   # Network Support
diff --git a/sysutils/edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.fdf b/sysutils/edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.fdf
new file mode 100644
index 000000000000..315f105e7542
--- /dev/null
+++ b/sysutils/edk2/files/patch-OvmfPkg_Bhyve_BhyveX64.fdf
@@ -0,0 +1,21 @@
+--- OvmfPkg/Bhyve/BhyveX64.fdf.orig	2025-08-12 17:42:44 UTC
++++ OvmfPkg/Bhyve/BhyveX64.fdf
+@@ -274,6 +274,18 @@ INF MdeModulePkg/Logo/LogoDxe.inf
+ INF MdeModulePkg/Logo/LogoDxe.inf
+ 
+ #
++# Protocol producers the NetworkPkg drivers depend on, both absent from
++# the stock Bhyve build:
++#  - RngDxe: every NetworkPkg depex requires gEfiRngProtocolGuid, and
++#    bhyve has no virtio-rng device for VirtioRngDxe to bind to.
++#  - Hash2DxeCrypto: TcpDxe requires gEfiHash2ServiceBindingProtocolGuid;
++#    without TcpDxe there is no HttpServiceBinding and HttpBootDxe never
++#    binds. OvmfPkgX64 ships both; the Bhyve platform omitted them.
++#
++INF  SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
++INF  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
++
++#
+ # Network modules
+ #
+ !if $(E1000_ENABLE)