Skip to content

Commit a30d4d6

Browse files
Archcadyadbridge
authored andcommitted
enable sdram usage of REALTEK_RTL8195AM
Signed-off-by: Tony Wu <[email protected]>
1 parent 98e5e23 commit a30d4d6

File tree

4 files changed

+77
-26
lines changed

4 files changed

+77
-26
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/rtl8195a.sct

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ LR_RAM 0x10006000 0x6FFFF {
4747

4848
LR_DRAM 0x30000000 0x1FFFFF{
4949
_DRAM_CODE 0x30000000 0x1FFFFF{
50+
*.o(.text*)
5051
}
51-
}
52+
}

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/rlx8195A-symbol-v02-img2.ld

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ SECTIONS
731731
*(.hal.flash.text*)
732732
*(.hal.sdrc.text*)
733733
*(.hal.gpio.text*)
734-
*(.text*)
735734

736735
KEEP(*(.init))
737736
KEEP(*(.fini))
@@ -840,6 +839,15 @@ SECTIONS
840839
*(.stack)
841840
} > BD_RAM
842841

842+
.sdr_all :
843+
{
844+
__sdram_data_start__ = .;
845+
*(.text*)
846+
__sdram_data_end__ = .;
847+
__sdram_bss_start__ = .;
848+
__sdram_bss_end__ = .;
849+
} > SD_RAM
850+
843851
/* Set stack top to end of RAM, and stack limit move down by
844852
* size of stack_dummy section */
845853
__StackTop = ORIGIN(BD_RAM) + LENGTH(BD_RAM);

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ define block .ram_image2.text with fixed order{ section .infra.ram.start*,
142142
section .hal.flash.text*,
143143
section .hal.gpio.text*,
144144
section .text* object main.o,
145-
section .text*,
146145
section .wlan.text,
147146
section .wps.text,
148147
section CODE,
@@ -189,7 +188,9 @@ place at end of BD_RAM_region {
189188
block HEAP,
190189
};
191190

192-
define block SDRAM with fixed order{ section .sdram.text*,
191+
define block SDRAM with fixed order{
192+
section .text*,
193+
section .sdram.text*,
193194
section .sdram.data*,
194195
section .mdns.text*,
195196
section .mdns.data*,

tools/targets/REALTEK_RTL8195AM.py

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
# Constant Variables
2727
RAM2_RSVD = 0x3131373835393138
28+
RAM3_RSVD = 0xFFFFFFFFFFFFFFFF
29+
IMG2_OFFSET = 0x10006000 #default
2830

2931
def write_fixed_width_string(value, width, output):
3032
# cut string to list & reverse
@@ -44,22 +46,39 @@ def write_fixed_width_value(value, width, output):
4446
output.write("".join([chr(long(b, 16)) for b in line]))
4547

4648
def append_image_file(image, output):
47-
input = open(image, "rb")
48-
output.write(input.read())
49+
try:
50+
input = open(image, "rb")
51+
output.write(input.read())
52+
except Exception:
53+
return
4954
input.close()
5055

5156
def prepend(image, image_prepend, toolchain, info):
57+
if info['size'] == 0:
58+
return
5259
output = open(image_prepend, "wb")
5360
write_fixed_width_value(info['size'], 8, output)
5461
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":
58-
input.seek(info['addr'])
59-
output.write(input.read(info['size']))
62+
if info['img'] == 2 :
63+
write_fixed_width_value(RAM2_RSVD, 16, output)
64+
elif info['img'] == 3 :
65+
write_fixed_width_value(RAM3_RSVD, 16, output)
66+
if os.path.isfile(image):
67+
with open(image, "rb") as input:
68+
if toolchain == "IAR":
69+
input.seek(info['addr'])
70+
elif info['img'] == 3: #toolchain is not IAR
71+
input.seek(info['addr']-IMG2_OFFSET)
72+
output.write(input.read(info['size']))
73+
else:
74+
image = os.path.join(image, info['name'])
75+
with open(image, "rb") as input:
76+
output.write(input.read(info['size']))
77+
6078
output.close()
79+
6180

62-
def parse_section(toolchain, elf, section):
81+
def _parse_section(toolchain, elf, section):
6382
info = {'addr':None, 'size':0};
6483
if toolchain not in ["GCC_ARM", "ARM_STD", "ARM", "ARM_MICRO", "IAR"]:
6584
print "[ERROR] unsupported toolchain " + toolchain
@@ -104,38 +123,60 @@ def parse_section(toolchain, elf, section):
104123
print "[ERROR] cannot find the address of section " + section
105124
return info
106125

126+
def parse_section(toolchain, elf, sections, img):
127+
img_info = {'name':"", 'addr':None, 'size':0, 'img':img}
128+
for section in sections:
129+
section_info = _parse_section(toolchain, elf, section)
130+
if img_info['addr'] is None or img_info['addr'] > section_info['addr']:
131+
img_info['addr'] = section_info['addr']
132+
img_info['name'] = section
133+
img_info['size'] = img_info['size'] + section_info['size']
134+
return img_info
135+
107136
# ----------------------------
108137
# main function
109138
# ----------------------------
110139
def rtl8195a_elf2bin(toolchain, image_elf, image_bin):
111140
if toolchain == "GCC_ARM":
112141
img2_sections = [".image2.table", ".text", ".data"]
142+
img3_sections = [".sdr_all"]
113143
elif toolchain in ["ARM_STD", "ARM", "ARM_MICRO"]:
114144
img2_sections = [".image2.table", ".text", ".data"]
145+
img3_sections = ["_DRAM_CODE"]
115146
elif toolchain == "IAR":
116-
# actually it's block
117147
img2_sections = ["IMAGE2"]
148+
img3_sections = ["SDRAM"]
118149
else:
119150
print("[error] unsupported toolchain") + toolchain
120151
return
121-
ram2_info = {'addr':None, 'size':0}
152+
image2_info = {'addr':None, 'size':0, 'img':2}
153+
image3_info = {'addr':None, 'size':0, 'img':3}
122154
image_name = os.path.splitext(image_elf)[0]
123155

124-
ram1_prepend_bin = os.path.join(TOOLS_BOOTLOADERS, "REALTEK_RTL8195AM", "ram_1_prepend.bin")
125-
ram2_prepend_bin = image_name + '-ram_2_prepend.bin'
156+
img1_prepend_bin = os.path.join(TOOLS_BOOTLOADERS, "REALTEK_RTL8195AM", "ram_1_prepend.bin")
157+
img2_prepend_bin = image_name + '-ram_2_prepend.bin'
158+
img3_prepend_bin = image_name + '-ram_3_prepend.bin'
159+
160+
old_bin = image_name + '.bin'
161+
162+
img_info = parse_section(toolchain, image_elf, img2_sections, 2)
163+
prepend(old_bin, img2_prepend_bin, toolchain, img_info)
164+
img_info = parse_section(toolchain, image_elf, img3_sections, 3)
165+
prepend(old_bin, img3_prepend_bin, toolchain, img_info)
126166

127-
old_bin = image_name + '.bin'
128-
for section in img2_sections:
129-
section_info = parse_section(toolchain, image_elf, section)
130-
if ram2_info['addr'] is None or ram2_info['addr'] > section_info['addr']:
131-
ram2_info['addr'] = section_info['addr']
132-
ram2_info['size'] = ram2_info['size'] + section_info['size']
133-
134-
prepend(old_bin, ram2_prepend_bin, toolchain, ram2_info)
167+
#delete original binary
168+
if os.path.isfile(image_bin):
169+
os.remove(image_bin)
170+
else:
171+
for i in os.listdir(image_bin):
172+
os.remove(os.path.join(image_bin, i))
173+
os.removedirs(image_bin)
174+
135175
# write output file
136176
output = open(image_bin, "wb")
137-
append_image_file(ram1_prepend_bin, output)
138-
append_image_file(ram2_prepend_bin, output)
177+
append_image_file(img1_prepend_bin, output)
178+
append_image_file(img2_prepend_bin, output)
179+
append_image_file(img3_prepend_bin, output)
139180
output.close()
140181
# post built done
141182

0 commit comments

Comments
 (0)