Skip to content

Commit 78894e9

Browse files
committed
refactor(core/bootloader): unify bootloader event loop in rust
[no changelog]
1 parent 185785d commit 78894e9

File tree

24 files changed

+479
-594
lines changed

24 files changed

+479
-594
lines changed

core/embed/projects/bootloader/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ int bootloader_main(void) {
576576
uint32_t touched = 0;
577577
#ifndef USE_POWER_MANAGER
578578
#ifdef USE_TOUCH
579-
if (firmware_present == sectrue && stay_in_bootloader != sectrue) {
579+
if (fw.firmware_present == sectrue && stay_in_bootloader != sectrue) {
580580
// Wait until the touch controller is ready
581581
// (on hardware this may take a while)
582582
if (touch_initialized != secfalse) {

core/embed/projects/bootloader/wire/wire_iface_ble.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,11 @@ bool ble_iface_start_pairing(void) {
198198
return true;
199199
}
200200

201+
wire_iface_t* ble_iface_get(void) {
202+
if (!g_ble_iface.initialized) {
203+
return NULL;
204+
}
205+
return &g_ble_iface;
206+
}
207+
201208
#endif

core/embed/projects/bootloader/wire/wire_iface_ble.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ void ble_iface_deinit(void);
2828
bool ble_iface_start_pairing(void);
2929

3030
void ble_iface_end_pairing(void);
31+
32+
wire_iface_t* ble_iface_get(void);

core/embed/projects/bootloader/wire/wire_iface_usb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,10 @@ void usb_iface_deinit(void) {
9797
memset(iface, 0, sizeof(wire_iface_t));
9898
usb_stop();
9999
}
100+
101+
wire_iface_t* usb_iface_get(void) {
102+
if (!g_usb_iface.initialized) {
103+
return NULL;
104+
}
105+
return &g_usb_iface;
106+
}

core/embed/projects/bootloader/wire/wire_iface_usb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424

2525
wire_iface_t *usb_iface_init(secbool usb21_landing);
2626

27+
wire_iface_t *usb_iface_get(void);
28+
2729
void usb_iface_deinit(void);

core/embed/projects/bootloader/workflow/wf_auto_update.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@
3232
workflow_result_t workflow_auto_update(const fw_info_t *fw) {
3333
ui_set_initial_setup(true);
3434

35-
workflow_result_t res = WF_CANCELLED;
3635
uint32_t ui_result = CONNECT_CANCEL;
3736

3837
protob_ios_t ios;
3938

4039
workflow_ifaces_init(secfalse, &ios);
4140
notify_send(NOTIFY_UNLOCK);
4241

43-
c_layout_t layout;
44-
memset(&layout, 0, sizeof(layout));
45-
screen_connect(true, false, &layout);
46-
res = workflow_host_control(fw, &layout, &ui_result, &ios);
42+
workflow_result_t res = screen_connect(true, false, &ui_result);
4743

4844
if (res == WF_OK_UI_ACTION && ui_result == CONNECT_CANCEL) {
4945
bootargs_set(BOOT_COMMAND_NONE, NULL, 0);

core/embed/projects/bootloader/workflow/wf_ble_pairing_request.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ workflow_result_t workflow_ble_pairing_request(const fw_info_t *fw) {
5858
rgb_led_effect_start(RGB_LED_EFFECT_PAIRING, 0);
5959
#endif
6060

61-
c_layout_t layout;
62-
memset(&layout, 0, sizeof(layout));
63-
screen_pairing_mode(ui_get_initial_setup(), name, strlen(name), &layout);
64-
6561
uint32_t code = 0;
66-
workflow_result_t res = workflow_host_control(fw, &layout, &code, NULL);
62+
workflow_result_t res =
63+
screen_pairing_mode(ui_get_initial_setup(), name, strlen(name), &code);
6764

6865
#ifdef USE_RGB_LED
6966
rgb_led_effect_stop();
@@ -140,12 +137,8 @@ workflow_result_t workflow_wireless_setup(const fw_info_t *fw,
140137
rgb_led_effect_start(RGB_LED_EFFECT_PAIRING, 0);
141138
#endif
142139

143-
c_layout_t layout;
144-
memset(&layout, 0, sizeof(layout));
145-
screen_wireless_setup(name, strlen(name), &layout);
146-
147140
uint32_t code = 0;
148-
workflow_result_t res = workflow_host_control(fw, &layout, &code, ios);
141+
workflow_result_t res = screen_wireless_setup(name, strlen(name), &code);
149142

150143
#ifdef USE_RGB_LED
151144
rgb_led_effect_stop();

core/embed/projects/bootloader/workflow/wf_bootloader.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,9 @@
4141

4242
workflow_result_t workflow_menu(const fw_info_t* fw, protob_ios_t* ios) {
4343
while (true) {
44-
c_layout_t layout;
45-
memset(&layout, 0, sizeof(layout));
46-
screen_menu(ui_get_initial_setup(), &layout);
4744
uint32_t ui_result = 0;
4845
workflow_result_t result =
49-
workflow_host_control(fw, &layout, &ui_result, ios);
46+
screen_menu(ui_get_initial_setup(), ios != NULL, &ui_result);
5047

5148
if (result != WF_OK_UI_ACTION) {
5249
return result;
@@ -129,8 +126,6 @@ static screen_t handle_menu(const fw_info_t* fw,
129126

130127
static screen_t handle_wait_for_host(const fw_info_t* fw,
131128
workflow_result_t* out_result) {
132-
c_layout_t layout;
133-
memset(&layout, 0, sizeof(layout));
134129
uint32_t ui_res = 0;
135130

136131
protob_ios_t ios;
@@ -141,8 +136,7 @@ static screen_t handle_wait_for_host(const fw_info_t* fw,
141136
screen_t next_screen = SCREEN_WAIT_FOR_HOST;
142137

143138
while (next_screen == SCREEN_WAIT_FOR_HOST) {
144-
screen_connect(false, true, &layout);
145-
workflow_result_t res = workflow_host_control(fw, &layout, &ui_res, &ios);
139+
workflow_result_t res = screen_connect(false, true, &ui_res);
146140

147141
switch (res) {
148142
case WF_OK_UI_ACTION: {

core/embed/projects/bootloader/workflow/wf_empty_device.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ workflow_result_t workflow_empty_device(void) {
6868
uint32_t ui_result = WELCOME_CANCEL;
6969
while (res == WF_CANCELLED ||
7070
(res == WF_OK_UI_ACTION && ui_result == WELCOME_CANCEL)) {
71-
c_layout_t layout;
72-
memset(&layout, 0, sizeof(layout));
73-
screen_welcome(&layout);
74-
res = workflow_host_control(NULL, &layout, &ui_result, &ios);
71+
res = screen_welcome(&ui_result);
7572
#ifdef USE_BLE
7673
if (res == WF_OK_UI_ACTION && ui_result == WELCOME_PAIRING_MODE) {
7774
res = workflow_wireless_setup(NULL, &ios);

0 commit comments

Comments
 (0)