Page MenuHomeFreeBSD

D61476.1796504222.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61476.1796504222.diff

diff --git a/stand/efi/loader/memdisk.c b/stand/efi/loader/memdisk.c
--- a/stand/efi/loader/memdisk.c
+++ b/stand/efi/loader/memdisk.c
@@ -225,18 +225,50 @@
{
#ifdef LOADER_NET_SUPPORT
struct devdesc dev;
+ struct devsw *dv;
+ EFI_DEVICE_PATH *copy, *devpath;
+ EFI_HANDLE h;
const char *url;
- int error;
+ char *fetch;
+ int error, unit;
+
+ /*
+ * Configure the interface we were loaded from: DHCP on any other may
+ * get no answer, and the boot manager's watchdog is still armed. Walk
+ * up our device handle's device path to the first device we know, as
+ * find_currdev() does. The MAC address alone is not enough: a network
+ * boot program that drives the NIC through the firmware's SNP, iPXE
+ * for one, holds that SNP exclusively and loads us from beneath its
+ * own SNP, which has the same MAC address.
+ */
+ h = boot_img->DeviceHandle;
+ copy = NULL;
+ while (h != NULL && efi_handle_lookup(h, &dv, &unit, NULL) != 0) {
+ free(copy);
+ devpath = efi_lookup_devpath(h);
+ copy = (devpath != NULL) ? efi_devpath_trim(devpath) : NULL;
+ h = (copy != NULL) ? efi_devpath_handle(copy) : NULL;
+ }
+ free(copy);
+ if (h == NULL) {
+ printf("Could not find the boot interface for initmd\n");
+ return;
+ }
- if (efi_find_handle(&efinet_dev, 0) == NULL)
+ /*
+ * Under HTTP boot this finds http0 on the NIC's handle. Leave the NIC
+ * alone: opening its SNP disconnects the firmware HTTP stack we boot
+ * through.
+ */
+ if (dv != &efinet_dev)
return;
memset(&dev, 0, sizeof(dev));
dev.d_dev = &efinet_dev;
- dev.d_unit = 0;
+ dev.d_unit = unit;
error = net_configure(&dev);
if (error != 0) {
- printf("Could not configure net0 for initmd: %s\n",
+ printf("Could not configure net%d for initmd: %s\n", unit,
strerror(error));
return;
}
@@ -245,12 +277,25 @@
if (url == NULL || *url == '\0')
return;
+ /* An http URL without a unit makes efihttp fetch through net0. */
+ fetch = NULL;
+ if (strncmp(url, "http://", 7) == 0) {
+ asprintf(&fetch, "http%d://%s", unit, url + 7);
+ if (fetch == NULL) {
+ printf("Could not download initmd: %s\n",
+ strerror(ENOMEM));
+ return;
+ }
+ url = fetch;
+ }
+
/* Release SNP so the firmware network stack can fetch the image. */
net_deconfigure();
printf("Downloading initmd from %s\n", url);
error = download_md_image(url);
if (error != 0 && error != ECANCELED)
printf("Could not download initmd: %s\n", strerror(error));
+ free(fetch);
#endif
}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 5, 8:57 PM (22 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42021195
Default Alt Text
D61476.1796504222.diff (2 KB)

Event Timeline