Skip to content

Commit d461776

Browse files
Archcady0xc0170
authored andcommitted
Fix postbuild for ARM & GCC
1 parent 7867a81 commit d461776

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

tools/REALTEK_RTL8195AM.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,17 @@ def append_image_file(image, output):
5050

5151
def prepend(image, image_prepend, toolchain, info):
5252
output = open(image_prepend, "wb")
53-
if toolchain in ["GCC_ARM", "ARM_STD", "ARM", "ARM_MICRO"]:
54-
write_fixed_width_value(os.stat(image).st_size, 8, output)
55-
write_fixed_width_value(info['addr'], 8, output)
56-
write_fixed_width_value(RAM2_RSVD, 16, output)
57-
append_image_file(image, output)
58-
59-
elif toolchain == "IAR":
60-
write_fixed_width_value(info['size'], 8, output)
61-
write_fixed_width_value(info['addr'], 8, output)
62-
write_fixed_width_value(RAM2_RSVD, 16, output)
63-
with open(image, "rb") as input:
53+
write_fixed_width_value(info['size'], 8, output)
54+
write_fixed_width_value(info['addr'], 8, output)
55+
write_fixed_width_value(RAM2_RSVD, 16, output)
56+
with open(image, "rb") as input:
57+
if toolchain == "IAR":
6458
input.seek(info['addr'])
65-
output.write(input.read(info['size']))
59+
output.write(input.read(info['size']))
6660
output.close()
6761

6862
def parse_section(toolchain, elf, section):
69-
info = {'addr':None, 'size':None};
63+
info = {'addr':None, 'size':0};
7064
if toolchain not in ["GCC_ARM", "ARM_STD", "ARM", "ARM_MICRO", "IAR"]:
7165
print "[ERROR] unsupported toolchain " + toolchain
7266
sys.exit(-1)
@@ -81,15 +75,15 @@ def parse_section(toolchain, elf, section):
8175
# 0x[00000000]30000000 __image2_start__ = .
8276
# 0x[00000000]30000000 __image2_entry_func__ = .
8377
match = re.match(r'^' + section + \
84-
r'\s+0x0{,8}(?P<addr>[0-9A-Fa-f]{8})\s+.*$', line)
78+
r'\s+0x0{,8}(?P<addr>[0-9A-Fa-f]{8})\s+0x(?P<size>[0-9A-Fa-f]+).*$', line)
8579
elif toolchain in ["ARM_STD", "ARM", "ARM_MICRO"]:
8680
# Memory Map of the image
8781
# Load Region LR_DRAM (Base: 0x30000000, Size: 0x00006a74, Max: 0x00200000, ABSOLUTE)
8882
# Execution Region IMAGE2_TABLE (Base: 0x30000000, Size: 0x00000018, Max: 0xffffffff, ABSOLUTE, FIXED)
8983
# Base Addr Size Type Attr Idx E Section Name Object
9084
# 0x30000000 0x00000004 Data RO 5257 .image2.ram.data rtl8195a_init.o
9185
match = re.match(r'^.*Region\s+' + section + \
92-
r'\s+\(Base: 0x(?P<addr>[0-9A-Fa-f]{8}),\s+Size:.*\)$', line)
86+
r'\s+\(Base: 0x(?P<addr>[0-9A-Fa-f]{8}),\s+Size: 0x(?P<size>[0-9A-Fa-f]+), .*\)$', line)
9387
elif toolchain == "IAR":
9488
# Section Kind Address Size Object
9589
# ------- ---- ------- ---- ------
@@ -104,38 +98,39 @@ def parse_section(toolchain, elf, section):
10498
try:
10599
info['size'] = int(match.group("size"), 16)
106100
except IndexError:
107-
info['size'] = 0x0
101+
print "[WARNING] cannot find the size of section " + section
108102
return info
109103

110-
print "[ERROR] cannot find the address of section " + section
111-
if not info['size']:
112-
if toolchain == "IAR":
113-
print "[WARNING] cannot find the size of section " + section
114-
104+
print "[ERROR] cannot find the address of section " + section
115105
return info
116106

117107
# ----------------------------
118108
# main function
119109
# ----------------------------
120110
def rtl8195a_elf2bin(toolchain, image_elf, image_bin):
121111
if toolchain == "GCC_ARM":
122-
img2_section = ".image2.table"
112+
img2_sections = [".image2.table", ".text", ".data"]
123113
elif toolchain in ["ARM_STD", "ARM", "ARM_MICRO"]:
124-
img2_section = ".image2.table"
114+
img2_sections = [".image2.table", ".text", ".data"]
125115
elif toolchain == "IAR":
126116
# actually it's block
127-
img2_section = "IMAGE2"
117+
img2_sections = ["IMAGE2"]
128118
else:
129119
printf("[error] unsupported toolchain") + toolchain
130120
return
131-
ram2_info = {'addr':None, 'size':None}
121+
ram2_info = {'addr':None, 'size':0}
132122
image_name = os.path.splitext(image_elf)[0]
133123

134124
ram1_prepend_bin = os.path.join(TOOLS_BOOTLOADERS, "REALTEK_RTL8195AM", "ram_1_prepend.bin")
135125
ram2_prepend_bin = image_name + '-ram_2_prepend.bin'
136126

137127
old_bin = image_name + '.bin'
138-
ram2_info = parse_section(toolchain, image_elf, img2_section)
128+
for section in img2_sections:
129+
section_info = parse_section(toolchain, image_elf, section)
130+
#print("addr 0x%x, size 0x%x" % (section_info['addr'], section_info['size']))
131+
if ram2_info['addr'] is None or ram2_info['addr'] > section_info['addr']:
132+
ram2_info['addr'] = section_info['addr']
133+
ram2_info['size'] = ram2_info['size'] + section_info['size']
139134

140135
#print("toolchain = %s, bin name = \"%s, ram2_addr = 0x%x, ram2_size = 0x%x" % (toolchain, old_bin, ram2_info['addr'], ram2_info['size']))
141136

0 commit comments

Comments
 (0)