Skip to content

Commit 572be99

Browse files
thomasw04xarantolus
andcommitted
The Bootloader.
Co-authored-by: xarantolus <[email protected]>
0 parents  commit 572be99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3700
-0
lines changed

.devcontainer/Dockerfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM ubuntu:22.04
2+
3+
# The packages we need, as documented in the README
4+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
5+
build-essential cmake libusb-1.0 libusb-1.0-0-dev gdb-multiarch gcc-arm-none-eabi openocd \
6+
qemu-system-arm curl wget git \
7+
pkg-config libssl-dev # required for the cargo-tarpaulin install
8+
9+
RUN ln -s /usr/bin/gdb-multiarch /usr/bin/arm-none-eabi-gdb
10+
11+
# Install Rust
12+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
13+
echo 'source $HOME/.cargo/env' >> $HOME/.bashrc && \
14+
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> $HOME/.bashrc
15+
ENV PATH="${HOME}/.cargo/bin:${PATH}"
16+
17+
RUN $HOME/.cargo/bin/rustup default nightly
18+
RUN $HOME/.cargo/bin/rustup target add thumbv7em-none-eabi
19+
RUN $HOME/.cargo/bin/rustup component add llvm-tools-preview
20+
21+
# Install tools for:
22+
# - binary (size) inspection
23+
# - test coverage generation
24+
# - file watching
25+
RUN $HOME/.cargo/bin/cargo install cargo-binutils cargo-tarpaulin watchexec-cli
26+
27+
# Install specific version of stlink tools
28+
RUN git clone --single-branch -b fix-stm32l4r5 https://github.com/bauen1/stlink.git /tmp/stlink && \
29+
cd /tmp/stlink && \
30+
make clean && \
31+
make release && \
32+
make install && \
33+
ldconfig && \
34+
rm -r /tmp/stlink
35+
36+
# Tools for formal verification
37+
RUN apt-get install -y \
38+
python3 python3-pip python3-setuptools python3-wheel
39+
40+
RUN $HOME/.cargo/bin/cargo install --locked kani-verifier && \
41+
$HOME/.cargo/bin/cargo kani setup

.devcontainer/devcontainer.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
3+
{
4+
"name": "Container",
5+
"build": {
6+
"context": "..",
7+
"dockerfile": "Dockerfile"
8+
},
9+
"runArgs": [
10+
// Required for USB device access for flashing
11+
"--privileged",
12+
// If we don't mount /dev, we can only access devices that were available when
13+
// the container was started, not those that were plugged in while it was running
14+
"-v", "/dev:/dev"
15+
],
16+
"mounts": [
17+
"type=bind,source=${localWorkspaceFolder},target=/work",
18+
//"type=bind,source=/home/${localEnv:USER}/.ssh,target=/root/.ssh,readonly"
19+
],
20+
// Features to add to the dev container. More info: https://containers.dev/features.
21+
// "features": {},
22+
23+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
24+
// "forwardPorts": [],
25+
26+
// Uncomment the next line to run commands after the container is created.
27+
// "postCreateCommand": "cat /etc/os-release",
28+
29+
// Configure tool-specific properties.
30+
"customizations": {
31+
"vscode": {
32+
"extensions": [
33+
"donjayamanne.githistory",
34+
"davidanson.vscode-markdownlint",
35+
"streetsidesoftware.code-spell-checker",
36+
"rust-lang.rust-analyzer",
37+
"marus25.cortex-debug",
38+
"vadimcn.vscode-lldb",
39+
"ryanluker.vscode-coverage-gutters",
40+
"ms-vscode.hexeditor"
41+
]
42+
}
43+
},
44+
"features": {
45+
// This allows connecting to the host docker daemon from inside the container
46+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
47+
},
48+
// Policies that allow debugging inside of container
49+
"capAdd": [
50+
"SYS_PTRACE"
51+
],
52+
"securityOpt": [
53+
"seccomp=unconfined"
54+
],
55+
56+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
57+
"remoteUser": "root"
58+
}

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/target
2+
*.bin

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
**/lcov.info
2+
*.bin
3+
**/*.rs.bk
4+
.#*
5+
.gdb_history
6+
Cargo.lock
7+
target/
8+
9+
# editor files
10+
.vscode/*
11+
!.vscode/*.md
12+
!.vscode/*.svd
13+
!.vscode/launch.json
14+
!.vscode/tasks.json
15+
!.vscode/extensions.json
16+
!.vscode/openocd.gdb
17+
**/lcov.info
18+
19+
.cache

.vscode/extensions.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3+
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4+
5+
// List of extensions which should be recommended for users of this workspace.
6+
"recommendations": [
7+
"rust-lang.rust-analyzer",
8+
"marus25.cortex-debug",
9+
],
10+
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
11+
"unwantedRecommendations": [
12+
13+
]
14+
}

.vscode/launch.json

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
/*
3+
* Requires the Rust Language Server (rust-analyzer) and Cortex-Debug extensions
4+
* https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer
5+
* https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
6+
* This configuration is exclusively for the STM32L4R5 I annotated the things you have to change for other L4's.
7+
*/
8+
"version": "0.2.0",
9+
"configurations": [
10+
{
11+
"type": "cortex-debug",
12+
"request": "launch",
13+
"name": "Debug (QEMU)",
14+
"servertype": "qemu",
15+
"cwd": "${workspaceRoot}",
16+
"preLaunchTask": "Cargo Build (debug)",
17+
"runToEntryPoint": "main",
18+
"executable": "./bootloader/target/thumbv7em-none-eabi/debug/stm-bootloader",
19+
"cpu": "cortex-m4",
20+
"machine": "lm3s6965evb",
21+
},
22+
{
23+
/* Configuration for the STM32L4R5 */
24+
"type": "cortex-debug",
25+
"request": "launch",
26+
"name": "Debug (OpenOCD)",
27+
"servertype": "openocd",
28+
"cwd": "${workspaceRoot}",
29+
"preLaunchTask": "Build and Flash onto Chip (debug)",
30+
"postLaunchCommands": ["source .vscode/openocd.gdb"],
31+
"runToEntryPoint": "main",
32+
"executable": "./bootloader/target/thumbv7em-none-eabi/debug/stm-bootloader",
33+
"configFiles": [
34+
"interface/stlink.cfg",
35+
"target/stm32l4x.cfg"
36+
]
37+
},
38+
{
39+
/* Configuration for the STM32L4R5 */
40+
"type": "cortex-debug",
41+
"request": "launch",
42+
"name": "Release (OpenOCD)",
43+
"servertype": "openocd",
44+
"cwd": "${workspaceRoot}",
45+
"preLaunchTask": "Build and Flash onto Chip (release)",
46+
"postLaunchCommands": [
47+
"source .vscode/openocd.gdb"
48+
],
49+
// Yes, this wrong executable is intentional
50+
"executable": "./bootloader/target/thumbv7em-none-eabi/debug/stm-bootloader",
51+
"configFiles": [
52+
"interface/stlink.cfg",
53+
"target/stm32l4x.cfg"
54+
]
55+
},
56+
{
57+
/* Configuration for the STM32L4R5 */
58+
"type": "cortex-debug",
59+
"request": "launch",
60+
"name": "Release broken md1 (OpenOCD)",
61+
"servertype": "openocd",
62+
"cwd": "${workspaceRoot}",
63+
"preLaunchTask": "Build and Flash onto Chip (release, broken md1)",
64+
"postLaunchCommands": [
65+
"source .vscode/openocd.gdb"
66+
],
67+
// Yes, this wrong executable is intentional
68+
"executable": "./bootloader/target/thumbv7em-none-eabi/debug/stm-bootloader",
69+
"configFiles": [
70+
"interface/stlink.cfg",
71+
"target/stm32l4x.cfg"
72+
]
73+
},
74+
{
75+
/* Configuration for the STM32L4R5 */
76+
"type": "cortex-debug",
77+
"request": "launch",
78+
"name": "Release all metadata broken (OpenOCD)",
79+
"servertype": "openocd",
80+
"cwd": "${workspaceRoot}",
81+
"preLaunchTask": "Build and Flash onto Chip (release, all metadata broken)",
82+
"postLaunchCommands": [
83+
"source .vscode/openocd.gdb"
84+
],
85+
// Yes, this wrong executable is intentional
86+
"executable": "./bootloader/target/thumbv7em-none-eabi/debug/stm-bootloader",
87+
"configFiles": [
88+
"interface/stlink.cfg",
89+
"target/stm32l4x.cfg"
90+
]
91+
}
92+
]
93+
}

.vscode/openocd.gdb

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# print demangled symbols
2+
set print asm-demangle on
3+
4+
# set backtrace limit to not have infinite backtrace loops
5+
set backtrace limit 32
6+
7+
# detect unhandled exceptions, hard faults and panics
8+
break DefaultHandler
9+
break HardFault
10+
break rust_begin_unwind
11+
# # run the next few lines so the panic message is printed immediately
12+
# # the number needs to be adjusted for your panic handler
13+
# commands $bpnum
14+
# next 4
15+
# end
16+
17+
monitor arm semihosting enable
18+
19+
# *try* to stop at the user entry point (it might be gone due to inlining)
20+
break main
21+
22+
23+
24+
# # send captured ITM to the file itm.fifo
25+
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
26+
# # 8000000 must match the core clock frequency
27+
# monitor tpiu config internal itm.txt uart off 8000000
28+
29+
# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
30+
# # 8000000 must match the core clock frequency
31+
# # 2000000 is the frequency of the SWO pin
32+
# monitor tpiu config external uart off 8000000 2000000
33+
34+
# # enable ITM port 0
35+
# monitor itm port 0 on
36+
37+
load
38+
39+
# start the process but immediately halt the processor
40+
stepi

0 commit comments

Comments
 (0)