forked from pvvx/ATC_MiThermometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTlsrMemInfo.py
141 lines (122 loc) · 5.31 KB
/
TlsrMemInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
### TlsrMemInfo.py ###
### Autor: pvvx ###
import sys
import signal
import struct
import platform
import time
import argparse
import subprocess
import os
import io
__progname__ = "TLSR825x MemInfo"
__filename__ = "TlsrMemInfo"
__version__ = "12.11.20"
SRAM_BASE_ADDR = 0x840000
class FatalError(RuntimeError):
def __init__(self, message):
RuntimeError.__init__(self, message)
@staticmethod
def WithResult(message, result):
message += " (result was %s)" % hexify(result)
return FatalError(message)
def signal_handler(signal, frame):
print()
print('Keyboard Break!')
sys.exit(0)
def arg_auto_int(x):
return int(x, 0)
class ELFFile:
def __init__(self, name, tool_nm):
self.name = name
self.tool_nm = tool_nm
self.symbols = {}
try:
#tool_nm = "tc32-elf-nm"
#if sys.platform == 'linux2':
# tool_nm = "tc32-elf-nm"
proc = subprocess.Popen([self.tool_nm, self.name], stdout=subprocess.PIPE)
except OSError:
print("Error calling " + self.tool_nm + ", do you have toolchain in PATH?")
sys.exit(1)
for l in proc.stdout:
fields = l.strip().split()
try:
if fields[0] == b"U":
print("Warning: Undefined symbol '%s'!" %(fields[1].decode('ASCII')))
continue
if fields[0] == b"w":
continue # can skip weak symbols
self.symbols[fields[2]] = int(fields[0], 16)
except ValueError:
raise FatalError("Failed to strip symbol output from nm: %s" % fields)
def get_symbol_addr(self, sym, default = 0):
try:
x = self.symbols[sym]
except:
return default
return x
'''
def load_section(self, section):
tool_objcopy = "e:/Telink/SDK/opt/tc32/bin/tc32-elf-objcopy.exe"
if sys.platform == 'linux2':
tool_nm = "tc32-elf-objcopy"
tmpsection = tempfile.mktemp(suffix=".section")
try:
subprocess.check_call([tool_objcopy, "--only-section", section, "-Obinary", self.name, tmpsection])
with open(tmpsection, "rb") as f:
data = f.read()
finally:
os.remove(tmpsection)
return data
'''
def main():
signal.signal(signal.SIGINT, signal_handler)
parser = argparse.ArgumentParser(description='%s version %s' % (__progname__, __version__), prog=__filename__)
parser.add_argument(
"--size", "-s",
help="Chip SRAM Size (default: 65536)",
type=arg_auto_int,
default=65536)
parser.add_argument('-t','--tools', help='Path and name tc32-elf-nm', default = 'tc32-elf-nm');
parser.add_argument('elffname', help='Name of elf file')
args = parser.parse_args()
print('%s version %s' % (__progname__, __version__))
# 0 1 2 3 4 5 6 7 8 9 10 11
sec_name = ["ramcode", "text", "rodata", "rtdata", "nc", "ictag", "icdata", "data", "bss", "irq_stk", "stack", "flash"]
sec_des = ["Resident Code SRAM","Code Flash","Read Only Data Flash","Retention SRAM","Wasteful Area SRAM","Cache Table SRAM","Cache Data SRAM","Init Data SRAM","BSS Data SRAM","BSS Data SRAM","CPU Stack SRAM","Bin Size Flash"]
sec_start = [b"__start",b"_start_text_", b"_start_rodata_",b"_retention_data_start_",b"_retention_data_end_",b"_ictag_start_",b"_ictag_end_", b"_start_data_", b"_start_bss_", b"_start_bss_", b"_end_bss_", b"__start"]
sec_end = [b"_rstored_", b"_end_text_", b"_end_rodata_", b"_retention_data_end_", b"_ictag_start_", b"_ictag_end_", b"_ictag_end_", b"_end_data_", b"_end_bss_", b"IRQ_STK_SIZE", b"__RAM_SIZE_MAX", b"_bin_size_"]
sec_start_add = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
sec_end_add = [0, 0, 0, 0, 0, 0, 0x800, 0, 0, 0, SRAM_BASE_ADDR, 0]
sec_size = []
e = ELFFile(args.elffname, args.tools);
if e.get_symbol_addr(b"_start_bss_") > 0:
chip_sram_size = e.get_symbol_addr(b"__RAM_SIZE_MAX");
else:
chip_sram_size = args.size;
if e.get_symbol_addr(b"_start_bss_"):
sec_end_add[9] = e.get_symbol_addr(b"_start_bss_")
load_sram = e.get_symbol_addr(b"_icload_size_div_16_") << 4;
ictag = e.get_symbol_addr(b"_ictag_addr_div_256_") << 8;
print("===================================================================")
print("{0:>8}|{1:>21}|{2:>12}|{3:>12}|{4:>8}".format("Section", "Description", "Start (hex)", "End (hex)", "Used space"))
print("-------------------------------------------------------------------")
for i in range(len(sec_name)):
#ss = e.get_symbol_addr(sec_start[i], sec_start_def[i]) + sec_start_add[i]
ss = e.get_symbol_addr(sec_start[i], 0) + sec_start_add[i]
#se = e.get_symbol_addr(sec_end[i], sec_end_def[i]) + sec_end_add[i]
se = e.get_symbol_addr(sec_end[i], 0) + sec_end_add[i]
sec_size.append(int(se - ss))
print("{0:>8}|{1:>21}|{2:>12X}|{3:>12X}|{4:>8d}".format(sec_name[i], sec_des[i], ss, se, sec_size[i]))
print("-------------------------------------------------------------------")
ram_used = e.get_symbol_addr(b"_end_bss_") - SRAM_BASE_ADDR
print("{0} : {1:d} {2}{3:X}{4}".format("Start Load SRAM", load_sram, "(ICtag: 0x", ictag,")"))
print("{0} : {1:d} {2} {3}".format("Total Used SRAM", ram_used, "from", chip_sram_size))
print("{0} : {1:d}{2}{3}{4}{5}".format("Total Free SRAM", sec_size[4], " + stack[", sec_size[10], '] = ', sec_size[4] + sec_size[10]))
if sec_size[10] < 256:
print("Warning! Stack is low!")
sys.exit(0);
if __name__ == '__main__':
main()