Module Name:    src
Committed By:   martin
Date:           Mon Oct  5 12:28:46 UTC 2020

Modified Files:
        src/usr.sbin/sysinst: README.md_defs bsddisklabel.c
        src/usr.sbin/sysinst/arch/amd64: md.h
        src/usr.sbin/sysinst/arch/evbarm: md.h
        src/usr.sbin/sysinst/arch/i386: md.h

Log Message:
Add a heuristic to detect and properly mark EFI system partitions
when re-using pre-existing partitions.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/sysinst/README.md_defs
cvs rdiff -u -r1.48 -r1.49 src/usr.sbin/sysinst/bsddisklabel.c
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/sysinst/arch/amd64/md.h
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/sysinst/arch/evbarm/md.h
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/sysinst/arch/i386/md.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/README.md_defs
diff -u src/usr.sbin/sysinst/README.md_defs:1.5 src/usr.sbin/sysinst/README.md_defs:1.6
--- src/usr.sbin/sysinst/README.md_defs:1.5	Mon Sep 28 18:40:23 2020
+++ src/usr.sbin/sysinst/README.md_defs	Mon Oct  5 12:28:45 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: README.md_defs,v 1.5 2020/09/28 18:40:23 martin Exp $ */
+/* $NetBSD: README.md_defs,v 1.6 2020/10/05 12:28:45 martin Exp $ */
 
 The following is trying to document the most important machine dependent
 defines used in the sysinst code.
@@ -112,5 +112,8 @@ partitions this way).
 
 HAVE_GPT_BOOT			defined if the architecture can boot from GPT
 
+HAVE_EFI_BOOT			defined if the architecture may be able
+				to boot from an EFI partition
+
 NO_DISKLABEL_BOOT		defined if the architecture can NOT boot
 				from a disklabel partitioned disk

Index: src/usr.sbin/sysinst/bsddisklabel.c
diff -u src/usr.sbin/sysinst/bsddisklabel.c:1.48 src/usr.sbin/sysinst/bsddisklabel.c:1.49
--- src/usr.sbin/sysinst/bsddisklabel.c:1.48	Sun Oct  4 19:05:47 2020
+++ src/usr.sbin/sysinst/bsddisklabel.c	Mon Oct  5 12:28:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bsddisklabel.c,v 1.48 2020/10/04 19:05:47 martin Exp $	*/
+/*	$NetBSD: bsddisklabel.c,v 1.49 2020/10/05 12:28:45 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1776,12 +1776,19 @@ make_bsd_partitions(struct install_parti
 	}
 
 	/*
-	 * Make sure the target root partition is properly marked
+	 * Make sure the target root partition is properly marked,
+	 * check for existing EFI boot partition.
 	 */
 	bool have_inst_target = false;
+#ifdef HAVE_EFI_BOOT
+	daddr_t target_start = -1;
+#endif
 	for (size_t i = 0; i < wanted.num; i++) {
 		if (wanted.infos[i].cur_flags & PTI_INSTALL_TARGET) {
 			have_inst_target = true;
+#ifdef HAVE_EFI_BOOT
+			target_start = wanted.infos[i].cur_start;
+#endif
 			break;
 		 }
 	}
@@ -1800,9 +1807,53 @@ make_bsd_partitions(struct install_parti
 			info.flags |= PTI_INSTALL_TARGET;
 			wanted.parts->pscheme->set_part_info(wanted.parts,
 			    wanted.infos[i].cur_part_id, &info, NULL);
+#ifdef HAVE_EFI_BOOT
+			target_start = wanted.infos[i].cur_start;
+#endif
 			break;
 		}
 	}
+#ifdef HAVE_EFI_BOOT
+	size_t boot_part = ~0U;
+	for (part_id i = 0; i < wanted.num; i++) {
+		if ((wanted.infos[i].cur_flags & PTI_BOOT) != 0 ||
+		    wanted.infos[i].type ==  PT_EFI_SYSTEM) {
+			boot_part = i;
+			break;
+		}
+	}
+	if (boot_part == ~0U) {
+		for (part_id i = 0; i < wanted.num; i++) {
+			/*
+			 * heuristic to recognize existing MBR FAT
+			 * partitions as EFI without looking for
+			 * details
+			 */
+			if ((wanted.infos[i].type != PT_FAT &&
+			    wanted.infos[i].type != PT_EFI_SYSTEM) ||
+			    wanted.infos[i].fs_type != FS_MSDOS)
+				continue;
+			daddr_t ps = wanted.infos[i].cur_start;
+			daddr_t pe = ps + wanted.infos[i].size;
+			if (target_start >= 0 &&
+			   (ps >= target_start || pe >= target_start)) 
+				continue;
+			boot_part = i;
+			break;
+		}
+	}
+	if (boot_part != ~0U) {
+		struct disk_part_info info;
+
+		if (wanted.parts->pscheme->get_part_info(wanted.parts,
+		    wanted.infos[boot_part].cur_part_id, &info)) {
+			info.flags |= PTI_BOOT;
+			wanted.parts->pscheme->set_part_info(wanted.parts,
+			    wanted.infos[boot_part].cur_part_id, &info, NULL);
+		}
+		wanted.infos[boot_part].instflags |= PUIINST_BOOT;
+	}
+#endif
 
 	/*
 	 * OK, we have a partition table. Give the user the chance to

Index: src/usr.sbin/sysinst/arch/amd64/md.h
diff -u src/usr.sbin/sysinst/arch/amd64/md.h:1.8 src/usr.sbin/sysinst/arch/amd64/md.h:1.9
--- src/usr.sbin/sysinst/arch/amd64/md.h:1.8	Sat Nov 16 21:25:14 2019
+++ src/usr.sbin/sysinst/arch/amd64/md.h	Mon Oct  5 12:28:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.h,v 1.8 2019/11/16 21:25:14 martin Exp $	*/
+/*	$NetBSD: md.h,v 1.9 2020/10/05 12:28:45 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -128,3 +128,6 @@ bool x86_md_need_bootblock(struct instal
 /* post-process boot.cfg for KASLR if that kernel has been selected */
 void amd64_md_boot_cfg_finalize(const char*);
 #define	MD_BOOT_CFG_FINALIZE(P)	amd64_md_boot_cfg_finalize(P)
+
+#define	HAVE_EFI_BOOT		1	/* we support EFI boot partitions */
+

Index: src/usr.sbin/sysinst/arch/evbarm/md.h
diff -u src/usr.sbin/sysinst/arch/evbarm/md.h:1.6 src/usr.sbin/sysinst/arch/evbarm/md.h:1.7
--- src/usr.sbin/sysinst/arch/evbarm/md.h:1.6	Mon May  4 18:19:34 2020
+++ src/usr.sbin/sysinst/arch/evbarm/md.h	Mon Oct  5 12:28:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.h,v 1.6 2020/05/04 18:19:34 joerg Exp $	*/
+/*	$NetBSD: md.h,v 1.7 2020/10/05 12:28:45 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -118,3 +118,5 @@ void evbarm_part_defaults(struct pm_devs
 
 #define MD_PART_DEFAULTS(A,B,C)	evbarm_part_defaults(A,B,C)
 
+#define	HAVE_EFI_BOOT		1	/* we support EFI boot partitions */
+

Index: src/usr.sbin/sysinst/arch/i386/md.h
diff -u src/usr.sbin/sysinst/arch/i386/md.h:1.7 src/usr.sbin/sysinst/arch/i386/md.h:1.8
--- src/usr.sbin/sysinst/arch/i386/md.h:1.7	Wed Oct  2 11:16:02 2019
+++ src/usr.sbin/sysinst/arch/i386/md.h	Mon Oct  5 12:28:45 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.h,v 1.7 2019/10/02 11:16:02 maya Exp $	*/
+/*	$NetBSD: md.h,v 1.8 2020/10/05 12:28:45 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -123,3 +123,5 @@ void x86_md_part_defaults(struct pm_devs
 /* no need to install bootblock if installing for UEFI */
 bool x86_md_need_bootblock(struct install_partition_desc *install);
 #define	MD_NEED_BOOTBLOCK(A)	x86_md_need_bootblock(A)
+
+#define	HAVE_EFI_BOOT		1	/* we support EFI boot partitions */

Reply via email to