-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·118 lines (98 loc) · 4.32 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/python
import os
APP_NAME = 'rtthread'
APP_TYPE = 'mem' # flash, mem, sdram
APP_ARCH = 'riscv64-mycpu'
APP_ORG_BIN = APP_NAME + '-' + APP_ARCH + '.bin'
APP_ORG_ELF = APP_NAME + '-' + APP_ARCH + '.elf'
APP_LOD_BIN = 'loader-' + APP_ARCH + '.bin'
APP_LOD_ELF = 'loader-' + APP_ARCH + '.elf'
APP_STD_BIN = APP_NAME + '-' + APP_TYPE + '.bin'
APP_STD_ELF = APP_NAME + '-' + APP_TYPE + '.elf'
HOME_DIR = os.getcwd()
def chg_ld_script(app_type):
os.system("sed -i 's/core_[a-z]\+/core_" + app_type +
"/' $AM_HOME/scripts/" + APP_ARCH + ".mk")
def chg_ld_addr(addr):
os.system("sed -i 's/\(pmem_start=\)0x[0-9A-Z]\+/\\1" + addr +
"/' $AM_HOME/scripts/" + APP_ARCH + ".mk")
def chg_ld_sp(addr):
os.system("sed -i 's/\(_stack_top = ALIGN\)(0x[0-9A-Z]\+)/\\1(" + addr +
")/' $AM_HOME/scripts/platform/core_flash.ld")
def copy_oper(app_type):
if app_type == 'flash':
os.system('mv build/' + APP_ORG_BIN + ' build/' + APP_STD_BIN)
os.system('mv build/' + APP_ORG_ELF + ' build/' + APP_STD_ELF)
else:
os.system('mv build/' + APP_LOD_BIN + ' build/' + APP_STD_BIN)
os.system('mv build/' + APP_LOD_ELF + ' build/' + APP_STD_ELF)
os.system('cp build/' + APP_STD_BIN + ' build/' + APP_STD_ELF + ' ' +
HOME_DIR + '/../bin/' + APP_TYPE + '/')
if APP_TYPE == 'flash':
chg_ld_script(APP_TYPE)
chg_ld_addr('0x30000000')
os.chdir(APP_NAME)
if APP_NAME != 'rtthread':
os.system('make ARCH=' + APP_ARCH)
else:
# os.system('./cpu_test.py')
os.system('cp *.c rt-thread/bsp/qemu-riscv-virt64/applications/')
os.system('cp *.cc rt-thread/bsp/qemu-riscv-virt64/applications/')
os.system('cp *.h rt-thread/bsp/qemu-riscv-virt64/applications/')
os.chdir('rt-thread/bsp/qemu-riscv-virt64/')
os.system("sed -i 's/^FLASH = 0/FLASH = 1/' rtconfig.py")
os.system('scons')
os.system('cp rtthread.bin ' + APP_STD_BIN)
os.system('cp rtthread.elf ' + APP_STD_ELF)
os.system('mv ' + APP_STD_BIN + ' ' + APP_STD_ELF + ' ' + HOME_DIR +
'/../bin/' + APP_TYPE + '/')
elif APP_TYPE == 'mem':
chg_ld_script(APP_TYPE)
chg_ld_addr('0x80000000')
os.chdir(APP_NAME)
if APP_NAME != 'rtthread':
os.system('make ARCH=' + APP_ARCH + ' LOAD_TYPE=-DMEM_LOAD')
os.system('cp build/' + APP_ORG_BIN + ' ' + HOME_DIR + '/loader')
else:
# os.system('./cpu_test.py')
os.system('cp *.c rt-thread/bsp/qemu-riscv-virt64/applications/')
os.system('cp *.cc rt-thread/bsp/qemu-riscv-virt64/applications/')
os.system('cp *.h rt-thread/bsp/qemu-riscv-virt64/applications/')
os.chdir('rt-thread/bsp/qemu-riscv-virt64/')
os.system("sed -i 's/^FLASH = 1/FLASH = 0/' rtconfig.py")
os.system('scons')
os.system('cp rtthread.bin ' + HOME_DIR + '/loader/' + APP_ORG_BIN)
chg_ld_script('flash')
chg_ld_addr('0x30000000')
os.chdir(HOME_DIR + '/loader')
os.system("sed -i 's/^\(BIN_PATH\s\+=\s\+\)\(.\+\)/\\1" + APP_NAME + "-" +
APP_ARCH + "\.bin/' " + "Makefile")
os.system('make ARCH=' + APP_ARCH)
elif APP_TYPE == 'sdram':
chg_ld_script(APP_TYPE)
chg_ld_addr('0xFC000000')
os.chdir(APP_NAME)
if APP_NAME != 'rtthread':
os.system('make ARCH=' + APP_ARCH + ' LOAD_TYPE=-DMEM_LOAD')
os.system('cp build/' + APP_ORG_BIN + ' ' + HOME_DIR + '/loader')
else:
# os.system('./cpu_test.py')
os.system('cp *.c rt-thread/bsp/qemu-riscv-virt64/applications/')
os.system('cp *.cc rt-thread/bsp/qemu-riscv-virt64/applications/')
os.system('cp *.h rt-thread/bsp/qemu-riscv-virt64/applications/')
os.chdir('rt-thread/bsp/qemu-riscv-virt64/')
os.system("sed -i 's/^FLASH = 1/FLASH = 0/' rtconfig.py")
os.system('scons')
os.system('cp rtthread.bin ' + HOME_DIR + '/loader/' + APP_ORG_BIN)
chg_ld_script('flash')
chg_ld_addr('0x30000000')
os.chdir(HOME_DIR + '/loader')
os.system("sed -i 's/^\(BIN_PATH\s\+=\s\+\)\(.\+\)/\\1" + APP_NAME + "-" +
APP_ARCH + "\.bin/' " + "Makefile")
os.system('make ARCH=' + APP_ARCH)
if APP_NAME != 'rtthread' and APP_TYPE == 'flash':
copy_oper(APP_TYPE)
elif APP_TYPE == 'mem':
copy_oper(APP_TYPE)
elif APP_TYPE == 'sdram':
copy_oper(APP_TYPE)