Skip to content

Commit 96f68f7

Browse files
Merge pull request #5 from RusPiRo/fix/0.3.1
Fix severe exception handler issues
2 parents eb204cf + 8b36b38 commit 96f68f7

File tree

15 files changed

+270
-183
lines changed

15 files changed

+270
-183
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
# Changelog
2+
## :apple: v0.3.1
3+
- ### :bulb: Features
4+
- add some console log statements in the panic handler that gives a clue of the panic when at least
5+
the console could be setup properly before panicing the first time :)
6+
- use Raspberry Pi Mailbox to retrieve clock speed to initialize miniUart with
7+
- ### :detective: Fixes
8+
- Fix the path created by the build script pointing to the linker script file. It should not contain a '\\\\'.
9+
In addition the examples for the build script to be implementend on consumer side was updated.
10+
- Fix issues with the exception calls and returns as several registers where trashed that
11+
should have been preserved
12+
13+
- ### :wrench: Maintenance
14+
- Use additional ``cfg`` and ``cfg_attr`` to enable running ``cargo test`` which requires some functions from ``std``.
15+
- Update to latest ``ruspiro-register`` version
16+
- Remove ``ruspiro-gpio`` dependency
17+
- Remove the ``ruspiro_interrupt`` dependencie to let the using crate decide whether to incorporate
18+
interrupt handling or not. This than also includes the crate introducing interrupt handling usage need to
19+
proper initialize interrupt handling.
20+
21+
22+
223
## :carrot: v0.3.0
324
- ### :bulb: Features
425
Refactor the boot strapping code to support `Aarch32` and `Aarch64` build target architectures.

Cargo.lock

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
22
name = "ruspiro-boot"
33
authors = ["André Borrmann <[email protected]>"]
4-
version = "0.3.0" # remember to update html_root_url
4+
version = "0.3.1" # remember to update html_root_url
55
description = """
66
Baremetal boot strapper code for the Raspberry Pi 3 to conviniently start a custom kernel within the Rust environment
77
without the need to deal with all the initial setup like stack pointers, getting MMU setup and get all cores kicked off
88
for processing. Supports Aarch32 and Aarch64 builds.
99
"""
1010
license = "Apache-2.0"
11-
repository = "https://github.com/RusPiRo/ruspiro-boot"
12-
documentation = "https://docs.rs/ruspiro-boot/0.3.0"
11+
repository = "https://github.com/RusPiRo/ruspiro-boot/tree/v0.3.1"
12+
documentation = "https://docs.rs/ruspiro-boot/0.3.1"
1313
readme = "README.md"
1414
keywords = ["RusPiRo", "raspberrypi", "boot", "baremetal", "multicore"]
1515
categories = ["no-std", "embedded"]
@@ -27,19 +27,20 @@ maintenance = { status = "actively-developed" }
2727
cc = "1.0.38"
2828

2929
[dependencies]
30-
ruspiro-register = { path = "../register", version = "0.3" }
31-
ruspiro-gpio = { path = "../gpio", version = "0.3" }
32-
ruspiro-interrupt = { path = "../interrupt", version = "0.3" }
30+
ruspiro-register = { path = "../register", version = "0.4" }
31+
ruspiro-mailbox = { path = "../mailbox", version =" 0.3" }
3332
ruspiro-uart = { path = "../uart", version = "0.3" }
3433
ruspiro-console = { path = "../console", version = "0.3" }
35-
ruspiro-timer = { path = "../timer", version = "0.3" }
34+
ruspiro-timer = { path = "../timer", version = "0.4" }
3635
ruspiro-cache = { path = "../cache", version = "0.3" }
36+
ruspiro-interrupt = { path = "../interrupt", version = "0.3" }
3737

3838
[features]
3939
ruspiro_pi3 = [
40-
"ruspiro-gpio/ruspiro_pi3",
40+
"ruspiro-mailbox/ruspiro_pi3",
4141
"ruspiro-uart/ruspiro_pi3",
42-
"ruspiro-timer/ruspiro_pi3"
42+
"ruspiro-timer/ruspiro_pi3",
43+
"ruspiro-interrupt/ruspiro_pi3"
4344
]
4445
singlecore = []
4546
with_panic = []

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ This crate provides basic boot code that - when build into a kernel crate - will
88
[![License](https://img.shields.io/crates/l/ruspiro-boot.svg)](https://github.com/RusPiRo/ruspiro-boot#license)
99

1010
## Hint
11-
1211
The usage of this crate does only make sense when building a Raspberry Pi 3 bare metal kernel. The
1312
baremetal bootstrapping provided by this crate can be build for either Aarch32 or Aarch64 target
1413
architectures. It has been verified to cross compile from a Windows host machine successfully for
1514
both architectures and the execution is tested on a Raspberry Pi 3 B+.
1615

16+
## Features
17+
Feature | Purpose
18+
-------------------|--------------------------
19+
``with_panic`` | Implement a default panic handler
20+
``singlecore`` | Keep all cores except one in a "parked" state so the runtime only uses a single core.
21+
``ruspiro_pi3`` | This is passed to the dependend crates to ensure they will be build properly for this target device.
22+
1723
## Usage
1824
To use this crate simply add the following lines to your ``Cargo.toml`` file:
1925
(hint: git dependency as long as the crate is not registered at crates.io)
2026
```toml
2127
[dependencies]
22-
ruspiro-boot = { version = "0.3", features = ["with_panic"] }
28+
ruspiro-boot = { version = "0.3", features = ["ruspiro_pi3", "with_panic"] }
2329
```
2430
In the main rust file refer to this crate with this:
2531
```rust
@@ -29,13 +35,6 @@ extern crate ruspiro_boot;
2935
The usage of `extern crate` is mandatory to ensure the boot strapping is properly linked into the
3036
final binary.
3137

32-
## Features
33-
Feature | Purpose
34-
-------------------|--------------------------
35-
``with_panic`` | Implement a default panic handler
36-
``singlecore`` | Keep all cores except one in a "parked" state so the runtime only uses a single core.
37-
``ruspiro_pi3`` | This is passed to the dependend crates to ensure they will be build properly for this target device.
38-
3938
To successfully build a bare metal binary using this crate for the boot strapping part it is **highly recomended** to use the linker script provided by this crate. Based on the target architecture to be built it is either [link32.ld](link32.ld) or [link64.ld](link64.ld).
4039
To conviniently refer to the linker scripts contained in this crate it's recommended to use a specific build script in your project that copies the required file to your current project folder and could then be referred to with the ``RUSTFLAG`` ``-C link-arg=-T./link<aarch>.ld``.
4140
The build script is a simple ``build.rs`` rust file in your project root with the following contents:
@@ -46,7 +45,10 @@ fn main() {
4645
// copy the linker script from the boot crate to the current directory
4746
// so it will be invoked by the linker
4847
let ld_source = env::var_os("DEP_RUSPIRO_BOOT_LINKERSCRIPT")
49-
.expect("error in ruspiro build, `ruspiro-boot` not a dependency?");
48+
.expect("error in ruspiro build, `ruspiro-boot` not a dependency?")
49+
.to_str()
50+
.unwrap()
51+
.replace("\\", "/");
5052
let src_file = Path::new(&ld_source);
5153
let trg_file = format!(
5254
"{}/{}",

build.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ fn main() {
2525
.flag("-march=armv8-a")
2626
.compile("excvector");
2727
// print the linker file location of the boot crate to the env-variables
28-
println!(
29-
"cargo:linkerscript={}\\link32.ld",
30-
script_location.display()
31-
);
28+
println!("cargo:linkerscript={}/link32.ld", script_location.display());
29+
30+
println!("cargo:rerun-if-changed=link32.ld");
31+
println!("cargo:rerun-if-changed=src/asm/aarch32/bootstrap.S");
32+
println!("cargo:rerun-if-changed=src/asm/aarch32/exceptionvector.S");
3233
}
3334

3435
if target_arch == "aarch64" {
@@ -41,10 +42,11 @@ fn main() {
4142
.flag("-march=armv8-a")
4243
.compile("excvector");
4344
// print the linker file location of the boot crate to the env-variables
44-
println!(
45-
"cargo:linkerscript={}\\link64.ld",
46-
script_location.display()
47-
);
45+
println!("cargo:linkerscript={}/link64.ld", script_location.display());
46+
47+
println!("cargo:rerun-if-changed=link64.ld");
48+
println!("cargo:rerun-if-changed=src/asm/aarch64/bootstrap.S");
49+
println!("cargo:rerun-if-changed=src/asm/aarch64/exceptionvector.S");
4850
}
4951
}
5052
}

build.sh

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,50 @@
11
#!/bin/sh
2-
2+
#*********************************************************************************
3+
# script to build the this crate
4+
#*********************************************************************************
35
set +ev
46

57
if [ $# -eq 0 ]
68
then
7-
echo "not enough parameter given"
9+
echo "provide the target architecture to build for - 32 or 64"
810
exit 1
911
fi
1012

11-
# check which aarch version to build
1213
if [ $1 = "64" ]
1314
then
1415
# aarch64
15-
export CFLAGS='-march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53'
16-
export RUSTFLAGS='-C linker=aarch64-elf-gcc -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0'
17-
if [ "$2" = "" ]
16+
# use the right compiler toolchain prefix when building on travis
17+
if [ -z "$2" ]
1818
then
19-
export CC='aarch64-elf-gcc'
20-
export AR='aarch64-elf-ar'
19+
PREFIX=aarch64-elf-
20+
else
21+
PREFIX=aarch64-linux-gnu-
2122
fi
22-
cargo xbuild --target aarch64-unknown-linux-gnu --release
23+
CFLAGS="-march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53"
24+
RUSTFLAGS="-C linker=${PREFIX}gcc -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0"
25+
TARGET="aarch64-unknown-linux-gnu"
2326
elif [ $1 = "32" ]
2427
then
2528
# aarch32
26-
export CFLAGS='-mfpu=neon-fp-armv8 -mfloat-abi=hard -march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53'
27-
export RUSTFLAGS='-C linker=arm-eabi-gcc.exe -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+v8,+vfp3,+d16,+thumb2,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0'
29+
# use the right compiler toolchain prefix when building on travis
2830
if [ -z "$2" ]
2931
then
30-
export CC='arm-eabi-gcc.exe'
31-
export AR='arm-eabi-ar.exe'
32+
PREFIX=arm-eabi-
33+
else
34+
PREFIX=arm-linux-gnueabihf-
3235
fi
33-
cargo xbuild --target armv7-unknown-linux-gnueabihf --release
36+
CFLAGS="-mfpu=neon-fp-armv8 -mfloat-abi=hard -march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53"
37+
RUSTFLAGS="-C linker=${PREFIX}gcc -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+v8,+vfp3,+d16,+thumb2,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0"
38+
TARGET="armv7-unknown-linux-gnueabihf"
3439
else
35-
echo 'provide the archtitecture to be build. Use either "build.sh 32" or "build.sh 64"'
40+
echo 'provide the archtitecture to be build. Use either "build.sh 32" or "build.sh 64".'
41+
exit 1
3642
fi
43+
44+
export CFLAGS="${CFLAGS}"
45+
export RUSTFLAGS="${RUSTFLAGS}"
46+
export CC="${PREFIX}gcc"
47+
export AR="${PREFIX}ar"
48+
export TARGET="${TARGET}"
49+
50+
cargo xbuild --target ${TARGET} --release --features ruspiro_pi3

makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,31 @@ all32: export RUSTFLAGS = -C linker=arm-eabi-gcc.exe -C target-cpu=cortex-a53 -C
1414
all32: export CC = arm-eabi-gcc.exe
1515
all32: export AR = arm-eabi-ar.exe
1616
all32:
17-
cargo xbuild --target armv7-unknown-linux-gnueabihf --release --lib --target-dir ./target/
17+
cargo xbuild --target armv7-unknown-linux-gnueabihf --release --lib --features ruspiro_pi3
1818

1919

2020
all64: export CFLAGS = -march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53
2121
all64: export RUSTFLAGS = -C linker=aarch64-elf-gcc.exe -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0 -C link-arg=-T./link64.ld
2222
all64: export CC = aarch64-elf-gcc.exe
2323
all64: export AR = aarch64-elf-ar.exe
2424
all64:
25-
cargo xbuild --target aarch64-unknown-linux-gnu --release --lib --target-dir ./target/
25+
cargo xbuild --target aarch64-unknown-linux-gnu --release --lib --features ruspiro_pi3
2626

2727

2828
doc: export CFLAGS = -march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53
2929
doc: export RUSTFLAGS = -C linker=aarch64-elf-gcc.exe -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0
3030
doc: export CC = aarch64-elf-gcc.exe
3131
doc: export AR = aarch64-elf-ar.exe
3232
doc:
33-
cargo doc --no-deps --target aarch64-unknown-linux-gnu --release --open
33+
cargo doc --no-deps --target aarch64-unknown-linux-gnu --features ruspiro_pi3,with_panic --release --open
34+
35+
clippy: export CFLAGS = -march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53
36+
clippy: export RUSTFLAGS = -C linker=aarch64-elf-gcc.exe -C target-cpu=cortex-a53 -C target-feature=+strict-align,+a53,+fp-armv8,+neon -C link-arg=-nostartfiles -C opt-level=3 -C debuginfo=0
37+
clippy: export CC = aarch64-elf-gcc.exe
38+
clippy: export AR = aarch64-elf-ar.exe
39+
clippy:
40+
# run clippy for this crate using custom target
41+
cargo xclippy --target aarch64-unknown-linux-gnu --release --features ruspiro_pi3
3442

3543
clean:
3644
cargo clean

src/asm/aarch32/bootstrap.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ __boot:
8787
orr r0, r0, #0x300000 /* enable single precision */
8888
orr r0, r0, #0xC00000 /* enable double precision */
8989
mcr p15, 0, r0, c1, c0, 2
90+
9091
mov r0, #0x40000000
91-
fmxr fpexc, r0
92+
vmsr fpexc, r0
9293

9394
// finally call into the rust code entry point
9495
mrc p15, 0, r0, c0, c0, 5 // get core id

src/asm/aarch32/exceptionvector.S

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* save current core state before running any IRQ handler
2323
**********************************************************************/
2424
.macro save_state
25-
stmfd sp!, {r0-r3, lr} // store unbanked corruptile registers + return address
25+
stmfd sp!, {r0-r11, lr} // store corruptile registers + return address
2626
//mrs r0, spsr // get the saved pstate register and store it as well
2727
//stmfd sp!, {r0}
2828
@@ -41,7 +41,7 @@
4141

4242
//ldmfd sp!, {r0} // restore pstate
4343
//mcr cpsr, r0
44-
ldmfd sp!, {r0-r3, pc}^ // restore unbanked corruptile registers
44+
ldmfd sp!, {r0-r11, pc}^ // restore corruptile registers
4545
.endm
4646

4747
/***************************************************************************************************
@@ -168,4 +168,5 @@ __fast_interrupt_trampoline:
168168

169169
bl __exception_handler_default
170170

171-
restore_state_return // return from this exception
171+
restore_state_return // return from this exception
172+

0 commit comments

Comments
 (0)