mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
messages: introduce messages_map_limits
This commit is contained in:
parent
a7c32248bd
commit
f9ba64ea94
@ -45,6 +45,8 @@ static const struct MessagesMap_t MessagesMap[] = {
|
|||||||
{0, 0, 0, 0, 0}
|
{0, 0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "messages_map_limits.h"
|
||||||
|
|
||||||
const pb_field_t *MessageFields(char type, char dir, uint16_t msg_id)
|
const pb_field_t *MessageFields(char type, char dir, uint16_t msg_id)
|
||||||
{
|
{
|
||||||
const struct MessagesMap_t *m = MessagesMap;
|
const struct MessagesMap_t *m = MessagesMap;
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "trezor.h"
|
#include "trezor.h"
|
||||||
|
|
||||||
#define MSG_IN_SIZE (11 * 1024)
|
#define MSG_IN_SIZE (15 * 1024)
|
||||||
|
|
||||||
#define MSG_OUT_SIZE (11 * 1024)
|
#define MSG_OUT_SIZE (3 * 1024)
|
||||||
|
|
||||||
#define msg_read(buf, len) msg_read_common('n', (buf), (len))
|
#define msg_read(buf, len) msg_read_common('n', (buf), (len))
|
||||||
#define msg_write(id, ptr) msg_write_common('n', (id), (ptr))
|
#define msg_write(id, ptr) msg_write_common('n', (id), (ptr))
|
||||||
@ -34,7 +34,7 @@ const uint8_t *msg_out_data(void);
|
|||||||
|
|
||||||
#if DEBUG_LINK
|
#if DEBUG_LINK
|
||||||
|
|
||||||
#define MSG_DEBUG_OUT_SIZE (4 * 1024)
|
#define MSG_DEBUG_OUT_SIZE (2 * 1024)
|
||||||
|
|
||||||
#define msg_debug_read(buf, len) msg_read_common('d', (buf), (len))
|
#define msg_debug_read(buf, len) msg_read_common('d', (buf), (len))
|
||||||
#define msg_debug_write(id, ptr) msg_write_common('d', (id), (ptr))
|
#define msg_debug_write(id, ptr) msg_write_common('d', (id), (ptr))
|
||||||
|
1
firmware/protob/.gitignore
vendored
1
firmware/protob/.gitignore
vendored
@ -4,4 +4,5 @@
|
|||||||
*.pb.h
|
*.pb.h
|
||||||
*.pyc
|
*.pyc
|
||||||
messages_map.h
|
messages_map.h
|
||||||
|
messages_map_limits.h
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
@ -2,7 +2,7 @@ ifneq ($(V),1)
|
|||||||
Q := @
|
Q := @
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: messages_map.h messages-bitcoin.pb.c messages-common.pb.c messages-crypto.pb.c messages-debug.pb.c messages-ethereum.pb.c messages-management.pb.c messages-nem.pb.c messages.pb.c messages-stellar.pb.c messages-lisk.pb.c messages_nem_pb2.py
|
all: messages_map.h messages_map_limits.h messages-bitcoin.pb.c messages-common.pb.c messages-crypto.pb.c messages-debug.pb.c messages-ethereum.pb.c messages-management.pb.c messages-nem.pb.c messages.pb.c messages-stellar.pb.c messages-lisk.pb.c messages_nem_pb2.py
|
||||||
|
|
||||||
PYTHON ?= python
|
PYTHON ?= python
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ messages_%_pb2.py: messages-%.proto
|
|||||||
@printf " PROTOC $@\n"
|
@printf " PROTOC $@\n"
|
||||||
$(Q)protoc -I/usr/include -I. $< --python_out=.
|
$(Q)protoc -I/usr/include -I. $< --python_out=.
|
||||||
|
|
||||||
messages_map.h: messages_map.py messages_pb2.py
|
messages_map.h messages_map_limits.h: messages_map.py messages_pb2.py
|
||||||
$(Q)$(PYTHON) $< | grep -v -e MessageType_Cardano -e MessageType_Tezos -e MessageType_Ripple -e MessageType_Monero -e MessageType_DebugMonero -e MessageType_Ontology -e MessageType_Tron -e MessageType_Eos > $@
|
$(Q)$(PYTHON) $< Cardano Tezos Ripple Monero DebugMonero Ontology Tron Eos
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.pb *.o *.d *.pb.c *.pb.h *_pb2.py messages_map.h
|
rm -f *.pb *.o *.d *.pb.c *.pb.h *_pb2.py messages_map.h messages_map_limits.h
|
||||||
|
@ -47,5 +47,7 @@ TxRequestSerializedType.serialized_tx max_size:2048
|
|||||||
|
|
||||||
MultisigRedeemScriptType.pubkeys max_count:15
|
MultisigRedeemScriptType.pubkeys max_count:15
|
||||||
MultisigRedeemScriptType.signatures max_count:15 max_size:73
|
MultisigRedeemScriptType.signatures max_count:15 max_size:73
|
||||||
|
MultisigRedeemScriptType.nodes max_count:15
|
||||||
|
MultisigRedeemScriptType.address_n max_count:8
|
||||||
|
|
||||||
HDNodePathType.address_n max_count:8
|
HDNodePathType.address_n max_count:8
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from messages_pb2 import MessageType
|
from messages_pb2 import MessageType
|
||||||
from messages_pb2 import wire_in, wire_out
|
from messages_pb2 import wire_in, wire_out
|
||||||
from messages_pb2 import wire_debug_in, wire_debug_out
|
from messages_pb2 import wire_debug_in, wire_debug_out
|
||||||
from messages_pb2 import wire_bootloader, wire_no_fsm
|
from messages_pb2 import wire_bootloader, wire_no_fsm
|
||||||
|
|
||||||
|
fh = open("messages_map.h", "wt")
|
||||||
|
fl = open("messages_map_limits.h", "wt")
|
||||||
|
|
||||||
# len("MessageType_MessageType_") - len("_fields") == 17
|
# len("MessageType_MessageType_") - len("_fields") == 17
|
||||||
TEMPLATE = "\t{{ {type} {dir} {msg_id:46} {fields:29} {process_func} }},"
|
TEMPLATE = "\t{{ {type} {dir} {msg_id:46} {fields:29} {process_func} }},\n"
|
||||||
|
|
||||||
LABELS = {
|
LABELS = {
|
||||||
wire_in: "in messages",
|
wire_in: "in messages",
|
||||||
@ -16,11 +21,15 @@ LABELS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def handle_message(message, extension):
|
def handle_message(fh, fl, skipped, message, extension):
|
||||||
name = message.name
|
name = message.name
|
||||||
short_name = name.split("MessageType_", 1).pop()
|
short_name = name.split("MessageType_", 1).pop()
|
||||||
assert(short_name != name)
|
assert(short_name != name)
|
||||||
|
|
||||||
|
for s in skipped:
|
||||||
|
if short_name.startswith(s):
|
||||||
|
return
|
||||||
|
|
||||||
interface = "d" if extension in (wire_debug_in, wire_debug_out) else "n"
|
interface = "d" if extension in (wire_debug_in, wire_debug_out) else "n"
|
||||||
direction = "i" if extension in (wire_in, wire_debug_in) else "o"
|
direction = "i" if extension in (wire_in, wire_debug_in) else "o"
|
||||||
|
|
||||||
@ -29,27 +38,44 @@ def handle_message(message, extension):
|
|||||||
no_fsm = options.Extensions[wire_no_fsm]
|
no_fsm = options.Extensions[wire_no_fsm]
|
||||||
|
|
||||||
if getattr(options, 'deprecated', None):
|
if getattr(options, 'deprecated', None):
|
||||||
return '\t// Message %s is deprecated' % short_name
|
fh.write('\t// Message %s is deprecated\n' % short_name)
|
||||||
|
return
|
||||||
if bootloader:
|
if bootloader:
|
||||||
return '\t// Message %s is used in bootloader mode only' % short_name
|
fh.write('\t// Message %s is used in bootloader mode only\n' % short_name)
|
||||||
|
return
|
||||||
if no_fsm:
|
if no_fsm:
|
||||||
return '\t// Message %s is not used in FSM' % short_name
|
fh.write('\t// Message %s is not used in FSM\n' % short_name)
|
||||||
|
return
|
||||||
|
|
||||||
if direction == "i":
|
if direction == "i":
|
||||||
process_func = "(void (*)(void *)) fsm_msg%s" % short_name
|
process_func = "(void (*)(void *)) fsm_msg%s" % short_name
|
||||||
else:
|
else:
|
||||||
process_func = "0"
|
process_func = "0"
|
||||||
|
|
||||||
return TEMPLATE.format(
|
fh.write(TEMPLATE.format(
|
||||||
type="'%c'," % interface,
|
type="'%c'," % interface,
|
||||||
dir="'%c'," % direction,
|
dir="'%c'," % direction,
|
||||||
msg_id="MessageType_%s," % name,
|
msg_id="MessageType_%s," % name,
|
||||||
fields="%s_fields," % short_name,
|
fields="%s_fields," % short_name,
|
||||||
process_func=process_func,
|
process_func=process_func,
|
||||||
)
|
))
|
||||||
|
|
||||||
|
bufsize = None
|
||||||
|
t = interface + direction
|
||||||
|
if t == "ni":
|
||||||
|
bufsize = "MSG_IN_SIZE"
|
||||||
|
elif t == "no":
|
||||||
|
bufsize = "MSG_OUT_SIZE"
|
||||||
|
elif t == "do":
|
||||||
|
bufsize = "MSG_DEBUG_OUT_SIZE"
|
||||||
|
if bufsize:
|
||||||
|
fl.write("_Static_assert(%s >= sizeof(%s), \"msg buffer too small\");\n" % (bufsize, short_name))
|
||||||
|
|
||||||
|
|
||||||
print("\t// This file is automatically generated by messages_map.py -- DO NOT EDIT!")
|
skipped = sys.argv[1:]
|
||||||
|
|
||||||
|
fh.write("\t// This file is automatically generated by messages_map.py -- DO NOT EDIT!\n")
|
||||||
|
fl.write("// This file is automatically generated by messages_map.py -- DO NOT EDIT!\n\n")
|
||||||
|
|
||||||
messages = defaultdict(list)
|
messages = defaultdict(list)
|
||||||
|
|
||||||
@ -62,12 +88,17 @@ for message in MessageType.DESCRIPTOR.values:
|
|||||||
|
|
||||||
for extension in (wire_in, wire_out, wire_debug_in, wire_debug_out):
|
for extension in (wire_in, wire_out, wire_debug_in, wire_debug_out):
|
||||||
if extension == wire_debug_in:
|
if extension == wire_debug_in:
|
||||||
print("\n#if DEBUG_LINK")
|
fh.write("\n#if DEBUG_LINK\n")
|
||||||
|
fl.write("\n#if DEBUG_LINK\n")
|
||||||
|
|
||||||
print("\n\t// {label}\n".format(label=LABELS[extension]))
|
fh.write("\n\t// {label}\n\n".format(label=LABELS[extension]))
|
||||||
|
|
||||||
for message in messages[extension]:
|
for message in messages[extension]:
|
||||||
print(handle_message(message, extension))
|
handle_message(fh, fl, skipped, message, extension)
|
||||||
|
|
||||||
if extension == wire_debug_out:
|
if extension == wire_debug_out:
|
||||||
print("\n#endif")
|
fh.write("\n#endif\n")
|
||||||
|
fl.write("#endif\n")
|
||||||
|
|
||||||
|
fh.close()
|
||||||
|
fl.close()
|
||||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 4b41d2e63841517bf701618434c018acf4f1bca2
|
Subproject commit 0735c7d6f524b4c5108d201c789612aad7ce7920
|
Loading…
Reference in New Issue
Block a user