Skip to content

Commit

Permalink
firmware: integrate trezor-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkozlik authored and prusnak committed Feb 15, 2019
1 parent 5137f4e commit 4f32cb5
Show file tree
Hide file tree
Showing 27 changed files with 1,484 additions and 1,183 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "vendor/nanopb"]
path = vendor/nanopb
url = https://github.com/nanopb/nanopb.git
[submodule "vendor/trezor-storage"]
path = vendor/trezor-storage
url = https://github.com/trezor/trezor-storage.git
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ OBJS += startup.o
endif

OBJS += buttons.o
OBJS += common.o
OBJS += flash.o
OBJS += layout.o
OBJS += oled.o
OBJS += rng.o
Expand Down
3 changes: 2 additions & 1 deletion Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ CFLAGS += $(OPTFLAGS) \
-I$(TOP_DIR) \
-I$(TOP_DIR)gen \
-I$(TOP_DIR)vendor/trezor-crypto \
-I$(TOP_DIR)vendor/trezor-qrenc
-I$(TOP_DIR)vendor/trezor-qrenc \
-I$(TOP_DIR)vendor/trezor-storage

LDFLAGS += -L$(TOP_DIR) \
$(DBGFLAGS) \
Expand Down
65 changes: 65 additions & 0 deletions common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is part of the TREZOR project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include "common.h"
#include "rng.h"
#include "layout.h"
#include "firmware/usb.h"

void shutdown(void);

void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line_num, const char *func) {
char line[4][128] = {{0}};
int i = 0;
if (expr != NULL) {
snprintf(line[i], sizeof(line[0]), "Expr: %s", expr);
i++;
}
if (msg != NULL) {
snprintf(line[i], sizeof(line[0]), "Msg: %s", msg);
i++;
}
if (file != NULL) {
snprintf(line[i], sizeof(line[0]), "File: %s:%d", file, line_num);
i++;
}
if (func != NULL) {
snprintf(line[i], sizeof(line[0]), "Func: %s", func);
i++;
}
error_shutdown("FATAL ERROR:", NULL, line[0], line[1], line[2], line[3]);
}

void __attribute__((noreturn)) error_shutdown(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6) {
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, line2, line3, line4, line5, line6);
shutdown();
for (;;);
}

#ifndef NDEBUG
void __assert_func(const char *file, int line, const char *func, const char *expr) {
__fatal_error(expr, "assert failed", file, line, func);
}
#endif

void hal_delay(uint32_t ms)
{
usbSleep(ms);
}
43 changes: 43 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of the TREZOR project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __TREZORHAL_COMMON_H__
#define __TREZORHAL_COMMON_H__

#include <stdint.h>
#include "secbool.h"

#define XSTR(s) STR(s)
#define STR(s) #s

#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif

void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func);
void __attribute__((noreturn)) error_shutdown(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6);

#define ensure(expr, msg) (((expr) == sectrue) ? (void)0 : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))

void hal_delay(uint32_t ms);

#endif
10 changes: 9 additions & 1 deletion firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif

OBJS += u2f.o
OBJS += messages.o
OBJS += storage.o
OBJS += config.o
OBJS += trezor.o
OBJS += pinmatrix.o
OBJS += fsm.o
Expand Down Expand Up @@ -75,10 +75,18 @@ OBJS += ../vendor/trezor-crypto/aes/aeskey.o
OBJS += ../vendor/trezor-crypto/aes/aestab.o
OBJS += ../vendor/trezor-crypto/aes/aes_modes.o

OBJS += ../vendor/trezor-crypto/chacha20poly1305/chacha20poly1305.o
OBJS += ../vendor/trezor-crypto/chacha20poly1305/chacha_merged.o
OBJS += ../vendor/trezor-crypto/chacha20poly1305/poly1305-donna.o
OBJS += ../vendor/trezor-crypto/chacha20poly1305/rfc7539.o

OBJS += ../vendor/trezor-crypto/nem.o

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

OBJS += ../vendor/trezor-storage/storage.o
OBJS += ../vendor/trezor-storage/norcow.o

OBJS += ../vendor/nanopb/pb_common.o
OBJS += ../vendor/nanopb/pb_decode.o
OBJS += ../vendor/nanopb/pb_encode.o
Expand Down
Loading

0 comments on commit 4f32cb5

Please sign in to comment.