Skip to content

Commit 75f01ab

Browse files
authored
feat: bootloader new features, logic adjustments (#406)
Signed-off-by: Adam BZH <adam@onekey.so>
1 parent 7df105c commit 75f01ab

60 files changed

Lines changed: 5180 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,78 @@
1-
---
2-
BasedOnStyle: Google
3-
# Google style has a default of 80 lines, but clang-format 7 disregards it in
4-
# a weird case in modtrezorio-fatfs.h. Setting it explicitly helps.
5-
ColumnLimit: 80
6-
# This setting differs between clang-format 7 and 9.
7-
# Let's set it explicitly to v7 value
8-
IncludeBlocks: Preserve
1+
BasedOnStyle: LLVM
2+
Language: Cpp
3+
Standard: Auto
4+
DisableFormat: false
5+
UseCRLF: false
6+
UseTab: Never
7+
ColumnLimit: 110
8+
IndentWidth: 4
9+
PPIndentWidth: 2
10+
AccessModifierOffset: -4
11+
MaxEmptyLinesToKeep: 1
12+
FixNamespaceComments: true
13+
SortUsingDeclarations: true
14+
BreakInheritanceList: BeforeComma
15+
AlignAfterOpenBracket: BlockIndent
16+
# AlignArrayOfStructures: Left
17+
# AlignConsecutiveAssignments:
18+
# Enabled: true
19+
# AcrossEmptyLines: true
20+
# AcrossComments: false
21+
AlignConsecutiveBitFields:
22+
Enabled: true
23+
AcrossEmptyLines: true
24+
AcrossComments: false
25+
AlignConsecutiveMacros:
26+
Enabled: true
27+
AcrossEmptyLines: true
28+
AcrossComments: false
29+
AlignEscapedNewlines: Left
30+
AlignOperands: AlignAfterOperator
31+
AllowAllArgumentsOnNextLine: true
32+
AllowAllParametersOfDeclarationOnNextLine: true
33+
AllowShortBlocksOnASingleLine: Always
34+
AllowShortCaseLabelsOnASingleLine: false
35+
AllowShortEnumsOnASingleLine: false
36+
AllowShortFunctionsOnASingleLine: None
37+
AllowShortIfStatementsOnASingleLine: Never
38+
AlwaysBreakBeforeMultilineStrings : true
39+
BraceWrapping:
40+
AfterCaseLabel : false
41+
AfterClass : true
42+
AfterControlStatement : Always
43+
AfterEnum: true
44+
AfterFunction: true
45+
AfterNamespace: true
46+
AfterStruct: true
47+
AfterUnion: true
48+
AfterExternBlock: true
49+
BeforeCatch: true
50+
BeforeElse: true
51+
BeforeLambdaBody: true
52+
BeforeWhile: true
53+
IndentBraces: false
54+
SplitEmptyFunction: true
55+
SplitEmptyRecord: false
56+
SplitEmptyNamespace: true
57+
BreakBeforeBraces: Custom
58+
IndentAccessModifiers: false
59+
IndentCaseBlocks: true
60+
IndentCaseLabels: false
61+
IndentExternBlock: AfterExternBlock
62+
IndentGotoLabels: true
63+
IndentPPDirectives: BeforeHash
64+
# InsertTrailingCommas: Wrapped
65+
LambdaBodyIndentation: Signature
66+
NamespaceIndentation: All
67+
PointerAlignment: Left
68+
QualifierAlignment: Left
69+
ReferenceAlignment: Right
70+
ReflowComments: true
71+
SpaceAfterCStyleCast: false
72+
SpaceBeforeAssignmentOperators: true
73+
SpaceBeforeCaseColon: false
74+
SpaceBeforeRangeBasedForLoopColon: true
75+
SpaceBeforeSquareBrackets: false
76+
SpaceInEmptyBlock: false
77+
SpacesInConditionalStatement: true
78+
SpacesInContainerLiterals: true

.clang-format-old

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
BasedOnStyle: Google
3+
# Google style has a default of 80 lines, but clang-format 7 disregards it in
4+
# a weird case in modtrezorio-fatfs.h. Setting it explicitly helps.
5+
ColumnLimit: 80
6+
# This setting differs between clang-format 7 and 9.
7+
# Let's set it explicitly to v7 value
8+
IncludeBlocks: Preserve

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ help: ## show this help
66
## style commands:
77

88
PY_FILES = $(shell find . -type f -name '*.py' | sed 'sO^\./OO' | grep -f ./tools/style.py.include | grep -v -f ./tools/style.py.exclude )
9+
C_FILES_OLD_FORMAT = $(shell find . -type f -name '*.[ch]' | grep -f ./tools/style.c.old.include | grep -v -f ./tools/style.c.old.exclude )
910
C_FILES = $(shell find . -type f -name '*.[ch]' | grep -f ./tools/style.c.include | grep -v -f ./tools/style.c.exclude )
1011

1112

@@ -70,12 +71,16 @@ editor_check: ## check editorconfig formatting
7071

7172
cstyle_check: ## run code style check on low-level C code
7273
clang-format --version
74+
@echo [CLANG-FORMAT OLD STYLE]
75+
@clangFormatOptions=--style=file:./.clang-format-old ./tools/clang-format-check $(C_FILES_OLD_FORMAT)
7376
@echo [CLANG-FORMAT]
74-
@./tools/clang-format-check $(C_FILES)
77+
@clangFormatOptions=--style=file:./.clang-format ./tools/clang-format-check $(C_FILES)
7578

7679
cstyle: ## apply code style on low-level C code
80+
@echo [CLANG-FORMAT OLD STYLE]
81+
@clang-format --style=file:.clang-format-old -i $(C_FILES_OLD_FORMAT)
7782
@echo [CLANG-FORMAT]
78-
@clang-format -i $(C_FILES)
83+
@clang-format --style=file:.clang-format -i $(C_FILES)
7984

8085
defs_check: ## check validity of coin definitions and protobuf files
8186
jsonlint common/defs/*.json common/defs/*/*.json
@@ -119,6 +124,7 @@ icons_check: ## generate FIDO service icons
119124

120125
protobuf: ## generate python protobuf headers
121126
./tools/build_protobuf
127+
make -C core/embed/bootloader/protob/
122128

123129
protobuf_check: ## check that generated protobuf headers are up to date
124130
./tools/build_protobuf --check

ci/shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let
5555
# to use official binary, remove rustfmt from buildInputs and add it to extensions:
5656
extensions = [ "rust-src" "clippy" "rustfmt" ];
5757
};
58-
llvmPackages = nixpkgs.llvmPackages_14;
58+
llvmPackages = nixpkgs.llvmPackages_15;
5959
# see pyright/README.md for update procedure
6060
pyright = nixpkgs.callPackage ./pyright {};
6161
in

common/protob/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
check: messages.pb messages-binance.pb messages-bitcoin.pb messages-bootloader.pb messages-cardano.pb messages-common.pb messages-crypto.pb messages-debug.pb messages-ethereum.pb messages-management.pb messages-monero.pb messages-nem.pb messages-ripple.pb messages-stellar.pb messages-tezos.pb messages-eos.pb message-conflux.pb
1+
check: messages.pb messages-binance.pb messages-bitcoin.pb messages-bootloader.pb messages-cardano.pb messages-common.pb messages-crypto.pb messages-debug.pb messages-emmc.pb messages-ethereum.pb messages-management.pb messages-monero.pb messages-nem.pb messages-ripple.pb messages-stellar.pb messages-tezos.pb messages-eos.pb messages-conflux.pb messages-solana.pb messages-starcoin.pb messages-tron.pb messages-aptos.pb
22

33
%.pb: %.proto
44
protoc -I/usr/include -I. $< -o $@

common/protob/messages-bootloader.proto

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,38 @@ message FirmwareUpload {
5353
message SelfTest {
5454
optional bytes payload = 1; // payload to be used in self-test
5555
}
56+
57+
/**
58+
* Type of reboot request
59+
* @embed
60+
*/
61+
enum RebootType {
62+
Normal = 0;
63+
Boardloader = 1;
64+
BootLoader = 2;
65+
}
66+
67+
/**
68+
* Request: Reboot according to requested type
69+
* @start
70+
* @next Success
71+
* @next Failure
72+
*/
73+
message Reboot {
74+
required RebootType reboot_type = 1;
75+
}
76+
77+
/**
78+
* Request: Perform a firmware update by using file stored in EMMC
79+
* @next Success
80+
* @next Failure
81+
*/
82+
message FirmwareUpdateEmmc {
83+
// update firmware from emmc
84+
required string path = 1;
85+
// reboot or back to main screen when success
86+
optional bool reboot_on_success = 2;
87+
// default False, erase storage and SE decided by policy
88+
// if set to True, always erase storage and SE
89+
// optional bool force_erase = 3;
90+
}

common/protob/messages-emmc.proto

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
syntax = "proto2";
2+
package hw.trezor.messages.emmc;
3+
4+
// Sugar for easier handling in Java
5+
option java_package = "com.satoshilabs.trezor.lib.protobuf";
6+
option java_outer_classname = "TrezorMessageEmmc";
7+
8+
option (include_in_bitcoin_only) = true;
9+
10+
import "messages.proto";
11+
12+
/**
13+
* Request: Check and repair filesystem permissions on Emmc
14+
* @next Success
15+
* @next Failure
16+
*/
17+
message EmmcFixPermission {
18+
// fix update issue caused by some file has read only flag
19+
// available in boot only
20+
}
21+
22+
/**
23+
* Response: The result return by EmmcPathInfo
24+
* @end
25+
*/
26+
message EmmcPath {
27+
// exist
28+
required bool exist = 1;
29+
// size
30+
required uint64 size = 2;
31+
// last modified date and time
32+
required uint32 year = 3;
33+
required uint32 month = 4;
34+
required uint32 day = 5;
35+
required uint32 hour = 6;
36+
required uint32 minute = 7;
37+
required uint32 second = 8;
38+
// attribute
39+
required bool readonly = 9;
40+
required bool hidden = 10;
41+
required bool system = 11;
42+
required bool archive = 12;
43+
required bool directory = 13;
44+
}
45+
46+
/**
47+
* Request: Gather various information of the path
48+
* @start
49+
* @next EmmcPath
50+
* @next Failure
51+
*/
52+
message EmmcPathInfo {
53+
// available in boot and firmware
54+
required string path = 1;
55+
}
56+
57+
/**
58+
* Part of the request accepted by EmmcFileRead and EmmcFileWrite
59+
* The result returned by EmmcFileRead and EmmcFileWrite
60+
* @embed
61+
* @end
62+
*/
63+
message EmmcFile {
64+
required string path = 1;
65+
required uint32 offset = 2;
66+
required uint32 len = 3;
67+
optional bytes data = 4;
68+
optional uint32 data_hash = 5;
69+
optional uint32 processed_byte = 6;
70+
}
71+
72+
/**
73+
* Request: Read file chunk from Emmc
74+
* @start
75+
* @next EmmcFile
76+
* @next Failure
77+
*/
78+
message EmmcFileRead {
79+
// available in boot only
80+
required EmmcFile file = 1;
81+
// this is only used for progress display
82+
// if not provided, progress bar won't display
83+
optional uint32 ui_percentage = 2;
84+
}
85+
86+
/**
87+
* Request: Write file chunk to Emmc
88+
* @start
89+
* @next EmmcFile
90+
* @next Failure
91+
*/
92+
message EmmcFileWrite {
93+
// available in boot and firmware
94+
// allow overwrite in boot only
95+
// path that not exists will be created
96+
required EmmcFile file = 1;
97+
required bool overwrite = 2;
98+
required bool append = 3;
99+
// this is only used for progress display
100+
// if not provided, progress bar won't display
101+
optional uint32 ui_percentage = 4;
102+
}
103+
104+
/**
105+
* Request: Delete file from Emmc
106+
* @start
107+
* @next Success
108+
* @next Failure
109+
*/
110+
message EmmcFileDelete {
111+
// available in boot only
112+
required string path = 1;
113+
}
114+
115+
/**
116+
* Response: The result return by EmmcDirList
117+
* @end
118+
*/
119+
message EmmcDir {
120+
required string path = 1;
121+
// both are '\n' seprated multiline strings
122+
optional string child_dirs = 2;
123+
optional string child_files = 3;
124+
}
125+
126+
/**
127+
* Request: Gather Emmc file and directory list
128+
* @start
129+
* @next EmmcPath
130+
* @next Failure
131+
*/
132+
message EmmcDirList {
133+
// available in boot only
134+
// always recursive
135+
required string path = 1;
136+
}
137+
138+
/**
139+
* Request: Make directory on Emmc
140+
* @start
141+
* @next Success
142+
* @next Failure
143+
*/
144+
message EmmcDirMake {
145+
// available in boot and firmware
146+
// path that not exists will be created
147+
required string path = 1;
148+
}
149+
150+
/**
151+
* Request: Remove directory from Emmc
152+
* @start
153+
* @next Success
154+
* @next Failure
155+
*/
156+
message EmmcDirRemove {
157+
// available in boot only
158+
// always recursive
159+
required string path = 1;
160+
}

common/protob/messages.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ enum MessageType {
136136
MessageType_FirmwareRequest = 8 [(bitcoin_only) = true, (wire_out) = true, (wire_bootloader) = true];
137137
MessageType_FirmwareErase_ex = 16 [(wire_in) = true, (wire_bootloader) = true];
138138
MessageType_SelfTest = 32 [(bitcoin_only) = true, (wire_in) = true, (wire_bootloader) = true];
139+
MessageType_Reboot = 30000 [(bitcoin_only) = true, (wire_in) = true, (wire_bootloader) = true];
140+
MessageType_FirmwareUpdateEmmc = 30001 [(bitcoin_only) = true, (wire_in) = true, (wire_bootloader) = true];
139141

140142
// Bitcoin
141143
MessageType_GetPublicKey = 11 [(bitcoin_only) = true, (wire_in) = true];
@@ -185,6 +187,19 @@ enum MessageType {
185187
MessageType_DebugLinkEraseSdCard = 9005 [(bitcoin_only) = true, (wire_debug_in) = true];
186188
MessageType_DebugLinkWatchLayout = 9006 [(bitcoin_only) = true, (wire_debug_in) = true];
187189

190+
// Emmc
191+
MessageType_EmmcFixPermission = 30100 [(wire_in) = true, (wire_bootloader) = true];
192+
MessageType_EmmcPath = 30101 [(wire_in) = true, (wire_out) = true, (wire_bootloader) = false];
193+
MessageType_EmmcPathInfo = 30102 [(wire_in) = true, (wire_bootloader) = true];
194+
MessageType_EmmcFile = 30103 [(wire_in) = true, (wire_out) = true, (wire_bootloader) = false];
195+
MessageType_EmmcFileRead = 30104 [(wire_in) = true, (wire_bootloader) = true];
196+
MessageType_EmmcFileWrite = 30105 [(wire_in) = true, (wire_bootloader) = true];
197+
MessageType_EmmcFileDelete = 30106 [(wire_in) = true, (wire_bootloader) = true];
198+
MessageType_EmmcDir = 30107 [(wire_out) = true, (wire_bootloader) = false];
199+
MessageType_EmmcDirList = 30108 [(wire_in) = true, (wire_bootloader) = true];
200+
MessageType_EmmcDirMake = 30109 [(wire_in) = true, (wire_bootloader) = false];
201+
MessageType_EmmcDirRemove = 30110 [(wire_in) = true, (wire_bootloader) = true];
202+
188203
// Ethereum
189204
MessageType_EthereumGetPublicKey = 450 [(wire_in) = true];
190205
MessageType_EthereumPublicKey = 451 [(wire_out) = true];

0 commit comments

Comments
 (0)