Skip to content

Commit 42bda93

Browse files
authored
Merge pull request #1362 from NickeZ/nickez/bootloader-rtt
Debug: Adds RTT support to bootloader
2 parents 5f96d5e + fb44047 commit 42bda93

Some content is hidden

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

84 files changed

+27677
-136
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

+3
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ void _binExec(void* l_code_addr)
207207

208208
static void _binary_exec(void)
209209
{
210+
util_log("Jumping to firmware");
211+
util_log_flush();
210212
_render_bootloader_finished_marker();
211213

212214
int i;
@@ -988,6 +990,7 @@ void bootloader_jump(void)
988990
}
989991

990992
// App not entered. Start USB API to receive boot commands
993+
util_log("Not jumping to firmware");
991994
_compute_is_app_flash_empty();
992995
_render_default_screen();
993996
if (usb_start(_api_setup) != ERR_NONE) {

src/hardfault.c

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

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

src/optiga/pal/pal_os_datastore.c

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pal_status_t pal_os_datastore_write(uint16_t datastore_id, const uint8_t* p_buff
4949
{
5050
(void)p_buffer;
5151
(void)length;
52+
(void)datastore_id;
5253
util_log("pal_datastore_write, id=%d", datastore_id);
5354
return PAL_STATUS_FAILURE;
5455
}

src/platform/platform_init.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@
1818
#if !defined(BOOTLOADER)
1919
#include "sd_mmc/sd_mmc_start.h"
2020
#endif
21-
#include "rust/rust.h"
21+
#include "util.h"
22+
23+
#if defined(BOOTLOADER)
24+
#define PREFIX "boot"
25+
#else
26+
#define PREFIX "fw"
27+
#endif
2228

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
30-
rust_rtt_init();
31-
util_log("platform_init");
35+
util_log_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/probe-rs/rtt-target.git?rev=117d9519a5d3b1f4bc024bc05f9e3c5dec0a57f5"]
5+
git = "https://github.com/probe-rs/rtt-target.git"
6+
rev = "117d9519a5d3b1f4bc024bc05f9e3c5dec0a57f5"
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

+9-3
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/probe-rs/rtt-target.git", rev = "117d9519a5d3b1f4bc024bc05f9e3c5dec0a57f5" }
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
@@ -59,6 +59,11 @@ pub extern "C" fn rust_rtt_init() {
5959
::util::log::rtt_init();
6060
}
6161

62+
#[no_mangle]
63+
pub extern "C" fn rust_rtt_flush() {
64+
::util::log::rtt_flush();
65+
}
66+
6267
/// # Safety
6368
///
6469
/// 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)