Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug: Adds RTT support to bootloader #1362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bootloader.ld
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ SECTIONS
. = ALIGN(4);
_etext = .;

/* Place RTT allocations first in RAM in debug builds, so that they are
* aligned between bootloader and firmware */
.rtt (NOLOAD) :
{
. = ALIGN(4);
_srtt = .;
*(.segger_rtt);
*(.segger_rtt_buf);
_ertt = .;
} > ram

.relocate :
{
. = ALIGN(4);
Expand Down
11 changes: 11 additions & 0 deletions firmware.ld
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ SECTIONS
. = ALIGN(4);
_etext = .;

/* Place RTT allocations first in RAM in debug builds, so that they are
* aligned between bootloader and firmware */
.rtt (NOLOAD) :
{
. = ALIGN(4);
_srtt = .;
*(.segger_rtt);
*(.segger_rtt_buf);
_ertt = .;
} > ram

.relocate :
{
. = ALIGN(4);
Expand Down
3 changes: 3 additions & 0 deletions src/bootloader/bootloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ void _binExec(void* l_code_addr)

static void _binary_exec(void)
{
util_log("Jumping to firmware");
util_log_flush();
_render_bootloader_finished_marker();

int i;
Expand Down Expand Up @@ -981,6 +983,7 @@ void bootloader_jump(void)
}

// App not entered. Start USB API to receive boot commands
util_log("Not jumping to firmware");
_compute_is_app_flash_empty();
_render_default_screen();
if (usb_start(_api_setup) != ERR_NONE) {
Expand Down
1 change: 1 addition & 0 deletions src/hardfault.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void MemManage_Handler(void)

void Abort(const char* msg)
{
util_log("%s", msg);
screen_print_debug(msg, 0);
usb_stop();
#if !defined(TESTING)
Expand Down
1 change: 1 addition & 0 deletions src/optiga/pal/pal_os_datastore.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pal_status_t pal_os_datastore_write(uint16_t datastore_id, const uint8_t* p_buff
{
(void)p_buffer;
(void)length;
(void)datastore_id;
util_log("pal_datastore_write, id=%d", datastore_id);
return PAL_STATUS_FAILURE;
}
Expand Down
14 changes: 10 additions & 4 deletions src/platform/platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@
#if !defined(BOOTLOADER)
#include "sd_mmc/sd_mmc_start.h"
#endif
#include "rust/rust.h"
#include "util.h"

#if defined(BOOTLOADER)
#define PREFIX "boot"
#else
#define PREFIX "fw"
#endif

void platform_init(void)
{
oled_init();
#if !defined(BOOTLOADER)
// The factory setup image already has a c implementation of RTT.
#if FACTORYSETUP != 1
// these two functions are noops if "rtt" feature isn't enabled in rust
rust_rtt_init();
util_log("platform_init");
util_log_init();
util_log(PREFIX ": platform_init");
#endif
#if !defined(BOOTLOADER)
sd_mmc_start();
#endif
}
5 changes: 5 additions & 0 deletions src/rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[source.crates-io]
replace-with = "vendored-sources"

[source."git+https://github.com/BitBoxSwiss/rtt-target.git?branch=bitbox02"]
git = "https://github.com/BitBoxSwiss/rtt-target.git"
branch = "bitbox02"
replace-with = "vendored-sources"

[source."git+https://github.com/digitalbitbox/rust-bip32-ed25519?tag=v0.1.2"]
git = "https://github.com/BitBoxSwiss/rust-bip32-ed25519"
tag = "v0.2.0"
Expand Down
14 changes: 10 additions & 4 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ sha2 = { version = "0.10.8", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
zeroize = "1.7.0"

[patch.crates-io]
rtt-target = { git = "https://github.com/BitBoxSwiss/rtt-target.git", branch = "bitbox02" }

[profile.release]
# This only affects the .elf output. Debug info is stripped from the final .bin.
# Paths to source code can still appear in the final bin, as they are part of the panic!() output.
Expand Down
5 changes: 5 additions & 0 deletions src/rust/bitbox02-rust-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ pub extern "C" fn rust_rtt_init() {
::util::log::rtt_init();
}

#[no_mangle]
pub extern "C" fn rust_rtt_flush() {
::util::log::rtt_flush();
}

/// # Safety
///
/// The pointer `ptr` must point to a null terminated string
Expand Down
2 changes: 1 addition & 1 deletion src/rust/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ license = "Apache-2.0"

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

[features]
Expand Down
25 changes: 23 additions & 2 deletions src/rust/util/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ pub use log;

pub fn rtt_init() {
#[cfg(feature = "rtt")]
rtt_target::rtt_init_print!();
log!("RTT Initialized");
{
let channels = rtt_target::rtt_init! {
up: {
0: {
size: 1024,
mode: rtt_target::ChannelMode::NoBlockSkip,
name: "Terminal",
section: ".segger_rtt_buf",
}
}
section_cb: ".segger_rtt"
};

rtt_target::set_print_channel(channels.up.0);

log!("RTT Initialized");
}
}

/// Wait until all messages have been read by host
pub fn rtt_flush() {
#[cfg(feature = "rtt")]
rtt_target::with_terminal_channel(|c| c.flush());
}
1 change: 1 addition & 0 deletions src/rust/vendor/portable-atomic/.cargo-checksum.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading