svn commit: r271636 - in stable/10: sbin/geom/class/part sys/geom/part sys/sys usr.sbin/bsdinstall/partedit

Ed Maste emaste at FreeBSD.org
Mon Sep 15 17:49:49 UTC 2014


Author: emaste
Date: Mon Sep 15 17:49:46 2014
New Revision: 271636
URL: http://svnweb.freebsd.org/changeset/base/271636

Log:
  MFC EFI support for the installer
  
  r264978 (nwhitehorn):
  
      Add EFI support to the installer. This requires that the kernel
      provide a sysctl to determine what firmware is in use. This sysctl
      does not exist yet, so the following blocks are in front of the
      wheels:
      - I've provisionally called this "hw.platform" after the equivalent
        thing on PPC
      - The logic to check the sysctl is short-circuited to always choose
        BIOS.  There's a comment in the top of the file about how to turn
        this off.
  
      If IA64 acquired a boot1.efifat-like thing (probably with very few
      modifications), the same code could be adapted there.
  
  r265016 (nwhitehorn):
  
      Finish connecting up installer UEFI support. If the kernel was
      booted using EFI, set up the disks for an EFI system. If booted from
      BIOS/CSM, set up for BIOS.
  
  r268256 (nwhitehorn):
  
      After EFI support was added to the installer, it needed to allow
      boot partitions of types other than "freebsd-boot" (in particular,
      "efi").  This allows the removal of some nasty hacks for supporting
      PowerPC systems, in particular aliasing freebsd-boot to apple-boot
      on APM and an IBM-specific code on MBR.
  
      This changes the installer to use the correct names, which also
      breaks a degeneracy in the meaning of "freebsd-boot" that allows the
      addition of support for some newer IBM systems that can boot from
      GPT in addition to MBR. Since I have no idea how to detect which
      those systems are, leave the default on IBM PPC systems as MBR for
      now.
  
  Approved by:	re
  PR:		193658
  Relnotes:	Yes

Modified:
  stable/10/sbin/geom/class/part/gpart.8
  stable/10/sys/geom/part/g_part.c
  stable/10/sys/geom/part/g_part.h
  stable/10/sys/geom/part/g_part_apm.c
  stable/10/sys/geom/part/g_part_gpt.c
  stable/10/sys/geom/part/g_part_mbr.c
  stable/10/sys/sys/gpt.h
  stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c
  stable/10/usr.sbin/bsdinstall/partedit/partedit.h
  stable/10/usr.sbin/bsdinstall/partedit/partedit_generic.c
  stable/10/usr.sbin/bsdinstall/partedit/partedit_pc98.c
  stable/10/usr.sbin/bsdinstall/partedit/partedit_powerpc.c
  stable/10/usr.sbin/bsdinstall/partedit/partedit_sparc64.c
  stable/10/usr.sbin/bsdinstall/partedit/partedit_x86.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/geom/class/part/gpart.8
==============================================================================
--- stable/10/sbin/geom/class/part/gpart.8	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sbin/geom/class/part/gpart.8	Mon Sep 15 17:49:46 2014	(r271636)
@@ -574,6 +574,16 @@ Symbolic names currently understood and 
 .Fx
 are:
 .Bl -tag -width ".Cm dragonfly-disklabel64"
+.It Cm apple-boot
+The system partition dedicated to storing boot loaders on some Apple
+systems.
+The scheme-specific types are
+.Qq Li "!171"
+for MBR,
+.Qq Li "!Apple_Bootstrap"
+for APM, and
+.Qq Li "!426f6f74-0000-11aa-aa11-00306543ecac"
+for GPT.
 .It Cm bios-boot
 The system partition dedicated to second stage of the boot loader program.
 Usually it is used by the GRUB 2 loader for GPT partitioning schemes.
@@ -844,6 +854,14 @@ A partition that contains a NTFS or exFA
 The scheme-specific type is
 .Qq Li "!7"
 for MBR.
+.It Cm prep-boot
+The system partition dedicated to storing boot loaders on some PowerPC systems,
+notably those made by IBM.
+The scheme-specific types are
+.Qq Li "!65"
+for MBR and
+.Qq Li "!0x9e1a2d38-c612-4316-aa26-8b49521e5a8b"
+for GPT.
 .It Cm vmware-vmfs
 A partition that contains a VMware File System (VMFS).
 The scheme-specific types are
@@ -1039,7 +1057,7 @@ Instead, the 800 KBytes bootstrap code i
 should be written with the
 .Cm gpart bootcode
 command to a partition of type
-.Cm freebsd-boot ,
+.Cm apple-boot ,
 which should also be 800 KB in size.
 .Sh OPERATIONAL FLAGS
 Actions other than the

Modified: stable/10/sys/geom/part/g_part.c
==============================================================================
--- stable/10/sys/geom/part/g_part.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sys/geom/part/g_part.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -117,6 +117,7 @@ struct g_part_alias_list {
 	{ "dragonfly-legacy", G_PART_ALIAS_DFBSD_LEGACY },
 	{ "dragonfly-hammer", G_PART_ALIAS_DFBSD_HAMMER },
 	{ "dragonfly-hammer2", G_PART_ALIAS_DFBSD_HAMMER2 },
+	{ "prep-boot", G_PART_ALIAS_PREP_BOOT },
 };
 
 SYSCTL_DECL(_kern_geom);

Modified: stable/10/sys/geom/part/g_part.h
==============================================================================
--- stable/10/sys/geom/part/g_part.h	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sys/geom/part/g_part.h	Mon Sep 15 17:49:46 2014	(r271636)
@@ -84,6 +84,7 @@ enum g_part_alias {
 	G_PART_ALIAS_DFBSD_LEGACY,	/* A DfBSD legacy partition entry */
 	G_PART_ALIAS_DFBSD_HAMMER,	/* A DfBSD HAMMER FS partition entry */
 	G_PART_ALIAS_DFBSD_HAMMER2,	/* A DfBSD HAMMER2 FS partition entry */
+	G_PART_ALIAS_PREP_BOOT,		/* A PREP/CHRP boot partition entry. */
 	/* Keep the following last */
 	G_PART_ALIAS_COUNT
 };

Modified: stable/10/sys/geom/part/g_part_apm.c
==============================================================================
--- stable/10/sys/geom/part/g_part_apm.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sys/geom/part/g_part_apm.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -149,11 +149,6 @@ apm_parse_type(const char *type, char *b
 		strcpy(buf, APM_ENT_TYPE_APPLE_UFS);
 		return (0);
 	}
-	alias = g_part_alias_name(G_PART_ALIAS_FREEBSD_BOOT);
-	if (!strcasecmp(type, alias)) {
-		strcpy(buf, APM_ENT_TYPE_APPLE_BOOT);
-		return (0);
-	}
 	alias = g_part_alias_name(G_PART_ALIAS_FREEBSD);
 	if (!strcasecmp(type, alias)) {
 		strcpy(buf, APM_ENT_TYPE_FREEBSD);

Modified: stable/10/sys/geom/part/g_part_gpt.c
==============================================================================
--- stable/10/sys/geom/part/g_part_gpt.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sys/geom/part/g_part_gpt.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -190,6 +190,7 @@ static struct uuid gpt_uuid_dfbsd_hammer
 static struct uuid gpt_uuid_dfbsd_hammer2 = GPT_ENT_TYPE_DRAGONFLY_HAMMER2;
 static struct uuid gpt_uuid_dfbsd_label32 = GPT_ENT_TYPE_DRAGONFLY_LABEL32;
 static struct uuid gpt_uuid_dfbsd_label64 = GPT_ENT_TYPE_DRAGONFLY_LABEL64;
+static struct uuid gpt_uuid_prep_boot = GPT_ENT_TYPE_PREP_BOOT;
 
 static struct g_part_uuid_alias {
 	struct uuid *uuid;
@@ -240,6 +241,7 @@ static struct g_part_uuid_alias {
 	{ &gpt_uuid_dfbsd_hammer2,	G_PART_ALIAS_DFBSD_HAMMER2,	 0 },
 	{ &gpt_uuid_dfbsd_label32,	G_PART_ALIAS_DFBSD,		 0xa5 },
 	{ &gpt_uuid_dfbsd_label64,	G_PART_ALIAS_DFBSD64,		 0xa5 },
+	{ &gpt_uuid_prep_boot,		G_PART_ALIAS_PREP_BOOT,		 0x41 },
 	{ NULL, 0, 0 }
 };
 

Modified: stable/10/sys/geom/part/g_part_mbr.c
==============================================================================
--- stable/10/sys/geom/part/g_part_mbr.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sys/geom/part/g_part_mbr.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -135,7 +135,7 @@ static struct g_part_mbr_alias {
 	{ DOSPTYP_LINUX,	G_PART_ALIAS_LINUX_DATA },
 	{ DOSPTYP_LINLVM,	G_PART_ALIAS_LINUX_LVM },
 	{ DOSPTYP_LINRAID,	G_PART_ALIAS_LINUX_RAID },
-	{ DOSPTYP_PPCBOOT,	G_PART_ALIAS_FREEBSD_BOOT },
+	{ DOSPTYP_PPCBOOT,	G_PART_ALIAS_PREP_BOOT },
 	{ DOSPTYP_VMFS,		G_PART_ALIAS_VMFS },
 	{ DOSPTYP_VMKDIAG,	G_PART_ALIAS_VMKDIAG },
 };

Modified: stable/10/sys/sys/gpt.h
==============================================================================
--- stable/10/sys/sys/gpt.h	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/sys/sys/gpt.h	Mon Sep 15 17:49:46 2014	(r271636)
@@ -91,6 +91,8 @@ struct gpt_ent {
 	{0x516e7cb8,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
 #define	GPT_ENT_TYPE_FREEBSD_ZFS	\
 	{0x516e7cba,0x6ecf,0x11d6,0x8f,0xf8,{0x00,0x02,0x2d,0x09,0x71,0x2b}}
+#define	GPT_ENT_TYPE_PREP_BOOT		\
+	{0x9e1a2d38,0xc612,0x4316,0xaa,0x26,{0x8b,0x49,0x52,0x1e,0x5a,0x8b}}
 
 /*
  * The following are unused but documented here to avoid reuse.

Modified: stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -584,7 +584,7 @@ set_default_part_metadata(const char *na
 
 	if (strcmp(type, "freebsd-swap") == 0)
 		mountpoint = "none";
-	if (strcmp(type, "freebsd-boot") == 0)
+	if (strcmp(type, bootpart_type(scheme)) == 0)
 		md->bootcode = 1;
 
 	/* VTOC8 needs partcode in UFS partitions */
@@ -949,7 +949,8 @@ addpartform:
 		LIST_FOREACH(gc, &pp->lg_config, lg_config)
 			if (strcmp(gc->lg_name, "type") == 0)
 				break;
-		if (gc != NULL && strcmp(gc->lg_val, "freebsd-boot") == 0)
+		if (gc != NULL && strcmp(gc->lg_val,
+		    bootpart_type(scheme)) == 0)
 			break;
 	}
 
@@ -971,7 +972,7 @@ addpartform:
 			gctl_ro_param(r, "arg0", -1, geom->lg_name);
 			gctl_ro_param(r, "flags", -1, GPART_FLAGS);
 			gctl_ro_param(r, "verb", -1, "add");
-			gctl_ro_param(r, "type", -1, "freebsd-boot");
+			gctl_ro_param(r, "type", -1, bootpart_type(scheme));
 			snprintf(sizestr, sizeof(sizestr), "%jd",
 			    bootpart_size(scheme) / sector);
 			gctl_ro_param(r, "size", -1, sizestr);
@@ -1031,7 +1032,7 @@ addpartform:
 	gctl_issue(r); /* Error usually expected and non-fatal */
 	gctl_free(r);
 
-	if (strcmp(items[0].text, "freebsd-boot") == 0)
+	if (strcmp(items[0].text, bootpart_type(scheme)) == 0)
 		get_part_metadata(newpartname, 1)->bootcode = 1;
 	else if (strcmp(items[0].text, "freebsd") == 0)
 		gpart_partition(newpartname, "BSD");

Modified: stable/10/usr.sbin/bsdinstall/partedit/partedit.h
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/partedit.h	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/partedit.h	Mon Sep 15 17:49:46 2014	(r271636)
@@ -74,9 +74,10 @@ void set_default_part_metadata(const cha
 
 /* machine-dependent bootability checks */
 const char *default_scheme(void);
-int is_scheme_bootable(const char *part_type);
-size_t bootpart_size(const char *part_type);
-const char *bootcode_path(const char *part_type);
-const char *partcode_path(const char *part_type);
+int is_scheme_bootable(const char *scheme);
+size_t bootpart_size(const char *scheme);
+const char *bootpart_type(const char *scheme);
+const char *bootcode_path(const char *scheme);
+const char *partcode_path(const char *scheme);
 
 #endif

Modified: stable/10/usr.sbin/bsdinstall/partedit/partedit_generic.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/partedit_generic.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/partedit_generic.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -58,6 +58,11 @@ bootpart_size(const char *part_type) {
 }
 
 const char *
+bootpart_type(const char *scheme) {
+	return ("freebsd-boot");
+}
+
+const char *
 bootcode_path(const char *part_type) {
 	return (NULL);
 }

Modified: stable/10/usr.sbin/bsdinstall/partedit/partedit_pc98.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/partedit_pc98.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/partedit_pc98.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -52,6 +52,11 @@ bootpart_size(const char *part_type) {
 }
 
 const char *
+bootpart_type(const char *scheme) {
+	return ("freebsd-boot");
+}
+
+const char *
 bootcode_path(const char *part_type) {
 	if (strcmp(part_type, "PC98") == 0)
 		return ("/boot/pc98boot");

Modified: stable/10/usr.sbin/bsdinstall/partedit/partedit_powerpc.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/partedit_powerpc.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/partedit_powerpc.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -60,7 +60,8 @@ is_scheme_bootable(const char *part_type
 	if (strcmp(platform, "ps3") == 0 && strcmp(part_type, "GPT") == 0)
 		return (1);
 	if (strcmp(platform, "chrp") == 0 &&
-	    (strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0))
+	    (strcmp(part_type, "MBR") == 0 || strcmp(part_type, "BSD") == 0 ||
+	     strcmp(part_type, "GPT") == 0))
 		return (1);
 
 	return (0);
@@ -68,21 +69,46 @@ is_scheme_bootable(const char *part_type
 
 size_t
 bootpart_size(const char *part_type) {
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
+
 	if (strcmp(part_type, "APM") == 0 || strcmp(part_type, "MBR") == 0)
 		return (800*1024);
+	if (strcmp(platform, "chrp") == 0 && strcmp(part_type, "GPT") == 0)
+		return (800*1024);
 	return (0);
 }
 
 const char *
+bootpart_type(const char *scheme) {
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
+
+	if (strcmp(platform, "chrp") == 0)
+		return ("prep-boot");
+	if (strcmp(platform, "powermac") == 0)
+		return ("apple-boot");
+
+	return ("freebsd-boot");
+}
+
+const char *
 bootcode_path(const char *part_type) {
 	return (NULL);
 }
 	
 const char *
 partcode_path(const char *part_type) {
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname("hw.platform", platform, &platlen, NULL, -1);
+
 	if (strcmp(part_type, "APM") == 0)
 		return ("/boot/boot1.hfs");
-	if (strcmp(part_type, "MBR") == 0)
+	if (strcmp(part_type, "MBR") == 0 ||
+	    (strcmp(platform, "chrp") == 0 && strcmp(part_type, "GPT") == 0))
 		return ("/boot/boot1.elf");
 	return (NULL);
 }

Modified: stable/10/usr.sbin/bsdinstall/partedit/partedit_sparc64.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/partedit_sparc64.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/partedit_sparc64.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -50,6 +50,11 @@ bootpart_size(const char *part_type) {
 }
 
 const char *
+bootpart_type(const char *scheme) {
+	return ("freebsd-boot");
+}
+
+const char *
 bootcode_path(const char *part_type) {
 	return (NULL);
 }

Modified: stable/10/usr.sbin/bsdinstall/partedit/partedit_x86.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/partedit_x86.c	Mon Sep 15 17:20:13 2014	(r271635)
+++ stable/10/usr.sbin/bsdinstall/partedit/partedit_x86.c	Mon Sep 15 17:49:46 2014	(r271636)
@@ -26,10 +26,15 @@
  * $FreeBSD$
  */
 
+#include <sys/types.h>
+#include <sys/sysctl.h>
 #include <string.h>
 
 #include "partedit.h"
 
+static char platform[255] = "";
+static const char *platform_sysctl = "machdep.bootmethod";
+
 const char *
 default_scheme(void) {
 	return ("GPT");
@@ -37,27 +42,60 @@ default_scheme(void) {
 
 int
 is_scheme_bootable(const char *part_type) {
-	if (strcmp(part_type, "BSD") == 0)
-		return (1);
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+
 	if (strcmp(part_type, "GPT") == 0)
 		return (1);
-	if (strcmp(part_type, "MBR") == 0)
-		return (1);
+	if (strcmp(platform, "BIOS") == 0) {
+		if (strcmp(part_type, "BSD") == 0)
+			return (1);
+		if (strcmp(part_type, "MBR") == 0)
+			return (1);
+	}
 
 	return (0);
 }
 
 size_t
-bootpart_size(const char *part_type) {
-	if (strcmp(part_type, "GPT") == 0)
-		return (64*1024);
+bootpart_size(const char *scheme) {
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
 
 	/* No partcode except for GPT */
+	if (strcmp(scheme, "GPT") != 0)
+		return (0);
+
+	if (strcmp(platform, "BIOS") == 0)
+		return (64*1024);
+	else 
+		return (800*1024);
+
 	return (0);
 }
 
 const char *
+bootpart_type(const char *scheme) {
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+
+	if (strcmp(platform, "UEFI") == 0)
+		return ("efi");
+
+	return ("freebsd-boot");
+}
+
+const char *
 bootcode_path(const char *part_type) {
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+	if (strcmp(platform, "UEFI") == 0)
+		return (NULL);
+
 	if (strcmp(part_type, "GPT") == 0)
 		return ("/boot/pmbr");
 	if (strcmp(part_type, "MBR") == 0)
@@ -70,8 +108,16 @@ bootcode_path(const char *part_type) {
 	
 const char *
 partcode_path(const char *part_type) {
-	if (strcmp(part_type, "GPT") == 0)
-		return ("/boot/gptboot");
+	size_t platlen = sizeof(platform);
+	if (strlen(platform) == 0)
+		sysctlbyname(platform_sysctl, platform, &platlen, NULL, -1);
+
+	if (strcmp(part_type, "GPT") == 0) {
+		if (strcmp(platform, "UEFI") == 0)
+			return ("/boot/boot1.efifat");
+		else
+			return ("/boot/gptboot");
+	}
 	
 	/* No partcode except for GPT */
 	return (NULL);


More information about the svn-src-all mailing list