OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [tools/] [pyelf/] [readelf.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#!/usr/bin/env python
2
 
3
from aistruct import AIStruct
4
import elf, sys
5
from optparse import OptionParser
6
from os import path
7
 
8
class AfterBurner(AIStruct):
9
        def __init__(self, *args, **kwargs):
10
                AIStruct.__init__(self, AIStruct.SIZE32)
11
                self.setup(
12
                        ('UINT32', 'addr')
13
                )
14
 
15
        def __str__(self):
16
            return "0x%x" % self.ai.addr.get()
17
 
18
def main():
19
    parser = OptionParser(add_help_option=False)
20
    parser.add_option("-h", "--file-header",
21
                      action="store_true", dest="header", default=False,
22
                      help="Display the ELF file header")
23
    parser.add_option("-l", "--program-headers",
24
                      action="store_true", dest="program_headers", default=False,
25
                      help="Display the program headers")
26
    parser.add_option("-S", "--section-headers",
27
                      action="store_true", dest="section_headers", default=False,
28
                      help="Display the section headers")
29
    parser.add_option("--afterburn",
30
                      action="store_true", dest="afterburn", default=False,
31
                      help="Display the afterburn relocations")
32
    parser.add_option("--first-free-page",
33
                      action="store_true", dest="ffpage", default=False,
34
                      help="Prints out (in .lds format) the address of the first free physical" + \
35
                           "page after this image at load time. Using this information at link" + \
36
                           "time, images can be compiled and linked consecutively and loaded in" + \
37
                           "consecutive memory regions at load time.")
38
    parser.add_option("--lma-start-end", action="store_true", dest="lma_boundary", default=False,
39
                      help="Prints out the start and end LMA boundaries of an image." + \
40
                           "This is useful for autogenerating a structure for the microkernel" + \
41
                           "to discover at run-time where svc tasks are loaded.")
42
    (options, args) = parser.parse_args()
43
    if len(args) != 1:
44
        parser.print_help()
45
        return
46
    elffile = elf.ElfFile.from_file(args[0])
47
 
48
    if options.header:
49
        print elffile.header
50
    if options.program_headers:
51
        print elffile.pheaders
52
    if options.section_headers:
53
        print elffile.sheaders
54
    if options.afterburn:
55
        burnheader = elffile.sheaders[".afterburn"]
56
        burns = burnheader.container(AfterBurner)
57
        print "There are %d afterburn entry points" % len(burns)
58
        print "Afterburn:"
59
        for burn in burns:
60
            print " ", burn
61
 
62
if __name__ == "__main__":
63
    main()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.