Merge #207 207: boards: opentitan: Update the OpenTitan SRAM address r=jrvanwhy a=alistair23 Update the OpenTitan SRAM address to make current master Tock, also update the submodule to use the latest Tock SHA. Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Co-authored-by: Alistair Francis <alistair.francis@wdc.com>
diff --git a/.github/workflows/size-diff.yml b/.github/workflows/size-diff.yml index 4d14308..6f8c7d0 100644 --- a/.github/workflows/size-diff.yml +++ b/.github/workflows/size-diff.yml
@@ -44,6 +44,7 @@ git remote set-branches "${UPSTREAM_REMOTE_NAME}" "${GITHUB_BASE_REF}" git fetch --depth=1 "${UPSTREAM_REMOTE_NAME}" "${GITHUB_BASE_REF}" git checkout "${UPSTREAM_REMOTE_NAME}/${GITHUB_BASE_REF}" + rustup target add riscv32imc-unknown-none-elf thumbv7em-none-eabi make -j2 examples cargo run --release -p print_sizes >'${{runner.temp}}/base-sizes'
diff --git a/Makefile b/Makefile index 2f48887..fe74caa 100644 --- a/Makefile +++ b/Makefile
@@ -16,6 +16,7 @@ @echo " - opentitan" @echo " - hifive1" @echo " - nrf52" + @echo " - imxrt1050" @echo " - apollo3" @echo @echo "Run 'make setup' to setup Rust to build libtock-rs." @@ -152,6 +153,15 @@ flash-nrf52: PLATFORM=nrf52 cargo run $(release) --target=thumbv7em-none-eabi --example $(EXAMPLE) $(features) +.PHONY: imxrt1050 +imxrt1050: + PLATFORM=imxrt1050 cargo build $(release) --target=thumbv7em-none-eabi --examples $(features) + +.PHONY: flash-imxrt1050 +flash-imxrt1050: + PLATFORM=imxrt1050 cargo run $(release) --target=thumbv7em-none-eabi --example $(EXAMPLE) $(features) + + .PHONY: clean clean: cargo clean
diff --git a/boards/layout_imxrt1050.ld b/boards/layout_imxrt1050.ld new file mode 100644 index 0000000..56ecf11 --- /dev/null +++ b/boards/layout_imxrt1050.ld
@@ -0,0 +1,17 @@ +/* Layout for the iMX.RT1050 board, used by the examples in this repository. */ + +MEMORY { + /* The application region is 64 bytes (0x40) */ + FLASH (rx) : ORIGIN = 0x63002040, LENGTH = 0xFFFFC0 + SRAM (rwx) : ORIGIN = 0x20004000, LENGTH = 112K +} + +/* + * Any change to STACK_SIZE should be accompanied by a corresponding change to + * `elf2tab`'s `--stack` option + */ +STACK_SIZE = 2048; + +MPU_MIN_ALIGN = 8K; + +INCLUDE layout_generic.ld
diff --git a/core/Cargo.toml b/core/Cargo.toml index 3f1723b..bfa9570 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml
@@ -5,7 +5,8 @@ edition = "2018" [features] -alloc = [ "linked_list_allocator" ] +alloc = ["alloc_init", "linked_list_allocator"] +alloc_init = [] custom_panic_handler = [] custom_alloc_error_handler = []
diff --git a/core/src/alloc.rs b/core/src/alloc.rs index 05e9669..f971849 100644 --- a/core/src/alloc.rs +++ b/core/src/alloc.rs
@@ -4,7 +4,12 @@ use core::ptr::NonNull; use linked_list_allocator::Heap; -pub static mut HEAP: Heap = Heap::empty(); +static mut HEAP: Heap = Heap::empty(); + +#[no_mangle] +unsafe fn libtock_alloc_init(app_heap_start: usize, app_heap_size: usize) { + HEAP.init(app_heap_start, app_heap_size); +} struct TockAllocator;
diff --git a/core/src/debug/platform_arm.rs b/core/src/debug/platform_arm.rs index 46211b3..a777334 100644 --- a/core/src/debug/platform_arm.rs +++ b/core/src/debug/platform_arm.rs
@@ -1,5 +1,5 @@ pub fn get_stack_pointer() -> usize { let stack_pointer; - unsafe { asm!("mov $0, sp" : "=r"(stack_pointer) : : : "volatile") }; + unsafe { llvm_asm!("mov $0, sp" : "=r"(stack_pointer) : : : "volatile") }; stack_pointer }
diff --git a/core/src/debug/platform_riscv32.rs b/core/src/debug/platform_riscv32.rs index 7f4a4e0..c276442 100644 --- a/core/src/debug/platform_riscv32.rs +++ b/core/src/debug/platform_riscv32.rs
@@ -1,5 +1,5 @@ pub fn get_stack_pointer() -> usize { let stack_pointer; - unsafe { asm!("mv $0, sp" : "=r"(stack_pointer) : : : "volatile") }; + unsafe { llvm_asm!("mv $0, sp" : "=r"(stack_pointer) : : : "volatile") }; stack_pointer }
diff --git a/core/src/entry_point/mod.rs b/core/src/entry_point/mod.rs index 40bdb62..850c213 100644 --- a/core/src/entry_point/mod.rs +++ b/core/src/entry_point/mod.rs
@@ -104,10 +104,8 @@ ); // Zero .bss (specified by the linker script). - let bss_end = layout_header.bss_start + layout_header.bss_size; // 1 past the end of .bss - for i in layout_header.bss_start..bss_end { - core::ptr::write(i as *mut u8, 0); - } + let bss_start = layout_header.bss_start as *mut u8; + core::ptr::write_bytes(bss_start, 0u8, layout_header.bss_size); // TODO: Wait for rustc to have working ROPI-RWPI relocation support, then // implement dynamic relocations here. At the moment, rustc does not have @@ -127,8 +125,8 @@ // Tell the kernel the new app heap break. memop::set_brk(app_heap_end as *const u8); - #[cfg(feature = "alloc")] - crate::alloc::HEAP.init(app_heap_start, app_heap_size); + #[cfg(feature = "alloc_init")] + crate::libtock_alloc_init(app_heap_start, app_heap_size); main(0, ptr::null());
diff --git a/core/src/entry_point/start_item_arm.rs b/core/src/entry_point/start_item_arm.rs index c9390f6..894088e 100644 --- a/core/src/entry_point/start_item_arm.rs +++ b/core/src/entry_point/start_item_arm.rs
@@ -12,7 +12,7 @@ _memory_len: usize, app_heap_break: usize, ) -> ! { - asm!(" + llvm_asm!(" // Because ROPI-RWPI support in LLVM/rustc is incomplete, Rust // applications must be statically linked. An offset between the // location the program is linked at and its actual location in flash @@ -23,7 +23,7 @@ // the Program Counter) will match the intended location of .start. We // don't have an easy way to signal an error, so for now we just yield // if the location is wrong. - sub r4, pc, #4 // r4 = pc + subw r4, pc, #4 // r4 = pc ldr r5, =.start // r5 = address of .start cmp r4, r5 beq .Lstack_init // Jump to stack initialization if pc was correct
diff --git a/core/src/entry_point/start_item_riscv32.rs b/core/src/entry_point/start_item_riscv32.rs index 347400c..f8a0e19 100644 --- a/core/src/entry_point/start_item_riscv32.rs +++ b/core/src/entry_point/start_item_riscv32.rs
@@ -14,7 +14,7 @@ // Due to Rust issue: https://github.com/rust-lang/rust/issues/42779 we can't have // args to the function pub unsafe extern "C" fn _start() -> ! { - asm!( + llvm_asm!( // Compute the stack top. // // struct hdr* myhdr = (struct hdr*) app_start; @@ -105,7 +105,7 @@ #[export_name = "abort"] pub extern "C" fn abort() { unsafe { - asm! (" + llvm_asm! (" // Simply go back to the start as if we had just booted. j _start "
diff --git a/core/src/lib.rs b/core/src/lib.rs index e465f4d..3bdfe5b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs
@@ -1,4 +1,4 @@ -#![feature(asm, lang_items, naked_functions)] +#![feature(lang_items, llvm_asm, naked_functions)] #![cfg_attr(any(target_arch = "arm", target_arch = "riscv32"), no_std)] #![cfg_attr(feature = "alloc", feature(alloc_error_handler))] @@ -8,6 +8,11 @@ #[cfg(any(target_arch = "arm", target_arch = "riscv32"))] mod lang_items; +#[cfg(feature = "alloc_init")] +extern "Rust" { + fn libtock_alloc_init(app_heap_start: usize, app_heap_size: usize); +} + pub mod callback; pub mod debug; pub mod memop;
diff --git a/core/src/syscalls/platform_arm.rs b/core/src/syscalls/platform_arm.rs index 4ff146a..066459e 100644 --- a/core/src/syscalls/platform_arm.rs +++ b/core/src/syscalls/platform_arm.rs
@@ -22,7 +22,7 @@ // registers r4-r8, r10, r11 and SP (and r9 in PCS variants that designate // r9 as v6) As our compilation flags mark r9 as the PIC base register, it // does not need to be saved. Thus we must clobber r0-3, r12, and LR - asm!( + llvm_asm!( "svc 0" : : @@ -40,7 +40,7 @@ ud: usize, ) -> isize { let res; - asm!("svc 1" : "={r0}"(res) + llvm_asm!("svc 1" : "={r0}"(res) : "{r0}"(major) "{r1}"(minor) "{r2}"(cb) "{r3}"(ud) : "memory" : "volatile"); @@ -52,7 +52,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn command(major: usize, minor: usize, arg1: usize, arg2: usize) -> isize { let res; - asm!("svc 2" : "={r0}"(res) + llvm_asm!("svc 2" : "={r0}"(res) : "{r0}"(major) "{r1}"(minor) "{r2}"(arg1) "{r3}"(arg2) : "memory" : "volatile"); @@ -64,7 +64,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn command1(major: usize, minor: usize, arg: usize) -> isize { let res; - asm!("svc 2" : "={r0}"(res) + llvm_asm!("svc 2" : "={r0}"(res) : "{r0}"(major) "{r1}"(minor) "{r2}"(arg) : "memory" : "volatile"); @@ -76,7 +76,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn allow(major: usize, minor: usize, slice: *mut u8, len: usize) -> isize { let res; - asm!("svc 3" : "={r0}"(res) + llvm_asm!("svc 3" : "={r0}"(res) : "{r0}"(major) "{r1}"(minor) "{r2}"(slice) "{r3}"(len) : "memory" : "volatile"); @@ -88,7 +88,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn memop(major: u32, arg1: usize) -> isize { let res; - asm!("svc 4" : "={r0}"(res) + llvm_asm!("svc 4" : "={r0}"(res) : "{r0}"(major) "{r1}"(arg1) : "memory" : "volatile");
diff --git a/core/src/syscalls/platform_riscv32.rs b/core/src/syscalls/platform_riscv32.rs index f7d1858..f2c49fe 100644 --- a/core/src/syscalls/platform_riscv32.rs +++ b/core/src/syscalls/platform_riscv32.rs
@@ -3,7 +3,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn yieldk() { /* TODO: Stop yielding */ - asm! ( + llvm_asm! ( "li a0, 0 ecall" : @@ -23,7 +23,7 @@ ud: usize, ) -> isize { let res; - asm!("li a0, 1 + llvm_asm!("li a0, 1 ecall" : "={x10}" (res) : "{x11}" (major), "{x12}" (minor), "{x13}" (cb), "{x14}" (ud) @@ -37,7 +37,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn command(major: usize, minor: usize, arg1: usize, arg2: usize) -> isize { let res; - asm!("li a0, 2 + llvm_asm!("li a0, 2 ecall" : "={x10}" (res) : "{x11}" (major), "{x12}" (minor), "{x13}" (arg1), "{x14}" (arg2) @@ -51,7 +51,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn command1(major: usize, minor: usize, arg: usize) -> isize { let res; - asm!("li a0, 2 + llvm_asm!("li a0, 2 ecall" : "={x10}" (res) : "{x11}" (major), "{x12}" (minor), "{x13}" (arg) @@ -65,7 +65,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn allow(major: usize, minor: usize, slice: *mut u8, len: usize) -> isize { let res; - asm!("li a0, 3 + llvm_asm!("li a0, 3 ecall" : "={x10}" (res) : "{x11}" (major), "{x12}" (minor), "{x13}" (slice), "{x14}" (len) @@ -79,7 +79,7 @@ #[allow(clippy::missing_safety_doc)] pub unsafe fn memop(major: u32, arg1: usize) -> isize { let res; - asm!("li a0, 4 + llvm_asm!("li a0, 4 ecall" : "={x10}" (res) : "{x11}" (major), "{x12}" (arg1)
diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 4a67404..052cf69 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs
@@ -1,4 +1,6 @@ // This example just prints "Hello Tock World" to the terminal. +// Run `tockloader listen`, or use any serial program of your choice +// (e.g. `screen`, `minicom`) to view the message. #![no_std]
diff --git a/layout_generic.ld b/layout_generic.ld index 35b10f4..dd101ab 100644 --- a/layout_generic.ld +++ b/layout_generic.ld
@@ -88,6 +88,15 @@ /* Application stack */ .stack (NOLOAD) : { + /* elf2tab requires that the `_sram_origin` symbol be present to + * mark the first address in the SRAM memory. Since ELF files do + * not really need to specify this address as they only care about + * loading into flash, we need to manually mark this address for + * elf2tab. elf2tab will use it to add a fixed address header in the + * TBF header if needed. + */ + _sram_origin = .; + . = . + STACK_SIZE; _stack_top_unaligned = .;
diff --git a/rust-toolchain b/rust-toolchain index 8bd4ff0..4aec5c6 100644 --- a/rust-toolchain +++ b/rust-toolchain
@@ -1 +1 @@ -nightly-2020-04-06 +nightly-2020-06-10
diff --git a/src/ble_composer.rs b/src/ble_composer.rs index 0bb96d8..589dfc3 100644 --- a/src/ble_composer.rs +++ b/src/ble_composer.rs
@@ -21,7 +21,7 @@ self.bytes[self.occupied] = (content.len() + 1) as u8; self.bytes[self.occupied + 1] = kind; let write = &mut self.bytes[self.occupied + 2..(self.occupied + content.len() + 2)]; - write.clone_from_slice(content); + write.copy_from_slice(content); self.occupied += 2 + content.len(); Ok(()) } @@ -44,7 +44,7 @@ self.bytes[self.occupied + 3] = uuid[1]; let write = &mut self.bytes[self.occupied + 4..(self.occupied + content.len() + 4)]; - write.clone_from_slice(content); + write.copy_from_slice(content); self.occupied += 4 + content.len(); Ok(()) }
diff --git a/src/ble_parser.rs b/src/ble_parser.rs index 1d12b19..216d974 100644 --- a/src/ble_parser.rs +++ b/src/ble_parser.rs
@@ -53,7 +53,7 @@ 0x02, 0x02, 0x01, 0x02, 0x01, 0x03, 0x03, 0x16, 0x01, 0x02, 0x04, 0xFF, 0x01, 0x02, 0x03, ]; - slice.clone_from_slice(data); + slice.copy_from_slice(data); } assert_eq!(find(&buf, 0x02), Some(&[0x01][0..1])); assert_eq!(find(&buf, 0x01), Some(&[0x03][0..1])); @@ -67,7 +67,7 @@ { let slice = &mut buf[8..18]; let data = &[0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x0, 0x16, 0x01, 0x02]; - slice.clone_from_slice(data); + slice.copy_from_slice(data); } } @@ -77,7 +77,7 @@ { let slice = &mut buf[8..10]; let data = &[0x04, 0x02]; - slice.clone_from_slice(data); + slice.copy_from_slice(data); } assert_eq!(find(&buf, 0xF2), None); }
diff --git a/src/hmac.rs b/src/hmac.rs index e5475cc..5185128 100644 --- a/src/hmac.rs +++ b/src/hmac.rs
@@ -99,7 +99,7 @@ syscalls::allow(DRIVER_NUMBER, allow_nr::DEST, &mut buffer.buffer).map_err(Into::into) } - pub fn subscribe<CB: FnMut(usize, usize) -> () + FnMut(usize, usize)>( + pub fn subscribe<CB: FnMut(usize, usize)>( &self, callback: &'a mut CB, ) -> TockResult<CallbackSubscription> {
diff --git a/tools/flash.sh b/tools/flash.sh index 1a7d74c..cee7571 100755 --- a/tools/flash.sh +++ b/tools/flash.sh
@@ -40,6 +40,11 @@ binary_name=rv32imac.elf tockload=n ;; + "imxrt1050") + tockloader_flags="" + binary_name=cortex-m7.elf + tockload=n + ;; "opentitan") tockloader_flags="" binary_name=rv32imc.elf