Source-Changes-HG archive

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

[src/trunk]: src/distrib/utils/sysinst Fix mbr bootcode handling to ensure th...



details:   https://anonhg.NetBSD.org/src/rev/72750e1e62aa
branches:  trunk
changeset: 566028:72750e1e62aa
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sun Apr 25 21:55:18 2004 +0000

description:
Fix mbr bootcode handling to ensure that the bootselect table is always
written into the correct place - even if the user decides not to update
the mbr code and has the old (pre layout change) code installed.
Tell the user that the mbr code needs updating if the new install uses
'all the disk' and teh old version had the bootselect code (otherwise you
get an empty menu).
Probably fixes PR install/25146

diffstat:

 distrib/utils/sysinst/Makefile.inc   |    3 +-
 distrib/utils/sysinst/arch/i386/md.c |   64 +++++++++++++--------
 distrib/utils/sysinst/mbr.c          |  101 +++++++++++++++++++---------------
 distrib/utils/sysinst/mbr.h          |    5 +-
 4 files changed, 100 insertions(+), 73 deletions(-)

diffs (truncated from 365 to 300 lines):

diff -r 37a3ad1671b4 -r 72750e1e62aa distrib/utils/sysinst/Makefile.inc
--- a/distrib/utils/sysinst/Makefile.inc        Sun Apr 25 21:16:57 2004 +0000
+++ b/distrib/utils/sysinst/Makefile.inc        Sun Apr 25 21:55:18 2004 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.35 2004/04/12 03:49:24 grant Exp $
+#      $NetBSD: Makefile.inc,v 1.36 2004/04/25 21:55:18 dsl Exp $
 #
 # Makefile for sysinst
 
@@ -19,7 +19,6 @@
 
 DPADD=         ${LIBCURSES} ${LIBTERMCAP} ${LIBUTIL}
 LDADD=         -lcurses -ltermcap -lutil
-LDSTATIC?=     -static
 
 UNIF_AWK=      ${.CURDIR}/../../unif.awk
 MSG_XLAT_SH=   ${.CURDIR}/../../msg_xlat.sh
diff -r 37a3ad1671b4 -r 72750e1e62aa distrib/utils/sysinst/arch/i386/md.c
--- a/distrib/utils/sysinst/arch/i386/md.c      Sun Apr 25 21:16:57 2004 +0000
+++ b/distrib/utils/sysinst/arch/i386/md.c      Sun Apr 25 21:55:18 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.c,v 1.100 2004/03/22 07:11:00 lukem Exp $ */
+/*     $NetBSD: md.c,v 1.101 2004/04/25 21:55:18 dsl Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -104,8 +104,13 @@
                        root_limit = bcyl * bhead * bsec;
        }
 
-       /* Ensure the install partition and active partition are bootable */
-       fl = MBR_BS_NEWMBR;
+       /*
+        * Ensure the install partition (at sector ptstart) and the active
+        * partition are bootable.
+        * Determine whether the bootselect code is needed.
+        * Note that MBR_BS_NEWMBR is always set, so we ignore it!
+        */
+       fl = 0;
        names = 0;
        for (ext = &mbr; ext != NULL; ext = ext->extended) {
                p = ext->mbr.mbr_parts;
@@ -115,14 +120,19 @@
                            if (ext->sector + p->mbrp_start == ptstart)
                                fl |= NETBSD_ACTIVE;
                        }
-                       if (ext->nametab[i][0] == 0) {
+                       if (ext->mbrb.mbrbs_nametab[i][0] == 0) {
+                               /* No bootmenu label... */
                                if (ext->sector == 0)
                                        continue;
                                if (ext->sector + p->mbrp_start == ptstart)
-                                       /* force name & bootsel... */
+                                       /*
+                                        * Have installed into an extended ptn
+                                        * force name & bootsel...
+                                        */
                                        names++;
                                continue;
                        }
+                       /* Partition has a bootmenu label... */
                        if (ext->sector != 0)
                                fl |= MBR_BS_EXTLBA;
                        if (ext->sector + p->mbrp_start == ptstart)
@@ -159,6 +169,7 @@
                        goto edit;
        }
 
+       /* Sort out the name of the mbr code we need */
        if (names > 0 || fl & (NETBSD_NAMED | ACTIVE_NAMED)) {
                /* Need bootselect code */
                fl |= MBR_BS_ACTIVE;
@@ -166,27 +177,21 @@
        } else
                bootcode = _PATH_MBR;
 
+       fl &=  MBR_BS_ACTIVE | MBR_BS_EXTLBA;
+
        /* Look at what is installed */
-       if (mbr.mbr.mbr_bootsel_magic == htole16(MBR_BS_MAGIC))
-               /* Netbsd bootcode, grab its features */
-               ofl = mbr.mbr.mbr_bootsel.mbrbs_flags;
-       else {
-               /* Not netbsd code, might be ok if we are booting the active
-                * partition.
-                */
-/* XXXLUKEM: unconditionally set ofl=0 with new bootsel code? */
-               if (mbr.mbr.mbr_magic == htole16(MBR_MAGIC) &&
-                   mbr.mbr.mbr_jmpboot[0] != 0 &&
-                   (fl & (MBR_BS_ACTIVE | MBR_BS_EXTLBA)) == 0 &&
-                   !mbr_root_above_chs())
-                       ofl = MBR_BS_NEWMBR;
-               else
-                       ofl = 0;
+       ofl = mbr.mbrb.mbrbs_flags;
+       if (ofl == 0) {
+               /* Check there is some bootcode at all... */
+               if (mbr.mbr.mbr_magic != htole16(MBR_MAGIC) ||
+                   mbr.mbr.mbr_jmpboot[0] == 0 ||
+                   mbr_root_above_chs())
+                       /* Existing won't do, force update */
+                       fl |= MBR_BS_NEWMBR;
        }
+       ofl = mbr.oflags & (MBR_BS_ACTIVE | MBR_BS_EXTLBA);
 
-       fl &=  MBR_BS_NEWMBR | MBR_BS_ACTIVE | MBR_BS_EXTLBA;
-       ofl &= MBR_BS_NEWMBR | MBR_BS_ACTIVE | MBR_BS_EXTLBA;
-       if (fl & ~ofl) {
+       if (fl & ~ofl || (fl == 0 && ofl & MBR_BS_ACTIVE)) {
                /* Existing boot code isn't the right one... */
                if (fl & MBR_BS_ACTIVE)
                        msg_display(MSG_installbootsel);
@@ -197,8 +202,17 @@
                msg_display(MSG_updatembr);
 
        process_menu(MENU_yesno, NULL);
-       if (yesno)
-               md_read_bootcode(bootcode, &mbr.mbr);
+       if (!yesno)
+               /* User doesn't want to update mbr code */
+               return 1;
+
+       if (md_read_bootcode(bootcode, &mbr.mbr) == 0)
+               /* update suceeded - to memory copy */
+               return 1;
+
+       /* This shouldn't happen since the files are in the floppy fs... */
+       msg_display("Can't find %s", bootcode);
+       process_menu(MENU_yesno, NULL);
 
        return 1;
 }
diff -r 37a3ad1671b4 -r 72750e1e62aa distrib/utils/sysinst/mbr.c
--- a/distrib/utils/sysinst/mbr.c       Sun Apr 25 21:16:57 2004 +0000
+++ b/distrib/utils/sysinst/mbr.c       Sun Apr 25 21:55:18 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.61 2004/03/27 20:47:33 dsl Exp $ */
+/*     $NetBSD: mbr.c,v 1.62 2004/04/25 21:55:18 dsl Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -111,8 +111,8 @@
 
 static int get_mapping(struct mbr_partition *, int, int *, int *, int *,
                            unsigned long *);
-static void convert_mbr_chs(int, int, int, u_int8_t *, u_int8_t *,
-                                u_int8_t *, u_int32_t);
+static void convert_mbr_chs(int, int, int, uint8_t *, uint8_t *,
+                                uint8_t *, uint32_t);
 
 /*
  * Notes on the extended partition editor.
@@ -373,7 +373,8 @@
                if (ombri->bootsec == mbri->sector + mbrp->mbrp_start)
                        ombri->bootsec = 0;
                                
-               memset(mbri->nametab[opt], 0, sizeof mbri->nametab[opt]);
+               memset(mbri->mbrb.mbrbs_nametab[opt], 0,
+                   sizeof mbri->mbrb.mbrbs_nametab[opt]);
 #endif
                if (mbri->sector == 0) {
                        /* A main partition */
@@ -894,15 +895,14 @@
                opt = 0;
 
        msg_prompt_win(/* XXX translate? */ "bootmenu", -1, 18, 0, 0,
-               mbri->nametab[opt],
-               mbri->nametab[opt], sizeof mbri->nametab[opt]);
-       if (mbri->nametab[opt][0] == ' ')
-               mbri->nametab[opt][0] = 0;
-       if (mbri->nametab[opt][0] == 0) {
-               if (ombri->bootsec == mbri->sector + mbrp->mbrp_start)
-                       ombri->bootsec = 0;
-               return 0;
-       }
+               mbri->mbrb.mbrbs_nametab[opt],
+               mbri->mbrb.mbrbs_nametab[opt],
+               sizeof mbri->mbrb.mbrbs_nametab[opt]);
+       if (mbri->mbrb.mbrbs_nametab[opt][0] == ' ')
+               mbri->mbrb.mbrbs_nametab[opt][0] = 0;
+       if (mbri->mbrb.mbrbs_nametab[opt][0] == 0
+           && ombri->bootsec == mbri->sector + mbrp->mbrp_start)
+               ombri->bootsec = 0;
        return 0;
 }
 
@@ -1015,7 +1015,8 @@
                break;
 #ifdef BOOTSEL
        case PTN_OPT_BOOTMENU:
-               wprintw(m->mw, msg_string(MSG_bootmenu), mbri->nametab[opt]);
+               wprintw(m->mw, msg_string(MSG_bootmenu),
+                   mbri->mbrb.mbrbs_nametab[opt]);
                break;
        case PTN_OPT_BOOTDEFAULT:
                wprintw(m->mw, msg_string(MSG_boot_dflt),
@@ -1068,10 +1069,10 @@
        DISABLE(PTN_OPT_BOOTMENU, MBR_IS_EXTENDED(typ) || typ == 0);
 
        if (typ == 0)
-               mbri->nametab[opt][0] = 0;
+               mbri->mbrb.mbrbs_nametab[opt][0] = 0;
 
        /* Only partitions with bootmenu names can be made the default */
-       DISABLE(PTN_OPT_BOOTDEFAULT, mbri->nametab[opt][0] == 0);
+       DISABLE(PTN_OPT_BOOTDEFAULT, mbri->mbrb.mbrbs_nametab[opt][0] == 0);
 #endif
 #undef DISABLE
 }
@@ -1118,7 +1119,7 @@
        } else
                wprintw(m->mw, " %.*s", len, name);
 #ifdef BOOTSEL
-       if (mbri->nametab[opt][0] != 0) {
+       if (mbri->mbrb.mbrbs_nametab[opt][0] != 0) {
                int x, y;
                if (opt >= MBR_PART_COUNT)
                        opt = 0;
@@ -1127,7 +1128,8 @@
                        x = 52;
                        wmove(m->mw, y, x);
                }
-               wprintw(m->mw, "%*s %s", 53 - x, "", mbri->nametab[opt]);
+               wprintw(m->mw, "%*s %s", 53 - x, "",
+                   mbri->mbrb.mbrbs_nametab[opt]);
        }
 #endif
 }
@@ -1249,7 +1251,7 @@
                }
                memset(part, 0, MBR_PART_COUNT * sizeof *part);
 #ifdef BOOTSEL
-               memset(&mbri->nametab, 0, sizeof mbri->nametab);
+               memset(&mbri->mbrb, 0, sizeof mbri->mbrb);
 #endif
                part[0].mbrp_type = MBR_PTYPE_NETBSD;
                part[0].mbrp_size = dlsize - bsec;
@@ -1403,20 +1405,19 @@
                }
 #if BOOTSEL
                if (mbrs->mbr_bootsel_magic == htole16(MBR_MAGIC)) {
-                       /* old bootsel, move to new location */
-                       memmove(&mbrs->mbr_bootsel,
-                               (u_int8_t *)&mbrs->mbr_bootsel + 4,
-                               sizeof mbrs->mbr_bootsel);
-                       mbrs->mbr_bootsel_magic = htole16(MBR_BS_MAGIC);
-                       mbrs->mbr_bootsel.mbrbs_flags &= ~MBR_BS_NEWMBR;
+                       /* old bootsel, grab bootsel info */
+                       mbri->mbrb = *(struct mbr_bootsel *)
+                               ((uint8_t *)mbrs + MBR_BS_OLD_OFFSET);
+                       if (ext_base == 0)
+                               bootkey = mbri->mbrb.mbrbs_defkey - SCAN_1;
+               } else if (mbrs->mbr_bootsel_magic == htole16(MBR_BS_MAGIC)) {
+                       /* new location */
+                       mbri->mbrb = mbrs->mbr_bootsel;
+                       if (ext_base == 0)
+                               bootkey = mbri->mbrb.mbrbs_defkey - SCAN_1;
                }
-               if (mbrs->mbr_bootsel_magic == htole16(MBR_BS_MAGIC)) {
-                       if (ext_base == 0)
-                               bootkey = mbrs->mbr_bootsel.mbrbs_defkey
-                                           - SCAN_1;
-                       memcpy(mbri->nametab, mbrs->mbr_bootsel.mbrbs_nametab,
-                               sizeof mbri->nametab);
-               }
+               /* Save original flags for mbr code update tests */
+               mbri->oflags = mbri->mbrb.mbrbs_flags;
 #endif
                mbri->sector = next_ext + ext_base;
                next_ext = 0;
@@ -1444,7 +1445,8 @@
 #endif
                        }
 #if BOOTSEL
-                       if (mbri->nametab[i][0] != 0 && bootkey-- == 0)
+                       if (mbri->mbrb.mbrbs_nametab[i][0] != 0
+                           && bootkey-- == 0)
                                ombri->bootsec = mbri->sector +
                                                        mbrp->mbrp_start;
 #endif
@@ -1486,7 +1488,7 @@
                        ext_base = next_ext;
                        next_ext = 0;
                }
-               ext = malloc(sizeof *ext);
+               ext = calloc(sizeof *ext, 1);
                if (!ext)
                        break;
                mbrs = &ext->mbr;
@@ -1525,26 +1527,37 @@
         * If the main boot code (appears to) contain the netbsd bootcode,
         * copy in all the menu strings and set the default keycode
         * to be that for the default partition.
+        * Unfortunately we can't rely on the user having actually updated
+        * to the new mbr code :-(
         */
-       if (mbri->mbr.mbr_bootsel_magic == htole16(MBR_BS_MAGIC)) {
+       if (mbri->mbr.mbr_bootsel_magic == htole16(MBR_BS_MAGIC)
+           || mbri->mbr.mbr_bootsel_magic == htole16(MBR_MAGIC)) {
                int8_t key = SCAN_1;



Home | Main Index | Thread Index | Old Index