2021-03-23 12:14:33 +00:00
|
|
|
#![cfg_attr(not(test), no_std)]
|
|
|
|
#![deny(clippy::all)]
|
2021-10-06 21:21:47 +00:00
|
|
|
#![allow(clippy::new_without_default)]
|
2021-03-23 12:14:33 +00:00
|
|
|
#![deny(unsafe_op_in_unsafe_fn)]
|
2023-05-04 14:00:00 +00:00
|
|
|
// Allowing dead code not to cause a lot of warnings when building for a specific target
|
|
|
|
// (when building for TR, a lot of code only used in TT would get marked as unused).
|
2021-03-23 12:14:33 +00:00
|
|
|
#![allow(dead_code)]
|
2022-09-20 08:29:28 +00:00
|
|
|
#![feature(lang_items)]
|
2023-01-03 12:09:32 +00:00
|
|
|
#![feature(optimize_attribute)]
|
2021-03-23 12:14:33 +00:00
|
|
|
|
2022-08-16 14:51:10 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate num_derive;
|
|
|
|
|
2023-05-12 09:19:35 +00:00
|
|
|
#[macro_use]
|
2021-03-23 12:14:33 +00:00
|
|
|
mod error;
|
2022-06-16 13:40:33 +00:00
|
|
|
// use trezorhal for its macros early
|
|
|
|
#[macro_use]
|
|
|
|
mod trezorhal;
|
2023-04-13 14:01:40 +00:00
|
|
|
mod maybe_trace;
|
2022-06-08 08:31:23 +00:00
|
|
|
#[cfg(feature = "micropython")]
|
2021-03-23 12:14:33 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod micropython;
|
2022-06-08 08:31:23 +00:00
|
|
|
#[cfg(feature = "protobuf")]
|
2021-03-23 12:30:03 +00:00
|
|
|
mod protobuf;
|
2022-10-13 11:37:02 +00:00
|
|
|
mod storage;
|
2021-10-24 09:29:44 +00:00
|
|
|
mod time;
|
2021-06-08 11:29:03 +00:00
|
|
|
#[cfg(feature = "ui_debug")]
|
|
|
|
mod trace;
|
|
|
|
|
|
|
|
#[cfg(feature = "ui")]
|
|
|
|
#[macro_use]
|
2022-02-11 14:01:29 +00:00
|
|
|
pub mod ui;
|
2022-05-05 11:47:19 +00:00
|
|
|
pub mod strutil;
|
2021-03-23 12:14:33 +00:00
|
|
|
|
2022-07-20 09:18:56 +00:00
|
|
|
#[cfg(feature = "debug")]
|
|
|
|
#[panic_handler]
|
|
|
|
/// More detailed panic handling. The difference against
|
|
|
|
/// default `panic` below is that this "debug" version
|
|
|
|
/// takes around 10 kB more space in the flash region.
|
|
|
|
fn panic_debug(panic_info: &core::panic::PanicInfo) -> ! {
|
|
|
|
// Filling at least the file and line information, if available.
|
|
|
|
// TODO: find out how to display message from panic_info.message()
|
2022-08-24 15:03:55 +00:00
|
|
|
|
2022-07-20 09:18:56 +00:00
|
|
|
if let Some(location) = panic_info.location() {
|
2022-08-24 15:03:55 +00:00
|
|
|
let file = location.file();
|
2023-05-04 14:00:00 +00:00
|
|
|
print!(file);
|
|
|
|
print!(":");
|
|
|
|
println!(inttostr!(location.line()));
|
2022-08-24 15:03:55 +00:00
|
|
|
trezorhal::fatal_error::__fatal_error("", "rs", file, location.line(), "");
|
2022-07-20 09:18:56 +00:00
|
|
|
} else {
|
2022-08-24 15:03:55 +00:00
|
|
|
trezorhal::fatal_error::__fatal_error("", "rs", "", 0, "");
|
2022-07-20 09:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "debug"))]
|
2022-02-11 14:01:29 +00:00
|
|
|
#[cfg(not(test))]
|
2022-05-10 13:03:20 +00:00
|
|
|
#[cfg(any(not(feature = "test"), feature = "clippy"))]
|
2021-03-23 12:14:33 +00:00
|
|
|
#[panic_handler]
|
2022-07-20 09:18:56 +00:00
|
|
|
/// Default panic handling. Not showing any details - thus saving flash space.
|
2021-10-06 21:21:47 +00:00
|
|
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
2022-06-16 13:40:33 +00:00
|
|
|
// TODO: as of Rust 1.63 / nightly 2022-08, ignoring the `_info` parameter does
|
|
|
|
// not help with saving flash space -- the `fmt` machinery still gets
|
|
|
|
// compiled in. We can avoid that by using unstable Cargo arguments:
|
|
|
|
// -Zbuild-std=core -Zbuild-std-features=panic_immediate_abort
|
|
|
|
// Doing that will compile every panic!() to a single udf instruction which
|
|
|
|
// raises a Hard Fault on hardware.
|
|
|
|
//
|
|
|
|
// Otherwise, use `unwrap!` macro from trezorhal.
|
2022-08-24 15:03:55 +00:00
|
|
|
fatal_error!("", "rs");
|
2021-03-23 12:14:33 +00:00
|
|
|
}
|
2022-09-20 08:29:28 +00:00
|
|
|
|
|
|
|
#[cfg(not(target_arch = "arm"))]
|
|
|
|
#[cfg(not(test))]
|
|
|
|
#[cfg(any(not(feature = "test"), feature = "clippy"))]
|
|
|
|
#[lang = "eh_personality"]
|
|
|
|
/// Needed by full debuginfo `opt-level = 0` builds for some reason.
|
|
|
|
extern "C" fn eh_personality() {}
|