From db802adcfbfc22df158d498777b5150fa018a1c2 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 17 Jan 2009 19:35:10 -0500 Subject: [PATCH] Have layoutrom.py show info on utilization of fixed area. Also, try harder to fit sections with alignment greater than 1. --- tools/layoutrom.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/layoutrom.py b/tools/layoutrom.py index 592893b..7848957 100755 --- a/tools/layoutrom.py +++ b/tools/layoutrom.py @@ -29,6 +29,8 @@ def alignpos(pos, alignbytes): mask = alignbytes - 1 return (pos + mask) & ~mask +MAXPOS = 0x10000 + def doLayout(sections, outname): textsections = [] rodatasections = [] @@ -66,7 +68,7 @@ def doLayout(sections, outname): fixedsectioninfo = fixedsections[i] addr, section, extrasectionslist = fixedsectioninfo if i == len(fixedsections) - 1: - nextaddr = 0x10000 + nextaddr = MAXPOS else: nextaddr = fixedsections[i+1][0] avail = nextaddr - addr - section[0] @@ -75,6 +77,7 @@ def doLayout(sections, outname): # Attempt to fit other sections into fixed area fixedAddr.sort() canrelocate.sort() + unused = 0 for freespace, fixedsectioninfo in fixedAddr: fixedaddr, fixedsection, extrasections = fixedsectioninfo addpos = fixedaddr + fixedsection[0] @@ -85,14 +88,19 @@ def doLayout(sections, outname): canfit = None for fixedaddrinfo in canrelocate: fitsection, inlist = fixedaddrinfo - fitnextaddr = alignpos(addpos, fitsection[1]) + fitsection[0] + fitsize, fitalign, fitname = fitsection + if addpos + fitsize > nextfixedaddr: + # Can't fit and nothing else will fit. + break + fitnextaddr = alignpos(addpos, fitalign) + fitsize # print "Test %s - %x vs %x" % ( -# fitsection[2], fitnextaddr, nextfixedaddr) +# fitname, fitnextaddr, nextfixedaddr) if fitnextaddr > nextfixedaddr: - # Can't fit. - break + # This item can't fit. + continue canfit = (fitnextaddr, fixedaddrinfo) if canfit is None: + unused += nextfixedaddr - addpos break # Found a section that can fit. fitnextaddr, fixedaddrinfo = canfit @@ -101,9 +109,17 @@ def doLayout(sections, outname): inlist.remove(fitsection) extrasections.append(fitsection) addpos = fitnextaddr + unused += alignpos(addpos, fitsection[1]) - addpos # print " Adding %s (size %d align %d)" % ( # fitsection[2], fitsection[0], fitsection[1]) + firstfixed = fixedsections[0][0] + total = MAXPOS-firstfixed + totalused = total - unused + print "Fixed space: 0x%x-0x%x total: %d used: %d Percent used: %.1f%%" % ( + firstfixed, MAXPOS, total, totalused, + (float(totalused) / total) * 100.0) + # Write regular sections output = open(outname, 'wb') for section in textsections: -- 2.25.1