1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-20 09:09:02 +00:00

feat(vendor): update MicroPython to support sorted qstr pools

Requires https://github.com/trezor/micropython/pull/20.

[no changelog]
This commit is contained in:
Roman Zeyde 2025-04-08 15:49:28 +03:00
parent 16289c4ec9
commit 6473b3ca48
3 changed files with 33 additions and 15 deletions

View File

@ -132,8 +132,9 @@ WIRETYPE_ENTRY = c.Sequence(
"msg_offset" / c.Int16ul,
)
# QDEF(MP_QSTR_copysign, 5171, 8, "copysign")
QDEF_RE = re.compile(r'^QDEF\(MP_QSTR(\S+), ([0-9]+), ([0-9])+, "(.*)"\)$')
# QDEF1(MP_QSTR_copysign, 5171, 8, "copysign")
QDEF_RE = re.compile(r'^QDEF(\d)\(MP_QSTR\S+, [0-9]+, [0-9]+, "(.*)"\)$')
QDEF_RE_SKIP = re.compile("^$|^//") # empty line or a comment
@dataclass
@ -540,17 +541,18 @@ class RustBlobRenderer:
def build_qstr_map(self, qstr_defs):
# QSTR defs are rolled out into an enum in py/qstr.h, the numeric
# value is simply an incremented integer.
qstr_counter = 0
with open(qstr_defs, "r") as f:
for line in f:
match = QDEF_RE.match(line)
if not match:
continue
line = match.group(0)
string = match.group(4)
self.qstr_map[string] = qstr_counter
qstr_counter += 1
logging.debug(f"Found {qstr_counter} Qstr defs")
matches = [
QDEF_RE.match(line).groups()
for line in f
if not QDEF_RE_SKIP.match(line)
]
# QDEF0 are processed before QDEF1 (see `vendor/micropython/py/qstr.h`)
# Keep the original QSTR order (since Python's sort is stable)
matches.sort(key=lambda m: int(m[0]))
for i, (_qdef, string) in enumerate(matches):
self.qstr_map[string] = i
logging.debug(f"Found {len(matches)} Qstr defs")
def build_enums_with_offsets(self):
enums = []

View File

@ -1,5 +1,21 @@
enum Qstr {
#define QDEF(id, hash, len, str) id,
// Copied from `vendor/micropython/py/qstr.h`:
#define QDEF0(id, hash, len, str) id,
#define QDEF1(id, hash, len, str)
#include "genhdr/qstrdefs.generated.h"
#undef QDEF
#undef QDEF0
#undef QDEF1
MP_QSTRnumber_of_static,
// unused but shifts the enum counter back one
MP_QSTRstart_of_main = MP_QSTRnumber_of_static - 1,
#define QDEF0(id, hash, len, str)
#define QDEF1(id, hash, len, str) id,
#include "genhdr/qstrdefs.generated.h"
#undef QDEF0
#undef QDEF1
// no underscore so it can't clash with any of the above
MP_QSTRnumber_of,
};

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit 52747e831f4f81ae0bff3d8fee1828c6880545ba
Subproject commit 2d09fb5f206cd76220eb9ca19cee9da1f7886dfa