Skip to content

Commit f594b4e

Browse files
committed
simulator-ng: Initial commit
1 parent 5181916 commit f594b4e

File tree

21 files changed

+4535
-46
lines changed

21 files changed

+4535
-46
lines changed

.github/workflows/ci-common.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ jobs:
167167
- factory-setup
168168
- firmware-debug
169169
- simulator
170+
- simulator-ng
170171
runs-on: ubuntu-22.04
171172
container:
172173
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
1414
- simulator: simulate a Nova device
1515
- Add API call to fetch multiple xpubs at once
1616
- Add the option for the simulator to write its memory to file.
17+
- simulator-ng: a new simulator with a graphical user interface
1718

1819
### 9.23.2
1920
- Improve touch sensor reliability when the sdcard is inserted

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ else()
398398
include(CTest)
399399
add_subdirectory(test/unit-test)
400400
add_subdirectory(test/simulator)
401+
add_subdirectory(test/simulator-ng)
401402
if(COVERAGE)
402403
find_program(GCOVR gcovr)
403404
if(NOT GCOVR STREQUAL "GCOVR-NOTFOUND")

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ rust-docs: | build
108108
$(MAKE) -C build rust-docs
109109
simulator: | build-build-noasan
110110
$(MAKE) -C build-build-noasan simulator
111+
simulator-ng: | build-build-noasan
112+
$(MAKE) -C build-build-noasan simulator-ng
111113
run-simulator: | simulator
112114
./build-build-noasan/bin/simulator
113115
unit-test: | build-build
@@ -189,3 +191,7 @@ prepare-tidy: | build build-build
189191
$(MAKE) -C build-build rust-cbindgen
190192
clean:
191193
rm -rf build build-build build-debug build-build-noasan
194+
195+
# When you vendor rust libs avoid duplicates
196+
vendor-rust-deps:
197+
(cd external; ./vendor-rust.sh)

.cargo/config.toml renamed to src/rust/.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ branch = "bb02"
1717
replace-with = "vendored-sources"
1818

1919
[source.vendored-sources]
20-
directory = "external/vendor"
20+
directory = "../../external/vendor"

src/rust/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,16 @@ We generate one header file `rust.h` and ever product specific function is `#ifd
3838

3939
# Vendoring
4040

41-
Run the vendoring script `vendor.sh` to vendor dependencies from crates.io. The
42-
script will ensure that also rust std libs dependencies are vendored.
41+
Run the vendoring script `vendor-rust.sh` to vendor dependencies from
42+
crates.io. The script will ensure that also rust std libs dependencies are
43+
vendored.
44+
45+
When the toolchain (and standard libraries) are updated they usually depend on
46+
newer versions of crates. Update our lockfile to the same versions to avoid
47+
vendoringing duplicate versions. You can use:
48+
49+
```
50+
cargo update <package> --precise <version>
51+
```
52+
53+
to specify specific versions to up/downgrade to.

src/rust/bitbox02-rust-c/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ target-c-unit-tests = [
6868
"firmware",
6969
"c-unit-testing",
7070
]
71+
target-simulator-ng = [
72+
"dep:bitcoin", # for rust_base58_encode_check()
73+
"app-bitcoin",
74+
"app-litecoin",
75+
"app-ethereum",
76+
"app-cardano",
77+
"app-u2f",
78+
"firmware",
79+
]
7180

7281
platform-bitbox02 = []
7382
platform-bitbox02plus = ["util/sha2", "bitbox02-noise", "bitbox02-rust"]

src/rust/bitbox02-rust/src/general/screen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
use core::time::Duration;
1616

17-
use bitbox02::{delay, ug_clear_buffer, ug_font_select_9x9, ug_put_string, ug_send_buffer};
17+
use bitbox02::{delay, screen_clear, ug_font_select_9x9, ug_put_string, ug_send_buffer};
1818

1919
pub fn print_debug_internal(duration: Duration, msg: &str) {
20-
ug_clear_buffer();
20+
screen_clear();
2121
ug_font_select_9x9();
2222
ug_put_string(0, 0, msg, false);
2323
ug_send_buffer();

src/rust/bitbox02-sys/build.rs

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,62 @@ const ALLOWLIST_VARS: &[&str] = &[
2222
"BIP32_SERIALIZED_LEN",
2323
"BIP39_WORDLIST_LEN",
2424
"EC_PUBLIC_KEY_LEN",
25+
"font_font_a_11X10",
26+
"font_font_a_9X9",
27+
"font_monogram_5X9",
28+
"font_password_11X12",
2529
"INPUT_STRING_MAX_SIZE",
2630
"KEYSTORE_MAX_SEED_LENGTH",
2731
"MAX_LABEL_SIZE",
2832
"MAX_PK_SCRIPT_SIZE",
33+
"MAX_UNLOCK_ATTEMPTS",
2934
"MAX_VARINT_SIZE",
3035
"MEMORY_DEVICE_NAME_MAX_LEN",
3136
"MEMORY_MULTISIG_NAME_MAX_LEN",
32-
"SD_MAX_FILE_SIZE",
33-
"XPUB_ENCODED_LEN",
34-
"font_font_a_11X10",
35-
"font_font_a_9X9",
36-
"font_monogram_5X9",
37-
"font_password_11X12",
38-
"MEMORY_SPI_BLE_FIRMWARE_MAX_SIZE",
39-
"MEMORY_SPI_BLE_FIRMWARE_1_ADDR",
40-
"MEMORY_SPI_BLE_FIRMWARE_2_ADDR",
41-
"MEMORY_PLATFORM_BITBOX02",
4237
"MEMORY_PLATFORM_BITBOX02_PLUS",
38+
"MEMORY_PLATFORM_BITBOX02",
4339
"MEMORY_SECURECHIP_TYPE_ATECC",
4440
"MEMORY_SECURECHIP_TYPE_OPTIGA",
45-
"MAX_UNLOCK_ATTEMPTS",
41+
"MEMORY_SPI_BLE_FIRMWARE_1_ADDR",
42+
"MEMORY_SPI_BLE_FIRMWARE_2_ADDR",
43+
"MEMORY_SPI_BLE_FIRMWARE_MAX_SIZE",
44+
"SCREEN_HEIGHT",
45+
"SCREEN_WIDTH",
46+
"SD_MAX_FILE_SIZE",
47+
"SLIDER_POSITION_TWO_THIRD",
48+
"XPUB_ENCODED_LEN",
4649
];
4750

4851
const ALLOWLIST_TYPES: &[&str] = &[
4952
"buffer_t",
5053
"component_t",
5154
"confirm_params_t",
55+
"event_types",
56+
"event_slider_data_t",
5257
"trinary_input_string_params_t",
58+
"UG_COLOR",
5359
];
5460

5561
const ALLOWLIST_FNS: &[&str] = &[
56-
"UG_ClearBuffer",
57-
"UG_FontSelect",
58-
"UG_PutString",
59-
"UG_SendBuffer",
6062
"bip32_derive_xpub",
61-
"bitbox02_smarteeprom_init",
6263
"bitbox_secp256k1_dleq_prove",
6364
"bitbox_secp256k1_dleq_verify",
65+
"bitbox02_smarteeprom_init",
66+
"communication_mode_ble_enabled",
6467
"confirm_create",
6568
"confirm_transaction_address_create",
6669
"confirm_transaction_fee_create",
6770
"delay_ms",
6871
"delay_us",
72+
"emit_event",
6973
"empty_create",
74+
"fake_memory_factoryreset",
75+
"fake_securechip_event_counter_reset",
76+
"fake_securechip_event_counter",
77+
"hww_setup",
7078
"keystore_bip39_mnemonic_to_seed",
71-
"keystore_copy_seed",
7279
"keystore_copy_bip39_seed",
80+
"keystore_copy_seed",
7381
"keystore_create_and_store_seed",
7482
"keystore_encrypt_and_store_seed",
7583
"keystore_get_bip39_word",
@@ -78,59 +86,63 @@ const ALLOWLIST_FNS: &[&str] = &[
7886
"keystore_mock_unlocked",
7987
"keystore_secp256k1_nonce_commit",
8088
"keystore_secp256k1_sign",
81-
"keystore_unlock",
89+
"keystore_test_get_retained_bip39_seed_encrypted",
90+
"keystore_test_get_retained_seed_encrypted",
8291
"keystore_unlock_bip39_check",
8392
"keystore_unlock_bip39_finalize",
84-
"keystore_test_get_retained_seed_encrypted",
85-
"keystore_test_get_retained_bip39_seed_encrypted",
93+
"keystore_unlock_bip39",
94+
"keystore_unlock",
8695
"label_create",
8796
"localtime",
8897
"lock_animation_start",
8998
"lock_animation_stop",
90-
"memory_set_salt_root",
9199
"memory_add_noise_remote_static_pubkey",
100+
"memory_ble_enable",
101+
"memory_ble_enabled",
92102
"memory_bootloader_hash",
93103
"memory_check_noise_remote_static_pubkey",
94104
"memory_get_attestation_bootloader_hash",
95105
"memory_get_attestation_pubkey_and_certificate",
96-
"memory_get_encrypted_seed_and_hmac",
106+
"memory_get_ble_metadata",
97107
"memory_get_device_name",
108+
"memory_get_encrypted_seed_and_hmac",
98109
"memory_get_noise_static_private_key",
110+
"memory_get_platform",
111+
"memory_get_securechip_type",
99112
"memory_get_seed_birthdate",
100113
"memory_is_initialized",
101114
"memory_is_mnemonic_passphrase_enabled",
102115
"memory_is_seeded",
103116
"memory_multisig_get_by_hash",
104117
"memory_multisig_set_by_hash",
118+
"memory_set_ble_metadata",
105119
"memory_set_device_name",
106120
"memory_set_initialized",
107121
"memory_set_mnemonic_passphrase_enabled",
122+
"memory_set_salt_root",
108123
"memory_set_seed_birthdate",
109124
"memory_setup",
110-
"memory_ble_enabled",
111-
"memory_ble_enable",
112-
"memory_get_ble_metadata",
113-
"memory_set_ble_metadata",
114-
"memory_get_platform",
115-
"memory_get_securechip_type",
116125
"memory_spi_get_active_ble_firmware_version",
117-
"spi_mem_protected_area_write",
118126
"menu_create",
119-
"fake_memory_factoryreset",
120-
"spi_mem_full_erase",
127+
"orientation_screen",
121128
"printf",
122129
"progress_create",
123130
"progress_set",
131+
"queue_hww_queue",
132+
"queue_pull",
124133
"random_32_bytes_mcu",
125134
"random_32_bytes",
126135
"random_fake_reset",
127136
"reboot_to_bootloader",
128-
"reset_reset",
129137
"reset_ble",
138+
"reset_reset",
139+
"screen_clear",
140+
"screen_init",
130141
"screen_print_debug",
131142
"screen_process",
132143
"screen_saver_disable",
133144
"screen_saver_enable",
145+
"screen_splash",
134146
"sd_card_inserted",
135147
"sd_erase_file_in_subdir",
136148
"sd_format",
@@ -144,23 +156,31 @@ const ALLOWLIST_FNS: &[&str] = &[
144156
"securechip_model",
145157
"securechip_monotonic_increments_remaining",
146158
"securechip_u2f_counter_set",
147-
"fake_securechip_event_counter",
148-
"fake_securechip_event_counter_reset",
149-
"smarteeprom_is_enabled",
150-
"smarteeprom_disable",
151159
"smarteeprom_bb02_config",
160+
"smarteeprom_disable",
161+
"smarteeprom_is_enabled",
162+
"spi_mem_full_erase",
163+
"spi_mem_protected_area_write",
152164
"status_create",
153165
"trinary_choice_create",
154166
"trinary_input_string_create",
155167
"trinary_input_string_set_input",
156-
"ui_screen_stack_pop",
168+
"UG_ClearBuffer",
169+
"UG_FontSelect",
170+
"UG_PutString",
171+
"UG_SendBuffer",
157172
"ui_screen_stack_pop_all",
173+
"ui_screen_stack_pop",
158174
"ui_screen_stack_push",
175+
"usb_packet_process",
176+
"usb_processing_hww",
177+
"usb_processing_init",
178+
"usb_processing_process",
159179
"util_format_datetime",
160-
"communication_mode_ble_enabled",
161180
];
162181

163182
const RUSTIFIED_ENUMS: &[&str] = &[
183+
"event_types",
164184
"keystore_error_t",
165185
"keystore_secp256k1_pubkey_format",
166186
"memory_result_t",

src/rust/bitbox02-sys/wrapper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@
5050
#include <ui/screen_stack.h>
5151
#include <ui/ugui/ugui.h>
5252
#include <util.h>
53+
#include <workflow/orientation_screen.h>
5354

5455
#if defined(TESTING)
5556
#include <fake_memory.h>
57+
#include <hww.h>
58+
#include <touch/gestures.h>
59+
#include <ui/event.h>
60+
#include <ui/event_handler.h>
61+
#include <usb/usb_packet.h>
62+
#include <usb/usb_processing.h>
5663
#endif
5764

5865
#if !defined(TESTING)

0 commit comments

Comments
 (0)