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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [tools/] [pyelf/] [elf_section_info.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
import elf
4
 
5
# Define section markers for various sections in elf
6
def elf_loadable_section_info(img):
7
    elffile = elf.ElfFile.from_file(img)
8
 
9
    # Sections markers for RW sections
10
    rw_sections_start = 0
11
    rw_sections_end = 0
12
 
13
    # Section markers for RX and RO section combined
14
    rx_sections_start = 0
15
    rx_sections_end = 0
16
 
17
    # Flag encoding used by elf
18
    sh_flag_write = 1 << 0
19
    sh_flag_load = 1 << 1
20
    sh_flag_execute = 1 << 2
21
 
22
    for sheader in elffile.sheaders:
23
        x = sheader.ai
24
 
25
        # Check for loadable sections
26
        if x.sh_flags.get() & sh_flag_load:
27
                start = x.sh_addr.get()
28
                end = start + x.sh_size.get()
29
 
30
                # RW Section
31
                if x.sh_flags.get() & sh_flag_write:
32
                    if (rw_sections_start == 0) or (rw_sections_start > start):
33
                        rw_sections_start = start
34
                    if (rw_sections_end == 0) or (rw_sections_end < end):
35
                        rw_sections_end = end
36
 
37
                # RX, RO Section
38
                else:
39
                    if (rx_sections_start == 0) or (rx_sections_start > start):
40
                            rx_sections_start = start
41
                    if (rx_sections_end == 0) or (rx_sections_end < end):
42
                            rx_sections_end = end
43
 
44
    return rw_sections_start, rw_sections_end, \
45
           rx_sections_start, rx_sections_end
46
 

powered by: WebSVN 2.1.0

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