diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2008-07-05 20:41:53 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2008-07-05 20:41:53 -0400 |
commit | 2fda7cbb234a2966599d1de135f55aece69220c6 (patch) | |
tree | 6b397d4e076238db74a4a942d2cef8dea72fa0be /tools | |
parent | f85fde0cb7ae5706a90c89b199c4554607dd3201 (diff) | |
download | seabios-2fda7cbb234a2966599d1de135f55aece69220c6.tar.gz |
Use ld to build final rom; remove custom build utilities.
It's possible to build the final rom with a little LD magic - so use
that instead of the buildrom.py / defsyms.py method.
Also, rename all occurances of ".globl" to the more clear ".global".
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/buildrom.py | 89 | ||||
-rwxr-xr-x | tools/checkrom.py | 33 | ||||
-rwxr-xr-x | tools/defsyms.py | 55 |
3 files changed, 33 insertions, 144 deletions
diff --git a/tools/buildrom.py b/tools/buildrom.py deleted file mode 100755 index 87b61f3d..00000000 --- a/tools/buildrom.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python -# Script to merge a rom32.bin file into a rom16.bin file. -# -# Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> -# -# This file may be distributed under the terms of the GNU GPLv3 license. - -import sys -import struct -import os - -ROM16='out/rom16.bin' -ROM32='out/rom32.bin' -OFFSETS16='out/rom16.offset.auto.h' -OFFSETS32='out/rom32.offset.auto.h' -OUT='out/bios.bin' - -def align(v, a): - return (v + a - 1) // a * a - -def scanconfig(file): - f = open(file, 'rb') - opts = {} - for l in f.readlines(): - parts = l.split() - if len(parts) != 3: - continue - if parts[0] != '#define': - continue - opts[parts[1]] = parts[2] - return opts - -def alteraddr(data, offset, ptr): - rel = struct.pack("<i", ptr) - return data[:offset] + rel + data[offset+4:] - - -def main(): - # Read in files - f = open(ROM16, 'rb') - data16 = f.read() - f = open(ROM32, 'rb') - data32 = f.read() - - if len(data16) != 65536: - print "16bit code is not 65536 bytes long" - sys.exit(1) - - # Get config options - o16 = scanconfig(OFFSETS16) - o32 = scanconfig(OFFSETS32) - - # Inject 32bit code - spos = align(int(o16['OFFSET_bios16c_end'], 16), 16) - epos = int(o16['OFFSET_post16'], 16) - size32 = len(data32) - freespace = epos - spos - if size32 > freespace: - print "32bit code too large (%d vs %d)" % (size32, freespace) - sys.exit(1) - spos -= 0xf0000 - if data16[spos:spos+size32] != '\0'*size32: - print "Non zero data in 16bit freespace (0x%x to 0x%x)" % ( - spos, spos+size32) - sys.exit(1) - outrom = data16[:spos] + data32 + data16[spos+size32:] - - # Fixup initial jump to 32 bit code - jmppos = int(o16['OFFSET_set_entry32'], 16) - 0xf0000 - start32 = int(o32['OFFSET__start'], 16) - outrom = alteraddr(outrom, jmppos+2, start32) - - print "Writing output rom %s" % OUT - print " 16bit C-code size: %d" % spos - print " 32bit C-code size: %d" % size32 - print " Total C-code size: %d" % (spos+size32) - - # Write output rom - f = open(OUT, 'wb') - f.write(outrom) - f.close() - - # Build elf file with 32bit entry point - os.system( - "ld -melf_i386 -e %s -Tdata 0xf0000 -b binary %s -o %s" % ( - int(o32['OFFSET_post32'], 16), OUT, OUT+".elf")) - -if __name__ == '__main__': - main() diff --git a/tools/checkrom.py b/tools/checkrom.py new file mode 100755 index 00000000..6eda341b --- /dev/null +++ b/tools/checkrom.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# Script to check a bios image and report info on it. +# +# Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +import sys + +def main(): + # Read in symbols (that are valid) + syms = {} + for line in sys.stdin.readlines(): + try: + addr, type, sym = line.split() + syms[sym] = int(addr, 16) + except: + pass + + if syms['code16_start'] != syms['_code32_code16_start']: + print "Error! 16bit code moved during linking" + sys.exit(1) + + size16 = syms['code16_end'] - syms['code16_start'] + size32 = syms['code32_end'] - syms['code32_start'] + sizefree = syms['freespace1_end'] - syms['freespace1_start'] + print "16bit C-code size: %d" % size16 + print "32bit C-code size: %d" % size32 + print "Total C-code size: %d" % (size16+size32) + print "Free C-code space: %d" % sizefree + +if __name__ == '__main__': + main() diff --git a/tools/defsyms.py b/tools/defsyms.py deleted file mode 100755 index e4b3215f..00000000 --- a/tools/defsyms.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -# Simple script to convert the output from 'nm' to a C style header -# file with defined offsets. -# -# Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> -# -# This file may be distributed under the terms of the GNU GPLv3 license. - -import sys -import string - -def printUsage(): - print "Usage:\n %s <output file>" % (sys.argv[0],) - sys.exit(1) - -def main(): - if len(sys.argv) != 2: - printUsage() - # Find symbols (that are valid) - syms = [] - lines = sys.stdin.readlines() - for line in lines: - addr, type, sym = line.split() - if type not in 'Tt': - # Only interested in global symbols in text segment - continue - for c in sym: - if c not in string.letters + string.digits + '_': - break - else: - syms.append((sym, addr)) - # Build guard string - guardstr = '' - for c in sys.argv[1]: - if c not in string.letters + string.digits + '_': - guardstr += '_' - else: - guardstr += c - # Generate header - f = open(sys.argv[1], 'wb') - f.write(""" -#ifndef __OFFSET_AUTO_H__%s -#define __OFFSET_AUTO_H__%s -// Auto generated file - please see defsyms.py. -// This file contains symbol offsets of a compiled binary. - -""" % (guardstr, guardstr)) - for sym, addr in syms: - f.write("#define OFFSET_%s 0x%s\n" % (sym, addr)) - f.write(""" -#endif // __OFFSET_AUTO_H__%s -""" % (guardstr,)) - -if __name__ == '__main__': - main() |