File tree 6 files changed +21
-31
lines changed
6 files changed +21
-31
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,7 @@ SECTIONS
116
116
{
117
117
. = ALIGN (4);
118
118
_srtt = .;
119
+ *(.auto_enter);
119
120
*(.segger_rtt);
120
121
*(.segger_rtt_buf);
121
122
_ertt = .;
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ SECTIONS
115
115
{
116
116
. = ALIGN (4);
117
117
_srtt = .;
118
+ *(.auto_enter);
118
119
*(.segger_rtt);
119
120
*(.segger_rtt_buf);
120
121
_ertt = .;
Original file line number Diff line number Diff line change 39
39
40
40
#include <assert.h>
41
41
42
+ // Section is fixed in ram, so can be used to communicate between fw/bl
43
+ volatile secbool_u32 auto_enter __attribute__((section (".auto_enter" )));
44
+
42
45
#define BOOT_OP_LEN 2u // 1 byte op code and 1 byte parameter
43
46
#define BOOTLOADER_CMD (HID_VENDOR_FIRST + 0x03) // Hardware wallet command
44
47
@@ -758,12 +761,7 @@ static size_t _api_versions(uint8_t* output)
758
761
759
762
static void _api_reboot (void )
760
763
{
761
- chunk_shared_t shared_data ;
762
- memory_read_shared_bootdata (& shared_data );
763
- if (shared_data .fields .auto_enter == sectrue_u8 ) {
764
- shared_data .fields .auto_enter = secfalse_u8 ;
765
- _write_chunk (FLASH_SHARED_DATA_START , shared_data .bytes );
766
- }
764
+ auto_enter = secfalse_u32 ;
767
765
_reset_mcu ();
768
766
}
769
767
@@ -977,7 +975,7 @@ void bootloader_jump(void)
977
975
978
976
UG_FontSelect (& font_font_a_9X9 );
979
977
980
- if (shared_data . fields . auto_enter != sectrue_u8 ) {
978
+ if (auto_enter != sectrue_u32 ) {
981
979
#ifdef BOOTLOADER_DEVDEVICE
982
980
if (!_devdevice_enter (_firmware_verified_jump (& bootdata , secfalse_u32 ))) {
983
981
_binary_exec ();
Original file line number Diff line number Diff line change 20
20
#include "platform_init.h"
21
21
#include "screen.h"
22
22
#include "securechip/securechip.h"
23
+ #include "system.h"
23
24
#include "usb/usb.h"
24
25
#include "usb/usb_packet.h"
25
26
#include "usb/usb_processing.h"
@@ -312,19 +313,8 @@ int main(void)
312
313
screen_splash ();
313
314
common_main ();
314
315
315
- {
316
- // Set to re-enter bootloader again, otherwise we are stuck with this
317
- // firmware forever.
318
- auto_enter_t auto_enter = {
319
- .value = sectrue_u8 ,
320
- };
321
- upside_down_t upside_down = {
322
- .value = false,
323
- };
324
- if (!memory_bootloader_set_flags (auto_enter , upside_down )) {
325
- // Not much we can do here.
326
- }
327
- }
316
+ // After reset we prefer to stay in bootloader
317
+ auto_enter = sectrue_u32 ;
328
318
329
319
SEGGER_RTT_Init ();
330
320
Original file line number Diff line number Diff line change 15
15
#include "system.h"
16
16
#include <memory/memory.h>
17
17
#include <screen.h>
18
+ #include <stdint.h>
18
19
#ifndef TESTING
19
20
#include <driver_init.h>
20
21
#endif
21
22
23
+ volatile secbool_u32 auto_enter __attribute__((section (".auto_enter" )));
24
+
22
25
void reboot (void )
23
26
{
24
- auto_enter_t auto_enter = {
25
- .value = sectrue_u8 ,
26
- };
27
- upside_down_t upside_down = {
28
- .value = screen_is_upside_down (),
29
- };
30
- if (!memory_bootloader_set_flags (auto_enter , upside_down )) {
31
- // If this failed, we might not be able to reboot into the bootloader.
32
- // We will try anyway, no point in aborting here.
33
- }
27
+ auto_enter = sectrue_u32 ;
34
28
#ifndef TESTING
35
29
_reset_mcu ();
36
30
#endif
Original file line number Diff line number Diff line change 15
15
#ifndef _SYSTEM_H_
16
16
#define _SYSTEM_H_
17
17
18
+ #include "util.h"
19
+
20
+ // Set this to `sectrue_u32` to stay in bootloader, or anything else to jump to firmware
21
+
22
+ extern volatile secbool_u32 auto_enter ;
23
+
18
24
/**
19
- * Reboots the device.
25
+ * Reboots the device into bootloader
20
26
*/
21
27
void reboot (void );
22
28
You can’t perform that action at this time.
0 commit comments