rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,99 @@
#! /usr/bin/env python
# Load application to ram helper script
# Note: sys.stdout.flush() and sys.stderr.flush() are required for proper
# console output in eclipse
import os, sys, re, struct, platform, getopt, subprocess
from sys import platform as _platform
def print_usage():
print ""
print "Usage: Merge a bin file into an exist bin file, create one if target is not exist"
print sys.argv[0]
print "Optional Usage:"
print " [<-o> <target binary file>]"
print " The file that will be merged into, create <input binary file>_out if not defined."
print " [<-f> <the offset>]"
print " The input file will be merged into this address. 0x0 if not defined."
print " [-h | --help]"
print " Display usage"
print " [<input binary file>]"
print " The input file need to be merged into the exist file."
sys.stdout.flush()
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'o:f:h')
except getopt.GetoptError as err:
print str(err)
print_usage()
sys.exit(2)
OFFSET = 0
OUTPUT_FILE = 0
if not len(args) == 1:
print_usage()
sys.exit(2)
else:
INPUT_FILE = args[0]
if not os.path.exists(INPUT_FILE):
print "Please input an existed input binary file"
sys.exit(2)
for opt, arg in opts:
if opt == "-o":
OUTPUT_FILE = arg
elif opt == "-f":
OFFSET = int(arg, 16)
elif opt == "-h":
print_usage()
sys.exit()
if OUTPUT_FILE == 0:
OUTPUT_FILE = re.sub(r'.bin$', '.output.bin', INPUT_FILE)
input_file = open(INPUT_FILE, 'rb')
output_file = open(OUTPUT_FILE, 'ab')
input = input_file.read()
gap_szie = OFFSET - os.path.getsize(OUTPUT_FILE)
if gap_szie > 0:
output_file.seek(os.path.getsize(OUTPUT_FILE))
output_file.write('\xFF'*gap_szie)
output_file.write(input)
input_file.close()
output_file.close()
#app = moc_app.read()
# kernel = moc_kernel.read()
# crc = CRC16( bytes(app[8::]) )
# moc_app_output.write( struct.pack('<L', os.path.getsize(MOC_APP_FILE)-8 ) )
# moc_app_output.write( struct.pack('<HH', crc, crc ) )
# moc_app_output.write( bytes(app[8::]) )
# moc_ota_output.write( bytes(kernel) )
# moc_ota_output.seek(MOC_APP_OFFSET)
# # moc_ota_output.write( struct.pack('<L', os.path.getsize(MOC_APP_FILE)-8 ) )
# moc_ota_output.write( struct.pack('<HH', crc, crc ) )
# moc_ota_output.write( bytes(app[8::]) )
# moc_app.close()
# moc_kernel.close()
# moc_app_output.close()
# moc_ota_output.close()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass

104
tools/scripts/map_parse_gcc.py Executable file
View file

@ -0,0 +1,104 @@
#!/usr/bin/python
import sys
import re
def get_mem_info(map_file):
total_ram = 0
total_rom = 0
map_lines = []
with open(map_file, 'r') as f:
s = f.read()
# find the memory configuration
mem_config_list = re.findall('Memory Configuration\r?\n\r?\nName Origin Length Attributes\r?\n([\s\S]+)\r?\nLinker script and memory map', s)
mem_config_text = '' if not mem_config_list else mem_config_list[0]
if not mem_config_text:
print 'Can\'t parse memory configure, memory info get fail!'
return
# find the ROM configuration
rom_config_text = re.findall('\w+\s+(0x\w+)\s+(0x\w+)\s+(?:xr|r)\r?\n',mem_config_text)
# get every ROM configuration's start - end address
rom_config = []
for rom in rom_config_text:
rom_config += [{'start':int(rom[0], 16), 'end':int(rom[0], 16) + int(rom[1], 16)}]
# find the RAM configuration
ram_config_text = re.findall('\w+\s+(0x\w+)\s+(0x\w+)\s+(?:xrw|rw)\r?\n',mem_config_text)
if (len(ram_config_text)+len(rom_config_text)) == 0:
ram_config_text = re.findall('\*default\*\s+(0x\w+)\s+(0x\w+)\r?\n',mem_config_text)
print ('no definite address hint,using default mem configuration')
# get every RAM configuration's start - end address
ram_config = []
for ram in ram_config_text:
ram_config += [{'start':int(ram[0], 16), 'end':int(ram[0], 16) + int(ram[1], 16)}]
# find memory map (without discard and debug sections)
mem_map_list = re.findall('Linker script and memory map([\s\S]+?)OUTPUT\('+map_file.replace('.map','.elf'), s)
mem_map = '' if not mem_map_list else mem_map_list[0]
if not mem_map:
print 'Can\'t parse memory info, memory info get fail!'
return
mem_map = mem_map.replace('\r', '')
modules = []
for l in mem_map.split('\n'):
m = re.search('0x\w+\s+0x\w+\s+.+?([^/\\\]+\.[ao])\((.+\.o)\)', l)
if m == None:
continue
modules.append(m.groups()[0])
modules = list(set(modules))
# find sections address - length in memory map
# modules = list(set(item[0] for item in re.findall('0x\w+\s+0x\w+\s+.+?([^/\\\]+\.[ao])(\(.+\.o\))?\r?\n', mem_map)))
modules.sort(key = lambda x : x.upper())
modules += ['*fill*']
for module in modules:
rom_size = 0
ram_size = 0
module = module.replace('+', '\+')
# get module's sections's address and size
if(module == '*fill*'):
sections = map(lambda arg : {'address':int(arg[0], 16), 'size':int(arg[1], 16)}, re.findall('\*fill\*[ \t]+(0x\w+)[ \t]+(0x\w+)[ \t]+\r?\n', mem_map))
else:
sections = map(lambda arg : {'address':int(arg[0], 16), 'size':int(arg[1], 16)}, re.findall('(0x\w+)[ \t]+(0x\w+)[ \t]+.+[/\\\]'+module+'(\(.+\.o\))?\r?\n', mem_map))
if(not sections):
continue
def ram_size_def(arg):
for ram_info in ram_config:
if(ram_info['start'] <= arg['address'] < ram_info['end']):
return arg['size']
return 0
def rom_size_def(arg):
for rom_info in rom_config:
if(rom_info['start'] <= arg['address'] < rom_info['end']):
return arg['size']
return 0
ram_size = reduce(lambda x,y:x+y, map(ram_size_def, sections))
rom_size = reduce(lambda x,y:x+y, map(rom_size_def, sections))
total_ram += ram_size
total_rom += rom_size
map_lines.append('| %-40s | %-8d | %-8d |'%(re.sub('\.[ao]','',module)[:40],rom_size,ram_size))
print '\n AOS MEMORY MAP '
print '|=================================================================|'
print '| %-40s | %-8s | %-8s |'%('MODULE','ROM','RAM')
print '|=================================================================|'
for line in map_lines:
print line
print '|=================================================================|'
print '| %-40s | %-8d | %-8d |'%('TOTAL (bytes)', total_rom, total_ram)
print '|=================================================================|'
def main():
get_mem_info(sys.argv[1])
if __name__ == "__main__":
main()

View file

@ -0,0 +1,84 @@
#! /usr/bin/env python
import os, sys, re, struct, platform, getopt, subprocess
from sys import platform as _platform
import array,hashlib,struct
def crc16A(dat):
crc=0xFFFF #65535
index=0
for j in dat:
crc=crc^j
print("crc=%x"%crc)
for i in range(8):
if (crc & 1)==1:
crc =crc >> 1
crc =crc ^ 0xA001 #40961
else:
crc=crc>>1
return crc
def print_usage():
print ""
print "Usage: Merge a bin file into an exist bin file, create one if target is not exist"
print sys.argv[0]
print "Optional Usage:"
print " [-o] <target binary file>"
print " [-h | --help] Display usage"
print " [<input binary file>]"
sys.stdout.flush()
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'o:h')
except getopt.GetoptError as err:
print str(err)
print_usage()
sys.exit(2)
OUTPUT_FILE = 0
if not len(args) == 1:
print_usage()
sys.exit(2)
else:
INPUT_FILE = args[0]
if not os.path.exists(INPUT_FILE):
print "Please input a binary file"
sys.exit(2)
for opt, arg in opts:
if opt == "-o":
OUTPUT_FILE = arg
elif opt == "-h":
print_usage()
sys.exit()
if OUTPUT_FILE == 0:
OUTPUT_FILE = re.sub(r'.bin$', '.md5.bin', INPUT_FILE)
fin = open(INPUT_FILE, 'rb')
fout = open(OUTPUT_FILE, 'wb')
data = fin.read()
fout.write(data)
magic = bytearray([0xef,0xef,0xef,0xef])
size = os.path.getsize(INPUT_FILE)
print size
fout.write(magic)
fout.write(struct.pack('<I', size))
fout.write(hashlib.md5(data).digest())
print(hashlib.md5(data).hexdigest())
reserve = bytearray([0xFF,0xFF])
fout.write(reserve)
fout.write(reserve)
fin.close()
fout.close()
os.remove(INPUT_FILE)
os.rename(OUTPUT_FILE,INPUT_FILE)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass