Skip to content

Commit 4f32cb5

Browse files
andrewkozlikprusnak
authored andcommitted
firmware: integrate trezor-storage
1 parent 5137f4e commit 4f32cb5

27 files changed

+1484
-1183
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "vendor/nanopb"]
1414
path = vendor/nanopb
1515
url = https://github.com/nanopb/nanopb.git
16+
[submodule "vendor/trezor-storage"]
17+
path = vendor/trezor-storage
18+
url = https://github.com/trezor/trezor-storage.git

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ OBJS += startup.o
33
endif
44

55
OBJS += buttons.o
6+
OBJS += common.o
7+
OBJS += flash.o
68
OBJS += layout.o
79
OBJS += oled.o
810
OBJS += rng.o

Makefile.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ CFLAGS += $(OPTFLAGS) \
7272
-I$(TOP_DIR) \
7373
-I$(TOP_DIR)gen \
7474
-I$(TOP_DIR)vendor/trezor-crypto \
75-
-I$(TOP_DIR)vendor/trezor-qrenc
75+
-I$(TOP_DIR)vendor/trezor-qrenc \
76+
-I$(TOP_DIR)vendor/trezor-storage
7677

7778
LDFLAGS += -L$(TOP_DIR) \
7879
$(DBGFLAGS) \

common.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This file is part of the TREZOR project, https://trezor.io/
3+
*
4+
* Copyright (c) SatoshiLabs
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <stdio.h>
21+
#include "common.h"
22+
#include "rng.h"
23+
#include "layout.h"
24+
#include "firmware/usb.h"
25+
26+
void shutdown(void);
27+
28+
void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line_num, const char *func) {
29+
char line[4][128] = {{0}};
30+
int i = 0;
31+
if (expr != NULL) {
32+
snprintf(line[i], sizeof(line[0]), "Expr: %s", expr);
33+
i++;
34+
}
35+
if (msg != NULL) {
36+
snprintf(line[i], sizeof(line[0]), "Msg: %s", msg);
37+
i++;
38+
}
39+
if (file != NULL) {
40+
snprintf(line[i], sizeof(line[0]), "File: %s:%d", file, line_num);
41+
i++;
42+
}
43+
if (func != NULL) {
44+
snprintf(line[i], sizeof(line[0]), "Func: %s", func);
45+
i++;
46+
}
47+
error_shutdown("FATAL ERROR:", NULL, line[0], line[1], line[2], line[3]);
48+
}
49+
50+
void __attribute__((noreturn)) error_shutdown(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) {
51+
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, line2, line3, line4, line5, line6);
52+
shutdown();
53+
for (;;);
54+
}
55+
56+
#ifndef NDEBUG
57+
void __assert_func(const char *file, int line, const char *func, const char *expr) {
58+
__fatal_error(expr, "assert failed", file, line, func);
59+
}
60+
#endif
61+
62+
void hal_delay(uint32_t ms)
63+
{
64+
usbSleep(ms);
65+
}

common.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the TREZOR project, https://trezor.io/
3+
*
4+
* Copyright (c) SatoshiLabs
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef __TREZORHAL_COMMON_H__
21+
#define __TREZORHAL_COMMON_H__
22+
23+
#include <stdint.h>
24+
#include "secbool.h"
25+
26+
#define XSTR(s) STR(s)
27+
#define STR(s) #s
28+
29+
#ifndef MIN
30+
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
31+
#endif
32+
#ifndef MAX
33+
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
34+
#endif
35+
36+
void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func);
37+
void __attribute__((noreturn)) error_shutdown(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6);
38+
39+
#define ensure(expr, msg) (((expr) == sectrue) ? (void)0 : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
40+
41+
void hal_delay(uint32_t ms);
42+
43+
#endif

firmware/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ endif
1111

1212
OBJS += u2f.o
1313
OBJS += messages.o
14-
OBJS += storage.o
14+
OBJS += config.o
1515
OBJS += trezor.o
1616
OBJS += pinmatrix.o
1717
OBJS += fsm.o
@@ -75,10 +75,18 @@ OBJS += ../vendor/trezor-crypto/aes/aeskey.o
7575
OBJS += ../vendor/trezor-crypto/aes/aestab.o
7676
OBJS += ../vendor/trezor-crypto/aes/aes_modes.o
7777

78+
OBJS += ../vendor/trezor-crypto/chacha20poly1305/chacha20poly1305.o
79+
OBJS += ../vendor/trezor-crypto/chacha20poly1305/chacha_merged.o
80+
OBJS += ../vendor/trezor-crypto/chacha20poly1305/poly1305-donna.o
81+
OBJS += ../vendor/trezor-crypto/chacha20poly1305/rfc7539.o
82+
7883
OBJS += ../vendor/trezor-crypto/nem.o
7984

8085
OBJS += ../vendor/trezor-qrenc/qr_encode.o
8186

87+
OBJS += ../vendor/trezor-storage/storage.o
88+
OBJS += ../vendor/trezor-storage/norcow.o
89+
8290
OBJS += ../vendor/nanopb/pb_common.o
8391
OBJS += ../vendor/nanopb/pb_decode.o
8492
OBJS += ../vendor/nanopb/pb_encode.o

0 commit comments

Comments
 (0)