git: 6413a870fa07 - main - loader: Move some support things around, maybe lame?

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 12 Sep 2026 18:19:14 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=6413a870fa0721ac509e38f24d5dd5204c603288

commit 6413a870fa0721ac509e38f24d5dd5204c603288
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2026-09-11 20:39:56 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-09-12 16:59:17 +0000

    loader: Move some support things around, maybe lame?
    
    Sponsored by:           Netflix
---
 stand/defs.mk              | 6 ++++++
 stand/efi/libefi/Makefile  | 3 +++
 stand/efi/libefi/efinet.c  | 6 ++++++
 stand/efi/libefi/efipart.c | 2 ++
 stand/efi/loader/memdisk.c | 7 +++++++
 stand/loader.mk            | 6 +-----
 6 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/stand/defs.mk b/stand/defs.mk
index e3908678b53a..8470e973fda8 100644
--- a/stand/defs.mk
+++ b/stand/defs.mk
@@ -127,6 +127,12 @@ CFLAGS+=	-I${SASRC}/geli
 .if ${LOADER_DISK_SUPPORT:Uyes} == "yes"
 CFLAGS+= -DLOADER_DISK_SUPPORT
 .endif
+.if ${LOADER_NET_SUPPORT:Uno} == "yes"
+CFLAGS+= -DLOADER_NET_SUPPORT
+.endif
+.if ${LOADER_MD_SUPPORT:Uno} == "yes"
+CFLAGS+= -DLOADER_MD_SUPPORT
+.endif
 
 # Machine specific flags for all builds here
 
diff --git a/stand/efi/libefi/Makefile b/stand/efi/libefi/Makefile
index 4f4586fbf253..61854dc8f20b 100644
--- a/stand/efi/libefi/Makefile
+++ b/stand/efi/libefi/Makefile
@@ -1,3 +1,6 @@
+LOADER_NET_SUPPORT?=	yes
+LOADER_MD_SUPPORT?=	yes
+
 .include <bsd.init.mk>
 
 LIB=	efi
diff --git a/stand/efi/libefi/efinet.c b/stand/efi/libefi/efinet.c
index 89a27cbaa9f7..c03130c2bd3b 100644
--- a/stand/efi/libefi/efinet.c
+++ b/stand/efi/libefi/efinet.c
@@ -452,9 +452,13 @@ efi_env_net_params(struct iodesc *desc)
 	 * There must be a rootpath. It may be ip:/path or it may be just the
 	 * path in which case the ip needs to be serverip.
 	 */
+#ifdef LOADER_NET_SUPPORT
 	rootaddr = net_parse_rootpath();
 	if (rootaddr == INADDR_NONE)
 		rootaddr = serveraddr;
+#else
+	rootaddr = serveraddr;
+#endif
 	rootip.s_addr = rootaddr;
 
 #ifdef EFINET_DEBUG
@@ -662,10 +666,12 @@ efinet_dev_init(void)
 	 */
 	efi_pxe_snapshot_all(nifs);
 
+#ifdef LOADER_NET_SUPPORT
 	efinet_dev.dv_cleanup = netdev.dv_cleanup;
 	efinet_dev.dv_open = netdev.dv_open;
 	efinet_dev.dv_close = netdev.dv_close;
 	efinet_dev.dv_strategy = netdev.dv_strategy;
+#endif
 
 done:
 	free(handles2);
diff --git a/stand/efi/libefi/efipart.c b/stand/efi/libefi/efipart.c
index 1b1795ccdd40..e064a2672c24 100644
--- a/stand/efi/libefi/efipart.c
+++ b/stand/efi/libefi/efipart.c
@@ -1275,6 +1275,7 @@ testmd(pdinfo_t *md)
 void
 efiblk_memdisk_preload(void)
 {
+#ifdef LOADER_MD_SUPPORT
 	MEDIA_RAM_DISK_DEVICE_PATH *ram;
 	uint64_t start, end;
 	pdinfo_t *md;
@@ -1289,4 +1290,5 @@ efiblk_memdisk_preload(void)
 		end = ((uint64_t)ram->EndingAddr[1] << 32) | ram->EndingAddr[0];
 		md_export_to_kernel(start, end - start + 1);
 	}
+#endif
 }
diff --git a/stand/efi/loader/memdisk.c b/stand/efi/loader/memdisk.c
index bb8ea63d0c5c..8990f9393e85 100644
--- a/stand/efi/loader/memdisk.c
+++ b/stand/efi/loader/memdisk.c
@@ -136,6 +136,7 @@ download_finish(IN VOID *Context, IN EFI_STATUS Status)
 static int
 fallback_to_md(EFI_PHYSICAL_ADDRESS pa, size_t len)
 {
+#ifdef LOADER_MD_SUPPORT
 	int unit;
 
 	unit = md_register((void *)(uintptr_t)pa, len, MD_FLAG_KERNEL);
@@ -146,6 +147,10 @@ fallback_to_md(EFI_PHYSICAL_ADDRESS pa, size_t len)
 	}
 	setenv("uefi_ignore_boot_mgr", "true", 1);
 	return (0);
+#else
+	printf("No memory disk support in this loader\n");
+	return (EOPNOTSUPP);
+#endif
 }
 
 int
@@ -218,6 +223,7 @@ out_close:
 void
 maybe_download_initmd(void)
 {
+#ifdef LOADER_NET_SUPPORT
 	struct devdesc dev;
 	const char *url;
 	int error;
@@ -243,6 +249,7 @@ maybe_download_initmd(void)
 	error = download_md_image(url);
 	if (error != 0 && error != ECANCELED)
 		printf("Could not download initmd: %s\n", strerror(error));
+#endif
 }
 
 static void
diff --git a/stand/loader.mk b/stand/loader.mk
index 7ef25586f77a..f03be166eed7 100644
--- a/stand/loader.mk
+++ b/stand/loader.mk
@@ -75,7 +75,6 @@ SRCS+=  bcache.c
 .if defined(MD_IMAGE_SIZE)
 CFLAGS+= -DMD_IMAGE_SIZE=${MD_IMAGE_SIZE}
 .endif
-CFLAGS+= -DLOADER_MD_SUPPORT
 SRCS+=	md.c
 CLEANFILES+=	md.o
 .endif
@@ -138,10 +137,7 @@ CFLAGS+=	-DLOADER_BZIP2_SUPPORT
 CFLAGS+=	-DLOADER_XZ_SUPPORT
 .endif
 
-# Network related things
-.if ${LOADER_NET_SUPPORT:Uno} == "yes"
-CFLAGS+=	-DLOADER_NET_SUPPORT
-.endif
+# Network related things (LOADER_NET_SUPPORT itself: see defs.mk)
 .if ${LOADER_NFS_SUPPORT:Uno} == "yes"
 CFLAGS+=	-DLOADER_NFS_SUPPORT
 .endif