summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/stand/boot/Makefile8
-rw-r--r--sys/arch/amd64/stand/boot/check-boot.pl65
-rw-r--r--sys/arch/i386/stand/boot/Makefile8
-rw-r--r--sys/arch/i386/stand/boot/check-boot.pl65
4 files changed, 142 insertions, 4 deletions
diff --git a/sys/arch/amd64/stand/boot/Makefile b/sys/arch/amd64/stand/boot/Makefile
index 2646353ac5c..cf61212da36 100644
--- a/sys/arch/amd64/stand/boot/Makefile
+++ b/sys/arch/amd64/stand/boot/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.14 2012/10/12 14:00:02 jsing Exp $
+# $OpenBSD: Makefile,v 1.15 2012/10/12 14:58:26 jsing Exp $
.include "${.CURDIR}/../Makefile.inc"
@@ -46,8 +46,12 @@ SRCS+= adler32.c crc32.c inflate.c inftrees.c
boot.bin: boot
objcopy -v -O binary ${PROG} boot.bin
+CLEANFILES+= ${PROG}.new
+
${PROG}: $(OBJS)
- $(LD) $(LDFLAGS) -o ${PROG} $(OBJS)
+ $(LD) $(LDFLAGS) -o ${PROG}.new $(OBJS)
+ @perl ${.CURDIR}/check-boot.pl ${PROG}.new
+ @mv ${PROG}.new ${PROG}
@$(SIZE) ${PROG}
.else
diff --git a/sys/arch/amd64/stand/boot/check-boot.pl b/sys/arch/amd64/stand/boot/check-boot.pl
new file mode 100644
index 00000000000..77a3d3f899f
--- /dev/null
+++ b/sys/arch/amd64/stand/boot/check-boot.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+#
+# Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+#
+# Ensure that the file offset for .text and .data aligns with the LMA. If they
+# do not match boot(8) will fail since biosboot(8) does not perform relocation.
+#
+
+$LINKBASE = 0x40000;
+
+if (scalar(@ARGV) != 1) {
+ print "Usage: check-boot.pl boot\n";
+ exit(2);
+}
+
+$boot = shift @ARGV;
+if (! -f $boot) {
+ print "No such file - $boot\n";
+ exit(2);
+}
+
+$valid = 1;
+$sections = 0;
+
+open(OBJDUMP, "/usr/bin/objdump -h $boot |") || die "Failed to run objdump";
+while (<OBJDUMP>) {
+ @section = split / +/, $_;
+ next if scalar(@section) < 7;
+ if ($section[2] =~ /(\.(text|data))/) {
+ $name = $1;
+ $lma = hex($section[5]);
+ $fileoff = hex($section[6]);
+ $offset = $lma - $LINKBASE;
+ $sections++;
+
+ if ($fileoff != $offset) {
+ printf "$name has incorrect file offset " .
+ "0x%x (should be 0x%x)\n", $fileoff, $offset;
+ $valid = 0;
+ }
+ }
+}
+close(OBJDUMP);
+
+if ($sections != 2) {
+ print "Failed to find .text or .data section!\n";
+ exit(1);
+}
+
+exit(1) if ! $valid;
diff --git a/sys/arch/i386/stand/boot/Makefile b/sys/arch/i386/stand/boot/Makefile
index fc7fff893bb..33d0f43ceea 100644
--- a/sys/arch/i386/stand/boot/Makefile
+++ b/sys/arch/i386/stand/boot/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.41 2012/10/12 14:00:02 jsing Exp $
+# $OpenBSD: Makefile,v 1.42 2012/10/12 14:58:26 jsing Exp $
.include "${.CURDIR}/../Makefile.inc"
@@ -53,8 +53,12 @@ SRCS+= adler32.c crc32.c inflate.c inftrees.c
boot.bin: boot
objcopy -v -O binary ${PROG} boot.bin
+CLEANFILES+= ${PROG}.new
+
${PROG}: $(OBJS)
- $(LD) $(LDFLAGS) -o ${PROG} $(OBJS)
+ $(LD) $(LDFLAGS) -o ${PROG}.new $(OBJS)
+ @perl ${.CURDIR}/check-boot.pl ${PROG}.new
+ @mv ${PROG}.new ${PROG}
@$(SIZE) ${PROG}
.else
diff --git a/sys/arch/i386/stand/boot/check-boot.pl b/sys/arch/i386/stand/boot/check-boot.pl
new file mode 100644
index 00000000000..77a3d3f899f
--- /dev/null
+++ b/sys/arch/i386/stand/boot/check-boot.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+#
+# Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+#
+# Ensure that the file offset for .text and .data aligns with the LMA. If they
+# do not match boot(8) will fail since biosboot(8) does not perform relocation.
+#
+
+$LINKBASE = 0x40000;
+
+if (scalar(@ARGV) != 1) {
+ print "Usage: check-boot.pl boot\n";
+ exit(2);
+}
+
+$boot = shift @ARGV;
+if (! -f $boot) {
+ print "No such file - $boot\n";
+ exit(2);
+}
+
+$valid = 1;
+$sections = 0;
+
+open(OBJDUMP, "/usr/bin/objdump -h $boot |") || die "Failed to run objdump";
+while (<OBJDUMP>) {
+ @section = split / +/, $_;
+ next if scalar(@section) < 7;
+ if ($section[2] =~ /(\.(text|data))/) {
+ $name = $1;
+ $lma = hex($section[5]);
+ $fileoff = hex($section[6]);
+ $offset = $lma - $LINKBASE;
+ $sections++;
+
+ if ($fileoff != $offset) {
+ printf "$name has incorrect file offset " .
+ "0x%x (should be 0x%x)\n", $fileoff, $offset;
+ $valid = 0;
+ }
+ }
+}
+close(OBJDUMP);
+
+if ($sections != 2) {
+ print "Failed to find .text or .data section!\n";
+ exit(1);
+}
+
+exit(1) if ! $valid;