1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-16 04:29:08 +00:00
trezor-firmware/core/SConscript.ble_firmware

443 lines
18 KiB
Plaintext

# pylint: disable=E0602
import os
import tools
TREZOR_MODEL = ARGUMENTS.get('TREZOR_MODEL', 'T')
CMAKELISTS = int(ARGUMENTS.get('CMAKELISTS', 0))
if TREZOR_MODEL in ('1', ):
# skip boardloader build
env = Environment()
def build_ble_firmware(target,source,env):
print(f'BLE FIRMWARE: nothing to build for Model {TREZOR_MODEL}')
program_bin = env.Command(
target='ble_firmware.bin',
source=None,
action=build_ble_firmware
)
Return()
CCFLAGS_MOD = ''
CPPPATH_MOD = []
CPPDEFINES_MOD = []
SOURCE_MOD = []
CCFLAGS_MOD += '-Wno-sequence-point '
if int(ARGUMENTS.get('PRODUCTION', 0)) == 0:
# Build for monitor debug mode.
MMD = True
else:
MMD = False
# C flags common to all targets
CPPDEFINES_MOD += [
'BOARD_PCA10056',
'CONFIG_GPIO_AS_PINRESET',
'FLOAT_ABI_HARD',
'NRF52840_XXAA',
'SOFTDEVICE_PRESENT',
('NRF_SD_BLE_API_VERSION', '7'),
'APP_TIMER_V2',
'APP_TIMER_V2_RTC1_ENABLED',
'S140',
('__HEAP_SIZE','8192'),
('__STACK_SIZE','8192'),
]
CPPPATH_MOD += [
]
CPPDEFINES_MOD += [
]
SOURCE_MOD += [
]
CPPPATH_MOD += [
'embed/sdk/nrf52/components/nfc/ndef/generic/message',
'embed/sdk/nrf52/components/nfc/t2t_lib',
'embed/sdk/nrf52/components/nfc/t4t_parser/hl_detection_procedure',
'embed/sdk/nrf52/components/ble/ble_services/ble_ancs_c',
'embed/sdk/nrf52/components/ble/ble_services/ble_ias_c',
'embed/sdk/nrf52/components/libraries/pwm',
'embed/sdk/nrf52/components/libraries/usbd/class/cdc/acm',
'embed/sdk/nrf52/components/libraries/usbd/class/hid/generic',
'embed/sdk/nrf52/components/libraries/usbd/class/msc',
'embed/sdk/nrf52/components/libraries/usbd/class/hid',
'embed/sdk/nrf52/modules/nrfx/hal',
'embed/sdk/nrf52/components/nfc/ndef/conn_hand_parser/le_oob_rec_parser',
'embed/sdk/nrf52/components/libraries/log',
'embed/sdk/nrf52/components/ble/ble_services/ble_gls',
'embed/sdk/nrf52/components/libraries/fstorage',
'embed/sdk/nrf52/components/nfc/ndef/text',
'embed/sdk/nrf52/components/libraries/mutex',
'embed/sdk/nrf52/components/libraries/gfx',
'embed/sdk/nrf52/components/libraries/bootloader/ble_dfu',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/common',
'embed/sdk/nrf52/components/libraries/fifo',
'embed/sdk/nrf52/components/boards',
'embed/sdk/nrf52/components/nfc/ndef/generic/record',
'embed/sdk/nrf52/components/nfc/t4t_parser/cc_file',
'embed/sdk/nrf52/components/ble/ble_advertising',
'embed/sdk/nrf52/external/utf_converter',
'embed/sdk/nrf52/components/ble/ble_services/ble_bas_c',
'embed/sdk/nrf52/modules/nrfx/drivers/include',
'embed/sdk/nrf52/components/libraries/experimental_task_manager',
'embed/sdk/nrf52/components/ble/ble_services/ble_hrs_c',
'embed/sdk/nrf52/components/softdevice/s140/headers/nrf52',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/le_oob_rec',
'embed/sdk/nrf52/components/libraries/queue',
'embed/sdk/nrf52/components/libraries/pwr_mgmt',
'embed/sdk/nrf52/components/ble/ble_dtm',
'embed/sdk/nrf52/components/toolchain/cmsis/include',
'embed/sdk/nrf52/components/ble/ble_services/ble_rscs_c',
'embed/sdk/nrf52/components/ble/common',
'embed/sdk/nrf52/components/ble/ble_services/ble_lls',
'embed/sdk/nrf52/components/nfc/platform',
'embed/sdk/nrf52/components/libraries/bsp',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/ac_rec',
'embed/sdk/nrf52/components/ble/ble_services/ble_bas',
'embed/sdk/nrf52/components/libraries/mpu',
'embed/sdk/nrf52/components/libraries/experimental_section_vars',
'embed/sdk/nrf52/components/ble/ble_services/ble_ans_c',
'embed/sdk/nrf52/components/libraries/slip',
'embed/sdk/nrf52/components/libraries/delay',
'embed/sdk/nrf52/components/libraries/csense_drv',
'embed/sdk/nrf52/components/libraries/memobj',
'embed/sdk/nrf52/components/ble/ble_services/ble_nus_c',
'embed/sdk/nrf52/components/softdevice/common',
'embed/sdk/nrf52/components/ble/ble_services/ble_ias',
'embed/sdk/nrf52/components/libraries/usbd/class/hid/mouse',
'embed/sdk/nrf52/components/libraries/low_power_pwm',
'embed/sdk/nrf52/components/nfc/ndef/conn_hand_parser/ble_oob_advdata_parser',
'embed/sdk/nrf52/components/ble/ble_services/ble_dfu',
'embed/sdk/nrf52/external/fprintf',
'embed/sdk/nrf52/components/libraries/svc',
'embed/sdk/nrf52/components/libraries/atomic',
'embed/sdk/nrf52/components',
'embed/sdk/nrf52/components/libraries/scheduler',
'embed/sdk/nrf52/components/libraries/cli',
'embed/sdk/nrf52/components/ble/ble_services/ble_lbs',
'embed/sdk/nrf52/components/ble/ble_services/ble_hts',
'embed/sdk/nrf52/components/ble/ble_services/ble_cts_c',
'embed/sdk/nrf52/components/libraries/crc16',
'embed/sdk/nrf52/components/nfc/t4t_parser/apdu',
'embed/sdk/nrf52/components/libraries/util',
'embed/sdk/nrf52/components/libraries/usbd/class/cdc',
'embed/sdk/nrf52/components/libraries/csense',
'embed/sdk/nrf52/components/libraries/balloc',
'embed/sdk/nrf52/components/libraries/ecc',
'embed/sdk/nrf52/components/libraries/hardfault',
'embed/sdk/nrf52/components/ble/ble_services/ble_cscs',
'embed/sdk/nrf52/components/libraries/uart',
'embed/sdk/nrf52/components/libraries/hci',
'embed/sdk/nrf52/components/libraries/usbd/class/hid/kbd',
'embed/sdk/nrf52/components/libraries/timer',
'embed/sdk/nrf52/components/softdevice/s140/headers',
'embed/sdk/nrf52/integration/nrfx',
'embed/sdk/nrf52/components/nfc/t4t_parser/tlv',
'embed/sdk/nrf52/components/libraries/sortlist',
'embed/sdk/nrf52/components/libraries/spi_mngr',
'embed/sdk/nrf52/components/libraries/led_softblink',
'embed/sdk/nrf52/components/nfc/ndef/conn_hand_parser',
'embed/sdk/nrf52/components/libraries/sdcard',
'embed/sdk/nrf52/components/nfc/ndef/parser/record',
'embed/sdk/nrf52/modules/nrfx/mdk',
'embed/sdk/nrf52/components/ble/ble_link_ctx_manager',
'embed/sdk/nrf52/components/ble/ble_services/ble_nus',
'embed/sdk/nrf52/components/libraries/twi_mngr',
'embed/sdk/nrf52/components/ble/ble_services/ble_hids',
'embed/sdk/nrf52/components/libraries/strerror',
'embed/sdk/nrf52/components/libraries/crc32',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/ble_oob_advdata',
'embed/sdk/nrf52/components/nfc/t2t_parser',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/ble_pair_msg',
'embed/sdk/nrf52/components/libraries/usbd/class/audio',
'embed/sdk/nrf52/components/nfc/t4t_lib',
'embed/sdk/nrf52/components/ble/peer_manager',
'embed/sdk/nrf52/components/libraries/mem_manager',
'embed/sdk/nrf52/components/libraries/ringbuf',
'embed/sdk/nrf52/components/ble/ble_services/ble_tps',
'embed/sdk/nrf52/components/nfc/ndef/parser/message',
'embed/sdk/nrf52/components/ble/ble_services/ble_dis',
'embed/sdk/nrf52/components/nfc/ndef/uri',
'embed/sdk/nrf52/components/ble/nrf_ble_gatt',
'embed/sdk/nrf52/components/ble/nrf_ble_qwr',
'embed/sdk/nrf52/components/libraries/gpiote',
'embed/sdk/nrf52/components/libraries/button',
'embed/sdk/nrf52/modules/nrfx',
'embed/sdk/nrf52/components/libraries/twi_sensor',
'embed/sdk/nrf52/integration/nrfx/legacy',
'embed/sdk/nrf52/components/libraries/usbd',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/ep_oob_rec',
'embed/sdk/nrf52/external/segger_rtt',
'embed/sdk/nrf52/components/libraries/atomic_fifo',
'embed/sdk/nrf52/components/ble/ble_services/ble_lbs_c',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/ble_pair_lib',
'embed/sdk/nrf52/components/libraries/crypto',
'embed/sdk/nrf52/components/ble/ble_racp',
'embed/sdk/nrf52/components/libraries/fds',
'embed/sdk/nrf52/components/nfc/ndef/launchapp',
'embed/sdk/nrf52/components/libraries/atomic_flags',
'embed/sdk/nrf52/components/ble/ble_services/ble_hrs',
'embed/sdk/nrf52/components/ble/ble_services/ble_rscs',
'embed/sdk/nrf52/components/nfc/ndef/connection_handover/hs_rec',
'embed/sdk/nrf52/components/nfc/ndef/conn_hand_parser/ac_rec_parser',
'embed/sdk/nrf52/components/libraries/stack_guard',
'embed/sdk/nrf52/components/libraries/log/src',
'embed'
]
SOURCE_MOD += [
]
SOURCE_NRFHAL_AS = [
'embed/sdk/nrf52/modules/nrfx/mdk/gcc_startup_nrf52840.S',
]
SOURCE_NRFHAL = [
'embed/sdk/nrf52/components/libraries/log/src/nrf_log_frontend.c',
'embed/sdk/nrf52/components/libraries/log/src/nrf_log_str_formatter.c',
'embed/sdk/nrf52/components/libraries/button/app_button.c',
'embed/sdk/nrf52/components/libraries/util/app_error.c',
'embed/sdk/nrf52/components/libraries/util/app_error_handler_gcc.c',
'embed/sdk/nrf52/components/libraries/util/app_error_weak.c',
'embed/sdk/nrf52/components/libraries/fifo/app_fifo.c',
'embed/sdk/nrf52/components/libraries/scheduler/app_scheduler.c',
'embed/sdk/nrf52/components/libraries/timer/app_timer2.c',
'embed/sdk/nrf52/components/libraries/uart/app_uart_fifo.c',
'embed/sdk/nrf52/components/libraries/util/app_util_platform.c',
'embed/sdk/nrf52/components/libraries/timer/drv_rtc.c',
'embed/sdk/nrf52/components/libraries/hardfault/hardfault_implementation.c',
'embed/sdk/nrf52/components/libraries/util/nrf_assert.c',
'embed/sdk/nrf52/components/libraries/atomic_fifo/nrf_atfifo.c',
'embed/sdk/nrf52/components/libraries/atomic_flags/nrf_atflags.c',
'embed/sdk/nrf52/components/libraries/atomic/nrf_atomic.c',
'embed/sdk/nrf52/components/libraries/balloc/nrf_balloc.c',
'embed/sdk/nrf52/external/fprintf/nrf_fprintf.c',
'embed/sdk/nrf52/external/fprintf/nrf_fprintf_format.c',
'embed/sdk/nrf52/components/libraries/memobj/nrf_memobj.c',
'embed/sdk/nrf52/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c',
'embed/sdk/nrf52/components/libraries/ringbuf/nrf_ringbuf.c',
'embed/sdk/nrf52/components/libraries/experimental_section_vars/nrf_section_iter.c',
'embed/sdk/nrf52/components/libraries/sortlist/nrf_sortlist.c',
'embed/sdk/nrf52/components/libraries/strerror/nrf_strerror.c',
'embed/sdk/nrf52/components/libraries/uart/retarget.c',
'embed/sdk/nrf52/modules/nrfx/mdk/system_nrf52840.c',
'embed/sdk/nrf52/components/boards/boards.c',
'embed/sdk/nrf52/integration/nrfx/legacy/nrf_drv_clock.c',
'embed/sdk/nrf52/integration/nrfx/legacy/nrf_drv_uart.c',
'embed/sdk/nrf52/modules/nrfx/soc/nrfx_atomic.c',
'embed/sdk/nrf52/modules/nrfx/drivers/src/nrfx_clock.c',
'embed/sdk/nrf52/modules/nrfx/drivers/src/nrfx_gpiote.c',
'embed/sdk/nrf52/modules/nrfx/drivers/src/prs/nrfx_prs.c',
'embed/sdk/nrf52/modules/nrfx/drivers/src/nrfx_uart.c',
'embed/sdk/nrf52/modules/nrfx/drivers/src/nrfx_uarte.c',
'embed/sdk/nrf52/components/libraries/bsp/bsp.c',
'embed/sdk/nrf52/components/libraries/bsp/bsp_btn_ble.c',
'embed/sdk/nrf52/components/ble/common/ble_advdata.c',
'embed/sdk/nrf52/components/ble/ble_advertising/ble_advertising.c',
'embed/sdk/nrf52/components/ble/common/ble_conn_params.c',
'embed/sdk/nrf52/components/ble/common/ble_conn_state.c',
'embed/sdk/nrf52/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c',
'embed/sdk/nrf52/components/ble/common/ble_srv_common.c',
'embed/sdk/nrf52/components/ble/nrf_ble_gatt/nrf_ble_gatt.c',
'embed/sdk/nrf52/components/ble/nrf_ble_qwr/nrf_ble_qwr.c',
'embed/sdk/nrf52/external/utf_converter/utf.c',
'embed/sdk/nrf52/components/softdevice/common/nrf_sdh.c',
'embed/sdk/nrf52/components/softdevice/common/nrf_sdh_ble.c',
'embed/sdk/nrf52/components/softdevice/common/nrf_sdh_soc.c',
'embed/sdk/nrf52/components/ble/peer_manager/gatt_cache_manager.c',
'embed/sdk/nrf52/components/ble/peer_manager/gatts_cache_manager.c',
'embed/sdk/nrf52/components/ble/peer_manager/id_manager.c',
'embed/sdk/nrf52/components/ble/peer_manager/peer_data_storage.c',
'embed/sdk/nrf52/components/ble/peer_manager/peer_database.c',
'embed/sdk/nrf52/components/ble/peer_manager/peer_id.c',
'embed/sdk/nrf52/components/ble/peer_manager/peer_manager.c',
'embed/sdk/nrf52/components/ble/peer_manager/peer_manager_handler.c',
'embed/sdk/nrf52/components/ble/peer_manager/pm_buffer.c',
'embed/sdk/nrf52/components/libraries/fds/fds.c',
'embed/sdk/nrf52/components/ble/peer_manager/security_manager.c',
'embed/sdk/nrf52/components/ble/peer_manager/security_dispatcher.c',
'embed/sdk/nrf52/components/libraries/fstorage/nrf_fstorage.c',
'embed/sdk/nrf52/components/libraries/fstorage/nrf_fstorage_sd.c',
]
SOURCE_BLE_FIRMWARE = [
'embed/ble_firmware/main.c',
'embed/ble_firmware/ble_nus.c',
'embed/ble_firmware/int_comm.c',
]
if MMD:
CPPDEFINES_MOD += [
'DEBUG',
'DEBUG_NRF',
'MMD'
]
SOURCE_BLE_FIRMWARE += [
'embed/segger/SEGGER_MMD/JLINK_MONITOR.c',
'embed/segger/SEGGER_MMD/JLINK_MONITOR_ISR_SES.S'
]
SOURCE_NRFHAL += [
'embed/sdk/nrf52/components/libraries/log/src/nrf_log_backend_rtt.c',
'embed/sdk/nrf52/components/libraries/log/src/nrf_log_backend_serial.c',
'embed/sdk/nrf52/components/libraries/log/src/nrf_log_backend_uart.c',
'embed/sdk/nrf52/components/libraries/log/src/nrf_log_default_backends.c',
'embed/sdk/nrf52/external/segger_rtt/SEGGER_RTT.c',
'embed/sdk/nrf52/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c',
'embed/sdk/nrf52/external/segger_rtt/SEGGER_RTT_printf.c',
]
CPPPATH_MOD += [
'embed/segger/SEGGER_MMD'
]
env = Environment(ENV=os.environ, CFLAGS='%s -DPRODUCTION=%s' % (ARGUMENTS.get('CFLAGS', ''), ARGUMENTS.get('PRODUCTION', '0')))
env.Replace(
CP='cp',
AS='arm-none-eabi-as',
AR='arm-none-eabi-ar',
CC='arm-none-eabi-gcc',
LINK='arm-none-eabi-gcc',
SIZE='arm-none-eabi-size',
STRIP='arm-none-eabi-strip',
OBJCOPY='arm-none-eabi-objcopy',
PYTHON='python',
MAKECMAKELISTS='$PYTHON tools/make_cmakelists.py', )
env.Replace(
TREZOR_MODEL=TREZOR_MODEL, )
CPU_ASFLAGS = '-mthumb -mabi=aapcs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16'
CPU_CCFLAGS = '-mthumb -mabi=aapcs -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 '
env.Replace(
COPT=env.get('ENV').get('OPTIMIZE', '-Og'),
CCFLAGS='$COPT '
'-g3 '
'-std=c99 -Wall -Werror -Wdouble-promotion -Wpointer-arith -Wno-missing-braces '
'-fdata-sections -ffunction-sections '
'-fno-strict-aliasing '
'-fno-builtin '
'-fshort-enums '
+ CPU_CCFLAGS + CCFLAGS_MOD,
LINKFLAGS='-Lembed/sdk/nrf52/modules/nrfx/mdk -T embed/ble_firmware/memory.ld -Wl,--gc-sections --specs=nano.specs -Wl,-Map=build/ble_firmware/ble_firmware.map -Wl,--warn-common -Wl,--print-memory-usage',
CPPPATH=[
'embed/ble_firmware',
'embed/sdk/nrf52',
] + CPPPATH_MOD,
CPPDEFINES=[
'BLE_FIRMWARE',
'TREZOR_MODEL_'+TREZOR_MODEL,
] + CPPDEFINES_MOD,
ASFLAGS=CPU_ASFLAGS,
ASPPFLAGS='$CFLAGS $CCFLAGS', )
#
# Program objects
#
obj_program = []
obj_program += env.Object(source=SOURCE_BLE_FIRMWARE)
obj_program += env.Object(source=SOURCE_NRFHAL_AS, COPT='-O0')
obj_program += env.Object(source=SOURCE_NRFHAL)
obj_program += env.Object(source=SOURCE_MOD)
env.Replace(
ALLSOURCES=SOURCE_NRFHAL_AS + SOURCE_MOD + SOURCE_BLE_FIRMWARE + SOURCE_NRFHAL,
ALLDEFS=tools.get_defs_for_cmake(env['CPPDEFINES']))
cmake_gen = env.Command(
target='CMakeLists.txt',
source='',
action='$MAKECMAKELISTS --sources $ALLSOURCES --dirs $CPPPATH --defs $ALLDEFS',
)
LIB_FILES = [
'embed/sdk/nrf52/external/nrf_oberon/lib/cortex-m4/hard-float/liboberon_3.0.8.a',
'embed/sdk/nrf52/external/nrf_cc310_bl/lib/cortex-m4/hard-float/libnrf_cc310_bl_0.9.13.a',
]
program_elf = env.Command(
target='ble_firmware.elf',
source=obj_program,
action=
'$LINK -o $TARGET $CCFLAGS $CFLAGS $LINKFLAGS $SOURCES ' + ' '.join(LIB_FILES) + ' -lc -lnosys -lm',
)
BINARY_NAME = f"build/ble_firmware/ble_firmware-{tools.get_model_identifier(TREZOR_MODEL)}"
BINARY_NAME += "-" + tools.get_version('embed/ble_firmware/version.h')
BINARY_NAME += "-" + tools.get_git_revision_short_hash()
BINARY_NAME += "-dirty" if tools.get_git_modified() else ""
BINARY_NAME += ".bin"
if CMAKELISTS != 0:
env.Depends(program_elf, cmake_gen)
program_hex = env.Command(
target='ble_firmware.hex',
source=program_elf,
action='$OBJCOPY -O ihex $SOURCE $TARGET',
)
program_pkg = env.Command(
target='ble_firmware.zip',
source=program_hex,
action=[
f'nrfutil pkg generate --hw-version 52 --sd-req=0x100 --application $SOURCE --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --key-file ./embed/ble_bootloader/priv.pem $TARGET --application-version-string {tools.get_version("embed/ble_firmware/version.h")}'
],
)
settings = env.Command(
target='settings.hex',
source=program_hex,
action=f'nrfutil settings generate --family NRF52840 --application $SOURCE --app-boot-validation VALIDATE_ECDSA_P256_SHA256 --application-version-string {tools.get_version("embed/ble_firmware/version.h")} --bootloader-version {tools.get_version_int("embed/ble_bootloader/version.h")} --bl-settings-version 2 --sd-boot-validation VALIDATE_ECDSA_P256_SHA256 --softdevice ./embed/sdk/nrf52/components/softdevice/s140/hex/s140_nrf52_7.2.0_softdevice.hex --key-file ./embed/ble_bootloader/priv.pem $TARGET',
)
program_merge = env.Command(
target='ble_firmware_merged.hex',
source=[program_hex, settings],
action='mergehex -m $SOURCES -o $TARGET',
)
program_bin = env.Command(
target='ble_firmware.bin',
source=program_elf,
action=[
'$OBJCOPY -O binary $SOURCE $TARGET',
'$CP $TARGET ' + BINARY_NAME,
],
)
env.Depends(program_bin, program_hex)
env.Depends(program_pkg, program_hex)
env.Depends(settings, program_hex)
env.Depends(program_bin, program_pkg)
env.Depends(program_merge, settings)
env.Depends(program_merge, program_hex)
env.Depends(program_bin, program_merge)