Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sysinst Add a heuristic to detect and properly mark...



details:   https://anonhg.NetBSD.org/src/rev/6aeeb3a184e3
branches:  trunk
changeset: 940176:6aeeb3a184e3
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Oct 05 12:28:45 2020 +0000

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

diffstat:

 usr.sbin/sysinst/README.md_defs   |   5 ++-
 usr.sbin/sysinst/arch/amd64/md.h  |   5 ++-
 usr.sbin/sysinst/arch/evbarm/md.h |   4 ++-
 usr.sbin/sysinst/arch/i386/md.h   |   4 ++-
 usr.sbin/sysinst/bsddisklabel.c   |  55 +++++++++++++++++++++++++++++++++++++-
 5 files changed, 67 insertions(+), 6 deletions(-)

diffs (148 lines):

diff -r 502895690bb9 -r 6aeeb3a184e3 usr.sbin/sysinst/README.md_defs
--- a/usr.sbin/sysinst/README.md_defs   Mon Oct 05 12:22:49 2020 +0000
+++ b/usr.sbin/sysinst/README.md_defs   Mon Oct 05 12:28:45 2020 +0000
@@ -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 @@
 
 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
diff -r 502895690bb9 -r 6aeeb3a184e3 usr.sbin/sysinst/arch/amd64/md.h
--- a/usr.sbin/sysinst/arch/amd64/md.h  Mon Oct 05 12:22:49 2020 +0000
+++ b/usr.sbin/sysinst/arch/amd64/md.h  Mon Oct 05 12:28:45 2020 +0000
@@ -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 @@
 /* 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 */
+
diff -r 502895690bb9 -r 6aeeb3a184e3 usr.sbin/sysinst/arch/evbarm/md.h
--- a/usr.sbin/sysinst/arch/evbarm/md.h Mon Oct 05 12:22:49 2020 +0000
+++ b/usr.sbin/sysinst/arch/evbarm/md.h Mon Oct 05 12:28:45 2020 +0000
@@ -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 @@
 
 #define MD_PART_DEFAULTS(A,B,C)        evbarm_part_defaults(A,B,C)
 
+#define        HAVE_EFI_BOOT           1       /* we support EFI boot partitions */
+
diff -r 502895690bb9 -r 6aeeb3a184e3 usr.sbin/sysinst/arch/i386/md.h
--- a/usr.sbin/sysinst/arch/i386/md.h   Mon Oct 05 12:22:49 2020 +0000
+++ b/usr.sbin/sysinst/arch/i386/md.h   Mon Oct 05 12:28:45 2020 +0000
@@ -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 @@
 /* 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 */
diff -r 502895690bb9 -r 6aeeb3a184e3 usr.sbin/sysinst/bsddisklabel.c
--- a/usr.sbin/sysinst/bsddisklabel.c   Mon Oct 05 12:22:49 2020 +0000
+++ b/usr.sbin/sysinst/bsddisklabel.c   Mon Oct 05 12:28:45 2020 +0000
@@ -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 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 @@
                        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



Home | Main Index | Thread Index | Old Index