]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/ConvertFceToStructurePcd.py
BaseTools Script: Add the script to generate Structure PCD setting
[mirror_edk2.git] / BaseTools / Scripts / ConvertFceToStructurePcd.py
1 #!/usr/bin/python
2 ## @file
3 # Firmware Configuration Editor (FCE) from https://firmware.intel.com/develop
4 # can parse BIOS image and generate Firmware Configuration file.
5 # This script bases on Firmware Configuration file, and generate the structure
6 # PCD setting in DEC/DSC/INF files.
7 #
8 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
9 # This program and the accompanying materials
10 # are licensed and made available under the terms and conditions of the BSD License
11 # which accompanies this distribution. The full text of the license may be found at
12 # http://opensource.org/licenses/bsd-license.php
13 #
14 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #
17
18 '''
19 ConvertFceToStructurePcd
20 '''
21
22 import re
23 import os
24 import datetime
25 import argparse
26
27 #
28 # Globals for help information
29 #
30 __prog__ = 'ConvertFceToStructurePcd'
31 __version__ = '%s Version %s' % (__prog__, '0.1 ')
32 __copyright__ = 'Copyright (c) 2018, Intel Corporation. All rights reserved.'
33 __description__ = 'Generate Structure PCD in DEC/DSC/INF based on Firmware Configuration.\n'
34
35
36 dscstatement='''[Defines]
37 VPD_TOOL_GUID = 8C3D856A-9BE6-468E-850A-24F7A8D38E08
38
39 [SkuIds]
40 0|DEFAULT # The entry: 0|DEFAULT is reserved and always required.
41
42 [DefaultStores]
43 0|STANDARD # UEFI Standard default 0|STANDARD is reserved.
44 1|MANUFACTURING # UEFI Manufacturing default 1|MANUFACTURING is reserved.
45
46 [PcdsDynamicExVpd.common.DEFAULT]
47 gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer|*
48 '''
49
50 decstatement = '''[Guids]
51 gStructPcdTokenSpaceGuid = {0x3f1406f4, 0x2b, 0x487a, {0x8b, 0x69, 0x74, 0x29, 0x1b, 0x36, 0x16, 0xf4}}
52
53 [PcdsFixedAtBuild,PcdsPatchableInModule,PcdsDynamic,PcdsDynamicEx]
54 '''
55
56 infstatement = '''[Pcd]
57 '''
58
59 SECTION='PcdsDynamicHii'
60 PCD_NAME='gStructPcdTokenSpaceGuid.Pcd'
61
62 WARNING=[]
63 ERRORMSG=[]
64
65 class parser_lst(object):
66
67 def __init__(self,filelist):
68 self._ignore=['BOOLEAN', 'UINT8', 'UINT16', 'UINT32', 'UINT64']
69 self.file=filelist
70 self.text=self.megre_lst()[0]
71 self.content=self.megre_lst()[1]
72
73 def megre_lst(self):
74 alltext=''
75 content={}
76 for file in self.file:
77 with open(file,'r') as f:
78 read =f.read()
79 alltext += read
80 content[file]=read
81 return alltext,content
82
83 def struct_lst(self):#{struct:lst file}
84 structs_file={}
85 name_format = re.compile(r'(?<!typedef)\s+struct (\w+) {.*?;', re.S)
86 for i in list(self.content.keys()):
87 structs= name_format.findall(self.content[i])
88 if structs:
89 for j in structs:
90 if j not in self._ignore:
91 structs_file[j]=i
92 else:
93 print("%s"%structs)
94 return structs_file
95
96 def struct(self):#struct:{offset:name}
97 unit_num = re.compile('(\d+)')
98 offset1_re = re.compile('(\d+)\[')
99 pcdname_num_re = re.compile('\w+\[(\S+)\]')
100 pcdname_re = re.compile('\](.*)\<')
101 pcdname2_re = re.compile('(\w+)\[')
102 uint_re = re.compile('\<(\S+)\>')
103 name_format = re.compile(r'(?<!typedef)\s+struct (\w+) {.*?;', re.S)
104 name=name_format.findall(self.text)
105 info={}
106 unparse=[]
107 if name:
108 tmp_n = [n for n in name if n not in self._ignore]
109 name = list(set(tmp_n))
110 name.sort(key = tmp_n.index)
111 name.reverse()
112 #name=list(set(name).difference(set(self._ignore)))
113 for struct in name:
114 s_re = re.compile(r'struct %s :(.*?)};'% struct, re.S)
115 content = s_re.search(self.text)
116 if content:
117 tmp_dict = {}
118 text = content.group().split('+')
119 for line in text[1:]:
120 offset = offset1_re.findall(line)
121 t_name = pcdname_re.findall(line)
122 uint = uint_re.findall(line)
123 if offset and uint:
124 offset = offset[0]
125 uint = uint[0]
126 if t_name:
127 t_name = t_name[0].strip()
128 if (' ' in t_name) or ("=" in t_name) or (";" in t_name) or("\\" in name) or (t_name ==''):
129 WARNING.append("Warning:Invalid Pcd name '%s' for Offset %s in struct %s" % (t_name,offset, struct))
130 else:
131 if '[' in t_name:
132 if uint in ['UINT8', 'UINT16', 'UINT32', 'UINT64']:
133 offset = int(offset, 10)
134 tmp_name = pcdname2_re.findall(t_name)[0] + '[0]'
135 tmp_dict[offset] = tmp_name
136 pcdname_num = int(pcdname_num_re.findall(t_name)[0],10)
137 uint = int(unit_num.findall(uint)[0],10)
138 bit = uint / 8
139 for i in range(1, pcdname_num):
140 offset += bit
141 tmp_name = pcdname2_re.findall(t_name)[0] + '[%s]' % i
142 tmp_dict[offset] = tmp_name
143 else:
144 tmp_name = pcdname2_re.findall(t_name)[0]
145 pcdname_num = pcdname_num_re.findall(t_name)[0]
146 line = [offset,tmp_name,pcdname_num,uint]
147 line.append(struct)
148 unparse.append(line)
149 else:
150 if uint not in ['UINT8', 'UINT16', 'UINT32', 'UINT64']:
151 line = [offset, t_name, 0, uint]
152 line.append(struct)
153 unparse.append(line)
154 else:
155 offset = int(offset,10)
156 tmp_dict[offset] = t_name
157 info[struct] = tmp_dict
158 if len(unparse) != 0:
159 for u in unparse:
160 if u[3] in list(info.keys()):
161 unpar = self.nameISstruct(u,info[u[3]])
162 info[u[4]]= dict(list(info[u[4]].items())+list(unpar[u[4]].items()))
163 else:
164 print("ERROR: No struct name found in %s" % self.file)
165 ERRORMSG.append("ERROR: No struct name found in %s" % self.file)
166 return info
167
168
169 def nameISstruct(self,line,key_dict):
170 dict={}
171 dict2={}
172 s_re = re.compile(r'struct %s :(.*?)};' % line[3], re.S)
173 size_re = re.compile(r'mTotalSize \[(\S+)\]')
174 content = s_re.search(self.text)
175 if content:
176 s_size = size_re.findall(content.group())[0]
177 else:
178 s_size = '0'
179 print("ERROR: Struct %s not define mTotalSize in lst file" %line[3])
180 ERRORMSG.append("ERROR: Struct %s not define mTotalSize in lst file" %line[3])
181 size = int(line[0], 10)
182 if line[2] != 0:
183 for j in range(0, int(line[2], 10)):
184 for k in list(key_dict.keys()):
185 offset = size + k
186 name ='%s.%s' %((line[1]+'[%s]'%j),key_dict[k])
187 dict[offset] = name
188 size = int(s_size,16)+size
189 elif line[2] == 0:
190 for k in list(key_dict.keys()):
191 offset = size + k
192 name = '%s.%s' % (line[1], key_dict[k])
193 dict[offset] = name
194 dict2[line[4]] = dict
195 return dict2
196
197 def efivarstore_parser(self):
198 efivarstore_format = re.compile(r'efivarstore.*?;', re.S)
199 struct_re = re.compile(r'efivarstore(.*?),',re.S)
200 name_re = re.compile(r'name=(\w+)')
201 efivarstore_dict={}
202 efitxt = efivarstore_format.findall(self.text)
203 for i in efitxt:
204 struct = struct_re.findall(i.replace(' ',''))
205 name = name_re.findall(i.replace(' ',''))
206 if struct and name:
207 efivarstore_dict[name[0]]=struct[0]
208 else:
209 print("ERROR: Can't find Struct or name in lst file, please check have this format:efivarstore XXXX, name=xxxx")
210 ERRORMSG.append("ERROR: Can't find Struct or name in lst file, please check have this format:efivarstore XXXX, name=xxxx")
211 return efivarstore_dict
212
213 class Config(object):
214
215 def __init__(self,Config):
216 self.config=Config
217
218 #Parser .config file,return list[offset,name,guid,value,help]
219 def config_parser(self):
220 ids_re =re.compile('_ID:(\d+)',re.S)
221 id_re= re.compile('\s+')
222 info = []
223 info_dict={}
224 with open(self.config, 'r') as text:
225 read = text.read()
226 if 'DEFAULT_ID:' in read:
227 all_txt = read.split('FCEKEY DEFAULT')
228 for i in all_txt[1:]:
229 part = [] #save all infomation for DEFAULT_ID
230 str_id=''
231 ids = ids_re.findall(i.replace(' ',''))
232 for m in ids:
233 str_id +=m+'_'
234 str_id=str_id[:-1]
235 part.append(ids)
236 section = i.split('\nQ') #split with '\nQ ' to get every block
237 part +=self.section_parser(section)
238 info_dict[str_id] = self.section_parser(section)
239 info.append(part)
240 else:
241 part = []
242 id=('0','0')
243 str_id='0_0'
244 part.append(id)
245 section = read.split('\nQ')
246 part +=self.section_parser(section)
247 info_dict[str_id] = self.section_parser(section)
248 info.append(part)
249 return info_dict
250
251 def eval_id(self,id):
252 id = id.split("_")
253 default_id=id[0:len(id)//2]
254 platform_id=id[len(id)//2:]
255 text=''
256 for i in range(len(default_id)):
257 text +="%s.common.%s.%s,"%(SECTION,self.id_name(platform_id[i],'PLATFORM'),self.id_name(default_id[i],'DEFAULT'))
258 return '\n[%s]\n'%text[:-1]
259
260 def id_name(self,ID, flag):
261 platform_dict = {'0': 'DEFAULT'}
262 default_dict = {'0': 'STANDARD', '1': 'MANUFACTURING'}
263 if flag == "PLATFORM":
264 try:
265 value = platform_dict[ID]
266 except KeyError:
267 value = 'SKUID%s' % ID
268 elif flag == 'DEFAULT':
269 try:
270 value = default_dict[ID]
271 except KeyError:
272 value = 'DEFAULTID%s' % ID
273 else:
274 value = None
275 return value
276
277 def section_parser(self,section):
278 offset_re = re.compile(r'offset=(\w+)')
279 name_re = re.compile(r'name=(\S+)')
280 guid_re = re.compile(r'guid=(\S+)')
281 # help_re = re.compile(r'help = (.*)')
282 attribute_re=re.compile(r'attribute=(\w+)')
283 value_re = re.compile(r'(//.*)')
284 part = []
285 for x in section[1:]:
286 line=x.split('\n')[0]
287 line=value_re.sub('',line) #delete \\... in "Q...." line
288 list1=line.split(' ')
289 value=self.value_parser(list1)
290 offset = offset_re.findall(x.replace(' ',''))
291 name = name_re.findall(x.replace(' ',''))
292 guid = guid_re.findall(x.replace(' ',''))
293 attribute =attribute_re.findall(x.replace(' ',''))
294 if offset and name and guid and value and attribute:
295 if attribute[0] in ['0x3','0x7']:
296 offset = int(offset[0], 16)
297 #help = help_re.findall(x)
298 text = offset, name[0], guid[0], value, attribute[0]
299 part.append(text)
300 return(part)
301
302 def value_parser(self, list1):
303 list1 = [t for t in list1 if t != ''] # remove '' form list
304 first_num = int(list1[0], 16)
305 if list1[first_num + 1] == 'STRING': # parser STRING
306 value = 'L%s' % list1[-1]
307 elif list1[first_num + 1] == 'ORDERED_LIST': # parser ORDERED_LIST
308 value_total = int(list1[first_num + 2])
309 list2 = list1[-value_total:]
310 tmp = []
311 line = ''
312 for i in list2:
313 if len(i) % 2 == 0 and len(i) != 2:
314 for m in range(0, len(i) // 2):
315 tmp.append('0x%02x' % (int('0x%s' % i, 16) >> m * 8 & 0xff))
316 else:
317 tmp.append('0x%s' % i)
318 for i in tmp:
319 line += '%s,' % i
320 value = '{%s}' % line[:-1]
321 else:
322 value = "0x%01x" % int(list1[-1], 16)
323 return value
324
325
326 #parser Guid file, get guid name form guid value
327 class GUID(object):
328
329 def __init__(self,path):
330 self.path = path
331 self.guidfile = self.gfile()
332 self.guiddict = self.guid_dict()
333
334 def gfile(self):
335 for root, dir, file in os.walk(self.path, topdown=True, followlinks=False):
336 if 'FV' in dir:
337 gfile = os.path.join(root,'Fv','Guid.xref')
338 if os.path.isfile(gfile):
339 return gfile
340 else:
341 print("ERROR: Guid.xref file not found")
342 ERRORMSG.append("ERROR: Guid.xref file not found")
343 exit()
344
345 def guid_dict(self):
346 guiddict={}
347 with open(self.guidfile,'r') as file:
348 lines = file.readlines()
349 guidinfo=lines
350 for line in guidinfo:
351 list=line.strip().split(' ')
352 if list:
353 if len(list)>1:
354 guiddict[list[0].upper()]=list[1]
355 elif list[0] != ''and len(list)==1:
356 print("Error: line %s can't be parser in %s"%(line.strip(),self.guidfile))
357 ERRORMSG.append("Error: line %s can't be parser in %s"%(line.strip(),self.guidfile))
358 else:
359 print("ERROR: No data in %s" %self.guidfile)
360 ERRORMSG.append("ERROR: No data in %s" %self.guidfile)
361 return guiddict
362
363 def guid_parser(self,guid):
364 if guid.upper() in self.guiddict:
365 return self.guiddict[guid.upper()]
366 else:
367 print("ERROR: GUID %s not found in file %s"%(guid, self.guidfile))
368 ERRORMSG.append("ERROR: GUID %s not found in file %s"%(guid, self.guidfile))
369 return guid
370
371 class PATH(object):
372
373 def __init__(self,path):
374 self.path=path
375 self.rootdir=self.get_root_dir()
376 self.usefuldir=[]
377 self.lstinf = {}
378 for path in self.rootdir:
379 for o_root, o_dir, o_file in os.walk(os.path.join(path, "OUTPUT"), topdown=True, followlinks=False):
380 for INF in o_file:
381 if os.path.splitext(INF)[1] == '.inf':
382 for l_root, l_dir, l_file in os.walk(os.path.join(path, "DEBUG"), topdown=True,
383 followlinks=False):
384 for LST in l_file:
385 if os.path.splitext(LST)[1] == '.lst':
386 self.lstinf[os.path.join(l_root, LST)] = os.path.join(o_root, INF)
387 self.usefuldir.append(path)
388
389 def get_root_dir(self):
390 rootdir=[]
391 for root,dir,file in os.walk(self.path,topdown=True,followlinks=False):
392 if "OUTPUT" in root:
393 updir=root.split("OUTPUT",1)[0]
394 rootdir.append(updir)
395 rootdir=list(set(rootdir))
396 return rootdir
397
398 def lst_inf(self):
399 return self.lstinf
400
401 def package(self):
402 package={}
403 package_re=re.compile(r'Packages\.\w+]\n(.*)',re.S)
404 for i in list(self.lstinf.values()):
405 with open(i,'r') as inf:
406 read=inf.read()
407 section=read.split('[')
408 for j in section:
409 p=package_re.findall(j)
410 if p:
411 package[i]=p[0].rstrip()
412 return package
413
414 def header(self,struct):
415 header={}
416 head_re = re.compile(r'} %s;[\s\S\n]+h{1}"'%struct,re.M|re.S)
417 head_re2 = re.compile(r'#line[\s\d]+"(\S+h)"')
418 for i in list(self.lstinf.keys()):
419 with open(i,'r') as lst:
420 read = lst.read()
421 h = head_re.findall(read)
422 if h:
423 head=head_re2.findall(h[0])
424 if head:
425 format = head[0].replace('\\\\','/').replace('\\','/')
426 name =format.split('/')[-1]
427 head = self.makefile(name).replace('\\','/')
428 header[struct] = head
429 return header
430
431 def makefile(self,filename):
432 re_format = re.compile(r'DEBUG_DIR.*(?:\S+Pkg)\\(.*\\%s)'%filename)
433 for i in self.usefuldir:
434 with open(os.path.join(i,'Makefile'),'r') as make:
435 read = make.read()
436 dir = re_format.findall(read)
437 if dir:
438 return dir[0]
439
440 class mainprocess(object):
441
442 def __init__(self,InputPath,Config,OutputPath):
443 self.init = 0xFCD00000
444 self.inputpath = os.path.abspath(InputPath)
445 self.outputpath = os.path.abspath(OutputPath)
446 self.LST = PATH(self.inputpath)
447 self.lst_dict = self.LST.lst_inf()
448 self.Config = Config
449 self.attribute_dict = {'0x3': 'NV, BS', '0x7': 'NV, BS, RT'}
450 self.guid = GUID(self.inputpath)
451 self.header={}
452
453 def main(self):
454 conf=Config(self.Config)
455 config_dict=conf.config_parser() #get {'0_0':[offset,name,guid,value,attribute]...,'1_0':....}
456 lst=parser_lst(list(self.lst_dict.keys()))
457 efi_dict=lst.efivarstore_parser() #get {name:struct} form lst file
458 keys=sorted(config_dict.keys())
459 all_struct=lst.struct()
460 stru_lst=lst.struct_lst()
461 title_list=[]
462 info_list=[]
463 header_list=[]
464 inf_list =[]
465 for i in stru_lst:
466 tmp = self.LST.header(i)
467 self.header.update(tmp)
468 for id_key in keys:
469 tmp_id=[id_key] #['0_0',[(struct,[name...]),(struct,[name...])]]
470 tmp_info={} #{name:struct}
471 for section in config_dict[id_key]:
472 c_offset,c_name,c_guid,c_value,c_attribute = section
473 if c_name in efi_dict:
474 struct = efi_dict[c_name]
475 title='%s%s|L"%s"|%s|0x00||%s\n'%(PCD_NAME,c_name,c_name,self.guid.guid_parser(c_guid),self.attribute_dict[c_attribute])
476 if struct in all_struct:
477 lstfile = stru_lst[struct]
478 struct_dict=all_struct[struct]
479 try:
480 title2 = '%s%s|{0}|%s|0xFCD00000{\n <HeaderFiles>\n %s\n <Packages>\n%s\n}\n' % (PCD_NAME, c_name, struct, self.header[struct], self.LST.package()[self.lst_dict[lstfile]])
481 except KeyError:
482 WARNING.append("Warning: No <HeaderFiles> for struct %s"%struct)
483 title2 = '%s%s|{0}|%s|0xFCD00000{\n <HeaderFiles>\n %s\n <Packages>\n%s\n}\n' % (PCD_NAME, c_name, struct, '', self.LST.package()[self.lst_dict[lstfile]])
484 header_list.append(title2)
485 else:
486 struct_dict ={}
487 print("ERROR: Struct %s can't found in lst file" %struct)
488 ERRORMSG.append("ERROR: Struct %s can't found in lst file" %struct)
489 if c_offset in struct_dict:
490 offset_name=struct_dict[c_offset]
491 info = "%s%s.%s|%s\n"%(PCD_NAME,c_name,offset_name,c_value)
492 inf = "%s%s\n"%(PCD_NAME,c_name)
493 inf_list.append(inf)
494 tmp_info[info]=title
495 else:
496 print("ERROR: Can't find offset %s with struct name %s"%(c_offset,struct))
497 ERRORMSG.append("ERROR: Can't find offset %s with name %s"%(c_offset,struct))
498 else:
499 print("ERROR: Can't find name %s in lst file"%(c_name))
500 ERRORMSG.append("ERROR: Can't find name %s in lst file"%(c_name))
501 tmp_id.append(list(self.reverse_dict(tmp_info).items()))
502 id,tmp_title_list,tmp_info_list = self.read_list(tmp_id)
503 title_list +=tmp_title_list
504 info_list.append(tmp_info_list)
505 inf_list = self.del_repeat(inf_list)
506 header_list = self.plus(self.del_repeat(header_list))
507 title_all=list(set(title_list))
508 info_list = self.del_repeat(info_list)
509 for i in range(len(info_list)-1,-1,-1):
510 if len(info_list[i]) == 0:
511 info_list.remove(info_list[i])
512 return keys,title_all,info_list,header_list,inf_list
513
514
515 def write_all(self):
516 title_flag=1
517 info_flag=1
518 if not os.path.isdir(self.outputpath):
519 os.makedirs(self.outputpath)
520 decwrite = write2file(os.path.join(self.outputpath,'StructurePcd.dec'))
521 dscwrite = write2file(os.path.join(self.outputpath,'StructurePcd.dsc'))
522 infwrite = write2file(os.path.join(self.outputpath, 'StructurePcd.inf'))
523 conf = Config(self.Config)
524 ids,title,info,header,inf=self.main()
525 decwrite.add2file(decstatement)
526 decwrite.add2file(header)
527 infwrite.add2file(infstatement)
528 infwrite.add2file(inf)
529 dscwrite.add2file(dscstatement)
530 for id in ids:
531 dscwrite.add2file(conf.eval_id(id))
532 if title_flag:
533 dscwrite.add2file(title)
534 title_flag=0
535 if len(info) == 1:
536 dscwrite.add2file(info)
537 elif len(info) == 2:
538 if info_flag:
539 dscwrite.add2file(info[0])
540 info_flag =0
541 else:
542 dscwrite.add2file(info[1])
543
544 def del_repeat(self,List):
545 if len(List) == 1 or len(List) == 0:
546 return List
547 else:
548 if type(List[0]) != type('xxx'):
549 alist=[]
550 for i in range(len(List)):
551 if i == 0:
552 alist.append(List[0])
553 else:
554 plist = []
555 for j in range(i):
556 plist += List[j]
557 alist.append(self.__del(list(set(plist)), List[i]))
558 return alist
559 else:
560 return list(set(List))
561
562
563 def __del(self,list1,list2):
564 return list(set(list2).difference(set(list1)))
565
566 def reverse_dict(self,dict):
567 data={}
568 for i in list(dict.items()):
569 if i[1] not in list(data.keys()):
570 data[i[1]]=[i[0]]
571 else:
572 data[i[1]].append(i[0])
573 return data
574
575 def read_list(self,list):
576 title_list=[]
577 info_list=[]
578 for i in list[1]:
579 title_list.append(i[0])
580 for j in i[1]:
581 info_list.append(j)
582 return list[0],title_list,info_list
583
584 def plus(self,list):
585 nums=[]
586 for i in list:
587 if type(i) != type([0]):
588 self.init += 1
589 num = "0x%01x" % self.init
590 j=i.replace('0xFCD00000',num.upper())
591 nums.append(j)
592 return nums
593
594 class write2file(object):
595
596 def __init__(self,Output):
597 self.output=Output
598 self.text=''
599 if os.path.exists(self.output):
600 os.remove(self.output)
601
602 def add2file(self,content):
603 self.text = ''
604 with open(self.output,'a+') as file:
605 file.write(self.__gen(content))
606
607 def __gen(self,content):
608 if type(content) == type(''):
609 return content
610 elif type(content) == type([0,0])or type(content) == type((0,0)):
611 return self.__readlist(content)
612 elif type(content) == type({0:0}):
613 return self.__readdict(content)
614
615 def __readlist(self,list):
616 for i in list:
617 if type(i) == type([0,0])or type(i) == type((0,0)):
618 self.__readlist(i)
619 elif type(i) == type('') :
620 self.text +=i
621 return self.text
622
623 def __readdict(self,dict):
624 content=list(dict.items())
625 return self.__readlist(content)
626
627 def stamp():
628 return datetime.datetime.now()
629
630 def dtime(start,end,id=None):
631 if id:
632 pass
633 print("%s time:%s" % (id,str(end - start)))
634 else:
635 print("Total time:%s" %str(end-start)[:-7])
636
637
638 def main():
639 start = stamp()
640 parser = argparse.ArgumentParser(prog = __prog__,
641 description = __description__ + __copyright__,
642 conflict_handler = 'resolve')
643 parser.add_argument('-v', '--version', action = 'version',version = __version__, help="show program's version number and exit")
644 parser.add_argument('-p', '--path', metavar='PATH', dest='path', help="platform build output directory")
645 parser.add_argument('-c', '--config',metavar='FILENAME', dest='config', help="firmware configuration file")
646 parser.add_argument('-o', '--outputdir', metavar='PATH', dest='output', help="output directoy")
647 options = parser.parse_args()
648 if options.config:
649 if options.path:
650 if options.output:
651 run = mainprocess(options.path, options.config, options.output)
652 print("Running...")
653 run.write_all()
654 if WARNING:
655 warning = list(set(WARNING))
656 for j in warning:
657 print(j)
658 if ERRORMSG:
659 ERROR = list(set(ERRORMSG))
660 with open("ERROR.log", 'w+') as error:
661 for i in ERROR:
662 error.write(i + '\n')
663 print("Some error find, error log in ERROR.log")
664 print('Finished, Output files in directory %s'%os.path.abspath(options.output))
665 else:
666 print('Error command, no output path, use -h for help')
667 else:
668 print('Error command, no build path input, use -h for help')
669 else:
670 print('Error command, no output file, use -h for help')
671 end = stamp()
672 dtime(start, end)
673
674 if __name__ == '__main__':
675 main()