1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

extract common stuff into trezorhal/common.[ch]

This commit is contained in:
Pavol Rusnak 2017-03-21 01:41:49 +01:00
parent e1ee7b78d2
commit 416676120b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
11 changed files with 61 additions and 64 deletions

View File

@ -64,6 +64,7 @@ OBJ_FW += $(addprefix $(BUILD_FW)/, \
bootloader/main.o \ bootloader/main.o \
extmod/modtrezorui/display.o \ extmod/modtrezorui/display.o \
extmod/modtrezorui/font_bitmap.o \ extmod/modtrezorui/font_bitmap.o \
trezorhal/common.o \
trezorhal/sdcard.o \ trezorhal/sdcard.o \
trezorhal/stm32_it.o \ trezorhal/stm32_it.o \
trezorhal/stm32_system.o \ trezorhal/stm32_system.o \

View File

@ -315,6 +315,7 @@ OBJ_MP += $(addprefix $(BUILD_MP)/,\
OBJ_FW += $(addprefix $(BUILD_FW)/, \ OBJ_FW += $(addprefix $(BUILD_FW)/, \
firmware/main.o \ firmware/main.o \
firmware/mphalport.o \ firmware/mphalport.o \
trezorhal/common.o \
trezorhal/flash.o \ trezorhal/flash.o \
trezorhal/rng.o \ trezorhal/rng.o \
trezorhal/sdcard.o \ trezorhal/sdcard.o \
@ -341,6 +342,7 @@ SRC_MOD = $(patsubst $(BUILD_FW)%.o, $(SRCDIR_FW)%.c, $(OBJ_MOD))
CROSS_COMPILE = arm-none-eabi- CROSS_COMPILE = arm-none-eabi-
INC += -I. INC += -I.
INC += -I$(SRCDIR_FW)/extmod/modtrezorui
INC += -I$(SRCDIR_FW)/firmware INC += -I$(SRCDIR_FW)/firmware
INC += -I$(SRCDIR_FW)/trezorhal INC += -I$(SRCDIR_FW)/trezorhal
INC += -I$(SRCDIR_FW)/trezorhal/hal INC += -I$(SRCDIR_FW)/trezorhal/hal

View File

@ -63,6 +63,7 @@ OBJ_FW += $(addprefix $(BUILD_FW)/, \
loader/main.o \ loader/main.o \
extmod/modtrezorui/display.o \ extmod/modtrezorui/display.o \
extmod/modtrezorui/font_bitmap.o \ extmod/modtrezorui/font_bitmap.o \
trezorhal/common.o \
trezorhal/stm32_it.o \ trezorhal/stm32_it.o \
trezorhal/stm32_system.o \ trezorhal/stm32_system.o \
trezorhal/hal/stm32f4xx_hal_sram.o \ trezorhal/hal/stm32f4xx_hal_sram.o \

View File

@ -3,46 +3,22 @@
#include <string.h> #include <string.h>
#include "crypto.h" #include "crypto.h"
#include "common.h"
#include "display.h" #include "display.h"
#include "sdcard.h" #include "sdcard.h"
#define STAGE2_START 0x08010000 #define STAGE2_START 0x08010000
#define BOOTLOADER_PRINT(X) do { display_print(X, -1); display_print_out(0xFFFF, 0x001F); } while(0) #define BOOTLOADER_FGCOLOR 0xFFFF
#define BOOTLOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(0xFFFF, 0x001F); } while(0) #define BOOTLOADER_BGCOLOR 0x0000
void SystemClock_Config(void); #define BOOTLOADER_PRINT(X) do { display_print(X, -1); display_print_out(BOOTLOADER_FGCOLOR, BOOTLOADER_BGCOLOR); } while(0)
#define BOOTLOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(BOOTLOADER_FGCOLOR, BOOTLOADER_BGCOLOR); } while(0)
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
for (;;) {}
}
void __attribute__((noreturn)) __fatal_error(const char *msg) {
for (volatile uint32_t delay = 0; delay < 10000000; delay++) {
}
display_print("FATAL ERROR:\n", -1);
display_print(msg, -1);
display_print("\n", -1);
display_print_out(0xFFFF, 0x001F);
for (;;) {
__WFI();
}
}
void mp_hal_stdout_tx_str(const char *str) { void mp_hal_stdout_tx_str(const char *str) {
} }
void halt(void)
{
BOOTLOADER_PRINTLN("HALT!");
for (;;) {
display_backlight(255);
HAL_Delay(950);
display_backlight(0);
HAL_Delay(50);
}
}
void periph_init(void) void periph_init(void)
{ {
HAL_Init(); HAL_Init();
@ -165,7 +141,7 @@ int main(void)
if (check_sdcard()) { if (check_sdcard()) {
if (!copy_sdcard()) { if (!copy_sdcard()) {
halt(); __fatal_error("halt");
} }
} }
@ -176,7 +152,7 @@ int main(void)
BOOTLOADER_PRINTLN("valid stage 2 signature"); BOOTLOADER_PRINTLN("valid stage 2 signature");
BOOTLOADER_PRINTLN("JUMP!"); BOOTLOADER_PRINTLN("JUMP!");
// TODO: jump to second stage // TODO: jump to second stage
halt(); __fatal_error("halt");
} else { } else {
BOOTLOADER_PRINTLN("invalid stage 2 signature"); BOOTLOADER_PRINTLN("invalid stage 2 signature");
} }
@ -184,7 +160,7 @@ int main(void)
BOOTLOADER_PRINTLN("invalid stage 2 header"); BOOTLOADER_PRINTLN("invalid stage 2 header");
} }
halt(); __fatal_error("halt");
return 0; return 0;
} }

View File

@ -118,7 +118,7 @@ void display_set_backlight(int val)
__HAL_TIM_SetCompare(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * val / 255); __HAL_TIM_SetCompare(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * val / 255);
} }
void display_init(void) { int display_init(void) {
// init peripherials // init peripherials
__GPIOE_CLK_ENABLE(); __GPIOE_CLK_ENABLE();
__TIM1_CLK_ENABLE(); __TIM1_CLK_ENABLE();
@ -273,6 +273,8 @@ void display_init(void) {
// clear buffer // clear buffer
display_clear(); display_clear();
display_unsleep(); display_unsleep();
return 0;
} }
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {

View File

@ -35,7 +35,7 @@ void DATA(uint8_t x) {
#define DATA(X) (void)(X); #define DATA(X) (void)(X);
#endif #endif
void display_init(void) int display_init(void)
{ {
#ifndef TREZOR_NOUI #ifndef TREZOR_NOUI
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@ -59,6 +59,7 @@ void display_init(void)
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_NONE); SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_NONE);
SDL_SetTextureAlphaMod(TEXTURE, 0); SDL_SetTextureAlphaMod(TEXTURE, 0);
#endif #endif
return 0;
} }
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)

View File

@ -21,7 +21,7 @@
// provided by port // provided by port
void display_init(void); int display_init(void);
void display_refresh(void); void display_refresh(void);
void display_save(const char *filename); void display_save(const char *filename);

View File

@ -13,22 +13,14 @@
#include "gccollect.h" #include "gccollect.h"
#include "pendsv.h" #include "pendsv.h"
#include "common.h"
#include "display.h"
#include "flash.h" #include "flash.h"
#include "rng.h" #include "rng.h"
#include "sdcard.h" #include "sdcard.h"
#include "touch.h" #include "touch.h"
#include "usb.h" #include "usb.h"
void SystemClock_Config(void);
void NORETURN nlr_jump_fail(void *val) {
for (;;) {}
}
void NORETURN __fatal_error(const char *msg) {
for (;;) {}
}
int main(void) { int main(void) {
// STM32F4xx HAL library initialization: // STM32F4xx HAL library initialization:
@ -61,6 +53,10 @@ int main(void) {
pendsv_init(); pendsv_init();
if (0 != display_init()) {
__fatal_error("display_init failed");
}
if (0 != flash_init()) { if (0 != flash_init()) {
__fatal_error("flash_init failed"); __fatal_error("flash_init failed");
} }

View File

@ -1,25 +1,8 @@
#include STM32_HAL_H #include STM32_HAL_H
#include "common.h"
#include "display.h" #include "display.h"
void SystemClock_Config(void);
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
for (;;) {}
}
void __attribute__((noreturn)) __fatal_error(const char *msg) {
for (volatile uint32_t delay = 0; delay < 10000000; delay++) {
}
display_print("FATAL ERROR:\n", -1);
display_print(msg, -1);
display_print("\n", -1);
display_print_out(0xFFFF, 0x001F);
for (;;) {
__WFI();
}
}
void mp_hal_stdout_tx_str(const char *str) { void mp_hal_stdout_tx_str(const char *str) {
} }

View File

@ -0,0 +1,25 @@
#include STM32_HAL_H
#include "display.h"
#define FATAL_FGCOLOR 0xFFFF
#define FATAL_BGCOLOR 0x001F
void __attribute__((noreturn)) __fatal_error(const char *msg) {
for (volatile uint32_t delay = 0; delay < 10000000; delay++) {
}
display_print("FATAL ERROR:\n", -1);
display_print(msg, -1);
display_print("\n", -1);
display_print_out(FATAL_FGCOLOR, FATAL_BGCOLOR);
for (;;) {
display_backlight(255);
HAL_Delay(950);
display_backlight(128);
HAL_Delay(50);
}
}
void __attribute__((noreturn)) nlr_jump_fail(void *val) {
__fatal_error("uncaught exception");
}

View File

@ -0,0 +1,10 @@
#ifndef __TREZORHAL_COMMON_H__
#define __TREZORHAL_COMMON_H__
void SystemClock_Config(void); // defined in stm32_system.c
void __attribute__((noreturn)) nlr_jump_fail(void *val);
void __attribute__((noreturn)) __fatal_error(const char *msg);
#endif