1#!/usr/bin/perl -w 2 3# 4# Copyright (c) 2012 Joel Sing <jsing@openbsd.org> 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17# 18 19# 20# Ensure that the file offset for .text and .data aligns with the LMA. If they 21# do not match boot(8) will fail since biosboot(8) does not perform relocation. 22# 23 24$LINKBASE = 0x40000; 25 26if (scalar(@ARGV) != 1) { 27 print "Usage: check-boot.pl boot\n"; 28 exit(2); 29} 30 31$boot = shift @ARGV; 32if (! -f $boot) { 33 print "No such file - $boot\n"; 34 exit(2); 35} 36 37$valid = 1; 38$sections = 0; 39 40open(OBJDUMP, "/usr/bin/objdump -h $boot |") || die "Failed to run objdump"; 41while (<OBJDUMP>) { 42 @section = split / +/, $_; 43 next if scalar(@section) < 7; 44 if ($section[2] =~ /(\.(text|data))/) { 45 $name = $1; 46 $lma = hex($section[5]); 47 $fileoff = hex($section[6]); 48 $offset = $lma - $LINKBASE; 49 $sections++; 50 51 if ($fileoff != $offset) { 52 printf "$name has incorrect file offset " . 53 "0x%x (should be 0x%x)\n", $fileoff, $offset; 54 $valid = 0; 55 } 56 } 57} 58close(OBJDUMP); 59 60if ($sections != 2) { 61 print "Failed to find .text or .data section!\n"; 62 exit(1); 63} 64 65exit(1) if ! $valid; 66