mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-29 10:58:21 +00:00
extract common stuff into trezorhal/common.[ch]
This commit is contained in:
parent
e1ee7b78d2
commit
416676120b
@ -64,6 +64,7 @@ OBJ_FW += $(addprefix $(BUILD_FW)/, \
|
||||
bootloader/main.o \
|
||||
extmod/modtrezorui/display.o \
|
||||
extmod/modtrezorui/font_bitmap.o \
|
||||
trezorhal/common.o \
|
||||
trezorhal/sdcard.o \
|
||||
trezorhal/stm32_it.o \
|
||||
trezorhal/stm32_system.o \
|
||||
|
@ -315,6 +315,7 @@ OBJ_MP += $(addprefix $(BUILD_MP)/,\
|
||||
OBJ_FW += $(addprefix $(BUILD_FW)/, \
|
||||
firmware/main.o \
|
||||
firmware/mphalport.o \
|
||||
trezorhal/common.o \
|
||||
trezorhal/flash.o \
|
||||
trezorhal/rng.o \
|
||||
trezorhal/sdcard.o \
|
||||
@ -341,6 +342,7 @@ SRC_MOD = $(patsubst $(BUILD_FW)%.o, $(SRCDIR_FW)%.c, $(OBJ_MOD))
|
||||
CROSS_COMPILE = arm-none-eabi-
|
||||
|
||||
INC += -I.
|
||||
INC += -I$(SRCDIR_FW)/extmod/modtrezorui
|
||||
INC += -I$(SRCDIR_FW)/firmware
|
||||
INC += -I$(SRCDIR_FW)/trezorhal
|
||||
INC += -I$(SRCDIR_FW)/trezorhal/hal
|
||||
|
@ -63,6 +63,7 @@ OBJ_FW += $(addprefix $(BUILD_FW)/, \
|
||||
loader/main.o \
|
||||
extmod/modtrezorui/display.o \
|
||||
extmod/modtrezorui/font_bitmap.o \
|
||||
trezorhal/common.o \
|
||||
trezorhal/stm32_it.o \
|
||||
trezorhal/stm32_system.o \
|
||||
trezorhal/hal/stm32f4xx_hal_sram.o \
|
||||
|
@ -3,46 +3,22 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "crypto.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "display.h"
|
||||
#include "sdcard.h"
|
||||
|
||||
#define STAGE2_START 0x08010000
|
||||
|
||||
#define BOOTLOADER_PRINT(X) do { display_print(X, -1); display_print_out(0xFFFF, 0x001F); } while(0)
|
||||
#define BOOTLOADER_PRINTLN(X) do { display_print(X "\n", -1); display_print_out(0xFFFF, 0x001F); } while(0)
|
||||
#define BOOTLOADER_FGCOLOR 0xFFFF
|
||||
#define BOOTLOADER_BGCOLOR 0x0000
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
#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 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)
|
||||
{
|
||||
HAL_Init();
|
||||
@ -165,7 +141,7 @@ int main(void)
|
||||
|
||||
if (check_sdcard()) {
|
||||
if (!copy_sdcard()) {
|
||||
halt();
|
||||
__fatal_error("halt");
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +152,7 @@ int main(void)
|
||||
BOOTLOADER_PRINTLN("valid stage 2 signature");
|
||||
BOOTLOADER_PRINTLN("JUMP!");
|
||||
// TODO: jump to second stage
|
||||
halt();
|
||||
__fatal_error("halt");
|
||||
} else {
|
||||
BOOTLOADER_PRINTLN("invalid stage 2 signature");
|
||||
}
|
||||
@ -184,7 +160,7 @@ int main(void)
|
||||
BOOTLOADER_PRINTLN("invalid stage 2 header");
|
||||
}
|
||||
|
||||
halt();
|
||||
__fatal_error("halt");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ void display_set_backlight(int val)
|
||||
__HAL_TIM_SetCompare(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * val / 255);
|
||||
}
|
||||
|
||||
void display_init(void) {
|
||||
int display_init(void) {
|
||||
// init peripherials
|
||||
__GPIOE_CLK_ENABLE();
|
||||
__TIM1_CLK_ENABLE();
|
||||
@ -273,6 +273,8 @@ void display_init(void) {
|
||||
// clear buffer
|
||||
display_clear();
|
||||
display_unsleep();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
|
||||
|
@ -35,7 +35,7 @@ void DATA(uint8_t x) {
|
||||
#define DATA(X) (void)(X);
|
||||
#endif
|
||||
|
||||
void display_init(void)
|
||||
int display_init(void)
|
||||
{
|
||||
#ifndef TREZOR_NOUI
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
@ -59,6 +59,7 @@ void display_init(void)
|
||||
SDL_SetTextureBlendMode(TEXTURE, SDL_BLENDMODE_NONE);
|
||||
SDL_SetTextureAlphaMod(TEXTURE, 0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
// provided by port
|
||||
|
||||
void display_init(void);
|
||||
int display_init(void);
|
||||
void display_refresh(void);
|
||||
void display_save(const char *filename);
|
||||
|
||||
|
@ -13,22 +13,14 @@
|
||||
#include "gccollect.h"
|
||||
#include "pendsv.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "display.h"
|
||||
#include "flash.h"
|
||||
#include "rng.h"
|
||||
#include "sdcard.h"
|
||||
#include "touch.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) {
|
||||
|
||||
// STM32F4xx HAL library initialization:
|
||||
@ -61,6 +53,10 @@ int main(void) {
|
||||
|
||||
pendsv_init();
|
||||
|
||||
if (0 != display_init()) {
|
||||
__fatal_error("display_init failed");
|
||||
}
|
||||
|
||||
if (0 != flash_init()) {
|
||||
__fatal_error("flash_init failed");
|
||||
}
|
||||
|
@ -1,25 +1,8 @@
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include "common.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) {
|
||||
}
|
||||
|
||||
|
25
micropython/trezorhal/common.c
Normal file
25
micropython/trezorhal/common.c
Normal 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");
|
||||
}
|
10
micropython/trezorhal/common.h
Normal file
10
micropython/trezorhal/common.h
Normal 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
|
Loading…
Reference in New Issue
Block a user