Skip to content

Commit

Permalink
refactor(core): restructure embed folder
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
cepetr committed Nov 18, 2024
1 parent 82bc0ef commit 089db2c
Show file tree
Hide file tree
Showing 624 changed files with 2,166 additions and 2,108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/core-hw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

# [Device tests](../tests/device-tests.md) that run against an actual physical Trezors.
# The device needs to have special bootloader, found in `core/embed/bootloader_ci`, that
# The device needs to have special bootloader, found in `core/embed/projects/bootloader_ci`, that
# makes it possible to flash firmware without confirmation on the touchscreen.
#
# All hardware tests are run nightly on the `main` branch,
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ before_script:
- . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh || true
- $NIX_SHELL --run "poetry install --sync"
- export LEGACY_VERSION=$($NIX_SHELL --run "./tools/version.sh legacy/firmware/version.h")
- export CORE_VERSION=$($NIX_SHELL --run "./tools/version.sh core/embed/firmware/version.h")
- export CORE_VERSION=$($NIX_SHELL --run "./tools/version.sh core/embed/projects/firmware/version.h")

include:
- ci/environment.yml
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pystyle: ## apply code style on application sources and tests

changelog_check: ## check changelog format
./tools/generate-changelog.py --check core
./tools/generate-changelog.py --check core/embed/boardloader
./tools/generate-changelog.py --check core/embed/bootloader
./tools/generate-changelog.py --check core/embed/bootloader_ci
./tools/generate-changelog.py --check core/embed/projects/boardloader
./tools/generate-changelog.py --check core/embed/projects/bootloader
./tools/generate-changelog.py --check core/embed/projects/bootloader_ci
./tools/generate-changelog.py --check legacy/bootloader
./tools/generate-changelog.py --check legacy/firmware
./tools/generate-changelog.py --check legacy/intermediate_fw
Expand Down
8 changes: 4 additions & 4 deletions ci/check_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ set -u
base_branch=main
fail=0
subdirs="core
core/embed/boardloader
core/embed/bootloader
core/embed/bootloader_ci
core/embed/prodtest
core/embed/projects/boardloader
core/embed/projects/bootloader
core/embed/projects/bootloader_ci
core/embed/projects/prodtest
legacy/bootloader
legacy/firmware
legacy/intermediate_fw
Expand Down
10 changes: 5 additions & 5 deletions ci/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ release core fw regular deploy:
needs:
- core fw regular build
script:
- export VERSION=$(./tools/version.sh core/embed/firmware/version.h)
- export VERSION=$(./tools/version.sh core/embed/projects/firmware/version.h)
- export NAME="firmware-T2T1-$VERSION-$CI_COMMIT_SHORT_SHA.bin"
- echo "Deploying to ${DEPLOY_DIRECTORY}/$NAME"
- mkdir -p "${DEPLOY_BASE_DIR}/${DEPLOY_DIRECTORY}"
Expand All @@ -34,7 +34,7 @@ release core fw btconly deploy:
needs:
- core fw btconly build
script:
- export VERSION=$(./tools/version.sh core/embed/firmware/version.h)
- export VERSION=$(./tools/version.sh core/embed/projects/firmware/version.h)
- export NAME="firmware-T2T1-btconly-$VERSION-$CI_COMMIT_SHORT_SHA.bin"
- echo "Deploying to ${DEPLOY_DIRECTORY}/$NAME"
- mkdir -p "${DEPLOY_BASE_DIR}/${DEPLOY_DIRECTORY}"
Expand All @@ -56,7 +56,7 @@ release core fw regular debug deploy:
needs:
- core fw regular debug build
script:
- export VERSION=$(./tools/version.sh core/embed/firmware/version.h)
- export VERSION=$(./tools/version.sh core/embed/projects/firmware/version.h)
- export NAME="firmware-T2T1-debug-$VERSION-$CI_COMMIT_SHORT_SHA.bin"
- echo "Deploying to ${DEPLOY_DIRECTORY}/$NAME"
- mkdir -p "${DEPLOY_BASE_DIR}/${DEPLOY_DIRECTORY}"
Expand All @@ -78,7 +78,7 @@ release core fw btconly debug deploy:
needs:
- core fw btconly debug build
script:
- export VERSION=$(./tools/version.sh core/embed/firmware/version.h)
- export VERSION=$(./tools/version.sh core/embed/projects/firmware/version.h)
- export NAME="firmware-T2T1-btconly-debug-$VERSION-$CI_COMMIT_SHORT_SHA.bin"
- echo "Deploying to ${DEPLOY_DIRECTORY}/$NAME"
- mkdir -p "${DEPLOY_BASE_DIR}/${DEPLOY_DIRECTORY}"
Expand Down Expand Up @@ -193,7 +193,7 @@ release core unix debug deploy:
- core unix frozen debug build
- core unix frozen debug build arm
script:
- export VERSION=$(./tools/version.sh core/embed/firmware/version.h)
- export VERSION=$(./tools/version.sh core/embed/projects/firmware/version.h)
- DEST="$DEPLOY_PATH/trezor-emu-core-v$VERSION"
- DEST_ARM="$DEPLOY_PATH/arm/trezor-emu-core-v$VERSION-arm"
- echo "Deploying to $DEST and $DEST_ARM"
Expand Down
6 changes: 3 additions & 3 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,18 @@ flash_erase_storage: ## erase storage sectors from flash
$(OPENOCD) -c "init; reset halt; flash erase_sector 0 $(STORAGE_1_SECTOR_START) $(STORAGE_1_SECTOR_END); flash erase_sector 0 $(STORAGE_2_SECTOR_START) $(STORAGE_2_SECTOR_END); exit"

flash_bootloader_jlink: $(BOOTLOADER_BUILD_DIR)/bootloader.bin ## flash bootloader using JLink
JLinkExe -nogui 1 -commanderscript embed/bootloader/bootloader_flash.jlink
JLinkExe -nogui 1 -commanderscript embed/projects/bootloader/bootloader_flash.jlink

flash_bootloader_ci_jlink: $(BOOTLOADER_CI_BUILD_DIR)/bootloader.bin ## flash CI bootloader using JLink
JLinkExe -nogui 1 -commanderscript embed/bootloader_ci/bootloader_flash.jlink
JLinkExe -nogui 1 -commanderscript embed/projects/bootloader_ci/bootloader_flash.jlink

flash_firmware_jlink: $(FIRMWARE_BUILD_DIR)/firmware.bin ## flash firmware using JLink. file names must end in .bin for JLink
cp -f $<.p1 $<.p1.bin
cp -f $<.p2 $<.p2.bin
## pad 2nd part so that FW integrity works after flash
## read&compare in flashing will avoid erasing unmodified sectors
truncate -s $(FIRMWARE_P2_MAXSIZE) $<.p2.bin
JLinkExe -nogui 1 -commanderscript embed/firmware/firmware_flash.jlink
JLinkExe -nogui 1 -commanderscript embed/projects/firmware/firmware_flash.jlink

## openocd debug commands:

Expand Down
50 changes: 29 additions & 21 deletions core/SConscript.boardloader
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ CPPPATH_MOD += [
'vendor/micropython/lib/uzlib',
]
SOURCE_MOD += [
'embed/lib/display_utils.c',
'embed/lib/error_handling.c',
'embed/lib/flash_utils.c',
'embed/lib/fonts/font_bitmap.c',
'embed/lib/fonts/fonts.c',
'embed/lib/gfx_color.c',
'embed/lib/gfx_bitblt_rgb565.c',
'embed/lib/gfx_bitblt_rgba8888.c',
'embed/lib/gfx_bitblt_mono8.c',
'embed/lib/image.c',
'embed/lib/mini_printf.c',
'embed/lib/rsod.c',
'embed/lib/terminal.c',
'embed/lib/gfx_draw.c'
'embed/gfx/bitblt/gfx_bitblt.c',
'embed/gfx/bitblt/gfx_bitblt_rgb565.c',
'embed/gfx/bitblt/gfx_bitblt_rgba8888.c',
'embed/gfx/bitblt/gfx_bitblt_mono8.c',
'embed/gfx/fonts/font_bitmap.c',
'embed/gfx/fonts/fonts.c',
'embed/gfx/gfx_color.c',
'embed/gfx/gfx_draw.c',
'embed/gfx/terminal.c',
'embed/io/display/display_utils.c',
'embed/util/flash/flash_utils.c',
'embed/util/image/image.c',
'embed/util/rsod/rsod.c',
'embed/rtl/error_handling.c',
'embed/rtl/mini_printf.c',
]

env = Environment(ENV=os.environ,
Expand All @@ -79,8 +80,8 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
FILE_SUFFIX= env.get('ENV')['SUFFIX']

SOURCE_BOARDLOADER = [
f"embed/trezorhal/{FILE_SUFFIX}/startup_stage_0.s",
'embed/boardloader/main.c',
f"embed/sys/startup/{FILE_SUFFIX}/startup_stage_0.s",
'embed/projects/boardloader/main.c',
]


Expand Down Expand Up @@ -113,11 +114,18 @@ env.Replace(
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
LINKFLAGS="-T build/boardloader/memory.ld -Wl,--gc-sections -Wl,-Map=build/boardloader/boardloader.map -Wl,--warn-common -Wl,--print-memory-usage",
CPPPATH=[
'embed/boardloader',
'embed/lib',
'embed/projects/boardloader',
'embed/rtl/inc',
'embed/models',
'embed/trezorhal',
'embed/extmod/modtrezorui',
'embed/upymod/modtrezorui',
'embed/gfx/inc',
'embed/io/button/inc',
'embed/io/haptic/inc',
'embed/io/touch/inc',
'embed/io/usb/inc',
'embed/sys/bsp/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
'vendor/micropython/lib/cmsis/inc',
] + CPPPATH_MOD + PATH_HAL,
CPPDEFINES=[
Expand Down Expand Up @@ -165,7 +173,7 @@ program_elf = env.Command(
env.Depends(program_elf, linkerscript_gen)

BINARY_NAME = f"build/boardloader/boardloader-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/boardloader/version.h')
BINARY_NAME += "-" + tools.get_version('embed/projects/boardloader/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
Expand Down
63 changes: 34 additions & 29 deletions core/SConscript.bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,22 @@ CPPPATH_MOD += [
]

SOURCE_MOD += [
'embed/extmod/modtrezorcrypto/rand.c',
'embed/lib/display_utils.c',
'embed/lib/error_handling.c',
'embed/lib/flash_utils.c',
'embed/lib/fonts/font_bitmap.c',
'embed/lib/fonts/fonts.c',
'embed/lib/gfx_color.c',
'embed/lib/gfx_bitblt_mono8.c',
'embed/lib/gfx_bitblt_rgb565.c',
'embed/lib/gfx_bitblt_rgba8888.c',
'embed/lib/image.c',
'embed/lib/mini_printf.c',
'embed/lib/rsod.c',
'embed/lib/terminal.c',
'embed/lib/gfx_draw.c',
'embed/upymod/modtrezorcrypto/rand.c',
'embed/gfx/bitblt/gfx_bitblt.c',
'embed/gfx/bitblt/gfx_bitblt_mono8.c',
'embed/gfx/bitblt/gfx_bitblt_rgb565.c',
'embed/gfx/bitblt/gfx_bitblt_rgba8888.c',
'embed/gfx/fonts/font_bitmap.c',
'embed/gfx/fonts/fonts.c',
'embed/gfx/gfx_color.c',
'embed/gfx/gfx_draw.c',
'embed/gfx/terminal.c',
'embed/io/display/display_utils.c',
'embed/util/flash/flash_utils.c',
'embed/util/image/image.c',
'embed/util/rsod/rsod.c',
'embed/rtl/error_handling.c',
'embed/rtl/mini_printf.c',
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',
Expand All @@ -100,13 +101,13 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
FILE_SUFFIX= env.get('ENV')['SUFFIX']

SOURCE_BOOTLOADER = [
f'embed/trezorhal/{FILE_SUFFIX}/startup_stage_1.s',
'embed/bootloader/header.S',
'embed/bootloader/bootui.c',
'embed/bootloader/main.c',
'embed/bootloader/messages.c',
'embed/bootloader/protob/messages.pb.c',
'embed/bootloader/version_check.c',
f'embed/sys/startup/{FILE_SUFFIX}/startup_stage_1.s',
'embed/projects/bootloader/header.S',
'embed/projects/bootloader/bootui.c',
'embed/projects/bootloader/main.c',
'embed/projects/bootloader/messages.c',
'embed/projects/bootloader/protob/messages.pb.c',
'embed/projects/bootloader/version_check.c',
]


Expand All @@ -128,13 +129,17 @@ env.Replace(

ALLPATHS = [
'embed/rust',
'embed/bootloader',
'embed/bootloader/nanopb',
'embed/bootloader/protob',
'embed/lib',
'embed/projects/bootloader',
'embed/projects/bootloader/nanopb',
'embed/projects/bootloader/protob',
'embed/rtl/inc',
'embed/models',
'embed/trezorhal',
'embed/extmod/modtrezorui',
'embed/sys/bsp/inc',
'embed/gfx/inc',
'embed/util/translations/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
'embed/upymod/modtrezorui',
'vendor/nanopb',
] + CPPPATH_MOD + PATH_HAL

Expand Down Expand Up @@ -253,7 +258,7 @@ env.Depends(program_elf, rust)
SUFFIX = '_qa' if BOOTLOADER_QA else ''

BINARY_NAME = f"build/bootloader/bootloader-{models.get_model_identifier(TREZOR_MODEL)}{SUFFIX}"
BINARY_NAME += "-" + tools.get_version('embed/bootloader/version.h')
BINARY_NAME += "-" + tools.get_version('embed/projects/bootloader/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
Expand Down
62 changes: 33 additions & 29 deletions core/SConscript.bootloader_ci
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ CPPPATH_MOD += [
'vendor/micropython/lib/uzlib',
]
SOURCE_MOD += [
'embed/extmod/modtrezorcrypto/rand.c',
'embed/lib/display_utils.c',
'embed/lib/error_handling.c',
'embed/lib/flash_utils.c',
'embed/lib/fonts/font_bitmap.c',
'embed/lib/fonts/fonts.c',
'embed/lib/gfx_color.c',
'embed/lib/gfx_bitblt_mono8.c',
'embed/lib/gfx_bitblt_rgb565.c',
'embed/lib/gfx_bitblt_rgba8888.c',
'embed/lib/image.c',
'embed/lib/mini_printf.c',
'embed/lib/rsod.c',
'embed/lib/terminal.c',
'embed/lib/gfx_draw.c',
'embed/upymod/modtrezorcrypto/rand.c',
'embed/gfx/bitblt/gfx_bitblt.c',
'embed/gfx/bitblt/gfx_bitblt_mono8.c',
'embed/gfx/bitblt/gfx_bitblt_rgb565.c',
'embed/gfx/bitblt/gfx_bitblt_rgba8888.c',
'embed/gfx/fonts/font_bitmap.c',
'embed/gfx/fonts/fonts.c',
'embed/gfx/gfx_color.c',
'embed/gfx/gfx_draw.c',
'embed/gfx/terminal.c',
'embed/io/display/display_utils.c',
'embed/util/flash/flash_utils.c',
'embed/util/image/image.c',
'embed/util/rsod/rsod.c',
'embed/rtl/error_handling.c',
'embed/rtl/mini_printf.c',
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',
Expand All @@ -94,13 +95,13 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
FILE_SUFFIX= env.get('ENV')['SUFFIX']

SOURCE_BOOTLOADER = [
f'embed/trezorhal/{FILE_SUFFIX}/startup_stage_1.s',
'embed/bootloader_ci/header.S',
'embed/bootloader_ci/bootui.c',
'embed/bootloader_ci/main.c',
'embed/bootloader_ci/messages.c',
'embed/bootloader_ci/protob/messages.pb.c',
'embed/bootloader_ci/version_check.c',
f'embed/sys/startup/{FILE_SUFFIX}/startup_stage_1.s',
'embed/projects/bootloader_ci/header.S',
'embed/projects/bootloader_ci/bootui.c',
'embed/projects/bootloader_ci/main.c',
'embed/projects/bootloader_ci/messages.c',
'embed/projects/bootloader_ci/protob/messages.pb.c',
'embed/projects/bootloader_ci/version_check.c',
]

env.Replace(
Expand Down Expand Up @@ -132,13 +133,16 @@ env.Replace(
CCFLAGS_QSTR='-DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB',
LINKFLAGS=f'-T build/bootloader_ci/memory.ld -Wl,--gc-sections -Wl,-Map=build/bootloader_ci/bootloader.map -Wl,--warn-common',
CPPPATH=[
'embed/bootloader_ci',
'embed/bootloader_ci/nanopb',
'embed/bootloader_ci/protob',
'embed/lib',
'embed/projects/bootloader_ci',
'embed/projects/bootloader_ci/nanopb',
'embed/projects/bootloader_ci/protob',
'embed/rtl/inc',
'embed/models',
'embed/trezorhal',
'embed/extmod/modtrezorui',
'embed/gfx/inc',
'embed/sys/bsp/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
'embed/upymod/modtrezorui',
'vendor/nanopb',
] + CPPPATH_MOD + PATH_HAL,
CPPDEFINES=[
Expand Down Expand Up @@ -195,7 +199,7 @@ program_elf = env.Command(
env.Depends(program_elf, linkerscript_gen)

BINARY_NAME = f"build/bootloader_ci/bootloader_ci-{models.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/bootloader_ci/version.h')
BINARY_NAME += "-" + tools.get_version('embed/projects/bootloader_ci/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
Expand Down
Loading

0 comments on commit 089db2c

Please sign in to comment.