scripts: Updated nrf51 id script for py3 and to parse newer oocd header.
This commit is contained in:
parent
728e955193
commit
fcb2a609fc
|
@ -5,56 +5,52 @@ pasting into blackmagic's nrf51.c
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess,re
|
import subprocess
|
||||||
|
import re
|
||||||
|
import io
|
||||||
|
|
||||||
cmd = 'git archive --remote=git://git.code.sf.net/p/openocd/code HEAD src/flash/nor/nrf51.c | tar -xO'
|
cmd = 'git archive --remote=git://git.code.sf.net/p/openocd/code HEAD src/flash/nor/nrf5.c | tar -xO'
|
||||||
|
|
||||||
class Spec():
|
class Spec():
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "0x%04X: /* %s %s %s */"%(self.hwid,self.comment, self.variant,self.build_code)
|
return "0x%04X: /* %s %s %s */"%(self.hwid,self.comment, self.variant,self.build_code)
|
||||||
|
|
||||||
fd = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout
|
proc = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
||||||
|
|
||||||
specdict={}
|
specdict = {}
|
||||||
specs=[]
|
specs = []
|
||||||
spec=Spec()
|
spec = Spec()
|
||||||
for line in fd.read().split('\n'):
|
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
|
||||||
m=re.search('/\*(.*)\*/',line)
|
m = re.search('/\*(.*)\*/',line)
|
||||||
if m:
|
if m:
|
||||||
lastcomment=m.group(1)
|
lastcomment=m.group(1)
|
||||||
|
|
||||||
m=re.search('.hwid.*=\s*(0x[0-9A-F]*),',line)
|
m = re.search('NRF51_DEVICE_DEF\((0x[0-9A-F]*),\s*"(.*)",\s*"(.*)",\s*"(.*)",\s*([0-9]*)\s*\),', line)
|
||||||
if m:
|
if m:
|
||||||
spec.hwid=int(m.group(1),base=0)
|
spec.hwid = int(m.group(1), base=0)
|
||||||
m=re.search('.variant.*=\s*"(.*)",',line)
|
spec.variant = m.group(3)
|
||||||
if m:
|
spec.build_code = m.group(4)
|
||||||
spec.variant=m.group(1)
|
spec.flash_size_kb = int(m.group(5), base=0)
|
||||||
m=re.search('.build_code.*=\s*"(.*)",',line)
|
ram, flash = {'AA':(16,256),
|
||||||
if m:
|
'AB':(16,128),
|
||||||
spec.build_code=m.group(1)
|
'AC':(32,256)}[spec.variant[-2:]]
|
||||||
m=re.search('.flash_size_kb.*=\s*([0-9]*),',line)
|
assert flash == spec.flash_size_kb
|
||||||
if m:
|
|
||||||
spec.flash_size_kb=int(m.group(1),base=0)
|
|
||||||
ram,flash = {'AA':(16,256),
|
|
||||||
'AB':(16,128),
|
|
||||||
'AC':(32,256)}[spec.variant[-2:]]
|
|
||||||
assert flash==spec.flash_size_kb
|
|
||||||
spec.ram_size_kb = ram
|
spec.ram_size_kb = ram
|
||||||
nicecomment =lastcomment.strip().replace('IC ','').replace('Devices ','').replace('.','')
|
nicecomment = lastcomment.strip().replace('IC ','').replace('Devices ','').replace('.','')
|
||||||
spec.comment=nicecomment
|
spec.comment = nicecomment
|
||||||
|
|
||||||
specdict.setdefault((ram,flash),[]).append(spec)
|
specdict.setdefault((ram,flash),[]).append(spec)
|
||||||
specs.append(spec)
|
specs.append(spec)
|
||||||
spec=Spec()
|
spec=Spec()
|
||||||
|
|
||||||
for (ram,flash),specs in specdict.iteritems():
|
for (ram,flash),specs in specdict.items():
|
||||||
specs.sort(key=lambda x:x.hwid)
|
specs.sort(key=lambda x:x.hwid)
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
print "\tcase",spec
|
print("\tcase",spec)
|
||||||
print '\t\tt->driver = "Nordic nRF51";'
|
print('\t\tt->driver = "Nordic nRF51";')
|
||||||
print '\t\ttarget_add_ram(t, 0x20000000, 0x%X);'%(1024*ram)
|
print('\t\ttarget_add_ram(t, 0x20000000, 0x%X);'%(1024*ram))
|
||||||
print '\t\tnrf51_add_flash(t, 0x00000000, 0x%X, NRF51_PAGE_SIZE);'%(1024*flash)
|
print('\t\tnrf51_add_flash(t, 0x00000000, 0x%X, NRF51_PAGE_SIZE);'%(1024*flash))
|
||||||
print '\t\tnrf51_add_flash(t, NRF51_UICR, 0x100, 0x100);'
|
print('\t\tnrf51_add_flash(t, NRF51_UICR, 0x100, 0x100);')
|
||||||
print '\t\ttarget_add_commands(t, nrf51_cmd_list, "nRF51");'
|
print('\t\ttarget_add_commands(t, nrf51_cmd_list, "nRF51");')
|
||||||
print '\t\treturn true;'
|
print('\t\treturn true;')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue