30 lines
1006 B
Python
30 lines
1006 B
Python
|
#!/bin/python3
|
||
|
import os
|
||
|
|
||
|
base_address = 0x80400000
|
||
|
step = 0x20000
|
||
|
linker = 'src/linker.ld'
|
||
|
target_dir = "target/riscv64gc-unknown-none-elf/release/"
|
||
|
|
||
|
app_id = 0
|
||
|
apps = os.listdir('src/bin')
|
||
|
apps.sort()
|
||
|
for app in apps:
|
||
|
app = app[:app.find('.')]
|
||
|
lines = []
|
||
|
lines_before = []
|
||
|
with open(linker, 'r') as f:
|
||
|
for line in f.readlines():
|
||
|
lines_before.append(line)
|
||
|
line = line.replace(hex(base_address), hex(base_address+step * app_id))
|
||
|
lines.append(line)
|
||
|
with open(linker, 'w+') as f:
|
||
|
f.writelines(lines)
|
||
|
os.system('cargo build --bin %s --release' % app)
|
||
|
source_name = target_dir + app
|
||
|
dest_name = target_dir + app + ".bin"
|
||
|
os.system("rust-objcopy %s --binary-architecture=riscv64 --strip-all -O binary %s" %(source_name, dest_name))
|
||
|
print('[build.py] application %s start with address %s' %(app, hex(base_address+step*app_id)))
|
||
|
with open(linker, 'w+') as f:
|
||
|
f.writelines(lines_before)
|
||
|
app_id = app_id + 1
|