mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-02 04:42:33 +00:00
refactor(core): conditional inclusion of BLE
This commit is contained in:
parent
03dee83036
commit
e1381f901b
@ -18,7 +18,7 @@ FEATURE_FLAGS = {
|
|||||||
"SYSTEM_VIEW": False,
|
"SYSTEM_VIEW": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", dma2d"]
|
FEATURES_WANTED = ["input", "sbu", "sd_card", "rgb_led", "ble", "dma2d"]
|
||||||
|
|
||||||
CCFLAGS_MOD = ''
|
CCFLAGS_MOD = ''
|
||||||
CPPPATH_MOD = []
|
CPPPATH_MOD = []
|
||||||
@ -379,10 +379,6 @@ SOURCE_TREZORHAL = [
|
|||||||
'embed/trezorhal/usbd_ioreq.c',
|
'embed/trezorhal/usbd_ioreq.c',
|
||||||
'embed/trezorhal/util.s',
|
'embed/trezorhal/util.s',
|
||||||
'embed/trezorhal/vectortable.s',
|
'embed/trezorhal/vectortable.s',
|
||||||
'embed/trezorhal/ble/comm.c',
|
|
||||||
'embed/trezorhal/ble/dfu.c',
|
|
||||||
'embed/trezorhal/ble/fwu.c',
|
|
||||||
'embed/trezorhal/ble/state.c',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +131,9 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
ret->items[1] = usb_connected ? mp_const_true : mp_const_false;
|
ret->items[1] = usb_connected ? mp_const_true : mp_const_false;
|
||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
} else if (iface == BLE_EVENTS_IFACE) {
|
}
|
||||||
|
#ifdef USE_BLE
|
||||||
|
else if (iface == BLE_EVENTS_IFACE) {
|
||||||
ble_event_poll();
|
ble_event_poll();
|
||||||
uint8_t connected = ble_connected();
|
uint8_t connected = ble_connected();
|
||||||
if (connected != ble_connected_previously) {
|
if (connected != ble_connected_previously) {
|
||||||
@ -142,6 +144,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#if USE_BUTTON
|
#if USE_BUTTON
|
||||||
else if (iface == BUTTON_IFACE) {
|
else if (iface == BUTTON_IFACE) {
|
||||||
const uint32_t evt = button_read();
|
const uint32_t evt = button_read();
|
||||||
@ -190,7 +193,9 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (iface == BLE_IFACE_INT) {
|
}
|
||||||
|
#ifdef USE_BLE
|
||||||
|
else if (iface == BLE_IFACE_INT) {
|
||||||
if (mode == POLL_READ) {
|
if (mode == POLL_READ) {
|
||||||
uint8_t buf[64] = {0};
|
uint8_t buf[64] = {0};
|
||||||
int len = ble_int_comm_receive(buf, sizeof(buf));
|
int len = ble_int_comm_receive(buf, sizeof(buf));
|
||||||
@ -219,6 +224,7 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
|
|||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mp_hal_ticks_ms() >= deadline) {
|
if (mp_hal_ticks_ms() >= deadline) {
|
||||||
|
@ -50,7 +50,9 @@ bool ble_last_internal = false;
|
|||||||
#include "modtrezorio-webusb.h"
|
#include "modtrezorio-webusb.h"
|
||||||
#include "modtrezorio-usb.h"
|
#include "modtrezorio-usb.h"
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
#ifdef USE_BLE
|
||||||
#include "modtrezorio-ble.h"
|
#include "modtrezorio-ble.h"
|
||||||
|
#endif
|
||||||
#ifdef USE_SBU
|
#ifdef USE_SBU
|
||||||
#include "modtrezorio-sbu.h"
|
#include "modtrezorio-sbu.h"
|
||||||
#endif
|
#endif
|
||||||
@ -92,8 +94,9 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
|
|||||||
{MP_ROM_QSTR(MP_QSTR_fatfs), MP_ROM_PTR(&mod_trezorio_fatfs_module)},
|
{MP_ROM_QSTR(MP_QSTR_fatfs), MP_ROM_PTR(&mod_trezorio_fatfs_module)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_sdcard), MP_ROM_PTR(&mod_trezorio_sdcard_module)},
|
{MP_ROM_QSTR(MP_QSTR_sdcard), MP_ROM_PTR(&mod_trezorio_sdcard_module)},
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_BLE
|
||||||
{MP_ROM_QSTR(MP_QSTR_ble), MP_ROM_PTR(&mod_trezorio_BLE_module)},
|
{MP_ROM_QSTR(MP_QSTR_ble), MP_ROM_PTR(&mod_trezorio_BLE_module)},
|
||||||
|
#endif
|
||||||
#ifdef USE_TOUCH
|
#ifdef USE_TOUCH
|
||||||
{MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_INT(TOUCH_IFACE)},
|
{MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_INT(TOUCH_IFACE)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_ROM_INT((TOUCH_START >> 24) & 0xFFU)},
|
{MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_ROM_INT((TOUCH_START >> 24) & 0xFFU)},
|
||||||
|
@ -230,6 +230,7 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
|
|||||||
/// VERSION_MAJOR: int
|
/// VERSION_MAJOR: int
|
||||||
/// VERSION_MINOR: int
|
/// VERSION_MINOR: int
|
||||||
/// VERSION_PATCH: int
|
/// VERSION_PATCH: int
|
||||||
|
/// USE_BLE: bool
|
||||||
/// USE_SD_CARD: bool
|
/// USE_SD_CARD: bool
|
||||||
/// MODEL: str
|
/// MODEL: str
|
||||||
/// EMULATOR: bool
|
/// EMULATOR: bool
|
||||||
@ -257,6 +258,11 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
|
|||||||
#else
|
#else
|
||||||
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_false},
|
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_false},
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_BLE
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_USE_BLE), mp_const_true},
|
||||||
|
#else
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_USE_BLE), mp_const_false},
|
||||||
|
#endif
|
||||||
#if defined TREZOR_MODEL_1
|
#if defined TREZOR_MODEL_1
|
||||||
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MP_QSTR_1)},
|
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MP_QSTR_1)},
|
||||||
#elif defined TREZOR_MODEL_T
|
#elif defined TREZOR_MODEL_T
|
||||||
|
@ -63,6 +63,9 @@
|
|||||||
#ifdef USE_SD_CARD
|
#ifdef USE_SD_CARD
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_BLE
|
||||||
|
#include "ble/comm.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SYSTEM_VIEW
|
#ifdef SYSTEM_VIEW
|
||||||
#include "systemview.h"
|
#include "systemview.h"
|
||||||
@ -73,8 +76,6 @@
|
|||||||
#ifdef USE_SECP256K1_ZKP
|
#ifdef USE_SECP256K1_ZKP
|
||||||
#include "zkp_context.h"
|
#include "zkp_context.h"
|
||||||
|
|
||||||
#include "ble/comm.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// from util.s
|
// from util.s
|
||||||
@ -146,7 +147,9 @@ int main(void) {
|
|||||||
sdcard_init();
|
sdcard_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_BLE
|
||||||
ble_comm_init();
|
ble_comm_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined TREZOR_MODEL_1
|
#if !defined TREZOR_MODEL_1
|
||||||
// jump to unprivileged mode
|
// jump to unprivileged mode
|
||||||
|
@ -69,6 +69,7 @@ SCM_REVISION: bytes
|
|||||||
VERSION_MAJOR: int
|
VERSION_MAJOR: int
|
||||||
VERSION_MINOR: int
|
VERSION_MINOR: int
|
||||||
VERSION_PATCH: int
|
VERSION_PATCH: int
|
||||||
|
USE_BLE: bool
|
||||||
USE_SD_CARD: bool
|
USE_SD_CARD: bool
|
||||||
MODEL: str
|
MODEL: str
|
||||||
EMULATOR: bool
|
EMULATOR: bool
|
||||||
|
@ -4,7 +4,6 @@ if TYPE_CHECKING:
|
|||||||
from trezor.wire import Handler, Msg
|
from trezor.wire import Handler, Msg
|
||||||
from trezorio import WireInterface
|
from trezorio import WireInterface
|
||||||
|
|
||||||
|
|
||||||
workflow_handlers: dict[int, Handler] = {}
|
workflow_handlers: dict[int, Handler] = {}
|
||||||
|
|
||||||
|
|
||||||
@ -55,17 +54,17 @@ def _find_message_handler_module(msg_type: int, iface: WireInterface) -> str:
|
|||||||
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:
|
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:
|
||||||
return "apps.management.sd_protect"
|
return "apps.management.sd_protect"
|
||||||
|
|
||||||
# BLE
|
if utils.USE_BLE:
|
||||||
if iface.iface_num() != 16 and iface.iface_num() != 17:
|
if iface.iface_num() != 16 and iface.iface_num() != 17:
|
||||||
# cannot update over BLE
|
# cannot update over BLE
|
||||||
if msg_type == MessageType.UploadBLEFirmwareInit:
|
if msg_type == MessageType.UploadBLEFirmwareInit:
|
||||||
return "apps.management.ble.upload_ble_firmware_init"
|
return "apps.management.ble.upload_ble_firmware_init"
|
||||||
|
|
||||||
if iface.iface_num() == 16:
|
if iface.iface_num() == 16:
|
||||||
if msg_type == MessageType.PairingRequest:
|
if msg_type == MessageType.PairingRequest:
|
||||||
return "apps.management.ble.pairing_request"
|
return "apps.management.ble.pairing_request"
|
||||||
if msg_type == MessageType.RepairRequest:
|
if msg_type == MessageType.RepairRequest:
|
||||||
return "apps.management.ble.repair_request"
|
return "apps.management.ble.repair_request"
|
||||||
|
|
||||||
# bitcoin
|
# bitcoin
|
||||||
if msg_type == MessageType.AuthorizeCoinJoin:
|
if msg_type == MessageType.AuthorizeCoinJoin:
|
||||||
|
@ -3,7 +3,6 @@ from mutex import Mutex
|
|||||||
from trezor import log, loop, utils, wire, workflow
|
from trezor import log, loop, utils, wire, workflow
|
||||||
|
|
||||||
import apps.base
|
import apps.base
|
||||||
import bluetooth
|
|
||||||
import usb
|
import usb
|
||||||
|
|
||||||
apps.base.boot()
|
apps.base.boot()
|
||||||
@ -27,15 +26,19 @@ mutex = Mutex()
|
|||||||
|
|
||||||
mutex.add(usb.iface_wire.iface_num())
|
mutex.add(usb.iface_wire.iface_num())
|
||||||
mutex.add(usb.iface_debug.iface_num())
|
mutex.add(usb.iface_debug.iface_num())
|
||||||
mutex.add(bluetooth.iface_ble_int.iface_num())
|
|
||||||
mutex.add(bluetooth.iface_ble_ext.iface_num())
|
|
||||||
|
|
||||||
# initialize the wire codec
|
# initialize the wire codec
|
||||||
wire.setup(usb.iface_wire, mutex=mutex)
|
wire.setup(usb.iface_wire, mutex=mutex)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
wire.setup(usb.iface_debug, is_debug_session=True, mutex=mutex)
|
wire.setup(usb.iface_debug, is_debug_session=True, mutex=mutex)
|
||||||
wire.setup(bluetooth.iface_ble_int, mutex=mutex)
|
|
||||||
wire.setup(bluetooth.iface_ble_ext, mutex=mutex)
|
if utils.USE_BLE:
|
||||||
|
import bluetooth
|
||||||
|
|
||||||
|
mutex.add(bluetooth.iface_ble_int.iface_num())
|
||||||
|
mutex.add(bluetooth.iface_ble_ext.iface_num())
|
||||||
|
wire.setup(bluetooth.iface_ble_int, mutex=mutex)
|
||||||
|
wire.setup(bluetooth.iface_ble_ext, mutex=mutex)
|
||||||
|
|
||||||
|
|
||||||
loop.run()
|
loop.run()
|
||||||
|
@ -5,6 +5,7 @@ from trezorutils import ( # noqa: F401
|
|||||||
EMULATOR,
|
EMULATOR,
|
||||||
MODEL,
|
MODEL,
|
||||||
SCM_REVISION,
|
SCM_REVISION,
|
||||||
|
USE_BLE,
|
||||||
USE_SD_CARD,
|
USE_SD_CARD,
|
||||||
VERSION_MAJOR,
|
VERSION_MAJOR,
|
||||||
VERSION_MINOR,
|
VERSION_MINOR,
|
||||||
|
Loading…
Reference in New Issue
Block a user