@@ -50,23 +50,17 @@ def append_image_file(image, output):
50
50
51
51
def prepend (image , image_prepend , toolchain , info ):
52
52
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" :
64
58
input .seek (info ['addr' ])
65
- output .write (input .read (info ['size' ]))
59
+ output .write (input .read (info ['size' ]))
66
60
output .close ()
67
61
68
62
def parse_section (toolchain , elf , section ):
69
- info = {'addr' :None , 'size' :None };
63
+ info = {'addr' :None , 'size' :0 };
70
64
if toolchain not in ["GCC_ARM" , "ARM_STD" , "ARM" , "ARM_MICRO" , "IAR" ]:
71
65
print "[ERROR] unsupported toolchain " + toolchain
72
66
sys .exit (- 1 )
@@ -81,15 +75,15 @@ def parse_section(toolchain, elf, section):
81
75
# 0x[00000000]30000000 __image2_start__ = .
82
76
# 0x[00000000]30000000 __image2_entry_func__ = .
83
77
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 )
85
79
elif toolchain in ["ARM_STD" , "ARM" , "ARM_MICRO" ]:
86
80
# Memory Map of the image
87
81
# Load Region LR_DRAM (Base: 0x30000000, Size: 0x00006a74, Max: 0x00200000, ABSOLUTE)
88
82
# Execution Region IMAGE2_TABLE (Base: 0x30000000, Size: 0x00000018, Max: 0xffffffff, ABSOLUTE, FIXED)
89
83
# Base Addr Size Type Attr Idx E Section Name Object
90
84
# 0x30000000 0x00000004 Data RO 5257 .image2.ram.data rtl8195a_init.o
91
85
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 )
93
87
elif toolchain == "IAR" :
94
88
# Section Kind Address Size Object
95
89
# ------- ---- ------- ---- ------
@@ -104,38 +98,39 @@ def parse_section(toolchain, elf, section):
104
98
try :
105
99
info ['size' ] = int (match .group ("size" ), 16 )
106
100
except IndexError :
107
- info [ 'size' ] = 0x0
101
+ print "[WARNING] cannot find the size of section " + section
108
102
return info
109
103
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
115
105
return info
116
106
117
107
# ----------------------------
118
108
# main function
119
109
# ----------------------------
120
110
def rtl8195a_elf2bin (toolchain , image_elf , image_bin ):
121
111
if toolchain == "GCC_ARM" :
122
- img2_section = ".image2.table"
112
+ img2_sections = [ ".image2.table" , ".text" , ".data" ]
123
113
elif toolchain in ["ARM_STD" , "ARM" , "ARM_MICRO" ]:
124
- img2_section = ".image2.table"
114
+ img2_sections = [ ".image2.table" , ".text" , ".data" ]
125
115
elif toolchain == "IAR" :
126
116
# actually it's block
127
- img2_section = "IMAGE2"
117
+ img2_sections = [ "IMAGE2" ]
128
118
else :
129
119
printf ("[error] unsupported toolchain" ) + toolchain
130
120
return
131
- ram2_info = {'addr' :None , 'size' :None }
121
+ ram2_info = {'addr' :None , 'size' :0 }
132
122
image_name = os .path .splitext (image_elf )[0 ]
133
123
134
124
ram1_prepend_bin = os .path .join (TOOLS_BOOTLOADERS , "REALTEK_RTL8195AM" , "ram_1_prepend.bin" )
135
125
ram2_prepend_bin = image_name + '-ram_2_prepend.bin'
136
126
137
127
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' ]
139
134
140
135
#print("toolchain = %s, bin name = \"%s, ram2_addr = 0x%x, ram2_size = 0x%x" % (toolchain, old_bin, ram2_info['addr'], ram2_info['size']))
141
136
0 commit comments