to make a prom image...

gregory.menke at gregory.menke at
Thu Sep 27 13:55:00 UTC 2001

We use objcopy to relocate code, and built a little Python script
shown below to do it.  Happily, it works just fine under both Linux
and Cygwin.


import sys
import os

        fileInput= os.path.abspath( sys.argv[1] )
        fileOutput= os.path.abspath( sys.argv[3] )
        print ' error: ', sys.exc_info()[0]
        raise "exit"
    if len(sys.argv) != 4:
        print ' incorrect parameters'
        raise "exit"

    if not os.access(fileInput,os.R_OK):
        print ' unable to read %(fileInput)s' % vars()
        raise "exit"

    if targetAddr < 0x8000000:
        print ' target address %(targetAddr)08X less than 0x80000000' % vars()
        raise "exit"

except "exit":
    print ' usage:'
    print '    python <inputFile> <targetAddress> <outputFile>'
    print ' where:   <inputFile> is the pathname of a RTEMS executable'
    print '      <targetAddress> is the hex address at which the executable should be located'
    print '         <outputFile> is the pathname to receive the located s3 records'

print ' input file %(fileInput)s' % vars()
print 'output file %(fileOutput)s' % vars()
print 'target address 0x%(targetAddr)08X' % vars()

finfo=os.popen("mips-rtems-objdump -d %(fileInput)s | grep _ftext | cut -b 9-16" % vars(),'r')
baseAddr=long( "0x" + finfo.readline(), 16 )

print 'execution base address 0x%(baseAddr)08X' % vars()

delta=targetAddr - baseAddr
print 'shifting base address by 0x%(delta)08X' % vars()
os.system("mips-rtems-objcopy --change-addresses 0x%(delta)08X -O srec %(fileInput)s %(fileOutput)s" % vars())
print 'output file written'

# eof

This is principally to support our application where we link the app
to run in a particular address range, but store the image w/ a little
relocator routine in a different part of memory.  Here, just after the
app is linked, objcopy adds an offset to the addresses so proper S3
records can be generated for burning to eeprom.  I suspect warnings
about .data might be ignored, I <guess> its because your software
isn't putting anything in .data.  We modified linkcmds to set the base
address where the app will be linked, and to specify memory size,
etc...  If you post your linkcmds, I could try commenting on it, but
what I don't know about ld would fill a rather large textbook...


 > Hello, this sounds like the problem I had with
 > m68k-rtems-objcopy. It looks like the silly thing reallocates your
 > code... Can anybody shead any light on this? It realy is
 > unhandy... I posted somthing under the subject "ObjCopy" and did
 > not get any response. Looks like I am the only one using ObjCopy...
 > Thanks for any comments and help that will be given!  Gerke
 > *********** REPLY SEPARATOR ***********
 > On 27/09/01 at 11:38 Stan wrote:
 > Hello,
 > I try to make a prom image;
 > can you help me ?
 > after make,
 > m68k-rtems-size : text=47984 data=2208 bss=14512 dec=64704 hex=fcc0
 > and,
 > m68k-rtems-objcopy: warning :
 > --change-section-vma .data = 0x00000000 never used
 > m68k-rtems-objcopy: warning :
 > --change-section-lma .data = 0x00000000 never used
 > Can you tell me if linkcmd and hello.num are good ?
 > Thank's.

More information about the users mailing list