[313] | 1 | #!python
|
---|
| 2 | import subprocess
|
---|
| 3 | import os
|
---|
| 4 | import sys
|
---|
| 5 | import re # for regular expression
|
---|
| 6 | import shutil
|
---|
| 7 | import os.path
|
---|
| 8 |
|
---|
| 9 | #
|
---|
| 10 | # variable definition
|
---|
| 11 | #
|
---|
| 12 | INCLUDES = []
|
---|
| 13 | CFG1_DEF_TABLES = []
|
---|
| 14 |
|
---|
| 15 | # set relative path from top proj
|
---|
| 16 | proj_rel_dir = "../"
|
---|
| 17 |
|
---|
| 18 | # call definition file
|
---|
| 19 | common.Source(proj_rel_dir + "def.py")
|
---|
| 20 |
|
---|
| 21 | # path
|
---|
| 22 | src_abs_path = os.path.abspath(proj_rel_dir + SRCDIR)
|
---|
| 23 |
|
---|
| 24 | # call common file
|
---|
| 25 | common.Source(src_abs_path + "/arch/ccrx/common.py")
|
---|
| 26 |
|
---|
| 27 | #
|
---|
| 28 | # convert map file
|
---|
| 29 | #
|
---|
| 30 | inputfile = open("./DefaultBuild/cfg.map")
|
---|
| 31 | outputfile = open("cfg1_out.syms", 'w')
|
---|
| 32 |
|
---|
| 33 | r1 = re.compile("^\s+(_\w+)")
|
---|
| 34 | r2 = re.compile("^\s+([0-9a-f]+)\s+")
|
---|
| 35 | line = inputfile.readline()
|
---|
| 36 | while line:
|
---|
| 37 | line = line.replace('\r\n','') #delete newline
|
---|
| 38 | m1 = r1.search(line)
|
---|
| 39 | if m1:
|
---|
| 40 | line = inputfile.readline()
|
---|
| 41 | line = line.replace('\r\n','') #delete newline
|
---|
| 42 | m2 = r2.search(line)
|
---|
| 43 | outputfile.write("0x" + m2.group(1) + " T " + m1.group(1) + "\n")
|
---|
| 44 | line = inputfile.readline()
|
---|
| 45 |
|
---|
| 46 | inputfile.close()
|
---|
| 47 | outputfile.close()
|
---|
| 48 |
|
---|
| 49 | if TCPIP_API_TABLE != "":
|
---|
| 50 | cfg_tcpip_kernel_trb = srcdir + CFG_TCPIP_KERNEL_TRB
|
---|
| 51 | cfg_tcpip_api_table = srcdir + TCPIP_API_TABLE
|
---|
| 52 |
|
---|
| 53 | #
|
---|
| 54 | # Execute cfg path 2
|
---|
| 55 | #
|
---|
| 56 | # make command
|
---|
| 57 | cfg_command = cfg + " --pass 2 " + "--kernel " + CFG_KERNEL
|
---|
| 58 | cfg_command += " " + cfg_includes
|
---|
| 59 | if TCPIP_API_TABLE == "":
|
---|
| 60 | cfg_command += " -T " + cfg_kernel_trb
|
---|
| 61 | else:
|
---|
| 62 | cfg_command += " -T " + cfg_tcpip_kernel_trb + ":tcpip"
|
---|
| 63 | cfg_command += " -T " + cfg_kernel_trb + ":kernel"
|
---|
| 64 |
|
---|
| 65 | print cfg_command
|
---|
| 66 |
|
---|
| 67 | # Execute
|
---|
| 68 | try:
|
---|
| 69 | output = subprocess.check_output(cfg_command, stderr=subprocess.STDOUT,)
|
---|
| 70 | except subprocess.CalledProcessError, e:
|
---|
| 71 | print "ERROR!! : ", e.output
|
---|
| 72 | sys.exit()
|
---|
| 73 |
|
---|
| 74 | output.replace('\r','')
|
---|
| 75 | print output
|
---|
| 76 |
|
---|
| 77 | ##
|
---|
| 78 | ## mov Os_Cfg_tmp.h Os_Cfg.h
|
---|
| 79 | ##
|
---|
| 80 | #import filecmp
|
---|
| 81 | #if not os.path.isfile(r'Os_Cfg.h'):
|
---|
| 82 | # print "Rename Os_Cfg_tmp.h to Os_Cfg.h"
|
---|
| 83 | # shutil.move("Os_Cfg_tmp.h", "Os_Cfg.h")
|
---|
| 84 | #else:
|
---|
| 85 | # print "compare Os_Cfg_tmp.h and Os_Cfg.h"
|
---|
| 86 | # if not filecmp.cmp(r'Os_Cfg_tmp.h', r'Os_Cfg.h'):
|
---|
| 87 | # print "Rename Os_Cfg_tmp.h to Os_Cfg.h"
|
---|
| 88 | # shutil.move("Os_Cfg_tmp.h", "Os_Cfg.h")
|
---|
| 89 | # else:
|
---|
| 90 | # print "Delete Os_Cfg_tmp.h"
|
---|
| 91 | # os.remove("Os_Cfg_tmp.h")
|
---|
| 92 |
|
---|
| 93 | #
|
---|
| 94 | # Execute cfg path 3
|
---|
| 95 | #
|
---|
| 96 | # make command
|
---|
| 97 | cfg_command = cfg + " --pass 2 -O " + "--kernel " + CFG_KERNEL
|
---|
| 98 | cfg_command += " " + cfg_includes
|
---|
| 99 | cfg_command += " --rom-image cfg1_out.srec --rom-symbol cfg1_out.syms"
|
---|
| 100 | cfg_command += " -T " + cfg_offset_trb
|
---|
| 101 |
|
---|
| 102 | print cfg_command
|
---|
| 103 |
|
---|
| 104 | # Execute
|
---|
| 105 | try:
|
---|
| 106 | output = subprocess.check_output(cfg_command, stderr=subprocess.STDOUT,)
|
---|
| 107 | except subprocess.CalledProcessError, e:
|
---|
| 108 | print "ERROR!! : ", e.output
|
---|
| 109 | sys.exit()
|
---|
| 110 |
|
---|
| 111 | output.replace('\r','')
|
---|
| 112 | print output
|
---|
| 113 |
|
---|
| 114 | #
|
---|
| 115 | # convert map file
|
---|
| 116 | #
|
---|
| 117 | inputfile = open("offset.h")
|
---|
| 118 | outputfile = open("offset.inc", 'w')
|
---|
| 119 |
|
---|
| 120 | outputfile.write("; offset.inc\n");
|
---|
| 121 | outputfile.write("\n");
|
---|
| 122 |
|
---|
| 123 | r1 = re.compile("^#define\s+([0-9|a-z|A-Z|_]+)\s+(.+)\s*$")
|
---|
| 124 | r2 = re.compile("^0x([0-9A-Fa-f]+)$");
|
---|
| 125 | line = inputfile.readline()
|
---|
| 126 | while line:
|
---|
| 127 | line = line.replace('\r\n','') #delete newline
|
---|
| 128 | m1 = r1.search(line)
|
---|
| 129 | if m1:
|
---|
| 130 | value = m1.group(2)
|
---|
| 131 | m2 = r2.search(value)
|
---|
| 132 | if m2:
|
---|
| 133 | value = "0" + m2.group(1) + "H"
|
---|
| 134 | line = " " + m1.group(1) + " .equ " + value
|
---|
| 135 | outputfile.write(line + "\n")
|
---|
| 136 | line = inputfile.readline()
|
---|
| 137 |
|
---|
| 138 | inputfile.close()
|
---|
| 139 | outputfile.close()
|
---|