Skip to content

Commit d3c8f5f

Browse files
authored
Merge pull request #1437 from NickeZ/nickez/reboot-bootloader-naming
system: reboot was actually reboot_to_bootloader
2 parents 94e65f5 + 9a65990 commit d3c8f5f

File tree

9 files changed

+48
-21
lines changed

9 files changed

+48
-21
lines changed

src/memory/smarteeprom.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <screen.h>
2323
#include <stdint.h>
2424
#include <string.h>
25+
#include <system.h>
2526

2627
#define SMARTEEPROM_WRITE_MODE_UNBUFFERED (0)
2728
#define SMARTEEPROM_WRITE_MODE_BUFFERED (1)
@@ -100,7 +101,7 @@ void smarteeprom_bb02_config(void)
100101
*/
101102
if (!smarteeprom_is_enabled()) {
102103
smarteeprom_setup();
103-
_reset_mcu();
104+
reboot();
104105
}
105106
NVMCTRL->SEECFG.bit.WMODE = SMARTEEPROM_WRITE_MODE_BUFFERED;
106107
if (NVMCTRL->SEESTAT.bit.LOAD != 0) {

src/reset.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "keystore.h"
1919
#include "memory/memory.h"
2020
#include "memory/smarteeprom.h"
21+
#include "system.h"
2122

2223
#ifndef TESTING
2324
#include "securechip/securechip.h"
@@ -78,7 +79,7 @@ void reset_reset(bool status)
7879
/* Disable SmartEEPROM, so it will be erased on next reboot. */
7980
smarteeprom_disable();
8081
_show_reset_label(status);
81-
_reset_mcu();
82+
reboot();
8283
#else
8384
(void)status;
8485
#endif

src/rust/bitbox02-rust/src/hww.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ mod tests {
257257

258258
/// Can initiate noise and send the Reboot protobuf request when the device is not seeded.
259259
#[test]
260-
fn test_reboot_when_unitialized() {
260+
fn test_reboot_when_uninitialized() {
261261
mock_memory();
262262

263263
let mut make_request = init_noise();
@@ -275,7 +275,10 @@ mod tests {
275275
}));
276276
match reboot_called {
277277
Ok(()) => panic!("reboot was not called"),
278-
Err(msg) => assert_eq!(msg.downcast_ref::<&str>(), Some(&"reboot called")),
278+
Err(msg) => assert_eq!(
279+
msg.downcast_ref::<&str>(),
280+
Some(&"reboot_to_bootloader called")
281+
),
279282
}
280283
assert_eq!(
281284
mock_hal.ui.screens,
@@ -340,7 +343,10 @@ mod tests {
340343
}));
341344
match reboot_called {
342345
Ok(()) => panic!("reboot was not called"),
343-
Err(msg) => assert_eq!(msg.downcast_ref::<&str>(), Some(&"reboot called")),
346+
Err(msg) => assert_eq!(
347+
msg.downcast_ref::<&str>(),
348+
Some(&"reboot_to_bootloader called")
349+
),
344350
}
345351
assert_eq!(
346352
mock_hal.ui.screens,
@@ -454,7 +460,10 @@ mod tests {
454460
}));
455461
match reboot_called {
456462
Ok(()) => panic!("reboot was not called"),
457-
Err(msg) => assert_eq!(msg.downcast_ref::<&str>(), Some(&"reboot called")),
463+
Err(msg) => assert_eq!(
464+
msg.downcast_ref::<&str>(),
465+
Some(&"reboot_to_bootloader called")
466+
),
458467
}
459468
assert_eq!(
460469
mock_hal.ui.screens,

src/rust/bitbox02-rust/src/hww/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn can_call(request: &Request) -> bool {
161161
/// Handle a protobuf api call.
162162
async fn process_api(hal: &mut impl crate::hal::Hal, request: &Request) -> Result<Response, Error> {
163163
match request {
164-
Request::Reboot(ref request) => system::reboot(hal, request).await,
164+
Request::Reboot(ref request) => system::reboot_to_bootloader(hal, request).await,
165165
Request::DeviceInfo(_) => device_info::process(),
166166
Request::DeviceName(ref request) => set_device_name::process(hal, request).await,
167167
Request::SetPassword(ref request) => set_password::process(hal, request).await,

src/rust/bitbox02-rust/src/hww/api/system.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use pb::response::Response;
2121
use crate::hal::Ui;
2222
use crate::workflow::confirm;
2323

24-
pub async fn reboot(
24+
pub async fn reboot_to_bootloader(
2525
hal: &mut impl crate::hal::Hal,
2626
&pb::RebootRequest { purpose }: &pb::RebootRequest,
2727
) -> Result<Response, Error> {
@@ -38,7 +38,7 @@ pub async fn reboot(
3838
..Default::default()
3939
})
4040
.await?;
41-
bitbox02::reboot()
41+
bitbox02::reboot_to_bootloader()
4242
}
4343

4444
#[cfg(test)]
@@ -52,9 +52,9 @@ mod tests {
5252
use alloc::boxed::Box;
5353

5454
#[test]
55-
pub fn test_reboot() {
55+
pub fn test_reboot_to_bootloader() {
5656
let reboot_called = std::panic::catch_unwind(|| {
57-
block_on(reboot(
57+
block_on(reboot_to_bootloader(
5858
&mut TestingHal::new(),
5959
&pb::RebootRequest {
6060
purpose: Purpose::Upgrade as _,
@@ -63,17 +63,20 @@ mod tests {
6363
.unwrap();
6464
});
6565
match reboot_called {
66-
Ok(()) => panic!("reboot was not called"),
67-
Err(msg) => assert_eq!(msg.downcast_ref::<&str>(), Some(&"reboot called")),
66+
Ok(()) => panic!("reboot_to_bootloader was not called"),
67+
Err(msg) => assert_eq!(
68+
msg.downcast_ref::<&str>(),
69+
Some(&"reboot_to_bootloader called")
70+
),
6871
}
6972
}
7073

7174
#[test]
72-
pub fn test_reboot_aborted() {
75+
pub fn test_reboot_to_bootloader_aborted() {
7376
let mut mock_hal = TestingHal::new();
7477
mock_hal.ui.abort_nth(0);
7578
assert_eq!(
76-
block_on(reboot(
79+
block_on(reboot_to_bootloader(
7780
&mut mock_hal,
7881
&pb::RebootRequest {
7982
purpose: Purpose::Upgrade as _

src/rust/bitbox02-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const ALLOWLIST_FNS: &[&str] = &[
108108
"progress_set",
109109
"random_32_bytes_mcu",
110110
"random_mock_reset",
111-
"reboot",
111+
"reboot_to_bootloader",
112112
"reset_reset",
113113
"screen_print_debug",
114114
"screen_process",

src/rust/bitbox02/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ pub fn format_datetime(
212212
}
213213

214214
#[cfg(not(feature = "testing"))]
215-
pub fn reboot() -> ! {
216-
unsafe { bitbox02_sys::reboot() }
215+
pub fn reboot_to_bootloader() -> ! {
216+
unsafe { bitbox02_sys::reboot_to_bootloader() }
217217
loop {}
218218
}
219219

220220
#[cfg(feature = "testing")]
221-
pub fn reboot() -> ! {
222-
panic!("reboot called")
221+
pub fn reboot_to_bootloader() -> ! {
222+
panic!("reboot_to_bootloader called")
223223
}
224224

225225
#[cfg(any(feature = "testing", feature = "c-unit-testing"))]

src/system.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
#include "system.h"
1616
#include <memory/memory.h>
17+
#include <memory/memory_shared.h>
1718
#include <screen.h>
1819
#ifndef TESTING
1920
#include <driver_init.h>
2021
#endif
2122

22-
void reboot(void)
23+
void reboot_to_bootloader(void)
2324
{
2425
auto_enter_t auto_enter = {
2526
.value = sectrue_u8,
@@ -35,3 +36,10 @@ void reboot(void)
3536
_reset_mcu();
3637
#endif
3738
}
39+
40+
void reboot(void)
41+
{
42+
#ifndef TESTING
43+
_reset_mcu();
44+
#endif
45+
}

src/system.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#ifndef _SYSTEM_H_
1616
#define _SYSTEM_H_
1717

18+
/**
19+
* Reboots the device to bootloader
20+
*/
21+
void reboot_to_bootloader(void);
22+
1823
/**
1924
* Reboots the device.
2025
*/

0 commit comments

Comments
 (0)