//参数是 需要合并的app文件名称 let mut args =env::args(); args.next(); let files_number:u16=args.len() as u16;
let mut output_file: File =File::create("new_apps.bin").expect("open fails"); output_file.write(&files_number.to_be_bytes()).expect("write file numbers fails");
for file in args{ let length:u16= fs::metadata(file.clone()).expect("open file fails").len() as u16; println!("APP:{}:{}",file,length); output_file.write(&length.to_be_bytes()).expect("writing file length fails");
} args=env::args(); args.next(); for file in args{ let mut source_file=File::open(file).expect("Opening file fails"); let mut buffer=Vec::new(); source_file.read_to_end(&mut buffer).expect("reading file fails."); output_file.write_all(&buffer).expect("writing file fails."); }
实际上,所有 abi 函数都是跳转到 abi_entry 执行,不同之处在与参数的传递,我规定第一个参数 a0 是 abi 号,后面的是 abi 函数的参数。在 putchar 中,a0 被设置为 SYS_PUTCHAR,a1 被设置为 c 的值。注意,在内联汇编的结尾要加上 clobber_abi("C"),保持寄存器在执行这段汇编代码前后的一致,否则将出现混乱。
# Using Zero to fill the block to 32M(32Times, one times for 1M) dd if=/dev/zero of=./apps.bin bs=1M count=32 # Add origin app into the end of the file (not cover) dd if=./size.bin of=./apps.bin conv=notrunc bs=1B seek=2 dd if=./hello_app.bin of=./apps.bin conv=notrunc bs=1B seek=4 mv $BASE_DIR/hello_app/apps.bin "$BASE_DIR/apps.bin"
# Input: The Name of Directory # Output: The size of the binary image functiongenerateBinrary() { # Create Binrary echo$1 cd"$BASE_DIR/$1" echo `pwd` cargo build --target riscv64gc-unknown-none-elf --release # remove symbol information rust-objcopy --binary-architecture=riscv64 --strip-all -O binary ../../target/riscv64gc-unknown-none-elf/release/$1 ./$1.bin
// LOAD APPLICATION for i in0..app_num { println!("===================="); println!("= START OF APP {i} ="); println!("===================="); let i = i asusize; let read_only_app = unsafe { core::slice::from_raw_parts(apps[i].start_addr, apps[i].size) }; let load_app = unsafe { core::slice::from_raw_parts_mut(load_start as *mutu8, apps[i].size) }; println!( "Copy App {i} data from {:x} into {:x}", apps[i].start_addr asusize, LOAD_START );