Build application at 0x0 in release mode.

This commit is contained in:
Yifan Wu 2020-12-02 09:40:00 +08:00
parent 63aaa9d0a1
commit 4b01ff7cc4
4 changed files with 3 additions and 40 deletions

View File

@ -1,5 +1,5 @@
TARGET := riscv64gc-unknown-none-elf TARGET := riscv64gc-unknown-none-elf
MODE := debug MODE := release
APP_DIR := src/bin APP_DIR := src/bin
TARGET_DIR := target/$(TARGET)/$(MODE) TARGET_DIR := target/$(TARGET)/$(MODE)
APPS := $(wildcard $(APP_DIR)/*.rs) APPS := $(wildcard $(APP_DIR)/*.rs)
@ -10,7 +10,7 @@ OBJDUMP := rust-objdump --arch-name=riscv64
OBJCOPY := rust-objcopy --binary-architecture=riscv64 OBJCOPY := rust-objcopy --binary-architecture=riscv64
elf: $(APPS) elf: $(APPS)
@python3 build.py @cargo build --release
binary: elf binary: elf
$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));) $(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));)

View File

@ -1,25 +0,0 @@
import os
base_address = 0x80100000
step = 0x20000
linker = 'src/linker.ld'
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' % app)
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

View File

@ -11,7 +11,6 @@ mod lang_items;
#[no_mangle] #[no_mangle]
#[link_section = ".text.entry"] #[link_section = ".text.entry"]
pub extern "C" fn _start() -> ! { pub extern "C" fn _start() -> ! {
clear_bss();
syscall::sys_exit(main()); syscall::sys_exit(main());
panic!("unreachable after sys_exit!"); panic!("unreachable after sys_exit!");
} }
@ -22,14 +21,5 @@ fn main() -> i32 {
panic!("Cannot find main!"); panic!("Cannot find main!");
} }
fn clear_bss() {
extern "C" {
fn start_bss();
fn end_bss();
}
(start_bss as usize..end_bss as usize).for_each(|addr| {
unsafe { (addr as *mut u8).write_volatile(0); }
});
}
pub use syscall::*; pub use syscall::*;

View File

@ -2,7 +2,7 @@
OUTPUT_ARCH(riscv) OUTPUT_ARCH(riscv)
ENTRY(_start) ENTRY(_start)
BASE_ADDRESS = 0x80100000; BASE_ADDRESS = 0x0;
SECTIONS SECTIONS
{ {
@ -18,9 +18,7 @@ SECTIONS
*(.data .data.*) *(.data .data.*)
} }
.bss : { .bss : {
start_bss = .;
*(.bss .bss.*) *(.bss .bss.*)
end_bss = .;
} }
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)