Skip to content

Commit f47717c

Browse files
authored
Devel (#1)
* Add example M4 firmware stored in the A9 elf file as CPIO archive * Update README * Rename directories, update README * Update libsel4-sys, cleanup warnings
1 parent 5c78b5e commit f47717c

19 files changed

+794
-22
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors = ["jonlamb-gh <[email protected]>"]
77
# tracked as a submodule currently
88
#libsel4-sys = {git = "https://github.com/jonlamb-gh/libsel4-sys.git", branch = "devel"}
99
libsel4-sys = {path = "libsel4-sys"}
10+
rlibc = "1.0"
1011

1112
[dependencies.wee_alloc]
1213
version = "0.4"

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@ It first initializes the system, then runs a separate Rust application on the M4
1010

1111
## Building
1212

13+
Note that the L2 cache memory is currently defined as OCRAM for the M4 core.
14+
15+
Modify U-boot environment:
16+
17+
```bash
18+
# default loadaddr
19+
loadaddr=0x82000000
20+
21+
# move it up a bit so we don't overlap with the elf-loader
22+
setenv loadaddr 0x83000000
23+
24+
# boot alias command
25+
setenv bootfel4img 'tftp ${loadaddr} ${serverip}:feL4img; dcache flush; dcache off; go ${loadaddr}'
26+
```
27+
28+
Apply local patches to convert the imx6/sabre-lite platform into something the SoloX will run.
29+
1330
```bash
1431
./scripts/apply-patches
1532

33+
# a build.rs script is used to invoke the 'm4-firmware' project build
1634
cargo fel4 build
1735
```
1836

build.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
// Instead of a dependency on the project, invoke its build manually.
5+
// Needed because they are different targets.
6+
Command::new("./build")
7+
.current_dir("m4-firmware/")
8+
.output()
9+
.expect("Failed to run M4 build script");
10+
11+
println!("cargo:rerun-if-changed=m4-firmware");
12+
println!("cargo:rerun-if-changed=m4-firmware");
13+
14+
println!("cargo:rustc-link-search=native=m4-firmware/target/thumbv7em-none-eabi/release");
15+
println!("cargo:rustc-link-lib=static=m4archive");
16+
}

fel4.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ KernelPrinting = false
114114

115115
[armv7-sel4-fel4.sabre]
116116
KernelARMPlatform = "sabre"
117-
ElfloaderImage = "elf"
117+
ElfloaderImage = "binary"
118118
ElfloaderMode = "secure supervisor"
119119
ElfloaderErrata764369 = true
120120
KernelArmEnableA9Prefetcher = false
121121
KernelArmExportPMUUser = false
122-
KernelDebugDisableL2Cache = false
122+
# L2 cache memory is currently defined as OCRAM for the M4
123+
KernelDebugDisableL2Cache = true
123124

124125
[aarch64-sel4-fel4]
125126
BuildWithCommonSimulationSettings = true

libsel4-sys

m4-firmware/.cargo/config

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[target.thumbv7em-none-eabi]
2+
runner = 'arm-none-eabi-gdb'
3+
rustflags = [
4+
"-C", "link-arg=-Wl,-Tlink.x",
5+
"-C", "link-arg=-nostartfiles",
6+
"-C", "target-cpu=cortex-m4",
7+
"-C", "target-feature=+vfp2",
8+
9+
# uncomment to use rustc LLD to link programs (a)
10+
# "-C", "link-arg=-Tlink.x",
11+
# "-C", "linker=lld",
12+
# "-Z", "linker-flavor=ld.lld",
13+
]
14+
15+
# (a) you also need to comment out the other two `link-arg` lines. But note that as of v0.6.0 LLD
16+
# has a bug where it mislinks FFI calls and they up crashing the program at runtime
17+
[build]
18+
target = "thumbv7em-none-eabi"

m4-firmware/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
m4-build-result.txt

m4-firmware/Cargo.lock

+77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

m4-firmware/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "m4-firmware"
3+
version = "0.0.1"
4+
publish = false
5+
6+
[dependencies]
7+
cortex-m = "0.5.2"
8+
cortex-m-rt = "0.5.1"
9+
panic-abort = "0.2.0"
10+
11+
[profile.release]
12+
codegen-units = 1 # better optimizations
13+
debug = true
14+
lto = true # better optimizations

m4-firmware/build

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ -f /opt/arm-none-eabi-v7/env ]; then
6+
echo "Sourcing custom toolchain"
7+
source /opt/arm-none-eabi-v7/env
8+
fi
9+
10+
# unset some of cargo's environment since we're building for a different
11+
# target
12+
unset RUSTFLAGS
13+
unset RUST_TARGET_PATH
14+
unset TARGET
15+
16+
cargo build --target thumbv7em-none-eabi --release &> m4-build-result.txt
17+
18+
if [ ! -f ${PWD}/target/thumbv7em-none-eabi/release/m4-firmware ]; then
19+
echo "Failed to build the Rust M4 project"
20+
exit 1
21+
fi
22+
23+
#export V=3
24+
export PLAT=imx6
25+
export SEL4_ARCH=aarch32
26+
export TOOLPREFIX=arm-none-eabi-
27+
28+
# create a binary from the ELF file
29+
arm-none-eabi-objcopy -O binary \
30+
${PWD}/target/thumbv7em-none-eabi/release/m4-firmware \
31+
${PWD}/target/thumbv7em-none-eabi/release/m4-firmware.bin
32+
33+
# create a CPIO archive object from our binary
34+
../libsel4-sys/deps/seL4_tools/common-tool/files_to_obj.sh \
35+
${PWD}/target/thumbv7em-none-eabi/release/archive.o \
36+
_cpio_archive \
37+
${PWD}/target/thumbv7em-none-eabi/release/m4-firmware.bin
38+
39+
# turn the CPIO archive object into a static archive library
40+
arm-none-eabi-ar \
41+
rcs \
42+
${PWD}/target/thumbv7em-none-eabi/release/libm4archive.a \
43+
${PWD}/target/thumbv7em-none-eabi/release/archive.o
44+
45+
echo "ELF file: ${PWD}/target/thumbv7em-none-eabi/release/m4-firmware"
46+
echo "binary file: ${PWD}/target/thumbv7em-none-eabi/release/m4-firmware.bin"
47+
echo "CPIO archive object: ${PWD}/target/thumbv7em-none-eabi/release/archive.o"
48+
echo "static archive library: ${PWD}/target/thumbv7em-none-eabi/release/libm4archive.a"
49+
50+
exit 0

m4-firmware/memory.x

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* TODO - still need to tune this up, probably should define _stext and stack/heap bits */
2+
3+
MEMORY
4+
{
5+
/* NOTE K = KiBi = 1024 bytes */
6+
7+
/* TCM configuration */
8+
/* TCM(L) region for code, and the TCM(U) region for data */
9+
/* FLASH in TCM(L) at 0x1FFF_8000 (alias 0x0000_0000), this is 0x007F_8000 from the A9 */
10+
/* RAM in TCM(U) at 0x2000_0000, this is 0x0080_0000 from the A9 */
11+
FLASH (rx) : ORIGIN = 0x1FFF8000, LENGTH = 32K
12+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
13+
14+
/* OCRAM configuration */
15+
/* TODO - reference has 32K but TRM says 128 KB, should we then have L=128/2=64K */
16+
/* FLASH in OSCRAM at 0x0091_0000 (upper half of region), this is 0x0091_0000 from the A9 */
17+
/* RAM in TCM(U) at 0x2000_0000, this is 0x0080_0000 from the A9 */
18+
/* FLASH (rx) : ORIGIN = 0x00910000, LENGTH = 32K */
19+
/* RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K */
20+
21+
/* DDR configuration */
22+
/* FLASH in DDR at 0x9FF0_0000, this is 0x9FF0_0000 from the A9 */
23+
/* RAM in TCM(U) at 0x2000_0000, this is 0x0080_0000 from the A9 */
24+
/* FLASH (rx) : ORIGIN = 0x9FF00000, LENGTH = 1024K */
25+
/* RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K */
26+
}
27+
28+
/* This is where the call stack will be allocated. */
29+
/* The stack is of the full descending type. */
30+
/* You may want to use this variable to locate the call stack and static
31+
variables in different memory regions. Below is shown the default value */
32+
/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */
33+
34+
/* You can use this symbol to customize the location of the .text section */
35+
/* If omitted the .text section will be placed right after the .vector_table
36+
section */
37+
/* This is required only on microcontrollers that store some configuration right
38+
after the vector table */
39+
/* _stext = ORIGIN(FLASH) + 0x400; */
40+
41+
/* Size of the heap (in bytes) */
42+
/* _heap_size = 1024; */

0 commit comments

Comments
 (0)