Skip to content

Commit

Permalink
feat(core): add support for STM32U5A9J-DK board
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
TychoVrahe committed Oct 31, 2023
1 parent 18241de commit e7fee67
Show file tree
Hide file tree
Showing 29 changed files with 7,190 additions and 12 deletions.
10 changes: 10 additions & 0 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ BOOTLOADER_MAXSIZE = 131072
FIRMWARE_P1_MAXSIZE = 786432
FIRMWARE_P2_MAXSIZE = 917504
FIRMWARE_MAXSIZE = 1703936
else ifeq ($(TREZOR_MODEL),$(filter $(TREZOR_MODEL),DISC2))
OPENOCD_TARGET = target/stm32u5x.cfg
BOARDLOADER_START = 0x0C004000
BOARDLOADER_END = 0x0C010000
BOOTLOADER_START = 0x0C010000
FIRMWARE_START = 0x0C050000
PRODTEST_START = 0x0C050000
BOARDLOADER_MAXSIZE = 49152
BOOTLOADER_MAXSIZE = 131072
FIRMWARE_MAXSIZE = 3735552
else ifeq ($(TREZOR_MODEL), 1)
OPENOCD_TARGET = target/stm32uf2.cfg
FIRMWARE_START = 0x08010000
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if TREZOR_MODEL in ('R', ):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperator_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', 'DISC1'):
elif TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.bootloader_ci
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tools
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))

if TREZOR_MODEL in ('1', 'DISC1'):
if TREZOR_MODEL in ('1', 'DISC1', 'DISC2'):
# skip bootloader_ci build
env = Environment()
def build_bootloader_ci(target,source,env):
Expand Down
4 changes: 3 additions & 1 deletion core/SConscript.bootloader_emu
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperator_Regular_8'
FONT_BIG=None
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'DISC2'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD=None
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down Expand Up @@ -174,6 +174,8 @@ if TREZOR_MODEL in ('T', 'R'):
CPU_MODEL = 'STM32F427xx'
elif TREZOR_MODEL in ('DISC1', ):
CPU_MODEL = 'STM32F429xx'
elif TREZOR_MODEL in ('DISC2', ):
CPU_MODEL = 'STM32U5A9xx'
elif TREZOR_MODEL in ('1',):
CPU_MODEL = 'STM32F405xx'
else:
Expand Down
6 changes: 3 additions & 3 deletions core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
elif TREZOR_MODEL in ('T', 'DISC1'):
elif TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down Expand Up @@ -382,7 +382,7 @@ SOURCE_FIRMWARE = [
]


if TREZOR_MODEL in ('T', 'DISC1'):
if TREZOR_MODEL in ('T', 'DISC1', 'DISC2'):
UI_LAYOUT = 'UI_LAYOUT_TT'
ui_layout_feature = 'model_tt'
elif TREZOR_MODEL in ('1', 'R'):
Expand Down Expand Up @@ -781,7 +781,7 @@ if TREZOR_MODEL not in ('1',):
' --rename-section .data=.vendorheader,alloc,load,readonly,contents'
' $SOURCE $TARGET', ))

if TREZOR_MODEL not in ('DISC1', ):
if TREZOR_MODEL not in ('DISC1', 'DISC2'):
obj_program.extend(
env.Command(
target='embed/firmware/bootloaders/bootloader.o',
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.prodtest
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
PRODUCTION = ARGUMENTS.get('PRODUCTION', '0') == '1'
BOOTLOADER_DEVEL = ARGUMENTS.get('BOOTLOADER_DEVEL', '0') == '1'

if TREZOR_MODEL in ('DISC1', ):
if TREZOR_MODEL in ('DISC1', 'DISC2'):
# skip prodtest build
env = Environment()
def build_prodtest(target,source,env):
Expand Down
2 changes: 1 addition & 1 deletion core/SConscript.reflash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tools
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))

if TREZOR_MODEL in ('DISC1', ):
if TREZOR_MODEL in ('DISC1', 'DISC2'):
# skip reflash build
env = Environment()
def build_reflash(target,source,env):
Expand Down
6 changes: 4 additions & 2 deletions core/SConscript.unix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
DMA2D = TREZOR_MODEL in ('T', )
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))

if TREZOR_MODEL in ('DISC1', ):
if TREZOR_MODEL in ('DISC1', 'DISC2'):
# skip unix build
env = Environment()
def build_unix(target,source,env):
Expand Down Expand Up @@ -42,7 +42,7 @@ if TREZOR_MODEL in ('1', 'R'):
FONT_BOLD='Font_PixelOperator_Bold_8'
FONT_MONO='Font_PixelOperatorMono_Regular_8'
FONT_BIG='Font_Unifont_Regular_16'
elif TREZOR_MODEL in ('T', ):
elif TREZOR_MODEL in ('T', 'DISC2'):
FONT_NORMAL='Font_TTHoves_Regular_21'
FONT_DEMIBOLD='Font_TTHoves_DemiBold_21'
FONT_BOLD='Font_TTHoves_Bold_17'
Expand Down Expand Up @@ -494,6 +494,8 @@ if TREZOR_MODEL in ('T', 'R'):
CPU_MODEL = 'STM32F427xx'
elif TREZOR_MODEL in ('DISC1', ):
CPU_MODEL = 'STM32F429xx'
elif TREZOR_MODEL in ('DISC2', ):
CPU_MODEL = 'STM32U5A9xx'
elif TREZOR_MODEL in ('1',):
CPU_MODEL = 'STM32F405xx'
else:
Expand Down
119 changes: 119 additions & 0 deletions core/embed/firmware/memory_DISC2.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* TREZORv2 firmware linker script */

ENTRY(reset_handler)

MEMORY {
FLASH (rx) : ORIGIN = 0x0C050000, LENGTH = 3648K
SRAM1 (wal) : ORIGIN = 0x30000000, LENGTH = 768K - (0x100 + 4)
BOOT_ARGS (wal) : ORIGIN = 0x300BFEFC, LENGTH = (0x100 + 4)
SRAM2 (wal) : ORIGIN = 0x300C0000, LENGTH = 64K
SRAM3 (wal) : ORIGIN = 0x300D0000, LENGTH = 832K
SRAM5 (wal) : ORIGIN = 0x301A0000, LENGTH = 832K
SRAM6 (wal) : ORIGIN = 0x30270000, LENGTH = 512K
SRAM4 (wal) : ORIGIN = 0x38000000, LENGTH = 16K
}

main_stack_base = ORIGIN(SRAM2) + SIZEOF(.stack); /* 8-byte aligned full descending stack */
_sstack = ORIGIN(SRAM2) + 0x100;
_estack = main_stack_base;

/* used by the startup code to populate variables used by the C code */
data_lma = LOADADDR(.data);
data_vma = ADDR(.data);
data_size = SIZEOF(.data);

/* used by the startup code to populate variables used by the C code */
sensitive_lma = LOADADDR(.sensitive);
sensitive_vma = ADDR(.sensitive);
sensitive_size = SIZEOF(.sensitive);

/* used by the startup code to wipe memory */
sram1_start = ORIGIN(SRAM1);
sram1_end = ORIGIN(SRAM1) + LENGTH(SRAM1);
sram2_start = ORIGIN(SRAM2);
sram2_end = ORIGIN(SRAM2) + LENGTH(SRAM2);
sram3_start = ORIGIN(SRAM3);
sram3_end = ORIGIN(SRAM3) + LENGTH(SRAM3);
sram4_start = ORIGIN(SRAM4);
sram4_end = ORIGIN(SRAM4) + LENGTH(SRAM4);
sram5_start = ORIGIN(SRAM5);
sram5_end = ORIGIN(SRAM5) + LENGTH(SRAM5);
sram6_start = ORIGIN(SRAM6);
sram6_end = ORIGIN(SRAM6) + LENGTH(SRAM6);

/* reserve 256 bytes for bootloader arguments */
boot_args_start = ORIGIN(BOOT_ARGS);
boot_args_end = ORIGIN(BOOT_ARGS) + LENGTH(BOOT_ARGS);
g_boot_args = (boot_args_start + 4);
g_boot_flag = boot_args_start;

_codelen = SIZEOF(.flash) + SIZEOF(.data) + SIZEOF(.sensitive);
_flash_start = ORIGIN(FLASH);
_flash_end = ORIGIN(FLASH) + LENGTH(FLASH);
_heap_start = ADDR(.heap);
_heap_end = ADDR(.heap) + SIZEOF(.heap);

SECTIONS {
.vendorheader : ALIGN(4) {
KEEP(*(.vendorheader))
} >FLASH AT>FLASH

.header : ALIGN(4) {
KEEP(*(.header));
} >FLASH AT>FLASH

.flash : ALIGN(512) {
KEEP(*(.vector_table));
. = ALIGN(4);
*(.text*);
. = ALIGN(4);
*(.rodata*);
. = ALIGN(4);
KEEP(*(.bootloader));
*(.bootloader*);
. = ALIGN(512);
} >FLASH AT>FLASH

.data : ALIGN(4) {
*(.data*);
. = ALIGN(512);
} >SRAM1 AT>FLASH

/DISCARD/ : {
*(.ARM.exidx*);
}

.bss : ALIGN(4) {
*(.bss*);
. = ALIGN(4);
} >SRAM1

.data_ccm : ALIGN(4) {
*(.no_dma_buffers*);
. = ALIGN(4);
} >SRAM1

.heap : ALIGN(4) {
. = 37K; /* this acts as a build time assertion that at least this much memory is available for heap use */
. = ABSOLUTE(sram1_end); /* this explicitly sets the end of the heap */
} >SRAM1

.stack : ALIGN(8) {
. = 16K + 0x100; /* Exactly 16K allocated for stack. Overflow causes MemManage fault (when using MPU). */
} >SRAM2

.sensitive : ALIGN(512) {
*(.sensitive*);
. = ALIGN(512);
} >SRAM2 AT>FLASH

.fb1 : ALIGN(4) {
*(.fb1*);
. = ALIGN(4);
} >SRAM3

.fb2 : ALIGN(4) {
*(.fb2*);
. = ALIGN(4);
} >SRAM5
}
2 changes: 2 additions & 0 deletions core/embed/models/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "model_T2B1.h"
#elif defined TREZOR_MODEL_DISC1
#include "model_D001.h"
#elif defined TREZOR_MODEL_DISC2
#include "model_D002.h"
#else
#error Unknown Trezor model
#endif
Expand Down
32 changes: 32 additions & 0 deletions core/embed/models/model_D002.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef MODELS_MODEL_DISC2_H_
#define MODELS_MODEL_DISC2_H_

#define MODEL_NAME "T"
#define MODEL_FULL_NAME "Trezor Model T"
#define MODEL_INTERNAL_NAME "D002"
#define MODEL_INTERNAL_NAME_TOKEN T
#define MODEL_NAME_QSTR MP_QSTR_T
#define MODEL_INTERNAL_NAME_QSTR MP_QSTR_D001

/*** Discovery uses DEV keys in any build variant ***/
#define MODEL_BOARDLOADER_KEYS \
(const uint8_t *)"\xdb\x99\x5f\xe2\x51\x69\xd1\x41\xca\xb9\xbb\xba\x92\xba\xa0\x1f\x9f\x2e\x1e\xce\x7d\xf4\xcb\x2a\xc0\x51\x90\xf3\x7f\xcc\x1f\x9d", \
(const uint8_t *)"\x21\x52\xf8\xd1\x9b\x79\x1d\x24\x45\x32\x42\xe1\x5f\x2e\xab\x6c\xb7\xcf\xfa\x7b\x6a\x5e\xd3\x00\x97\x96\x0e\x06\x98\x81\xdb\x12", \
(const uint8_t *)"\x22\xfc\x29\x77\x92\xf0\xb6\xff\xc0\xbf\xcf\xdb\x7e\xdb\x0c\x0a\xa1\x4e\x02\x5a\x36\x5e\xc0\xe3\x42\xe8\x6e\x38\x29\xcb\x74\xb6",

#define MODEL_BOOTLOADER_KEYS \
(const uint8_t *)"\xd7\x59\x79\x3b\xbc\x13\xa2\x81\x9a\x82\x7c\x76\xad\xb6\xfb\xa8\xa4\x9a\xee\x00\x7f\x49\xf2\xd0\x99\x2d\x99\xb8\x25\xad\x2c\x48", \
(const uint8_t *)"\x63\x55\x69\x1c\x17\x8a\x8f\xf9\x10\x07\xa7\x47\x8a\xfb\x95\x5e\xf7\x35\x2c\x63\xe7\xb2\x57\x03\x98\x4c\xf7\x8b\x26\xe2\x1a\x56", \
(const uint8_t *)"\xee\x93\xa4\xf6\x6f\x8d\x16\xb8\x19\xbb\x9b\xeb\x9f\xfc\xcd\xfc\xdc\x14\x12\xe8\x7f\xee\x6a\x32\x4c\x2a\x99\xa1\xe0\xe6\x71\x48",

#define BOARDLOADER_START 0x0C004000
#define BOARD_CAPABILITIES_ADDR 0x0C00FF00
#define BOOTLOADER_START 0x0C010000
#define FIRMWARE_START 0x0C050000

#define IMAGE_CHUNK_SIZE (256 * 1024)
#define BOOTLOADER_IMAGE_MAXSIZE (128 * 1024 * 1) // 128 KB
#define FIRMWARE_IMAGE_MAXSIZE (128 * 1024 * 13) // 1664 KB
#define NORCOW_SECTOR_SIZE (64 * 1024)

#endif
93 changes: 93 additions & 0 deletions core/embed/models/model_D002_layout.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "flash.h"
#include "model.h"

const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT] = {
{
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0x18,
.num_sectors = 8,
},
},
{
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0x20,
.num_sectors = 8,
},
},
};

const flash_area_t BOARDLOADER_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 1,
.num_sectors = 6,
},
};

const flash_area_t BOOTLOADER_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0x08,
.num_sectors = 16,
},
};

const flash_area_t FIRMWARE_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0x28,
.num_sectors = 456,
},
};

const flash_area_t SECRET_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0,
.num_sectors = 2,
},
};

const flash_area_t BHK_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 1,
.num_sectors = 1,
},
};

const flash_area_t WIPE_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0x18,
.num_sectors = 488,
},
};

const flash_area_t ALL_WIPE_AREA = {
.num_subareas = 1,
.secure_area = true,
.subarea[0] =
{
.first_sector = 0x08,
.num_sectors = 504,
},
};
13 changes: 13 additions & 0 deletions core/embed/trezorhal/boards/stm32u5a9j-dk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef STM32U5A9J_DK_H_
#define STM32U5A9J_DK_H_

#define VDD_1V8 1
//#define USE_I2C 1
#define USE_RGB_COLORS 1
#define USE_TOUCH 1
//#define USE_SBU 1
//#define USE_DISP_I8080_8BIT_DW 1

#include "displays/dsi.h"

#endif // STM32U5A9J_DK_H_
Loading

0 comments on commit e7fee67

Please sign in to comment.