-# $OpenBSD: rc,v 1.502 2017/06/14 21:39:53 rpe Exp $
+# $OpenBSD: rc,v 1.503 2017/06/19 22:50:50 deraadt Exp $
# System startup script run by init on autoboot or after single-user.
# Output and error are redirected to console by init, and the console is the
# others aren't hurt.)
mount -uw /
chmod og-rwx /bsd
+ln -fh /bsd /bsd.booted
rm -f /fastboot
-/* $OpenBSD: biosvar.h,v 1.22 2015/08/30 10:05:09 yasuoka Exp $ */
+/* $OpenBSD: biosvar.h,v 1.23 2017/06/19 22:50:50 deraadt Exp $ */
/*
* Copyright (c) 1997-1999 Michael Shalayeff
#define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */
#define BDI_BADLABEL 0x00000004 /* Had another disklabel */
#define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */
+#define BDI_HIBVALID 0x00000010 /* hibernate signiture valid */
#define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */
} __packed bios_diskinfo_t;
-# $OpenBSD: Makefile,v 1.37 2017/05/30 22:32:10 naddy Exp $
+# $OpenBSD: Makefile,v 1.38 2017/06/19 22:50:50 deraadt Exp $
COPTS?=
MAN?= boot.8
.endif
CPPFLAGS+=-DBOOTMAGIC=$(BOOTMAGIC) ${DEBUGFLAGS} -DLINKADDR=${LINKADDR}
CPPFLAGS+=-DSLOW -DSMALL -DNOBYFOUR -DNO_GZIP -DDYNAMIC_CRC_TABLE
+CPPFLAGS+=-DHIBERNATE
CPPFLAGS+=-DHEAP_LIMIT=${HEAP_LIMIT} -I${S}/stand/boot #-DCOMPAT_UFS
CFLAGS+=-m32 $(SACFLAGS) -D__INTERNAL_LIBSA_CREAD -fno-pie
AFLAGS+=${NO_INTEGR_AS}
-# $OpenBSD: Makefile.common,v 1.10 2016/09/18 16:34:59 jsing Exp $
+# $OpenBSD: Makefile.common,v 1.11 2017/06/19 22:50:50 deraadt Exp $
S= ${.CURDIR}/../../../../..
SADIR= ${.CURDIR}/../..
.include <bsd.prog.mk>
CFLAGS+= -Wno-pointer-sign
CPPFLAGS+= -DSMALL -DSLOW -DNOBYFOUR -D__INTERNAL_LIBSA_CREAD
-CPPFLAGS+= -DHEAP_LIMIT=${EFI_HEAP_LIMIT}
+CPPFLAGS+= -DHEAP_LIMIT=${EFI_HEAP_LIMIT} -DHIBERNATE
${PROG.so}: ${OBJS}
${LD} ${LDFLAGS} -o ${.TARGET}.tmp ${OBJS} ${LDADD}
-/* $OpenBSD: diskprobe.c,v 1.17 2016/09/11 15:54:11 jsing Exp $ */
+/* $OpenBSD: diskprobe.c,v 1.18 2017/06/19 22:50:50 deraadt Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
#include <sys/queue.h>
#include <sys/reboot.h>
#include <sys/disklabel.h>
+#include <sys/hibernate.h>
#include <lib/libz/zlib.h>
#include <machine/biosvar.h>
/* Local Prototypes */
static int disksum(int);
+static void check_hibernate(struct diskinfo *);
+
+int bootdev_has_hibernate(void); /* export for loadfile() */
/* List of disk devices we found/probed */
struct disklist_lh disklist;
dip->bios_info.checksum = 0; /* just in case */
/* Fill out best we can */
- dip->bios_info.bsd_dev =
+ dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
+ check_hibernate(dip);
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
dip->bios_info.checksum = 0; /* just in case */
/* Fill out best we can */
- dip->bios_info.bsd_dev =
+ dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
+ check_hibernate(dip);
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
return reprobe;
}
+
+int
+bootdev_has_hibernate(void)
+{
+ return ((bootdev_dip->bios_info.flags & BDI_HIBVALID)? 1 : 0);
+}
+
+static void
+check_hibernate(struct diskinfo *dip)
+{
+ daddr_t sec;
+ int error;
+ union hibernate_info hib;
+
+ /* read hibernate */
+ if (dip->disklabel.d_partitions[1].p_fstype != FS_SWAP ||
+ DL_GETPSIZE(&dip->disklabel.d_partitions[1]) == 0)
+ return;
+
+ sec = DL_GETPOFFSET(&dip->disklabel.d_partitions[1]) +
+ DL_GETPSIZE(&dip->disklabel.d_partitions[1]) -
+ (sizeof(union hibernate_info) / DEV_BSIZE);
+
+ error = dip->strategy(dip, F_READ, (daddr32_t)sec, sizeof hib, &hib, NULL);
+ if (error == 0 && hib.magic == HIBERNATE_MAGIC) /* Hibernate present */
+ dip->bios_info.flags |= BDI_HIBVALID;
+ printf("&");
+}
-/* $OpenBSD: biosvar.h,v 1.64 2015/09/03 15:52:16 deraadt Exp $ */
+/* $OpenBSD: biosvar.h,v 1.65 2017/06/19 22:50:50 deraadt Exp $ */
/*
* Copyright (c) 1997-1999 Michael Shalayeff
#define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */
#define BDI_BADLABEL 0x00000004 /* Had another disklabel */
#define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */
+#define BDI_HIBVALID 0x00000010 /* hibernate signiture valid */
#define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */
} __packed bios_diskinfo_t;
-# $OpenBSD: Makefile,v 1.65 2017/06/01 11:18:53 naddy Exp $
+# $OpenBSD: Makefile,v 1.66 2017/06/19 22:50:50 deraadt Exp $
COPTS?=
MAN?= boot.8
.endif
CPPFLAGS+=-DBOOTMAGIC=$(BOOTMAGIC) ${DEBUGFLAGS} -DLINKADDR=${LINKADDR}
CPPFLAGS+=-DSLOW -DSMALL -DNOBYFOUR -DNO_GZIP -DDYNAMIC_CRC_TABLE
+CPPFLAGS+=-DHIBERNATE
CPPFLAGS+=-DHEAP_LIMIT=${HEAP_LIMIT} -I${S}/stand/boot #-DCOMPAT_UFS
CFLAGS+=-m32 $(SACFLAGS) -D__INTERNAL_LIBSA_CREAD -fno-pie
AFLAGS+=${NO_INTEGR_AS}
-/* $OpenBSD: diskprobe.c,v 1.41 2016/09/11 15:54:11 jsing Exp $ */
+/* $OpenBSD: diskprobe.c,v 1.42 2017/06/19 22:50:50 deraadt Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
#include <sys/queue.h>
#include <sys/reboot.h>
#include <sys/disklabel.h>
+#include <sys/hibernate.h>
#include <lib/libz/zlib.h>
#include <machine/biosvar.h>
/* Local Prototypes */
static int disksum(int);
+static void check_hibernate(struct diskinfo *);
+
+int bootdev_has_hibernate(void); /* export for loadfile() */
/* List of disk devices we found/probed */
struct disklist_lh disklist;
dip->bios_info.checksum = 0; /* just in case */
/* Fill out best we can */
- dip->bios_info.bsd_dev =
+ dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
+ check_hibernate(dip);
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
dip->bios_info.checksum = 0; /* just in case */
/* Fill out best we can */
- dip->bios_info.bsd_dev =
+ dip->bsddev = dip->bios_info.bsd_dev =
MAKEBOOTDEV(type, 0, 0, bsdunit, RAW_PART);
+ check_hibernate(dip);
/* Add to queue of disks */
TAILQ_INSERT_TAIL(&disklist, dip, list);
return reprobe;
}
+
+int
+bootdev_has_hibernate(void)
+{
+ return ((bootdev_dip->bios_info.flags & BDI_HIBVALID)? 1 : 0);
+}
+
+static void
+check_hibernate(struct diskinfo *dip)
+{
+ daddr_t sec;
+ int error;
+ union hibernate_info hib;
+
+ /* read hibernate */
+ if (dip->disklabel.d_partitions[1].p_fstype != FS_SWAP ||
+ DL_GETPSIZE(&dip->disklabel.d_partitions[1]) == 0)
+ return;
+
+ sec = DL_GETPOFFSET(&dip->disklabel.d_partitions[1]) +
+ DL_GETPSIZE(&dip->disklabel.d_partitions[1]) -
+ (sizeof(union hibernate_info) / DEV_BSIZE);
+
+ error = dip->strategy(dip, F_READ, (daddr32_t)sec, sizeof hib, &hib, NULL);
+ if (error == 0 && hib.magic == HIBERNATE_MAGIC) /* Hibernate present */
+ dip->bios_info.flags |= BDI_HIBVALID;
+ printf("&");
+}
-/* $OpenBSD: boot.c,v 1.43 2014/02/19 22:02:15 miod Exp $ */
+/* $OpenBSD: boot.c,v 1.44 2017/06/19 22:50:50 deraadt Exp $ */
/*
* Copyright (c) 2003 Dale Rahn
cmd.timeout = boottimeout;
st = read_conf();
+
+#ifdef HIBERNATE
+ int bootdev_has_hibernate(void);
+
+ if (bootdev_has_hibernate()) {
+ strlcpy(cmd.image, "/bsd.booted", sizeof(cmd.image));
+ printf("unhibernate detected: switching to %s\n", cmd.image);
+ }
+#endif
+
if (!bootprompt)
snprintf(cmd.path, sizeof cmd.path, "%s:%s",
cmd.bootdev, cmd.image);