29 def edit_file(full_file, new_kernel, udp, tcp, mtu, port, ddr):
30 f1 = open(full_file,
'r')
31 f2 = open(full_file+
"_new",
'w')
34 uaf_start_detected = taf_start_detected = 0
35 ddr_component_start_detected = ddr_component_end_detected = 0
36 ddr_uaf_start_detected = ddr_uaf_end_detected = 0
37 ddr_taf_start_detected = ddr_taf_end_detected = 0
38 ddr_Mp2_dummy_start_detected = ddr_Mp2_dummy_end_detected = 0
42 if search(
"vhdl", full_file):
43 search_str =
" component "
44 if search(search_str, s):
45 s2 =
" component "+new_kernel+
"Application is\n"
46 replaced = replaced + 1
48 search_str =
" end component "
49 if search(search_str, s):
50 s2 =
" end component "+new_kernel+
"Application;\n"
51 replaced = replaced + 1
57 search_str =
"SHELL / Mem / Mp0 Interface / Start Component"
58 if search(search_str, s):
60 ddr_component_start_detected = 1
63 search_str =
"SHELL / Mem / Mp1 Interface / End Component"
64 if search(search_str, s):
66 ddr_component_end_detected = 1
69 if (ddr_component_start_detected):
70 excluding_pattern =
"-- auto excluding component Mp0-Mp1 "
71 if (search(excluding_pattern, s2)):
73 s2 = s2.replace(
str(excluding_pattern),
str(
''))
74 replaced = replaced + 1
77 s2 = excluding_pattern + s2
78 replaced = replaced + 1
79 if (ddr_component_end_detected):
80 ddr_component_start_detected = ddr_component_end_detected = 0;
84 search_str =
"SHELL / Mem / Mp0 Interface / Start in UAF"
85 if search(search_str, s):
87 ddr_uaf_start_detected = 1
90 search_str =
"SHELL / Mem / Mp1 Interface / End in UAF"
91 if search(search_str, s):
93 ddr_uaf_end_detected = 1
96 if (ddr_uaf_start_detected):
97 excluding_pattern =
"-- auto excluding Mp0-Mp1 in UAF "
98 if (search(excluding_pattern, s2)):
100 s2 = s2.replace(
str(excluding_pattern),
str(
''))
101 replaced = replaced + 1
104 s2 = excluding_pattern + s2
105 replaced = replaced + 1
106 if (ddr_uaf_end_detected):
107 ddr_uaf_start_detected = ddr_uaf_end_detected = 0;
111 search_str =
"SHELL / Mem / Mp0 Interface / Start in TAF"
112 if search(search_str, s):
114 ddr_taf_start_detected = 1
117 search_str =
"SHELL / Mem / Mp1 Interface / End in TAF"
118 if search(search_str, s):
120 ddr_taf_end_detected = 1
123 if (ddr_taf_start_detected):
124 excluding_pattern =
"-- auto excluding Mp0-Mp1 in TAF "
125 if (search(excluding_pattern, s2)):
127 s2 = s2.replace(
str(excluding_pattern),
str(
''))
128 replaced = replaced + 1
131 s2 = excluding_pattern + s2
132 replaced = replaced + 1
133 if (ddr_taf_end_detected):
134 ddr_taf_start_detected = ddr_taf_end_detected = 0;
138 search_str =
"2nd Memory Port dummy connections Start"
139 if search(search_str, s):
141 ddr_Mp2_dummy_start_detected = 1
144 search_str =
"2nd Memory Port dummy connections End"
145 if search(search_str, s):
147 ddr_Mp2_dummy_end_detected = 1
150 if (ddr_Mp2_dummy_start_detected):
151 excluding_pattern =
"-- auto excluding Mp2 open connections "
152 if (search(excluding_pattern, s2)):
154 s2 = s2.replace(
str(excluding_pattern),
str(
''))
155 replaced = replaced + 1
158 s2 = excluding_pattern + s2
159 replaced = replaced + 1
160 if (ddr_Mp2_dummy_end_detected):
161 ddr_Mp2_dummy_start_detected = ddr_Mp2_dummy_end_detected = 0;
164 search_str =
" UAF: "
165 if search(search_str, s):
166 s2 =
" UAF: "+new_kernel+
"Application\n"
167 uaf_start_detected = 1
168 replaced = replaced + 1
170 search_str =
" TAF: "
171 if search(search_str, s):
172 s2 =
" TAF: "+new_kernel+
"Application\n"
173 taf_start_detected = 1
174 replaced = replaced + 1
177 if (uaf_start_detected):
178 excluding_pattern =
"-- auto excluding UAF "
179 if (search(excluding_pattern, s2)):
181 s2 = s2.replace(
str(excluding_pattern),
str(
''))
182 replaced = replaced + 1
185 s2 = excluding_pattern + s2
186 replaced = replaced + 1
187 if (search(
" \);", s)):
188 uaf_start_detected = 0;
191 if (taf_start_detected):
192 excluding_pattern =
"-- auto excluding TAF "
193 if (search(excluding_pattern, s2)):
195 s2 = s2.replace(
str(excluding_pattern),
str(
''))
196 replaced = replaced + 1
199 s2 = excluding_pattern + s2
200 replaced = replaced + 1
201 if (search(
" \);", s)):
202 taf_start_detected = 0;
204 new_s = s.replace(
str(s),
str(s2))
207 if search(
"tcl", full_file):
208 search_str =
"# IBM-HSL-IP : "
209 if search(search_str, s):
210 s2 =
"# IBM-HSL-IP : "+new_kernel+
" Application Flash\n"
211 replaced = replaced + 1
213 search_str =
"set ipModName"
214 if search(search_str, s):
215 s2 =
"set ipModName \""+new_kernel+
"Application\"\n"
216 replaced = replaced + 1
218 search_str =
"set ipName"
219 if search(search_str, s):
220 s2 =
"set ipName \""+new_kernel.lower()+
"\"\n"
221 replaced = replaced + 1
223 new_s = s.replace(
str(s),
str(s2))
226 if search(
"Makefile", full_file):
227 search_str =
".PHONY: all clean mem_test_flash "
228 if search(search_str, s):
229 s2 =
".PHONY: all clean mem_test_flash "+new_kernel.lower()+
"\n"
230 replaced = replaced + 1
232 search_str =
"all: mem_test_flash "
233 if search(search_str, s):
234 s2 =
"all: mem_test_flash "+new_kernel.lower()+
"\n"
235 replaced = replaced + 1
237 new_s = s.replace(
str(s),
str(s2))
240 if search(
"config.h", full_file):
241 search_str1 =
"#define NET_TYPE "
242 search_str2 =
"#define PACK_SIZE "
243 if search(search_str1, s):
245 s2 = search_str1 +
"udp //tcp\n"
247 s2 = search_str1 +
"udp\n"
249 s2 = search_str1 +
"tcp\n"
250 replaced = replaced + 1
251 elif search(search_str2, s):
252 s2 = search_str2 + mtu +
"\n"
253 replaced = replaced + 1
254 new_s = s.replace(
str(s),
str(s2))
258 if search(
".hpp", full_file):
259 search_str1 =
"#define DEFAULT_TX_PORT "
260 search_str2 =
"#define DEFAULT_RX_PORT "
261 if search(search_str1, s):
262 s2 = search_str1 + port +
"\n"
263 replaced = replaced + 1
264 elif search(search_str2, s):
265 s2 = search_str2 + port +
"\n"
266 replaced = replaced + 1
267 new_s = s.replace(
str(s),
str(s2))
269 search_str3 =
"#define ENABLE_DDR"
270 if search(search_str3, s):
272 s2 = search_str3 +
"\n"
274 s2 =
"// " + search_str3 +
"\n"
275 replaced = replaced + 1
276 new_s = new_s.replace(
str(s),
str(s2))
280 print(
"INFO: Edits of file " + full_file +
" : "+
str(replaced))
281 print(
"#################")
285 shutil.copyfile(full_file, full_file+
"_backup")
286 shutil.move(full_file+
"_new", full_file)
def edit_file(full_file, new_kernel, udp, tcp, mtu, port, ddr)