git: 6de311d309da - main - loader.efi: download DHCP initmd specified image

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 11 Sep 2026 05:04:31 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=6de311d309dadee0d66e7f1533c254a44b9b5635

commit 6de311d309dadee0d66e7f1533c254a44b9b5635
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2026-09-11 04:14:30 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-09-11 04:15:29 +0000

    loader.efi: download DHCP initmd specified image
    
    When we haven't downloaded an image via mem{disk,cd} and ipxe, try any
    image specified by the FreeBSD-specific initmd dhcp option. This allows
    direct booting of loader.efi with a detached root ramdisk filesystem.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D59433
---
 stand/efi/loader/loader_efi.h |  2 +-
 stand/efi/loader/main.c       |  6 ++++--
 stand/efi/loader/memdisk.c    | 23 +++++++++++++----------
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/stand/efi/loader/loader_efi.h b/stand/efi/loader/loader_efi.h
index d6a45e04e27c..e53e165d5ffc 100644
--- a/stand/efi/loader/loader_efi.h
+++ b/stand/efi/loader/loader_efi.h
@@ -59,7 +59,7 @@ void * efi_translate(vm_offset_t ptr);
 void	efi_copy_finish(void);
 void	efi_copy_finish_nop(void);
 
-void maybe_download_ramdisk(int argc, CHAR16 **argv);
+bool maybe_download_ramdisk(int argc, CHAR16 **argv);
 int download_md_image(const char *url);
 void maybe_download_initmd(void);
 
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index fa551e6fb742..0714b6647c13 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -1275,7 +1275,7 @@ EFI_STATUS
 main(int argc, CHAR16 *argv[])
 {
 	int howto, i, uhowto;
-	bool has_kbd;
+	bool has_ipxe, has_kbd;
 	char *s;
 	EFI_DEVICE_PATH *imgpath;
 	CHAR16 *text;
@@ -1340,7 +1340,7 @@ main(int argc, CHAR16 *argv[])
 	 * handles because it installs a handle and creates the right ACPI
 	 * tables for the kernel to find it.
 	 */
-	maybe_download_ramdisk(argc, argv);
+	has_ipxe = maybe_download_ramdisk(argc, argv);
 
 	/*
 	 * Scan the BLOCK IO MEDIA handles then
@@ -1358,6 +1358,8 @@ main(int argc, CHAR16 *argv[])
 	efiblk_memdisk_preload();
 
 	devinit();
+	if (!has_ipxe)
+		maybe_download_initmd();
 
 	/*
 	 * Detect console settings two different ways: one via the command
diff --git a/stand/efi/loader/memdisk.c b/stand/efi/loader/memdisk.c
index ce509e50c71c..e4d08f54c16b 100644
--- a/stand/efi/loader/memdisk.c
+++ b/stand/efi/loader/memdisk.c
@@ -237,11 +237,6 @@ do_download_ramdisk(CHAR8 *url, bool is_disk)
 	IPXE_DOWNLOAD_FILE token;
 	dl_state *ctx = &dl;
 
-	Status = BS->LocateProtocol(&ipxeGuid, NULL, (void**)&ipxe_download);
-	if (EFI_ERROR(Status)) {
-		printf("No ipxe download\n");
-		return; /* most uses won't have this, don't whine */
-	}
 	printf("Downloading %s as a %s\n", url, is_disk ? "disk" : "cd");
 	ctx->in_progress = true;
 	Status = ipxe_download->Start(ipxe_download, url, download_data, download_finish,
@@ -317,28 +312,36 @@ do_download_ramdisk(CHAR8 *url, bool is_disk)
 
 /*
  * Scan the command line for memdisk=url or memcd=url. Do nothing if that's not
- * present, otherwise try to download that image.
+ * present, otherwise try to download that image. Returns true when we've tried
+ * to download an image, whether successful or not.
  *
  * Open Question: Do we want some way to chain boot into the /boot/loader.efi or
  * \efi\boot\bootXXXXX.efi inside the ram disk we load? If so, how do we keep
  * from infinite chainbooting? Also, I don't understand the load it but don't save
  * it option...
  */
-void
+bool
 maybe_download_ramdisk(int argc, CHAR16 **argv)
 {
 	char var[256];
+	EFI_STATUS status;
+
+	status = BS->LocateProtocol(&ipxeGuid, NULL, (void **)&ipxe_download);
+	if (EFI_ERROR(status)) {
+		ipxe_download = NULL;
+		return (false);
+	}
 
 	for (int i = 0; i < argc; i++) {
 		cpy16to8(argv[i], var, sizeof(var));
 		if (strncmp(var, "memdisk=", 8) == 0) {
 			do_download_ramdisk(var + 8, true);
-			return;
+			return (true);
 		}
 		if (strncmp(var, "memcd=", 6) == 0) {
 			do_download_ramdisk(var + 6, false);
-			return;
+			return (true);
 		}
 	}
-	return;
+	return (false);
 }