Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2017 06:21:56 +0000
From:      "decui_microsoft.com (Dexuan Cui)" <phabric-noreply@FreeBSD.org>
To:        freebsd-virtualization@freebsd.org
Subject:   [Differential] D9904: fix UEFI boot on physical machines
Message-ID:  <72b83450b87d83fa9650c03aeb531da0@localhost.localdomain>
In-Reply-To: <differential-rev-PHID-DREV-wovfwnbw6lvlppwgkwpu-req@FreeBSD.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
decui_microsoft.com updated the summary for this revision.
decui_microsoft.com updated this revision to Diff 26023.

CHANGES SINCE LAST UPDATE
  https://reviews.freebsd.org/D9904?vs=26020&id=26023

REVISION DETAIL
  https://reviews.freebsd.org/D9904

AFFECTED FILES
  sys/boot/efi/loader/copy.c

EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: decui_microsoft.com, imp, jhb, will, kib, delphij, emaste, marcel, sepherosa_gmail.com, honzhan_microsoft.com, howard0su_gmail.com, tsoome, gonzo, manu, andrew, sbruno, ambrisko, allanjude, bapt, cem, smh, ian
Cc: freebsd-virtualization-list

[-- Attachment #2 --]
diff --git a/sys/boot/efi/loader/copy.c b/sys/boot/efi/loader/copy.c
--- a/sys/boot/efi/loader/copy.c
+++ b/sys/boot/efi/loader/copy.c
@@ -53,7 +53,7 @@
 	UINT32 dver;
 	EFI_STATUS status;
 	int i, ndesc;
-	unsigned long available_pages;
+	unsigned long available_pages = 0;
 
 	sz = 0;
 	status = BS->GetMemoryMap(&sz, 0, &key, &dsz, &dver);
@@ -70,7 +70,6 @@
 	}
 
 	ndesc = sz / dsz;
-
 	for (i = 0, p = map; i < ndesc;
 	     i++, p = NextMemoryDescriptor(p, dsz)) {
 		start = p->PhysicalStart;
@@ -81,20 +80,38 @@
 			continue;
 
 		if (p->Type != EfiConventionalMemory)
-			continue;
+			printf("Warning: wrong EFI memory type: %d\n",
+			    p->Type);
 
 		available_pages = p->NumberOfPages -
 			((KERNEL_PHYSICAL_BASE - start) >> EFI_PAGE_SHIFT);
+		break;
+	}
+
+	if (available_pages == 0) {
+		printf("Can't find valid memory map for staging area!\n");
+		goto out;
+	}
 
-		if (*nr_pages > available_pages) {
-			printf("staging area size is reduced: %ld -> %ld!\n",
-			    *nr_pages, available_pages);
-			*nr_pages = available_pages;
-		}
+	for ( ; i < ndesc;
+	     i++, p = NextMemoryDescriptor(p, dsz)) {
+		if (p->Type != EfiConventionalMemory &&
+		    p->Type != EfiLoaderData)
+			break;
 
-		break;
+		if (p->PhysicalStart != end)
+			break;
+
+		end = p->PhysicalStart + p->NumberOfPages * EFI_PAGE_SIZE;
+
+		available_pages += p->NumberOfPages;
 	}
 
+	if (*nr_pages > available_pages) {
+		printf("Staging area's size is reduced: %ld -> %ld!\n",
+		    *nr_pages, available_pages);
+		*nr_pages = available_pages;
+	}
 out:
 	free(map);
 }

home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?72b83450b87d83fa9650c03aeb531da0>