Skip to content

Commit 8ffbb5e

Browse files
committed
Merge branch 'reboot'
2 parents f1d41a8 + a6eca1c commit 8ffbb5e

File tree

17 files changed

+216
-55
lines changed

17 files changed

+216
-55
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44
- Attempt to fix flaky SD behavior
55
- Add securechip_model to DeviceInfo: ATECCC608A or ATECC608B.
6+
- Added reboot purpose for clearer UX: "Proceed to upgrade?" vs. "Go to startup settings?"
67

78
## 9.5.0 [released 2021-03-10]
89
- RestoreFrommnemonic: ported to Rust. Will now return UserAbortError on user abort instead of GenericError.

messages/system.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ syntax = "proto3";
1616
package shiftcrypto.bitbox02;
1717

1818
message RebootRequest {
19-
19+
enum Purpose {
20+
UPGRADE = 0;
21+
SETTINGS = 1;
22+
}
23+
Purpose purpose = 1;
2024
}

py/bitbox02/bitbox02/bitbox02/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
btc,
5555
common,
5656
eth,
57+
system,
5758
)
5859
from .bootloader import Bootloader

py/bitbox02/bitbox02/bitbox02/bitbox02.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
from bitbox02.communication.generated import common_pb2 as common
4545
from bitbox02.communication.generated import keystore_pb2 as keystore
4646
from bitbox02.communication.generated import antiklepto_pb2 as antiklepto
47+
48+
# pylint: disable=unused-import
49+
# We export it in __init__.py
50+
from bitbox02.communication.generated import system_pb2 as system
4751
except ModuleNotFoundError:
4852
print("Run `make py` to generate the protobuf messages")
4953
sys.exit()

py/bitbox02/bitbox02/communication/bitbox_api_protocol.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,17 @@ def _msg_query(
647647
print(response)
648648
return response
649649

650-
def reboot(self) -> bool:
651-
"""TODO: Document"""
650+
def reboot(
651+
self, purpose: system.RebootRequest.Purpose = system.RebootRequest.Purpose.UPGRADE
652+
) -> bool:
653+
"""
654+
Sends the reboot request. If the user confirms the request on the device, the device reboots
655+
into the bootloader.
656+
The purpose defines what confirmation message the user gets to see on the device.
657+
"""
652658
# pylint: disable=no-member
653659
request = hww.Request()
654-
request.reboot.CopyFrom(system.RebootRequest())
660+
request.reboot.CopyFrom(system.RebootRequest(purpose=purpose))
655661
try:
656662
self._msg_query(request)
657663
except OSError:

py/bitbox02/bitbox02/communication/generated/system_pb2.py

Lines changed: 34 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
11
# @generated by generate_proto_mypy_stubs.py. Do not edit!
22
import sys
3+
from google.protobuf.descriptor import (
4+
EnumDescriptor as google___protobuf___descriptor___EnumDescriptor,
5+
)
6+
37
from google.protobuf.message import (
48
Message as google___protobuf___message___Message,
59
)
610

11+
from typing import (
12+
List as typing___List,
13+
Optional as typing___Optional,
14+
Tuple as typing___Tuple,
15+
cast as typing___cast,
16+
)
17+
18+
from typing_extensions import (
19+
Literal as typing_extensions___Literal,
20+
)
21+
722

823
class RebootRequest(google___protobuf___message___Message):
24+
class Purpose(int):
25+
DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ...
26+
@classmethod
27+
def Name(cls, number: int) -> str: ...
28+
@classmethod
29+
def Value(cls, name: str) -> RebootRequest.Purpose: ...
30+
@classmethod
31+
def keys(cls) -> typing___List[str]: ...
32+
@classmethod
33+
def values(cls) -> typing___List[RebootRequest.Purpose]: ...
34+
@classmethod
35+
def items(cls) -> typing___List[typing___Tuple[str, RebootRequest.Purpose]]: ...
36+
UPGRADE = typing___cast(RebootRequest.Purpose, 0)
37+
SETTINGS = typing___cast(RebootRequest.Purpose, 1)
38+
UPGRADE = typing___cast(RebootRequest.Purpose, 0)
39+
SETTINGS = typing___cast(RebootRequest.Purpose, 1)
40+
41+
purpose = ... # type: RebootRequest.Purpose
942

1043
def __init__(self,
44+
*,
45+
purpose : typing___Optional[RebootRequest.Purpose] = None,
1146
) -> None: ...
1247
@classmethod
1348
def FromString(cls, s: bytes) -> RebootRequest: ...
1449
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
1550
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
51+
if sys.version_info >= (3,):
52+
def ClearField(self, field_name: typing_extensions___Literal[u"purpose"]) -> None: ...
53+
else:
54+
def ClearField(self, field_name: typing_extensions___Literal[u"purpose",b"purpose"]) -> None: ...

py/send_message.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ def _list_device_info(self) -> None:
241241
print(f"All info: {self._device.device_info()}")
242242

243243
def _reboot(self) -> None:
244-
if self._device.reboot():
244+
inp = input("Select one of: 1=upgrade; 2=go to startup settings: ").strip()
245+
purpose = {
246+
"1": bitbox02.system.RebootRequest.Purpose.UPGRADE, # pylint: disable=no-member
247+
"2": bitbox02.system.RebootRequest.Purpose.SETTINGS, # pylint: disable=no-member
248+
}[inp]
249+
if self._device.reboot(purpose=purpose):
245250
print("Device rebooted")
246251
self._stop = True
247252
else:
@@ -577,13 +582,6 @@ def _create_backup(self) -> None:
577582
except UserAbortException:
578583
print("Aborted by user")
579584

580-
def _reboot_bootloader(self) -> None:
581-
if self._device.reboot():
582-
print("Device rebooted")
583-
self._stop = True
584-
return
585-
print("User aborted")
586-
587585
def _toggle_mnemonic_passphrase(self) -> None:
588586
enabled = self._device.device_info()["mnemonic_passphrase_enabled"]
589587
try:
@@ -735,7 +733,7 @@ def _menu_init(self) -> None:
735733
("Check backup", self._check_backup),
736734
("Show mnemonic", self._show_mnemnoic_seed),
737735
("Create backup", self._create_backup),
738-
("Reboot into bootloader", self._reboot_bootloader),
736+
("Reboot into bootloader", self._reboot),
739737
("Check if SD card inserted", self._check_sd_presence),
740738
("Insert SD card", self._insert_sdcard),
741739
("Remove SD card", self._remove_sdcard),

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(DBB-FIRMWARE-SOURCES
2626
${CMAKE_SOURCE_DIR}/src/hardfault.c
2727
${CMAKE_SOURCE_DIR}/src/util.c
2828
${CMAKE_SOURCE_DIR}/src/sd.c
29+
${CMAKE_SOURCE_DIR}/src/system.c
2930
${CMAKE_SOURCE_DIR}/src/hww.c
3031
${CMAKE_SOURCE_DIR}/src/memory/bitbox02_smarteeprom.c
3132
${CMAKE_SOURCE_DIR}/src/memory/memory.c
@@ -45,7 +46,6 @@ set(DBB-FIRMWARE-SOURCES
4546
${CMAKE_SOURCE_DIR}/src/workflow/confirm_time.c
4647
${CMAKE_SOURCE_DIR}/src/workflow/idle_workflow.c
4748
${CMAKE_SOURCE_DIR}/src/workflow/password.c
48-
${CMAKE_SOURCE_DIR}/src/workflow/reboot.c
4949
${CMAKE_SOURCE_DIR}/src/workflow/restore.c
5050
${CMAKE_SOURCE_DIR}/src/workflow/orientation_screen.c
5151
${CMAKE_SOURCE_DIR}/src/workflow/status.c
@@ -423,6 +423,7 @@ add_custom_target(rust-bindgen
423423
--whitelist-function app_eth_erc20_params_get
424424
--whitelist-function app_eth_sighash
425425
--whitelist-function app_btc_address_simple
426+
--whitelist-function reboot
426427
${CMAKE_CURRENT_SOURCE_DIR}/rust/bitbox02-sys/wrapper.h --
427428
-DPB_NO_PACKED_STRUCTS=1 -DPB_FIELD_16BIT=1 -fshort-enums ${RUST_BINDGEN_FLAGS} ${RUST_INCLUDES}
428429
COMMAND

src/commander/commander.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <util.h>
3434
#include <version.h>
3535

36-
#include <workflow/reboot.h>
3736
#include <workflow/restore.h>
3837
#include <workflow/workflow.h>
3938

@@ -105,14 +104,6 @@ static commander_error_t _api_restore_backup(const RestoreBackupRequest* request
105104
}
106105
#endif
107106

108-
static commander_error_t _api_reboot(void)
109-
{
110-
if (!workflow_reboot()) {
111-
return COMMANDER_ERR_GENERIC;
112-
}
113-
return COMMANDER_OK;
114-
}
115-
116107
// ------------------------------------ Process ------------------------------------- //
117108

118109
/**
@@ -156,9 +147,6 @@ static commander_error_t _api_process(const Request* request, Response* response
156147
response->which_response = Response_success_tag;
157148
return commander_bitboxbase(&(request->request.bitboxbase));
158149
#endif
159-
case Request_reboot_tag:
160-
response->which_response = Response_success_tag;
161-
return _api_reboot();
162150
default:
163151
screen_print_debug("command unknown", 1000);
164152
return COMMANDER_ERR_INVALID_INPUT;

0 commit comments

Comments
 (0)