I'm writing and testing library code (with no_std
) and can currently build it for x86
and nRF52840
(ARM Cortex M4).
Everything works fine for x86
builds -- I can use the library's API functions and the code works.
Basically there are three API calls -- keygen()
, sign()
and verify()
.
I can also build the example code and library the nRF52840
target. Some of the library's API functions work fine.
But there's at least one function (sign()
) that causes problems on the target -- just having the function call in main()
causes the program to immediately crash, i.d. I can't even use any breakpoints to start debugging, and even the previously function call (before the "trouble function") seems not to get executed.
Error message
ERROR probe_rs::architecture::arm::core::armv7m: The core is in locked up status as a result of an unrecoverable exception
opt-level = "z"
With opt-level = "z"
I get a continuously running program and when I stop with CTRL-C
in gdb
, it reads:
^C
Program received signal SIGINT, Interrupt.
lms_demo_nrf52::__cortex_m_rt_HardFault_trampoline (warning: Could not fetch required XPSR content. Further unwinding is impossible.
frame=0x1fff0058) at examples/lms_demo_nrf52.rs:19
19 #[exception]
opt-level = 0
With opt-level = 0
I can stop at a breakpoint and then continue, from there on it's similar, I have to stop via CTRL-c
and then:
^C
Program received signal SIGINT, Interrupt.
lms_demo_nrf52::__cortex_m_rt_HardFault_trampoline (frame=<error reading variable: Cannot access memory at address 0x1ffffb04>) at examples/demo_nrf52.rs:19
19 #[exception]
At line 19:
#[exception]
unsafe fn HardFault(_ef: &cortex_m_rt::ExceptionFrame) -> ! {
dk::fail();
}
Noteworthy
There's a configuration option that can be changed and then allows the sign()
function to run. It's not a fix because it's a wrong configuration, and our library code reports an error (which is the expected behaviour in that case).
It's originally not my code, but I'll try to review this to see what changes with this configuration option.
I first was assuming problems with stack allocation, but afaik, the stack should only cause trouble at runtime.
Questions
- What could possible make the program crash right at the start?
- And are there ways to debug this?
Update
Using the workaround for main()
from this post slightly changes the situation:
- when just flashing and executing the program, I get some debug output right after entering
main()
viadefmt::println!("main()");
(which wasn't there before) - when debugging, I also don't get the crash immediately, but at the
push()
- but the
keygen()
, which gets executed successfully if there's no call tosign()
, does not get executed anymore (although the code beforesign()
is unchanged)
let mut vec_hss_params: ArrayVec<[_; REF_IMPL_MAX_ALLOWED_HSS_LEVELS]> = Default::default();
let hss_parameters = HssParameter::new(
LmotsAlgorithm::LmotsW1, LmsAlgorithm::LmsH5);
vec_hss_params.push(hss_parameters);
So I'll dig into that with the debugger.