summaryrefslogtreecommitdiff
path: root/sys/arch/i386/stand/boot
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2012-10-12 14:58:27 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2012-10-12 14:58:27 +0000
commit491396b0a3023f0f91541a3d746345186e056b64 (patch)
treed4ca36eb91b1eb2b7fdbcbc4acb178ce98415555 /sys/arch/i386/stand/boot
parent55cef35a66141a0725a968d7e7c55d018d656ff6 (diff)
Add a script that checks the file offsets for boot(8)'s .text and .data
sections match up with their LMAs. This is necessary since biosboot does not perform relocation. Discussed with deraadt@
Diffstat (limited to 'sys/arch/i386/stand/boot')
-rw-r--r--sys/arch/i386/stand/boot/Makefile8
-rw-r--r--sys/arch/i386/stand/boot/check-boot.pl65
2 files changed, 71 insertions, 2 deletions
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;