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

Subversion Repositories c0or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#! /usr/bin/env python2.6
2
# -*- mode: python; coding: utf-8; -*-
3
#
4
#  Codezero -- Virtualization microkernel for embedded systems.
5
#
6
#  Copyright © 2009  B Labs Ltd
7
#
8
import os, sys
9
from optparse import OptionParser
10
from os.path import join
11
from os import path
12
import elf, sys
13
 
14
def conv_hex(val):
15
    hexval = hex(val)
16
    if hexval[-1:] == 'L':
17
        hexval = hexval[:-1]
18
    return hexval
19
 
20
 
21
lds_header = \
22
'''
23
/*
24
 * The next free p_align'ed LMA base address
25
 *
26
 * Usually in ARM p_align == 16K
27
 *
28
 * p_align = %s
29
 */
30
'''
31
 
32
 
33
def main():
34
    usage = "usage: %prog [options] arg"
35
    parser = OptionParser(usage)
36
 
37
    parser.add_option("--first-free-page",
38
                      action = "store_true", dest = "ffpage",
39
                      default = False,
40
                      help = "Prints out the first free loadable page "
41
                             "available after the image in "
42
                             "linker script format")
43
    parser.add_option("--lma-start-end", action = "store_true",
44
                      dest = "lma_boundary", default = False,
45
                          help = "Prints out the start and end LMA boundaries "
46
                             "of an image. Useful for aligining images in "
47
                             "physical memory.")
48
 
49
    (options, args) = parser.parse_args()
50
 
51
    if len(args) != 1:
52
        parser.print_help()
53
 
54
    elffile = elf.ElfFile.from_file(args[0])
55
 
56
    if options.lma_boundary:
57
        paddr_first = 0
58
        paddr_start = 0
59
        paddr_end = 0
60
        for pheader in elffile.pheaders:
61
            x = pheader.ai
62
            if str(x.p_type) != "LOAD":
63
                continue
64
            if paddr_first == 0:
65
                paddr_first = 1
66
                paddr_start = x.p_paddr.value
67
            if paddr_start > x.p_paddr.value:
68
                paddr_start = x.p_paddr.value
69
            if paddr_end < x.p_paddr + x.p_memsz:
70
                paddr_end = x.p_paddr + x.p_memsz
71
 
72
        rest, image_name = path.split(args[0])
73
        if image_name[-4] == ".":
74
            image_name = image_name[:-4]
75
 
76
        print image_name
77
        if hex(paddr_start)[-1] == "L":
78
            print "image_start " + hex(paddr_start)[:-1]
79
        else:
80
            print "image_start " + hex(paddr_start)
81
        if hex(paddr_end)[-1] == "L":
82
            print "image_end " + hex(paddr_end)[:-1]
83
        else:
84
            print "image_end " + hex(paddr_end)
85
 
86
 
87
if __name__ == "__main__":
88
    main()

powered by: WebSVN 2.1.0

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