Skip to content

Commit f6f7411

Browse files
authored
feat: added build_id and hash information (#546)
added build_id and hash information of firmware bootloader to the About Device page
1 parent e75c5ce commit f6f7411

File tree

4 files changed

+74
-31
lines changed

4 files changed

+74
-31
lines changed

core/embed/trezorhal/usart.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
UART_HandleTypeDef uart;
1414
UART_HandleTypeDef *huart = &uart;
1515

16-
uint8_t usart_fifo[64] = {0};
16+
#define UART_PACKET_MAX_LEN 64
17+
uint8_t usart_fifo[UART_PACKET_MAX_LEN] = {0};
1718
uint8_t usart_fifo_len = 0;
1819

1920
uint8_t uart_data_in[UART_BUF_MAX_LEN];
@@ -140,7 +141,7 @@ static void usart_rev_package(uint8_t *buf) {
140141
return;
141142
}
142143
len = (p_buf[0] << 8) + p_buf[1];
143-
if (len > 32) {
144+
if (len > UART_PACKET_MAX_LEN) {
144145
return;
145146
}
146147
p_buf += 2;

core/src/all_modules.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
import trezor.lvglui.scrs.components.theme
218218
trezor.lvglui.scrs.components.transition
219219
import trezor.lvglui.scrs.components.transition
220+
trezor.lvglui.scrs.deviceinfo
221+
import trezor.lvglui.scrs.deviceinfo
220222
trezor.lvglui.scrs.homescreen
221223
import trezor.lvglui.scrs.homescreen
222224
trezor.lvglui.scrs.initscreen
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import binascii
2+
3+
from storage import device
4+
from trezor import uart, utils
5+
6+
7+
class DeviceInfoManager:
8+
_instance = None
9+
preloaded_info = {}
10+
11+
def preload_device_info(self):
12+
model = device.get_model()
13+
version = device.get_firmware_version()
14+
onekey_firmware_build_id = utils.BUILD_ID[-7:].decode()
15+
16+
onekey_firmware_hash = utils.onekey_firmware_hash()
17+
hex_hash = binascii.hexlify(onekey_firmware_hash).decode("ascii")
18+
short_hash = hex_hash[:7]
19+
version = f"{version} [{onekey_firmware_build_id}-{short_hash}]"
20+
21+
serial = device.get_serial()
22+
ble_name = device.get_ble_name() or uart.get_ble_name()
23+
ble_version = uart.get_ble_version()
24+
ble_build_id = uart.get_ble_build_id()
25+
ble_hash = uart.get_ble_hash()
26+
hex_hash = binascii.hexlify(ble_hash).decode("ascii")
27+
short_hash = hex_hash[:7]
28+
ble_version = f"{ble_version} [{ble_build_id}-{short_hash}]"
29+
30+
boot_version = utils.boot_version()
31+
onekey_boot_hash = utils.boot_hash()
32+
hex_hash = binascii.hexlify(onekey_boot_hash).decode("ascii")
33+
short_hash = hex_hash[:7]
34+
onekey_boot_build_id = utils.boot_build_id()
35+
boot_version = f"{boot_version} [{onekey_boot_build_id}-{short_hash}]"
36+
board_version = utils.board_version()
37+
38+
self.preloaded_info = {
39+
"version": version,
40+
"ble_name": ble_name,
41+
"ble_version": ble_version,
42+
"boot_version": boot_version,
43+
"board_version": board_version,
44+
"serial": serial,
45+
"model": model,
46+
}
47+
48+
@classmethod
49+
def instance(cls):
50+
if cls._instance is None:
51+
cls._instance = cls()
52+
cls._instance.preload_device_info()
53+
return cls._instance
54+
55+
def get_info(self):
56+
return self.preloaded_info

core/src/trezor/lvglui/scrs/homescreen.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .components.button import ListItemBtn, ListItemBtnWithSwitch, NormalButton
2020
from .components.container import ContainerFlexCol, ContainerGrid
2121
from .components.listitem import DisplayItem, ImgGridItem
22+
from .deviceinfo import DeviceInfoManager
2223
from .widgets.style import StyleWrapper
2324

2425

@@ -1471,22 +1472,14 @@ def __init__(self, prev_scr=None):
14711472
self._init = True
14721473
else:
14731474
return
1474-
model = device.get_model()
1475-
version = device.get_firmware_version()
1476-
serial = device.get_serial()
1477-
1478-
ble_name = device.get_ble_name() or uart.get_ble_name()
1479-
ble_version = uart.get_ble_version()
1480-
# storage = device.get_storage()
1481-
boot_version = utils.boot_version()
1482-
board_version = utils.board_version()
1475+
preloaded_info = DeviceInfoManager.instance().get_info()
14831476
super().__init__(
14841477
prev_scr=prev_scr, title=_(i18n_keys.TITLE__ABOUT_DEVICE), nav_back=True
14851478
)
1486-
14871479
self.container = ContainerFlexCol(self.content_area, self.title, padding_row=0)
1488-
1489-
self.model = DisplayItem(self.container, _(i18n_keys.ITEM__MODEL), model)
1480+
self.model = DisplayItem(
1481+
self.container, _(i18n_keys.ITEM__MODEL), preloaded_info["model"]
1482+
)
14901483
self.model.label.add_style(
14911484
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
14921485
)
@@ -1496,27 +1489,16 @@ def __init__(self, prev_scr=None):
14961489
self.ble_mac = DisplayItem(
14971490
self.container,
14981491
_(i18n_keys.ITEM__BLUETOOTH_NAME),
1499-
ble_name,
1492+
preloaded_info["ble_name"],
15001493
)
15011494
self.ble_mac.label.add_style(
15021495
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
15031496
)
15041497
self.ble_mac.label_top.add_style(StyleWrapper().text_color(lv_colors.WHITE), 0)
15051498
self.ble_mac.set_style_bg_color(lv_colors.BLACK, 0)
15061499

1507-
# self.storage = DisplayItem(
1508-
# self.container,
1509-
# _(i18n_keys.ITEM__STORAGE),
1510-
# storage,
1511-
# )
1512-
# self.storage.label.add_style(
1513-
# StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
1514-
# )
1515-
# self.storage.label_top.add_style(StyleWrapper().text_color(lv_colors.WHITE), 0)
1516-
# self.storage.set_style_bg_color(lv_colors.BLACK, 0)
1517-
15181500
self.version = DisplayItem(
1519-
self.container, _(i18n_keys.ITEM__SYSTEM_VERSION), version
1501+
self.container, _(i18n_keys.ITEM__SYSTEM_VERSION), preloaded_info["version"]
15201502
)
15211503
self.version.label.add_style(
15221504
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
@@ -1527,7 +1509,7 @@ def __init__(self, prev_scr=None):
15271509
self.ble_version = DisplayItem(
15281510
self.container,
15291511
_(i18n_keys.ITEM__BLUETOOTH_VERSION),
1530-
ble_version,
1512+
preloaded_info["ble_version"],
15311513
)
15321514
self.ble_version.label.add_style(
15331515
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
@@ -1538,7 +1520,9 @@ def __init__(self, prev_scr=None):
15381520
self.ble_version.set_style_bg_color(lv_colors.BLACK, 0)
15391521

15401522
self.boot_version = DisplayItem(
1541-
self.container, _(i18n_keys.ITEM__BOOTLOADER_VERSION), boot_version
1523+
self.container,
1524+
_(i18n_keys.ITEM__BOOTLOADER_VERSION),
1525+
preloaded_info["boot_version"],
15421526
)
15431527
self.boot_version.label.add_style(
15441528
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
@@ -1551,7 +1535,7 @@ def __init__(self, prev_scr=None):
15511535
self.board_version = DisplayItem(
15521536
self.container,
15531537
_(i18n_keys.ITEM__BOARDLOADER_VERSION),
1554-
board_version,
1538+
preloaded_info["board_version"],
15551539
)
15561540
self.board_version.label.add_style(
15571541
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0
@@ -1570,7 +1554,7 @@ def __init__(self, prev_scr=None):
15701554
self.build_id.set_style_bg_color(lv_colors.BLACK, 0)
15711555

15721556
self.serial = DisplayItem(
1573-
self.container, _(i18n_keys.ITEM__SERIAL_NUMBER), serial
1557+
self.container, _(i18n_keys.ITEM__SERIAL_NUMBER), preloaded_info["serial"]
15741558
)
15751559
self.serial.label.add_style(
15761560
StyleWrapper().text_font(font_PJSREG24).text_color(lv_colors.LIGHT_GRAY), 0

0 commit comments

Comments
 (0)