Skip to content

Commit 4481dbf

Browse files
committed
Debug: Adds RTT support to bootloader
To support "handover" from bootloader to application, the RTT allocations are put in the same places in RAM in both projects. Without this the J-Link software will only find one of the allocations and therefore not read the other.
1 parent 821a48f commit 4481dbf

Some content is hidden

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

81 files changed

+27655
-131
lines changed

bootloader.ld

+11
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ SECTIONS
110110
. = ALIGN(4);
111111
_etext = .;
112112

113+
/* Place RTT allocations first in RAM in debug builds, so that they are
114+
* aligned between bootloader and firmware */
115+
.rtt (NOLOAD) :
116+
{
117+
. = ALIGN(4);
118+
_srtt = .;
119+
*(.segger_rtt);
120+
*(.segger_rtt_buf);
121+
_ertt = .;
122+
} > ram
123+
113124
.relocate :
114125
{
115126
. = ALIGN(4);

firmware.ld

+11
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ SECTIONS
109109
. = ALIGN(4);
110110
_etext = .;
111111

112+
/* Place RTT allocations first in RAM in debug builds, so that they are
113+
* aligned between bootloader and firmware */
114+
.rtt (NOLOAD) :
115+
{
116+
. = ALIGN(4);
117+
_srtt = .;
118+
*(.segger_rtt);
119+
*(.segger_rtt_buf);
120+
_ertt = .;
121+
} > ram
122+
112123
.relocate :
113124
{
114125
. = ALIGN(4);

src/bootloader/bootloader.c

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <memory/memory_shared.h>
2727
#include <memory/nvmctrl.h>
2828
#include <pukcc/curve_p256.h>
29+
#include <rust/rust.h>
2930
#include <screen.h>
3031
#include <ui/components/ui_images.h>
3132
#include <ui/fonts/arial_fonts.h>
@@ -206,6 +207,8 @@ void _binExec(void* l_code_addr)
206207

207208
static void _binary_exec(void)
208209
{
210+
util_log("Jumping to firmware");
211+
rust_rtt_flush();
209212
_render_bootloader_finished_marker();
210213

211214
int i;
@@ -981,6 +984,7 @@ void bootloader_jump(void)
981984
}
982985

983986
// App not entered. Start USB API to receive boot commands
987+
util_log("Not jumping to firmware");
984988
_compute_is_app_flash_empty();
985989
_render_default_screen();
986990
if (usb_start(_api_setup) != ERR_NONE) {

src/hardfault.c

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void MemManage_Handler(void)
3434

3535
void Abort(const char* msg)
3636
{
37+
util_log("%s", msg);
3738
screen_print_debug(msg, 0);
3839
usb_stop();
3940
#if !defined(TESTING)

src/platform/platform_init.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@
2020
#endif
2121
#include "rust/rust.h"
2222

23+
#if defined(BOOTLOADER)
24+
#define PREFIX "boot"
25+
#else
26+
#define PREFIX "app"
27+
#endif
28+
2329
void platform_init(void)
2430
{
2531
oled_init();
26-
#if !defined(BOOTLOADER)
2732
// The factory setup image already has a c implementation of RTT.
2833
#if FACTORYSETUP != 1
2934
// these two functions are noops if "rtt" feature isn't enabled in rust
3035
rust_rtt_init();
31-
util_log("platform_init");
36+
util_log(PREFIX ": platform_init");
3237
#endif
38+
#if !defined(BOOTLOADER)
3339
sd_mmc_start();
3440
#endif
3541
}

src/rust/.cargo/config.toml

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
[source.crates-io]
22
replace-with = "vendored-sources"
33

4+
[source."git+https://github.com/BitBoxSwiss/rtt-target.git?branch=bitbox02"]
5+
git = "https://github.com/BitBoxSwiss/rtt-target.git"
6+
branch = "bitbox02"
7+
replace-with = "vendored-sources"
8+
49
[source."git+https://github.com/digitalbitbox/rust-bip32-ed25519?tag=v0.1.2"]
510
git = "https://github.com/BitBoxSwiss/rust-bip32-ed25519"
611
tag = "v0.2.0"

src/rust/Cargo.lock

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

src/rust/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ sha2 = { version = "0.10.8", default-features = false }
3636
sha3 = { version = "0.10.8", default-features = false }
3737
zeroize = "1.7.0"
3838

39+
[patch.crates-io]
40+
rtt-target = { git = "https://github.com/BitBoxSwiss/rtt-target.git", branch = "bitbox02" }
41+
3942
[profile.release]
4043
# This only affects the .elf output. Debug info is stripped from the final .bin.
4144
# Paths to source code can still appear in the final bin, as they are part of the panic!() output.

src/rust/bitbox02-rust-c/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pub extern "C" fn rust_rtt_init() {
5656
::util::log::rtt_init();
5757
}
5858

59+
#[no_mangle]
60+
pub extern "C" fn rust_rtt_flush() {
61+
::util::log::rtt_flush();
62+
}
63+
5964
/// # Safety
6065
///
6166
/// The pointer `ptr` must point to a null terminated string

src/rust/util/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ license = "Apache-2.0"
2222

2323
[dependencies]
2424
num-bigint = { workspace = true, default-features = false }
25-
rtt-target = { version = "0.5.0", optional = true }
25+
rtt-target = { version = "0.6.1", optional = true }
2626
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"], optional = true }
2727

2828
[features]

src/rust/util/src/log.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ pub use log;
1313

1414
pub fn rtt_init() {
1515
#[cfg(feature = "rtt")]
16-
rtt_target::rtt_init_print!();
17-
log!("RTT Initialized");
16+
{
17+
let channels = rtt_target::rtt_init! {
18+
up: {
19+
0: {
20+
size: 1024,
21+
mode: rtt_target::ChannelMode::NoBlockSkip,
22+
name: "Terminal",
23+
section: ".segger_rtt_buf",
24+
}
25+
}
26+
section_cb: ".segger_rtt"
27+
};
28+
29+
rtt_target::set_print_channel(channels.up.0);
30+
31+
log!("RTT Initialized");
32+
}
33+
}
34+
35+
/// Wait until all messages have been read by host
36+
pub fn rtt_flush() {
37+
#[cfg(feature = "rtt")]
38+
rtt_target::with_terminal_channel(|c| c.flush());
1839
}

src/rust/vendor/portable-atomic/.cargo-checksum.json

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

0 commit comments

Comments
 (0)