mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
core: add SD clearing via debuglink
This commit is contained in:
parent
d0b1b171f1
commit
ddee77ecb6
@ -173,3 +173,15 @@ message DebugLinkMemoryWrite {
|
||||
message DebugLinkFlashErase {
|
||||
optional uint32 sector = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Request: Erase the SD card
|
||||
* @start
|
||||
* @next Success
|
||||
* @next Failure
|
||||
*/
|
||||
message DebugLinkEraseSdCard {
|
||||
optional bool format = 1; // if true, the card will be formatted to FAT32.
|
||||
// if false, it will be all 0xFF bytes.
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ enum MessageType {
|
||||
MessageType_DebugLinkReseedRandom = 9002 [(wire_debug_in) = true];
|
||||
MessageType_DebugLinkRecordScreen = 9003 [(wire_debug_in) = true];
|
||||
MessageType_DebugLinkShowText = 9004 [(wire_debug_in) = true];
|
||||
MessageType_DebugLinkEraseSdCard = 9005 [(wire_debug_in) = true];
|
||||
|
||||
// Ethereum
|
||||
MessageType_EthereumGetPublicKey = 450 [(wire_in) = true];
|
||||
|
@ -17,6 +17,7 @@ if __debug__:
|
||||
from trezor.messages.DebugLinkRecordScreen import DebugLinkRecordScreen
|
||||
from trezor.messages.DebugLinkReseedRandom import DebugLinkReseedRandom
|
||||
from trezor.messages.DebugLinkState import DebugLinkState
|
||||
from trezor.messages.DebugLinkEraseSdCard import DebugLinkEraseSdCard
|
||||
|
||||
save_screen = False
|
||||
save_screen_directory = "."
|
||||
@ -138,6 +139,27 @@ if __debug__:
|
||||
crypto.random.reseed(msg.value)
|
||||
return Success()
|
||||
|
||||
async def dispatch_DebugLinkEraseSdCard(
|
||||
ctx: wire.Context, msg: DebugLinkEraseSdCard
|
||||
) -> Success:
|
||||
try:
|
||||
io.sdcard.power_on()
|
||||
if msg.format:
|
||||
fs = io.FatFS()
|
||||
fs.mkfs()
|
||||
else:
|
||||
# trash first 1 MB of data to destroy the FAT filesystem
|
||||
assert io.sdcard.capacity() >= 1024 * 1024
|
||||
empty_block = bytes([0xFF] * io.sdcard.BLOCK_SIZE)
|
||||
for i in range(1024 * 1024 // io.sdcard.BLOCK_SIZE):
|
||||
io.sdcard.write(i, empty_block)
|
||||
|
||||
except OSError:
|
||||
raise wire.ProcessError("SD card operation failed")
|
||||
finally:
|
||||
io.sdcard.power_off()
|
||||
return Success()
|
||||
|
||||
def boot() -> None:
|
||||
# wipe storage when debug build is used on real hardware
|
||||
if not utils.EMULATOR:
|
||||
@ -149,3 +171,4 @@ if __debug__:
|
||||
wire.register(MessageType.DebugLinkGetState, dispatch_DebugLinkGetState)
|
||||
wire.register(MessageType.DebugLinkReseedRandom, dispatch_DebugLinkReseedRandom)
|
||||
wire.register(MessageType.DebugLinkRecordScreen, dispatch_DebugLinkRecordScreen)
|
||||
wire.register(MessageType.DebugLinkEraseSdCard, dispatch_DebugLinkEraseSdCard)
|
||||
|
26
core/src/trezor/messages/DebugLinkEraseSdCard.py
Normal file
26
core/src/trezor/messages/DebugLinkEraseSdCard.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Automatically generated by pb2py
|
||||
# fmt: off
|
||||
import protobuf as p
|
||||
|
||||
if __debug__:
|
||||
try:
|
||||
from typing import Dict, List # noqa: F401
|
||||
from typing_extensions import Literal # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class DebugLinkEraseSdCard(p.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 9005
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
format: bool = None,
|
||||
) -> None:
|
||||
self.format = format
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls) -> Dict:
|
||||
return {
|
||||
1: ('format', p.BoolType, 0),
|
||||
}
|
@ -77,6 +77,7 @@ DebugLinkLayout = 9001 # type: Literal[9001]
|
||||
DebugLinkReseedRandom = 9002 # type: Literal[9002]
|
||||
DebugLinkRecordScreen = 9003 # type: Literal[9003]
|
||||
DebugLinkShowText = 9004 # type: Literal[9004]
|
||||
DebugLinkEraseSdCard = 9005 # type: Literal[9005]
|
||||
if not utils.BITCOIN_ONLY:
|
||||
EthereumGetPublicKey = 450 # type: Literal[450]
|
||||
EthereumPublicKey = 451 # type: Literal[451]
|
||||
|
@ -3,7 +3,7 @@ Q := @
|
||||
endif
|
||||
|
||||
SKIPPED_MESSAGES := Binance Cardano DebugMonero Eos Monero Ontology Ripple SdProtect Tezos WebAuthn \
|
||||
DebugLinkRecordScreen DebugLinkReseedRandom DebugLinkShowText
|
||||
DebugLinkRecordScreen DebugLinkReseedRandom DebugLinkShowText DebugLinkEraseSdCard
|
||||
|
||||
ifeq ($(BITCOIN_ONLY), 1)
|
||||
SKIPPED_MESSAGES += Ethereum Lisk NEM Stellar
|
||||
|
26
python/src/trezorlib/messages/DebugLinkEraseSdCard.py
Normal file
26
python/src/trezorlib/messages/DebugLinkEraseSdCard.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Automatically generated by pb2py
|
||||
# fmt: off
|
||||
from .. import protobuf as p
|
||||
|
||||
if __debug__:
|
||||
try:
|
||||
from typing import Dict, List # noqa: F401
|
||||
from typing_extensions import Literal # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
class DebugLinkEraseSdCard(p.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 9005
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
format: bool = None,
|
||||
) -> None:
|
||||
self.format = format
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls) -> Dict:
|
||||
return {
|
||||
1: ('format', p.BoolType, 0),
|
||||
}
|
@ -75,6 +75,7 @@ DebugLinkLayout = 9001 # type: Literal[9001]
|
||||
DebugLinkReseedRandom = 9002 # type: Literal[9002]
|
||||
DebugLinkRecordScreen = 9003 # type: Literal[9003]
|
||||
DebugLinkShowText = 9004 # type: Literal[9004]
|
||||
DebugLinkEraseSdCard = 9005 # type: Literal[9005]
|
||||
EthereumGetPublicKey = 450 # type: Literal[450]
|
||||
EthereumPublicKey = 451 # type: Literal[451]
|
||||
EthereumGetAddress = 56 # type: Literal[56]
|
||||
|
@ -40,6 +40,7 @@ from .CosiCommitment import CosiCommitment
|
||||
from .CosiSign import CosiSign
|
||||
from .CosiSignature import CosiSignature
|
||||
from .DebugLinkDecision import DebugLinkDecision
|
||||
from .DebugLinkEraseSdCard import DebugLinkEraseSdCard
|
||||
from .DebugLinkFlashErase import DebugLinkFlashErase
|
||||
from .DebugLinkGetState import DebugLinkGetState
|
||||
from .DebugLinkLayout import DebugLinkLayout
|
||||
|
Loading…
Reference in New Issue
Block a user