CMake has been implemented to manage ARM projects.

Add the mkversion bat and ps1 implementation to the Windows platform compilation.
Make armlib a static library so that bootrom and armsrc can be reused.
This commit is contained in:
DXL authored and Philippe Teuwen committed 2026-08-19 15:51:50 +02:00
1 parent 355d58b1cb
commit 0191fb78ec
15 files changed
+1936

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.20)
# Option to build the firmware for the Proxmark3/5. This will include the armsrc and bootrom directories.
option(BUILD_FIRMWARE "Build the firmware for the Proxmark3/5" ON)
# If building for pm3 device, not client, the compiler will be arm-none-eabi-gcc, so the test program will not compile.
# This is a workaround to prevent CMake from trying to compile the test program,
# which will fail because the compiler is not for the host system.
if (BUILD_FIRMWARE)
include(${CMAKE_CURRENT_LIST_DIR}/tools/FixCompileTest.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/tools/ToolchainForArm.cmake)
endif ()
# Project name and languages
project(Proxmark3 C CXX ASM)
# add subdirectories, which will contain their own CMakeLists.txt files
if (BUILD_FIRMWARE)
add_subdirectory(armsrc)
add_subdirectory(bootrom)
else ()
add_subdirectory(client)
endif ()
+89
View File
@@ -0,0 +1,89 @@
if (PM5 AND NOT TARGET pm5_at32_armlib)
add_library(pm5_at32_armlib STATIC
${CMAKE_CURRENT_LIST_DIR}/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_crm.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_misc.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_gpio.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_usb.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_qspi.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_tmr.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_ertc.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_pwc.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_spi.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_i2c.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_dma.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_adc.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_usart.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_exint.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_scfg.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_flash.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_crc.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_wdt.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_wwdt.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_can.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_dac.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_debug.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_dvp.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_edma.c
# ${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_emac.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_sdio.c
# ${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_xmc.c
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/src/at32f435_437_acc.c
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usb_core.c
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usbd_core.c
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usbd_int.c
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/src/usbd_sdr.c
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usbd_class/cdc/cdc_class.c
${CMAKE_CURRENT_LIST_DIR}/at32_i2c/at32f435_437_i2c_app.c
)
target_compile_options(pm5_at32_armlib
PRIVATE ${CROSS_CFLAGS}
PUBLIC -mcpu=cortex-m4 -Wno-missing-prototypes -Wno-missing-declarations
)
target_compile_definitions(pm5_at32_armlib PUBLIC
AT32F435RGT7
USE_STDPERIPH_DRIVER
AT_START_F435_V1
CRM_MODULE_ENABLED
MISC_MODULE_ENABLED
GPIO_MODULE_ENABLED
USB_MODULE_ENABLED
QSPI_MODULE_ENABLED
TMR_MODULE_ENABLED
ERTC_MODULE_ENABLED
PWC_MODULE_ENABLED
SPI_MODULE_ENABLED
I2C_MODULE_ENABLED
DMA_MODULE_ENABLED
ADC_MODULE_ENABLED
USART_MODULE_ENABLED
EXINT_MODULE_ENABLED
SCFG_MODULE_ENABLED
FLASH_MODULE_ENABLED
CRC_MODULE_ENABLED
WDT_MODULE_ENABLED
WWDT_MODULE_ENABLED
CAN_MODULE_ENABLED
DAC_MODULE_ENABLED
DEBUG_MODULE_ENABLED
DVP_MODULE_ENABLED
EDMA_MODULE_ENABLED
# EMAC_MODULE_ENABLED
SDIO_MODULE_ENABLED
# XMC_MODULE_ENABLED
ACC_MODULE_ENABLED
USBD_SUPPORT_WINUSB=1
)
target_include_directories(pm5_at32_armlib PUBLIC
${CMAKE_CURRENT_LIST_DIR}/at32_sys
${CMAKE_CURRENT_LIST_DIR}/at32_sys/cmsis/cm4/core_support
${CMAKE_CURRENT_LIST_DIR}/at32_sys/cmsis/cm4/device_support
${CMAKE_CURRENT_LIST_DIR}/at32_sys/drivers/inc
${CMAKE_CURRENT_LIST_DIR}/at32_usb
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usb_drivers/inc
${CMAKE_CURRENT_LIST_DIR}/at32_usb/usbd_class/cdc
${CMAKE_CURRENT_LIST_DIR}/at32_i2c
)
set_property(TARGET pm5_at32_armlib PROPERTY POSITION_INDEPENDENT_CODE ON)
endif ()
+556
View File
@@ -0,0 +1,556 @@
cmake_minimum_required(VERSION 3.20)
# Fix error when 'compile a simple test program.'
include(${CMAKE_CURRENT_LIST_DIR}/../tools/FixCompileTest.cmake)
# Ensure direct armsrc builds also select ARM cross-compilers.
include(${CMAKE_CURRENT_LIST_DIR}/../tools/ToolchainForArm.cmake)
# Set variables needs before the project defining.
project(fullimage C CXX ASM)
# Compile tools for project build step, preprocessor and postprocessor
# So this compiler need run on host platform
find_program(C_COMPILER_HOST gcc)
if (NOT C_COMPILER_HOST)
message(FATAL_ERROR "GCC for tools build on host is no found, Plz give the cmake arg like 'cmake -DC_COMPILER_HOST=/your path/'")
endif ()
# Genarate version info by mkversion script
include(${CMAKE_CURRENT_LIST_DIR}/../tools/MKVersionScript.cmake)
# Import options for standalone mode
# Used 'STANDALONE_REQ_DEFS' & 'STANDALONE_PLATFORM_DEFS' variables.
include(${CMAKE_CURRENT_LIST_DIR}/Standalone/StandAloneOption.cmake)
# Hardware abstraction layer for ARM platform.
include(${CMAKE_CURRENT_LIST_DIR}/../common_arm/Hal.cmake)
# Setup FPGA Compress.
include(${CMAKE_CURRENT_LIST_DIR}/../tools/FpgaCompress.cmake)
# ---------------------------------------------------------------------------------
set(APP_CFLAGS ${PLATFORM_DEFS} -ffunction-sections -fdata-sections)
set(INC_DIRS
../include
../common_arm
../common_arm/rssi
../common_arm/ticks
../common_arm/usb
../common_arm/flash_data
../common_arm/flash_code
../common_arm/gpio
../common_arm/sys
../common_arm/fpga
../common_arm/wdt
../common_fpga
../common
../common/lz4
.
)
# Hal for platform
if (PM5)
set(SRC_TICKS ../common_arm/ticks/ticks_hw_at32.c)
set(SRC_GPIO ../common_arm/gpio/gpio_hw_at32.c)
set(SRC_WDT ../common_arm/wdt/wdt_hw_at32.c)
set(SRC_RSSI ../common_arm/rssi/rssi_hw_at32.c)
set(SRC_SYS ../common_arm/sys/sys_hw_at32.c)
set(SRC_FLASH_DATA ../common_arm/flash_data/flashmem_hw_at32.c)
set(SRC_USB_CDC ../common_arm/usb/usb_cdc_at32.c)
set(SRC_FPGA ../common_arm/fpga/fpga_hw_at32.c ../common_arm/fpga/fpga_gw_jtag.c)
set(LDSCRIPT ${CMAKE_CURRENT_LIST_DIR}/ldscript.osimage.at32)
else ()
set(SRC_TICKS ../common_arm/ticks/ticks_hw_at91.c)
set(SRC_GPIO ../common_arm/gpio/gpio_hw_at91.c)
set(SRC_WDT ../common_arm/wdt/wdt_hw_at91.c)
set(SRC_RSSI ../common_arm/rssi/rssi_hw_at91.c)
set(SRC_SYS ../common_arm/sys/sys_hw_at91.c)
set(SRC_FLASH_DATA ../common_arm/flash_data/flashmem_hw_at91.c)
set(SRC_USB_CDC ../common_arm/usb/usb_cdc_at91.c)
set(SRC_FPGA ../common_arm/fpga/fpga_hw_at91.c)
set(LDSCRIPT ${CMAKE_CURRENT_LIST_DIR}/ldscript.osimage.at91)
endif ()
set(SRC_LF
lfops.c
lfsampling.c
pcf7931.c
../common/lfdemod.c
lfadc.c
)
set(SRC_HF hfops.c)
set(SRC_ISO15693
iso15693.c
../common/iso15693tools.c)
set(SRC_ISO14443a
iso14443a.c
secc.c
mifareutil.c
mifarecmd.c
epa.c
mifaresim.c
sam_common.c
sam_mfc.c
sam_seos.c
sam_sc.c
)
#UNUSED: mifaresniff.c
set(SRC_ISO14443b iso14443b.c)
set(SRC_FELICA felica.c felicasim.c)
set(SRC_CRAPTO1
../common/crapto1/crypto1.c
desfire_crypto.c
mifaredesfire.c
../common/mbedtls/des.c
../common/mbedtls/aes.c
../common/mbedtls/platform_util.c
)
set(SRC_CRC
../common/crc.c
../common/crc16.c
../common/crc32.c)
set(SRC_ICLASS
iclass.c
optimized_cipherutils.c
optimized_ikeys.c
optimized_elite.c
optimized_cipher.c
sam_picopass.c
)
set(SRC_SEOS
seos.c
../common/mbedtls/sha1.c
../common/mbedtls/sha256.c)
set(SRC_LEGIC
legicrf.c
legicrfsim.c
../common/legic_prng.c)
set(SRC_NFCBARCODE thinfilm.c)
# SRC_BEE = bee.c
# set(SRC_BEE bee.c)
message(STATUS "APP_CFLAGS = ${APP_CFLAGS}")
# RDV4 or PM5 related hardware support
if ("${APP_CFLAGS}" MATCHES "WITH_FLASH")
set(SRC_FLASH ${SRC_FLASH_DATA} ../common_arm/flash_data/flashmem_core.c)
set(SRC_SPIFFS
spiffs.c
spiffs_cache.c
spiffs_check.c
spiffs_gc.c
spiffs_nucleus.c
spiffs_hydrogen.c
)
else ()
set(SRC_FLASH)
set(SRC_SPIFFS)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_SMARTCARD")
set(SRC_SMARTCARD i2c.c i2c_direct.c emvsim.c)
else ()
set(SRC_SMARTCARD)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_FPC_USART")
set(SRC_FPC usart.c)
else ()
set(SRC_FPC)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_HITAG")
set(SRC_HITAG
../common/hitag2/hitag2_crypto.c
hitag_common.c
hitag2.c
hitagS.c
hitagu.c
hitag2_crack.c
)
list(APPEND INC_DIRS ../common/hitag2)
else ()
set(SRC_HITAG)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_EM4x50")
set(SRC_EM4x50
em4x50.c
../common/bruteforce.c)
else ()
set(SRC_EM4x50)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_EM4x70")
set(SRC_EM4x70 em4x70.c)
else ()
set(SRC_EM4x70)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_LCD")
# LCD module is disabled. file name is fonts_disabled.c and LCD_disabled.c
# So, if WITH_LCD enable, we need show error for DEV.
set(SRC_LCD fonts.c LCD.c)
message(FATAL_ERROR "LCD functions is unavailable")
else ()
set(SRC_LCD)
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_ZX8211")
set(SRC_ZX lfzx.c)
else ()
set(SRC_ZX)
endif ()
# Generic standalone Mode injection of source code
include(${CMAKE_CURRENT_LIST_DIR}/Standalone/StandAloneSource.cmake)
# The lz4 source files required for decompressing the fpga config at run time
set(SRC_LZ4 ../common/lz4/lz4.c)
# Additional defines required to compile lz4
set(LZ4_CFLAGS "-DLZ4_MEMORY_USAGE=8" "-DLZ4_HEAPMODE=0")
list(APPEND APP_CFLAGS ${LZ4_CFLAGS})
# lz4 includes:
list(APPEND INC_DIRS ../common/lz4)
# stdint.h provided locally until GCC 4.5 becomes C99 compliant,
# stack-protect , no-pie reduces size on Gentoo Hardened 8.2 gcc
list(APPEND APP_CFLAGS -I. -fno-stack-protector -fno-pie)
# Compile these in thumb mode (small size)
set(THUMBSRC
start.c
${SRC_LCD}
${SRC_ISO15693}
${SRC_NFCBARCODE}
${SRC_LF}
${SRC_LZ4}
${SRC_LEGIC}
${SRC_FLASH}
${SRC_SMARTCARD}
${SRC_FPC}
${SRC_HITAG}
${SRC_EM4x50}
${SRC_EM4x70}
${SRC_SPIFFS}
${SRC_HF}
${SRC_ISO14443a}
${SRC_ISO14443b}
${SRC_CRAPTO1}
${SRC_ICLASS}
${SRC_SEOS}
${SRC_EMV}
${SRC_CRC}
${SRC_FELICA}
${SRC_STANDALONE}
${SRC_ZX}
appmain.c
printf.c
dbprint.c
../common/commonutil.c
util.c
string.c
BigBuf.c
${SRC_RSSI}
${SRC_TICKS}
${SRC_GPIO}
${SRC_WDT}
${SRC_SYS}
../common_arm/rssi/rssi_core.c
../common_arm/ticks/ticks_core.c
hfsnoop.c
../common/generator.c
cmac_calc.c
cmac_3des.c
)
if (PM5)
list(APPEND THUMBSRC startup_at32f435_437.s)
list(APPEND THUMBSRC i2c.c)
list(APPEND THUMBSRC at32_unit_test.c) # TODO DXL: AT32单元测试代码
endif ()
# These are to be compiled in ARM mode
set(ARMSRC
../common_arm/fpga/fpga_loader.c
../common_arm/fpga/fpga_core.c
${SRC_FPGA}
../common_arm/usb/usb_read_ng.c
../common_arm/usb/usb_cdc_desc.c
${SRC_USB_CDC} # AT32 or AT91 usb module, api defs all in usb_cdc.h
cmd.c
)
set(VERSIONSRC version_pm3.c fpga_version_info.c)
# Import common settings for arm build, such as common cflags, etc.
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
include(${CMAKE_CURRENT_LIST_DIR}/../common_arm/Common.cmake)
if (PM5)
include(${CMAKE_CURRENT_LIST_DIR}/../armlib/pm5_at32_armlib.cmake)
set(LIBS ${LIBS} pm5_at32_armlib)
# set(CROSS_LDFLAGS ${CROSS_LDFLAGS} -mfloat-abi=hard -mfpu=fpv4-sp-d16) # TODO DXL: Hardware float core enable?
set(CROSS_LDFLAGS ${CROSS_LDFLAGS} -mcpu=cortex-m4)
endif ()
message(STATUS "LDSCRIPT = ${LDSCRIPT}")
message(STATUS "CROSS_CFLAGS = ${CROSS_CFLAGS}")
# =====================================================
# FPGA_COMPRESS_EXE -> 可执行文件完整路径(如 /path/to/fpga_compress)
# FPGA_BITSTREAMS -> 所有 .bit 文件列表
# OBJDIR -> 构建输出目录(如 ${CMAKE_BINARY_DIR}/obj)
# APP_CFLAGS -> 编译标志(如 "WITH_COMPRESSION")
# THUMBSRC -> 需用 -mthumb 编译的 C 源文件
# ARMSRC -> 可用 ARM 模式编译的 C 源文件
# ASMSRC -> 汇编文件(.s)
# VERSIONSRC -> version_pm3.c和fpga_version_info.c(或其路径)
# INC_DIRS -> 包含目录列表
# CROSS_CFLAGS -> 通用编译标志(如 -O2, -Wall)
# CROSS_LDFLAGS -> 链接标志(如 -nostartfiles)
# CMAKE_OBJCOPY -> objcopy 工具路径
# LDSCRIPT -> 链接脚本路径
# DEFAULT_VERSION_C -> 默认 version 模板文件
# =====================================================
#[[
# Firmware and Compressed Data Integration: LZ4-based .data Section Compression Scheme
1. Compile Firmware
- Compile C/C++ source code normally to generate an ELF file with the original .data section.
- The linker calculates the .data size and reserves VMA (Virtual Memory Address) space in RAM.
2. Extract .data Section to Binary
- Use objcopy to extract the raw .data section from the ELF, generating an uncompressed binary (e.g., data.bin).
3. Compress Data and Add Metadata
- Compress data.bin using LZ4 (or similar) to produce a compressed stream (e.g., data.bin.z).
- Prepend a 4-byte header containing the original .data size (avail_out), used for decompression bounds checking.
4. Update .data Content in ELF
- Use objcopy --update-section to replace the .data section in the ELF with the compressed data (including 4-byte header).
- This operation only changes the content and LMA (Load Memory Address) size, not the VMA (RAM address or reserved space).
5. Generate Final Firmware Image
- Convert the updated ELF to .bin or .hex format for flashing.
- The .data section in Flash now contains compressed data, significantly reducing firmware size.
6. Runtime Decompression
- At startup, read the .data section start address (__data_src_start__) from Flash.
- Read the first 4 bytes to get the original size (avail_out).
- Call LZ4_decompress_safe to decompress the data into the RAM region from __data_start__ to __data_end__.
- After decompression, .data variables are restored and the program continues.
# Key Insight: VMA Reservation Mechanism
- The linker reserves sufficient RAM space for the .data section at link time, based on the original (uncompressed) size.
- Compression only affects storage in Flash (LMA), not the runtime layout in RAM (VMA).
- The decompression target is precisely defined by linker symbols __data_start__ and __data_end__, ensuring safety and correctness.
]]
set(OBJDIR ${CMAKE_BINARY_DIR}/obj)
set(DEFAULT_VERSION_C ${CMAKE_CURRENT_LIST_DIR}/../common/default_version_pm3.c)
# ---------------- Output dir ----------------
file(MAKE_DIRECTORY ${OBJDIR})
get_filename_component(OBJDIR_NAME ${OBJDIR} NAME)
# ---------------- Output files ----------------
get_filename_component(FPGA_VERSION_C ${CMAKE_CURRENT_LIST_DIR}/fpga_version_info.c ABSOLUTE)
get_filename_component(FPGA_BIT_Z ${OBJDIR}/fpga_all.bit.z ABSOLUTE)
get_filename_component(FPGA_BIT_Z_NAME ${FPGA_BIT_Z} NAME)
get_filename_component(FPGA_ALL_O ${OBJDIR}/fpga_all.o ABSOLUTE)
get_filename_component(VERSION_PM3_C ${CMAKE_CURRENT_LIST_DIR}/version_pm3.c ABSOLUTE)
get_filename_component(STAGE1_ELF ${OBJDIR}/fullimage.stage1.elf ABSOLUTE)
get_filename_component(DATA_BIN ${OBJDIR}/fullimage.data.bin ABSOLUTE)
get_filename_component(DATA_BIN_Z ${OBJDIR}/fullimage.data.bin.z ABSOLUTE)
get_filename_component(FINAL_ELF ${OBJDIR}/fullimage.elf ABSOLUTE)
get_filename_component(OUTPUT_S19 ${OBJDIR}/fullimage.s19 ABSOLUTE)
get_filename_component(OUTPUT_STAGE1_HEX ${OBJDIR}/fullimage.stage1.hex ABSOLUTE)
get_filename_component(OUTPUT_STAGE1_BIN ${OBJDIR}/fullimage.stage1.bin ABSOLUTE)
get_filename_component(OUTPUT_FINAL_HEX ${OBJDIR}/fullimage.hex ABSOLUTE)
get_filename_component(OUTPUT_FINAL_BIN ${OBJDIR}/fullimage.bin ABSOLUTE)
# ---------------- 1. Create fpga_version_info.c ----------------
set(FPGA_BITSTREAMS_ABSOLUTE_PATH) # Convert all .bit files from relative to absolute path
foreach (bitFile ${FPGA_BITSTREAMS})
get_filename_component(bitFileAbPath ${bitFile} ABSOLUTE) # get absolute path
list(APPEND FPGA_BITSTREAMS_ABSOLUTE_PATH ${bitFileAbPath}) # append to list
endforeach ()
add_custom_command(
OUTPUT ${FPGA_VERSION_C}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(1) fpga_version_info.c"
COMMAND ${FPGA_COMPRESS_EXE} -v ${FPGA_BITSTREAMS_ABSOLUTE_PATH} ${FPGA_VERSION_C}
DEPENDS ${FPGA_BITSTREAMS_ABSOLUTE_PATH}
DEPENDS ${FPGA_COMPRESS_EXE} # Before this step run, we need to build 'fpga_compress' executable
COMMAND_EXPAND_LISTS
COMMENT "Call the 'fpga_compress' to generate 'fpga_version_info.c' for armsrc"
VERBATIM
)
# ---------------- 2. Create fpga_all.bit.z ----------------
# If no fpga pack to arm fw required, skip this.
add_custom_command(
OUTPUT ${FPGA_BIT_Z}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(2) fpga_all.bit.z"
COMMAND ${FPGA_COMPRESS_EXE} ${FPGA_BITSTREAMS_ABSOLUTE_PATH} ${FPGA_BIT_Z}
DEPENDS ${FPGA_BITSTREAMS_ABSOLUTE_PATH}
DEPENDS ${FPGA_COMPRESS_EXE} # Ensure host tool is built before running it.
COMMAND_EXPAND_LISTS
COMMENT "Call the 'fpga_compress' to compress fpga bit files, output 'fpga_all.bit.z'"
VERBATIM
)
# ---------------- 3. Create fpga_all.o ----------------
# If no fpga pack to arm fw required, skip this step.
# The _binary_obj_fpga_all_bit_z_start and _binary_obj_fpga_all_bit_z_end will generate by 'objcopy'
# Yes, fpga_all.o contain 'binary<path>_<format>_start', 'binary<path>_<format>_size', 'binary<path>_<format>_end'
# More info view: https://stackoverflow.com/questions/60295013/is-it-possible-to-make-a-hardcoding-with-the-help-of-the-command-objcopy
# Tips: the binary file put in '.data' section.
add_custom_command(
OUTPUT ${FPGA_ALL_O}
# !!! Important !!! Must enter parent dir of obj output dir, to create fpga_all.o
# The objcopy command needs to generate object file for 'fpga_all.bit.z' outside the obj directory.
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(3) fpga_all.o"
COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm -I binary -B arm --prefix-sections=fpga_all_bit ${OBJDIR_NAME}/${FPGA_BIT_Z_NAME} ${FPGA_ALL_O}
DEPENDS ${FPGA_BIT_Z}
COMMENT "Call the objcopy to convert binary to elf file."
VERBATIM
)
# ---------------- 4. Create version_pm3.c ----------------
if (SKIP_FPGA_EMBED) # If pack fpga bit files to arm, we need from step1,2,3 start build, otherwise skip step2,3.
set(FPGA_ALL_O_MKVERSION_DEP) # <-- Important, unset it will let this step(4) no DEPENDS with 'FPGA_ALL_O'.
else ()
set(FPGA_ALL_O_MKVERSION_DEP ${FPGA_ALL_O})
endif ()
add_custom_command(
OUTPUT ${VERSION_PM3_C}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(4) version_pm3.c"
DEPENDS ${DEFAULT_VERSION_C} ${FPGA_VERSION_C} ${FPGA_ALL_O_MKVERSION_DEP}
COMMAND ${MKVERSION_CMD} ${VERSION_PM3_C} || ${CMAKE_COMMAND} -E copy ${DEFAULT_VERSION_C} ${VERSION_PM3_C}
COMMENT "Call mkversion.xx script to generate 'version_pm3.c', if mkversion return fail, fallback is default_version_pm3.c"
VERBATIM
)
# ---------------- 5. Build fulliamge elf but stage1, not '.data' section compressed ----------------
set(ALL_SRCS ${THUMBSRC} ${ARMSRC} ${ASMSRC} ${VERSIONSRC})
add_executable(fullimage.stage1.elf ${ALL_SRCS})
set_target_properties(fullimage.stage1.elf PROPERTIES # The 'fullimage.stage1.elf' output to ${OBJDIR}
RUNTIME_OUTPUT_DIRECTORY "${OBJDIR}"
OUTPUT_NAME "fullimage.stage1"
SUFFIX ".elf" # OK, OBJDIR + OUTPUT_NAME + SUFFIX = /xxx/obj/fullimage.stage1.elf
)
target_link_options(fullimage.stage1.elf PRIVATE -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) # output map file
target_link_options(fullimage.stage1.elf PRIVATE -L ${CMAKE_CURRENT_LIST_DIR} -T ${LDSCRIPT} ${CROSS_LDFLAGS})
target_compile_options(fullimage.stage1.elf PRIVATE ${CROSS_CFLAGS}) # !!!! WARN !!!! No -mthumb on here
set_source_files_properties(${THUMBSRC} PROPERTIES COMPILE_OPTIONS "-mthumb") # THUMBSRC is '-mthumb' flag required.
target_include_directories(fullimage.stage1.elf PRIVATE ${INC_DIRS})
target_link_libraries(fullimage.stage1.elf ${LIBS})
if (NOT SKIP_FPGA_EMBED) # Link fpga data(not compressed)
set_property(TARGET fullimage.stage1.elf APPEND PROPERTY LINK_LIBRARIES ${FPGA_ALL_O})
endif ()
# Generate HEX and BIN files for stage 1 for easy downloading to device and debugging device.
add_custom_command(TARGET ${PROJECT_NAME}.stage1.elf POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(5) ${PROJECT_NAME}.stage1.(HEX,BIN)"
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.stage1.elf> ${OUTPUT_STAGE1_HEX}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.stage1.elf> ${OUTPUT_STAGE1_BIN}
COMMENT "Build ${PROJECT_NAME}.stage1.hex & ${PROJECT_NAME}.stage1.bin"
)
# ---------------- 6. Pull '.data' section from 'fullimage.stage1.elf' ----------------
# Tips: fpga_all.o maybe pack to elf on stage1, is uncompress data binary, next step will compress(all '.data' section).
# When this step is reached, the linker has allocated a specific vma for the data segment. Compression is only to reduce the firmware volume.
add_custom_command(
OUTPUT ${DATA_BIN}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(6) pull '.data'(uncompressed)"
COMMAND ${CMAKE_OBJCOPY} -O binary --only-section .data ${STAGE1_ELF} ${DATA_BIN}
DEPENDS fullimage.stage1.elf
COMMENT "Call the 'objcopy' to pull the '.data' section from 'fullimage.stage1.elf'"
VERBATIM
)
# ---------------- 7. Compress '.data' section binary to 'fullimage.data.bin.z' ----------------
# About '.data' section compress: https://www.eevblog.com/forum/microcontrollers/compression-of-data-(initialized-variables)-section/
add_custom_command(
OUTPUT ${DATA_BIN_Z}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(7) fullimage.data.bin.z"
COMMAND ${FPGA_COMPRESS_EXE} ${DATA_BIN} ${DATA_BIN_Z}
DEPENDS ${DATA_BIN}
DEPENDS ${FPGA_COMPRESS_EXE} # Ensure host tool is built before running it.
COMMENT "Call the 'fpga_compress' to compress '.data' section from 'fullimage.stage1.elf'"
VERBATIM
)
# ---------------- 8. Pack data bin and gen fullimage.elf ----------------
if ("${APP_CFLAGS}" MATCHES "WITH_COMPRESSION|WITH_COMPRESSION=1")
add_custom_command(
OUTPUT ${FINAL_ELF}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] LD(8) fullimage.elf (with compression)"
COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm --strip-all --update-section .data=${DATA_BIN_Z} ${STAGE1_ELF} ${FINAL_ELF}
DEPENDS ${STAGE1_ELF} ${DATA_BIN_Z}
COMMENT "Put the compressed '.data' section to 'fullimage.stage1.elf' for build 'fullimage.elf'"
VERBATIM
)
else ()
add_custom_command(
OUTPUT ${FINAL_ELF}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] MIN(8) fullimage.elf (without compression) "
COMMAND ${CMAKE_OBJCOPY} -O elf32-littlearm --strip-all ${STAGE1_ELF} ${FINAL_ELF}
DEPENDS ${STAGE1_ELF}
COMMENT "Copy 'fullimage.stage1.elf' to 'fullimage.elf' if no compress required"
VERBATIM
)
endif ()
# ---------------- 9. Generate S19 format file ----------------
add_custom_command(
OUTPUT ${OUTPUT_S19}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(9) S19 file"
COMMAND ${CMAKE_OBJCOPY}
-Osrec
--srec-forceS3
--strip-debug
--no-change-warnings
--change-addresses=-0x100000
--change-start=0
--change-section-address=.bss+0
--change-section-address=.data-0x100000
--change-section-address=.commonarea+0
${FINAL_ELF}
${OUTPUT_S19}
DEPENDS ${FINAL_ELF}
COMMENT "Call the objcopy to convert ELF to S19 format"
VERBATIM
)
# ---------------- 10. Finally, start build the fullimage, the 'All' build will from here start ----------------
add_custom_target(fullimage ALL DEPENDS ${OUTPUT_S19} COMMENT "Build fullimage")
add_dependencies(fullimage fullimage.stage1.elf) # fullimage dependencies tree start, 9 -> 1 -> 9
# Generate HEX and BIN files for fullimage finally
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(10) ${PROJECT_NAME}(HEX,BIN)"
COMMAND ${CMAKE_OBJCOPY} -Oihex ${FINAL_ELF} ${OUTPUT_FINAL_HEX}
COMMAND ${CMAKE_OBJCOPY} -Obinary ${FINAL_ELF} ${OUTPUT_FINAL_BIN}
COMMENT "Build ${PROJECT_NAME}.hex & ${PROJECT_NAME}.bin"
)
+185
View File
@@ -0,0 +1,185 @@
#[[
+==========================================================+
| STANDALONE | DESCRIPTION |
+==========================================================+
| (empty) | No standalone mode |
+----------------------------------------------------------+
| LF_SKELETON | standalone mode skeleton |
| | - iceman |
+----------------------------------------------------------+
| LF_EM4100EMUL | Simulate predefined em4100 tags only |
| | |
+----------------------------------------------------------+
| LF_EM4100RSWB | Read/simulate/brute em4100 tags & |
| | clone it to T555x tags |
+----------------------------------------------------------+
| LF_EM4100RSWW | Read/simulate/validate em4100 tags & |
| | clone it to T55xx tags, wipe T55xx tags|
+----------------------------------------------------------+
| LF_EM4100RWC | Read/simulate em4100 tags & clone it |
| | to T555x tags |
+----------------------------------------------------------+
| LF_HIDBRUTE | HID corporate 1000 bruteforce |
| | - Federico dotta & Maurizio Agazzini |
+----------------------------------------------------------+
| LF_HIDFCBRUTE | HID Facility Code bruteforce |
| (RDV4 only) | |
+----------------------------------------------------------+
| LF_ICEHID | LF HID collector to flashmem |
| (RDV4 only) | |
+----------------------------------------------------------+
| LF_MULTIHID | LF HID 26 Bit (H1031) multi simulator |
| | - Shain Lakin |
+----------------------------------------------------------+
| LF_NEDAP_SIM | LF Nedap ID simple simulator |
| | |
+----------------------------------------------------------+
| LF_NEXID | LF Nexwatch collector to flashmem |
| (RDV4 only) | |
+----------------------------------------------------------+
| LF_PROXBRUTE | HID ProxII bruteforce |
| | - Brad Antoniewicz |
+----------------------------------------------------------+
| LF_PROX2BRUTE | HID ProxII bruteforce v2 |
| | |
+----------------------------------------------------------+
| LF_SAMYRUN | HID26 read/clone/sim |
| (default) | - Samy Kamkar |
+----------------------------------------------------------+
| LF_THAREXDE | Simulate/read EM4x50 tags |
| (RDV4 only) | storing in flashmem |
+----------------------------------------------------------+
| HF_14ASNIFF | 14a sniff to flashmem (rdv4) or ram |
| | |
+----------------------------------------------------------+
| HF_14BSNIFF | 14b sniff to flashmem (rdv4) or ram |
| | |
+----------------------------------------------------------+
| HF_15SNIFF | 15693 sniff to flashmem (rdv4) or ram |
| | |
+----------------------------------------------------------+
| HF_15SIM | 15693 tag simulator |
| | |
+----------------------------------------------------------+
| HF_AVEFUL | Mifare ultralight read/simulation |
| | - Ave Ozkal |
+----------------------------------------------------------+
| HF_BOG | 14a sniff with ULC/ULEV1/NTAG auth |
| (RDV4 only) | storing in flashmem - Bogito |
+----------------------------------------------------------+
| HF_CARDHOPPER | Relay 14a protocols over long distances|
| (RDV4 only) | (w/ IP backbone) - Sam Haskins |
+----------------------------------------------------------+
| HF_COLIN | Mifare ultra fast sniff/sim/clone |
| (RDV4 only) | - Colin Brigato |
+----------------------------------------------------------+
| HF_CRAFTBYTE | UID stealer - Emulates scanned 14a UID |
| | - Anze Jensterle |
+----------------------------------------------------------+
| HF_ICECLASS | Simulate HID iCLASS legacy ags |
| (RDV4 only) | storing in flashmem |
+----------------------------------------------------------+
| HF_LEGIC | Read/simulate Legic Prime tags |
| | storing in flashmem |
+----------------------------------------------------------+
| HF_LEGICSIM | Simulate Legic Prime tags |
| (RDV4 only) | stored on flashmem |
+----------------------------------------------------------+
| HF_MATTYRUN | Mifare sniff/clone |
| | - Matías A. Ré Medina |
+----------------------------------------------------------+
| HF_MFCSIM | Simulate Mifare Classic 1k card |
| (RDV4 only) | storing in flashmem - Ray Lee |
+----------------------------------------------------------+
| HF_MSDSAL | Read and emulate MSD Visa cards |
| | - Salvador Mendoza |
+----------------------------------------------------------+
| HF_REBLAY | 14A Relay over BT |
| (RDV4 only) | - Salvador Mendoza |
+----------------------------------------------------------+
| HF_ST25_TEAROFF | Store/restore ST25TB tags with |
| | tear-off for counters - SecLabz |
+----------------------------------------------------------+
| HF_TCPRST | IKEA Rothult read/sim/dump/emul |
| | - Nick Draffen |
+----------------------------------------------------------+
| HF_TMUDFORD | Read and emulate 15 tags |
| | - Tim Mudford |
+----------------------------------------------------------+
| HF_UNISNIFF | Sniff 14a/14b/15 (optionally to flash) |
| | - hazardousvoltage |
+----------------------------------------------------------+
| HF_YOUNG | Mifare sniff/simulation |
| | - Craig Young |
+----------------------------------------------------------+
| DANKARMULTI | Load multiple standalone modes. |
| | - Daniel Karling |
+----------------------------------------------------------+
| HF_EMVPNG | Read and emulate EMV Visa cards |
| | - Davi Mikael (Penegui) |
+----------------------------------------------------------+
]]
# Default standalone if no standalone specified
set(DEFAULT_STANDALONE LF_SAMYRUN)
# (you can set explicitly STANDALONE= to disable standalone modes)
if (NOT DEFINED STANDALONE)
set(STANDALONE ${DEFAULT_STANDALONE})
endif ()
set(STANDALONE_REQ_DEFS)
# List of all standalone modes, and which ones require bluetooth, smartcard or flash.
# (for now, we only support one standalone mode at a time)
set(STANDALONE_MODES
LF_SKELETON LF_EM4100EMUL LF_EM4100RSWB LF_EM4100RSWW LF_EM4100RWC
LF_HIDBRUTE LF_HIDFCBRUTE LF_ICEHID LF_MULTIHID LF_NEDAP_SIM LF_NEXID
LF_PROXBRUTE LF_PROX2BRUTE LF_SAMYRUN LF_THAREXDE
HF_14ASNIFF HF_14BSNIFF HF_15SNIFF HF_15SIM
HF_AVEFUL HF_BOG HF_CARDHOPPER HF_COLIN HF_CRAFTBYTE HF_ICECLASS
HF_LEGIC HF_LEGICSIM HF_MATTYRUN HF_MFCSIM HF_MSDSAL HF_REBLAY
HF_ST25_TEAROFF HF_TCPRST HF_TMUDFORD HF_UNISNIFF HF_YOUNG HF_EMVPNG DANKARMULTI)
# List of modes that require bluetooth
set(STANDALONE_MODES_REQ_BT HF_CARDHOPPER HF_REBLAY)
# List of modes that require smartcard
set(STANDALONE_MODES_REQ_SMARTCARD)
# List of modes that require flash
set(STANDALONE_MODES_REQ_FLASH
LF_HIDFCBRUTE LF_ICEHID LF_NEXID LF_THAREXDE HF_BOG HF_COLIN
HF_ICECLASS HF_LEGICSIM HF_MFCSIM)
message(STATUS "STANDALONE = ${STANDALONE}")
message(STATUS "STANDALONE_MODES = ${STANDALONE_MODES}")
# Check if the specified standalone mode is valid, and set the corresponding definitions.
# 'MATCHES' is used to check if the specified standalone mode is in the list of valid modes.
if (DEFINED STANDALONE)
if ("${STANDALONE_MODES}" MATCHES "${STANDALONE}")
string(TOUPPER ${STANDALONE} STANDALONE_UPPER)
set(STANDALONE_PLATFORM_DEFS ${STANDALONE_PLATFORM_DEFS} "-DWITH_STANDALONE_${STANDALONE_UPPER}")
# Required for SmartCard, set '-DWITH_SMARTCARD'
if ("${STANDALONE_MODES_REQ_SMARTCARD}" MATCHES "${STANDALONE}")
set(STANDALONE_REQ_DEFS ${STANDALONE_REQ_DEFS} -DWITH_SMARTCARD)
endif ()
# Required for Flash, set '-DWITH_FLASH'
if ("${STANDALONE_MODES_REQ_FLASH}" MATCHES "${STANDALONE}")
set(STANDALONE_REQ_DEFS ${STANDALONE_REQ_DEFS} -DWITH_FLASH)
endif ()
# Required for Bluetooth, set '-DWITH_FPC_USART_HOST'
# (we use USART host for bluetooth communication in standalone modes)
if ("${STANDALONE_MODES_REQ_BT}" MATCHES "${STANDALONE}")
set(STANDALONE_REQ_DEFS ${STANDALONE_REQ_DEFS} -DWITH_FPC_USART_HOST)
endif ()
else ()
message(FATAL_ERROR "Invalid STANDALONE: ${STANDALONE}. ${KNOWN_DEFINITIONS}")
endif ()
endif ()
# Export the definitions for standalone mode to be used in the main CMakeLists.txt
# --- Usually referenced externally:
# STANDALONE_REQ_DEFS -> Definitions required by the selected standalone mode (e.g., -DWITH_FLASH)
# STANDALONE_PLATFORM_DEFS -> Definitions for the selected standalone mode (e.g., -DWITH_STANDALONE_LF_SAMYRUN)
# --- It is not usually used externally:
# STANDALONE_MODES -> List of all valid standalone modes (for error checking)
# STANDALONE_MODES_REQ_BT -> List of standalone modes that require bluetooth (for error checking)
# STANDALONE_MODES_REQ_SMARTCARD -> List of standalone modes that require smartcard (for error checking)
# STANDALONE_MODES_REQ_FLASH -> List of standalone modes that require flash (for error checking)
+161
View File
@@ -0,0 +1,161 @@
# --------------------- Standalone Source Files ---------------------
set(DIR_STANDALONE ${CMAKE_CURRENT_LIST_DIR})
set(SRC_STANDALONE "${DIR_STANDALONE}/placeholder.c")
# Check which standalone mode is selected, and set the corresponding source file.
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_SKELETON")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_skeleton.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100EMUL")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100emul.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100RSWB")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100rswb.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100RSWW")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100rsww.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_EM4100RWC")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_em4100rwc.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_HIDBRUTE")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_hidbrute.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_HIDFCBRUTE")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_hidfcbrute.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_ICEHID")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_icehid.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_MULTIHID")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_multihid.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_NEDAP_SIM")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_nedap_sim.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_NEXID")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_nexid.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_SAMYRUN")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_samyrun.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_PROXBRUTE")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_proxbrute.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_PROX2BRUTE")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_prox2brute.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_LF_THAREXDE")
set(SRC_STANDALONE "${DIR_STANDALONE}/lf_tharexde.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_14ASNIFF")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_14asniff.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_14BSNIFF")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_14bsniff.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_15SNIFF")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_15sniff.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_15SIM")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_15sim.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_AVEFUL")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_aveful.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_BOG")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_bog.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_CARDHOPPER")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_cardhopper.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_COLIN")
set(SRC_STANDALONE
"${DIR_STANDALONE}/vtsend.c"
"${DIR_STANDALONE}/hf_colin.c"
"${DIR_STANDALONE}/frozen.c"
"${DIR_STANDALONE}/nprintf.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_CRAFTBYTE")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_craftbyte.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_ICECLASS")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_iceclass.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_LEGIC")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_legic.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_LEGICSIM")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_legicsim.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_MATTYRUN")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_mattyrun.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_MFCSIM")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_mfcsim.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_MSDSAL")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_msdsal.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_REBLAY")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_reblay.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_TCPRST")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_tcprst.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_TMUDFORD")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_tmudford.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_UNISNIFF")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_unisniff.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_YOUNG")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_young.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_ST25_TEAROFF")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_st25_tearoff.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_HF_EMVPNG")
set(SRC_STANDALONE "${DIR_STANDALONE}/hf_emvpng.c")
endif ()
if ("${APP_CFLAGS}" MATCHES "WITH_STANDALONE_DANKARMULTI")
set(SRC_STANDALONE "${DIR_STANDALONE}/dankarmulti.c")
endif ()
+131
View File
@@ -0,0 +1,131 @@
cmake_minimum_required(VERSION 3.20)
# Fix error when 'compile a simple test program.'
include(${CMAKE_CURRENT_LIST_DIR}/../tools/FixCompileTest.cmake)
# Ensure direct bootrom builds also select ARM cross-compilers.
include(${CMAKE_CURRENT_LIST_DIR}/../tools/ToolchainForArm.cmake)
project(bootrom C ASM) # Set variables needs before the project defining.
# Hardware abstraction layer for ARM platform.
include(${CMAKE_CURRENT_LIST_DIR}/../common_arm/Hal.cmake)
# Include the MKVersion script for generating version_pm3.c
include(${CMAKE_CURRENT_LIST_DIR}/../tools/MKVersionScript.cmake)
# ---
set(OBJDIR ${CMAKE_BINARY_DIR}/obj)
set(DEFAULT_VERSION_C ${CMAKE_CURRENT_LIST_DIR}/../common/default_version_pm3.c)
set(VERSION_PM3_C ${CMAKE_CURRENT_BINARY_DIR}/version_pm3.c)
set(INC_DIRS
${CMAKE_CURRENT_LIST_DIR}/../include
${CMAKE_CURRENT_LIST_DIR}/../common
${CMAKE_CURRENT_LIST_DIR}/../common_arm/sys
${CMAKE_CURRENT_LIST_DIR}/../common_arm/wdt
${CMAKE_CURRENT_LIST_DIR}/../common_arm/flash_code
${CMAKE_CURRENT_LIST_DIR}/../common_arm/gpio
${CMAKE_CURRENT_LIST_DIR}/../common_arm/usb
${CMAKE_CURRENT_LIST_DIR}/../common_arm/ticks
)
set(THUMBSRC
${CMAKE_CURRENT_LIST_DIR}/bootrom.c
${VERSION_PM3_C}
../common_arm/usb/usb_cdc_desc.c)
if (PM5)
set(THUMBSRC ${THUMBSRC}
${CMAKE_CURRENT_LIST_DIR}/../common_arm/sys/sys_hw_at32.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/ticks/ticks_hw_at32.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/gpio/gpio_hw_at32.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/usb/usb_cdc_at32.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/flash_code/flash_code_hw_at32.c
)
set(ASMSRC flash-reset-at32.s ram-reset-at32.s)
else ()
set(THUMBSRC ${THUMBSRC}
${CMAKE_CURRENT_LIST_DIR}/../common_arm/sys/sys_hw_at91.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/ticks/ticks_hw_at91.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/gpio/gpio_hw_at91.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/usb/usb_cdc_at91.c
${CMAKE_CURRENT_LIST_DIR}/../common_arm/flash_code/flash_code_hw_at91.c
)
set(ASMSRC flash-reset-at91.s ram-reset-at91.s)
endif ()
# stdint.h provided locally until GCC 4.5 becomes C99 compliant
set(APP_CFLAGS -I. -ffunction-sections -fdata-sections -DAS_BOOTROM)
# stack-protect , no-pie reduces size on Gentoo Hardened 8.2 gcc, no-common makes sure uninitialized vars don't end up in COMMON area
set(APP_CFLAGS ${APP_CFLAGS} -fno-stack-protector -fno-pie -fno-common)
if ("${PLATFORM_DEFS}" MATCHES "WITH_FLASH")
set(INC_DIRS ${INC_DIRS} ${CMAKE_CURRENT_LIST_DIR}/../common_arm/flash_data)
if (PM5)
set(SRC_FLASH ../common_arm/flash_data/flashmem_hw_at32.c)
set(SRC_TICKS ../common_arm/ticks/ticks_hw_at32.c)
else ()
set(SRC_FLASH ../common_arm/flash_data/flashmem_hw_at91.c)
set(SRC_TICKS ../common_arm/ticks/ticks_hw_at91.c)
endif ()
set(SRC_FLASH ${SRC_FLASH} ../common_arm/flash_data/flashmem_core.c)
set(SRC_TICKS ${SRC_TICKS} ../common_arm/ticks/ticks_core.c)
set(THUMBSRC ${THUMBSRC} ${SRC_FLASH} ${SRC_TICKS})
endif ()
if (PM5)
set(LDSCRIPT ${CMAKE_CURRENT_LIST_DIR}/ldscript-flash-at32)
else ()
set(LDSCRIPT ${CMAKE_CURRENT_LIST_DIR}/ldscript-flash-at91)
endif ()
set(APP_CFLAGS ${APP_CFLAGS} ${PLATFORM_DEFS})
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
include(${CMAKE_CURRENT_LIST_DIR}/../common_arm/Common.cmake)
if (PM5)
include(${CMAKE_CURRENT_LIST_DIR}/../armlib/pm5_at32_armlib.cmake)
set(LIBS ${LIBS} pm5_at32_armlib)
endif ()
# Fix: warning: bootrom\bootrom.elf has a LOAD segment with RWX permissions
set(CROSS_LDFLAGS ${CROSS_LDFLAGS} -Wl,--no-warn-rwx-segments)
# Create version_pm3.c before bootrom build.
add_custom_command(
OUTPUT ${VERSION_PM3_C}
DEPENDS ${DEFAULT_VERSION_C}
COMMAND ${MKVERSION_CMD} ${VERSION_PM3_C} || ${CMAKE_COMMAND} -E copy ${DEFAULT_VERSION_C} ${VERSION_PM3_C}
COMMENT "Call mkversion.xx script to generate 'version_pm3.c', if mkversion return fail, fallback is default_version_pm3.c"
VERBATIM
)
# ---------------- Output dir ----------------
file(MAKE_DIRECTORY ${OBJDIR})
get_filename_component(OUTPUT_BOOTROM_HEX ${OBJDIR}/${PROJECT_NAME}.hex ABSOLUTE)
get_filename_component(OUTPUT_BOOTROM_BIN ${OBJDIR}/${PROJECT_NAME}.bin ABSOLUTE)
add_executable(bootrom.elf ${THUMBSRC} ${ASMSRC})
set_target_properties(bootrom.elf PROPERTIES # The 'bootrom.elf' output to ${OBJDIR}
RUNTIME_OUTPUT_DIRECTORY "${OBJDIR}"
OUTPUT_NAME "bootrom"
SUFFIX ".elf" # OK, OBJDIR + OUTPUT_NAME + SUFFIX = /xxx/obj/bootrom.elf
)
target_link_options(bootrom.elf PRIVATE -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) # output map file
target_link_options(bootrom.elf PRIVATE -L ${CMAKE_CURRENT_LIST_DIR} -T ${LDSCRIPT} ${CROSS_LDFLAGS})
target_compile_options(bootrom.elf PRIVATE ${CROSS_CFLAGS}) # !!!! WARN !!!! No -mthumb on here
set_source_files_properties(${THUMBSRC} PROPERTIES COMPILE_OPTIONS "-mthumb") # THUMBSRC is '-mthumb' flag required.
target_include_directories(bootrom.elf PRIVATE ${INC_DIRS})
target_link_libraries(bootrom.elf ${LIBS})
# Generate HEX and BIN files for fullimage finally
add_custom_command(TARGET bootrom.elf POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E echo "[=] GEN(10) bootrom.elf(HEX,BIN)"
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${OUTPUT_BOOTROM_HEX}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${OUTPUT_BOOTROM_BIN}
COMMENT "Build bootrom.hex & bootrom.bin"
)
+117
View File
@@ -0,0 +1,117 @@
#[[ VPATH in cmake is unavailable, so we need append path for source or include dir...
# Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the lz4 directory
VPATH = . ../common_arm ../common ../common/crapto1 ../common/mbedtls ../common/lz4 ../fpga ../armsrc/Standalone ../common/hitag2
]]
set(ARMCFLAGS -mthumb-interwork -fno-builtin)
set(DEFCFLAGS -Wall -Werror -Os -pedantic -fstrict-aliasing -pipe)
# Some more warnings we want as errors:
set(DEFCFLAGS ${DEFCFLAGS}
-Wbad-function-cast
-Wchar-subscripts
-Wundef
-Wunused
-Wuninitialized
-Wpointer-arith
-Wformat
-Wformat-security
-Winit-self
-Wmissing-include-dirs
-Wnested-externs
-Wempty-body
-Wignored-qualifiers
-Wmissing-field-initializers
-Wtype-limits)
# Some more warnings we need first to eliminate, so temporarely tolerated:
set(DEFCFLAGS ${DEFCFLAGS}
-Wshadow
-Wno-error=shadow
-Winline
-Wno-error=inline
-Wmissing-prototypes
-Wno-error=missing-prototypes
-Wmissing-declarations
-Wno-error=missing-declarations
-Wstrict-prototypes
-Wno-error=strict-prototypes
)
# still vsnprintf etc to sort out...
# for makefile: DEFCFLAGS += -Wredundant-decls -Wno-error=redundant-decls
# for makefile: DEFCFLAGS += -Wcast-align -Wno-error=cast-align
# Next ones are activated only if GCCEXTRA=1
set(EXTRACFLAGS
-Wunused-parameter
-Wno-error=unused-parameter
-Wswitch-enum
-Wno-error=switch-enum
-Wsign-compare
-Wno-error=sign-compare
-Wold-style-definition
-Wno-error=old-style-definition
-Wconversion
-Wno-error=conversion
-Wno-error=sign-conversion
-Wno-error=float-conversion
)
# unknown to clang or old gcc:
# First we activate Wextra then we explicitly list those we know about
# Those without -Wno-error are supposed to be completely solved
set(GCCEXTRACFLAGS -Wextra)
# unknown to arm-none-eabi/4.9.3
set(GCCEXTRACFLAGS ${GCCEXTRACFLAGS}
-Wwrite-strings
-Wno-error=discarded-qualifiers)
set(GCCEXTRACFLAGS ${GCCEXTRACFLAGS}
-Wold-style-declaration
-Wno-error=old-style-declaration
-Wimplicit-fallthrough=3
-Wno-error=implicit-fallthrough
-Wclobbered
-Wcast-function-type
-Wmissing-parameter-type
-Woverride-init
-Wshift-negative-value
-Wunused-but-set-parameter
)
# Not yet enabled in DEFCFLAGS:
set(GCCEXTRACFLAGS ${GCCEXTRACFLAGS}
-Wredundant-decls
-Wno-error=redundant-decls
-Wcast-align
-Wno-error=cast-align
)
if (GCCEXTRA)
set(DEFCFLAGS ${DEFCFLAGS} ${GCCEXTRACFLAGS} ${EXTRACFLAGS})
endif ()
if (NOERROR)
set(DEFCFLAGS ${DEFCFLAGS} -Wno-error)
endif ()
if (NOT DEFINED CROSS_CFLAGS)
set(CROSS_CFLAGS ${DEFCFLAGS})
endif ()
set(CROSS_CFLAGS ${CROSS_CFLAGS}
${ARMCFLAGS}
-c
${INCLUDE}
# -std=c99 TODO 暂时切换为c11标准,因为新的平台需要c11标准,AT32的官方库一堆c11写法,不这么做的话改起来很麻烦
-std=c11
-DON_DEVICE
${APP_CFLAGS})
set(CROSS_LDFLAGS ${CROSS_LDFLAGS}
-Wl,-gc-sections
-nostartfiles
-nodefaultlibs
-Wl,--build-id=none
-Wl,-n)
set(LIBS gcc)
+255
View File
@@ -0,0 +1,255 @@
#[[
+============================================+
| PLATFORM | DESCRIPTION |
+============================================+
| PM3RDV4 (def) | Proxmark3 RDV4 |
+--------------------------------------------+
| PM3GENERIC | Proxmark3 generic target |
+--------------------------------------------+
| PM3ICOPYX | iCopy-X with XC3S100E |
+--------------------------------------------+
| PM5 | Proxmark5 |
+--------------------------------------------+
]]
set(PLATFORM "PM3RDV4" CACHE STRING "Default platform is PM3RDV4 if no platform specified")
set_property(CACHE PLATFORM PROPERTY STRINGS "PM3RDV4" "PM3GENERIC" "PM3ICOPYX" "PM5")
#[[
+============================================+
| PLATFORM_EXTRAS | DESCRIPTION |
+============================================+
| BTADDON | Proxmark3 RDV4 BT add-on |
+--------------------------------------------+
]]
set(PLATFORM_EXTRAS "" CACHE STRING "Default PLATFORM_EXTRAS is unset")
set_property(CACHE PLATFORM_EXTRAS PROPERTY STRINGS "BTADDON" "")
# Skip fpga bit stream files pack to arm's fw?
# Some platform is no download in arm side required.
set(SKIP_FPGA_EMBED FALSE CACHE STRING "It is enabled by default. Package the fpga image to the arm firmware.")
# The arm platform name & fpga platform name
set(PLTNAME "Unknown Platform")
set(PLATFORM_FPGA "fpga-undefined")
if (PLATFORM STREQUAL "PM3RDV4")
# FPGA bitstream files, the order doesn't matter anymore
set(FPGA_BITSTREAMS ../fpga/fpga_pm3_hf.bit)
if (NOT SKIP_LF)
list(APPEND FPGA_BITSTREAMS ../fpga/fpga_pm3_lf.bit)
endif ()
if (NOT SKIP_FELICA)
list(APPEND FPGA_BITSTREAMS ../fpga/fpga_pm3_felica.bit)
endif ()
if (NOT SKIP_ISO15693)
list(APPEND FPGA_BITSTREAMS ../fpga/fpga_pm3_hf_15.bit)
endif ()
set(PLATFORM_DEFS -DWITH_SMARTCARD -DWITH_FLASH -DRDV4 -DCHIP_AT91SAM7S)
set(PLTNAME "Proxmark3 RDV4")
set(PLATFORM_FPGA "xc2s30")
set(RDV4 TRUE)
elseif (PLATFORM STREQUAL "PM3OTHER")
message(WARNING "PLATFORM=PM3OTHER is deprecated, please use PLATFORM=PM3GENERIC")
set(_IS_GENERIC TRUE) # Fall through to PM3GENERIC behavior
elseif (PLATFORM STREQUAL "PM3GENERIC")
set(_IS_GENERIC TRUE)
elseif (PLATFORM STREQUAL "PM3ICOPYX")
set(FPGA_BITSTREAMS ../fpga/fpga_icopyx_hf.bit)
set(PLATFORM_DEFS -DWITH_FLASH -DICOPYX -DXC3 -DCHIP_AT91SAM7S)
set(PLTNAME "iCopy-X with XC3S100E")
set(PLATFORM_FPGA "xc3s100e")
elseif (PLATFORM STREQUAL "PM5")
# TODO DXL 我们暂时不需要指定FPGA比特流文件,因为实际上我们大概率要做FPGA的静态烧录,而不是附加到ARM固件中动态下载
set(FPGA_BITSTREAMS ../fpga/fpga_pm3_hf.bit) # TODO DXL 虽然可以不把打包比特流,但是还是得把FPGA的版本信息给生成,让EXE依赖。
set(SKIP_FPGA_EMBED TRUE) # important!!! disable the fpga bit files pack to arm!
set(SKIP_COMPRESSION TRUE) # Skip data section compress. The new mcu has enough flash space.
set(PLATFORM_DEFS -DWITH_FLASH -DPM5 -DCHIP_AT32F435_37) # TODO DXL 暂时不要编译i2c -DWITH_SMARTCARD
set(PLTNAME "Proxmark5")
set(PLATFORM_FPGA "GW1NR-LV2MG49GC6/i5")
set(PM5 TRUE)
else ()
message(FATAL_ERROR "Invalid or empty PLATFORM: ${PLATFORM}. Known platforms: PM3RDV4, PM3GENERIC, PM3ICOPYX (PM3OTHER is deprecated)")
endif ()
# PM3GENERIC and PM3OTHER
if (_IS_GENERIC)
set(FPGA_BITSTREAMS ../fpga/fpga_pm3_hf.bit)
if (NOT SKIP_LF)
list(APPEND FPGA_BITSTREAMS ../fpga/fpga_pm3_lf.bit)
endif ()
if (NOT SKIP_FELICA)
list(APPEND FPGA_BITSTREAMS ../fpga/fpga_pm3_felica.bit)
endif ()
if (NOT SKIP_ISO15693)
list(APPEND FPGA_BITSTREAMS ../fpga/fpga_pm3_hf_15.bit)
endif ()
set(PLTNAME "Proxmark3 generic target")
set(PLATFORM_FPGA "xc2s30")
set(PLATFORM_DEFS -DCHIP_AT91SAM7S)
if (LED_ORDER STREQUAL "PM3EASY")
list(APPEND PLATFORM_DEFS -DLED_ORDER_PM3EASY)
endif ()
endif ()
# If no fpga bitstream pack to arm, set flag for arm compile.
if (SKIP_FPGA_EMBED)
list(APPEND PLATFORM_DEFS -DNO_FPGA_BITSTREAM_PACK)
endif ()
# parsing additional PLATFORM_EXTRAS tokens
set(PLATFORM_EXTRAS_TMP ${PLATFORM_EXTRAS})
if ("${PLATFORM_EXTRAS_TMP}" MATCHES "SMARTCARD")
list(APPEND PLATFORM_DEFS -DWITH_SMARTCARD)
list(REMOVE_ITEM PLATFORM_EXTRAS_TMP "SMARTCARD")
endif ()
if ("${PLATFORM_EXTRAS_TMP}" MATCHES "FLASH")
list(APPEND PLATFORM_DEFS -DWITH_FLASH)
list(REMOVE_ITEM PLATFORM_EXTRAS_TMP "FLASH")
endif ()
if ("${PLATFORM_EXTRAS_TMP}" MATCHES "BTADDON")
list(APPEND PLATFORM_DEFS -DWITH_FPC_USART_HOST)
list(REMOVE_ITEM PLATFORM_EXTRAS_TMP "BTADDON")
endif ()
if ("${PLATFORM_EXTRAS_TMP}" MATCHES "FPC_USART_DEV")
list(APPEND PLATFORM_DEFS -DWITH_FPC_USART_DEV)
list(REMOVE_ITEM PLATFORM_EXTRAS_TMP "FPC_USART_DEV")
endif ()
if (PLATFORM_EXTRAS_TMP)
message(FATAL_ERROR "Unknown PLATFORM_EXTRAS token(s): ${PLATFORM_EXTRAS_TMP}")
endif ()
# common LF support
if (NOT SKIP_LF)
list(APPEND PLATFORM_DEFS -DWITH_LF)
endif ()
if (NOT SKIP_HITAG)
list(APPEND PLATFORM_DEFS -DWITH_HITAG)
endif ()
if (NOT SKIP_EM4x50)
list(APPEND PLATFORM_DEFS -DWITH_EM4x50)
endif ()
if (NOT SKIP_EM4x70)
list(APPEND PLATFORM_DEFS -DWITH_EM4x70)
endif ()
if (NOT SKIP_ZX8211)
list(APPEND PLATFORM_DEFS -DWITH_ZX8211)
endif ()
# common HF support
if (NOT SKIP_HF)
list(APPEND PLATFORM_DEFS -DWITH_GENERAL_HF)
endif ()
if (NOT SKIP_ISO15693)
list(APPEND PLATFORM_DEFS -DWITH_ISO15693)
endif ()
if (NOT SKIP_LEGICRF)
list(APPEND PLATFORM_DEFS -DWITH_LEGICRF)
endif ()
if (NOT SKIP_ISO14443b)
list(APPEND PLATFORM_DEFS -DWITH_ISO14443b)
endif ()
if (NOT SKIP_ISO14443a)
list(APPEND PLATFORM_DEFS -DWITH_ISO14443a)
endif ()
if (NOT SKIP_ICLASS)
list(APPEND PLATFORM_DEFS -DWITH_ICLASS)
endif ()
if (NOT SKIP_FELICA)
list(APPEND PLATFORM_DEFS -DWITH_FELICA)
endif ()
if (NOT SKIP_NFCBARCODE)
list(APPEND PLATFORM_DEFS -DWITH_NFCBARCODE)
endif ()
if (NOT SKIP_HFSNIFF)
list(APPEND PLATFORM_DEFS -DWITH_HFSNIFF)
endif ()
if (NOT SKIP_HFPLOT)
list(APPEND PLATFORM_DEFS -DWITH_HFPLOT)
endif ()
if (NOT SKIP_COMPRESSION)
list(APPEND PLATFORM_DEFS -DWITH_COMPRESSION)
endif ()
# Standalone mode
if (STANDALONE_REQ_DEFS)
message(STATUS "-------------- PLATFORM_DEFS = ${PLATFORM_DEFS}")
if (NOT "${PLATFORM_DEFS};" MATCHES ".*;(${STANDALONE_REQ_DEFS});.*")
message(FATAL_ERROR "Chosen Standalone mode ${STANDALONE} requires ${STANDALONE_REQ_DEFS}, unsupported by ${PLTNAME}")
endif ()
endif ()
if (DEFINED STANDALONE_PLATFORM_DEFS AND NOT "${STANDALONE_PLATFORM_DEFS}" STREQUAL "")
list(APPEND PLATFORM_DEFS ${STANDALONE_PLATFORM_DEFS})
endif ()
# Find and print standalone-related definitions
string(REGEX MATCHALL "WITH_STANDALONE_[^;]+" STANDALONE_DEFS_FOUND "${PLATFORM_DEFS}")
# Misc (LCD support)
if ("${PLATFORM_DEFS}" MATCHES "WITH_LCD")
list(APPEND PLATFORM_DEFS -DWITH_LCD)
endif ()
# WITH_FPC_USART_* needs WITH_FPC_USART
string(FIND "${PLATFORM_DEFS}" "WITH_FPC_USART_" _FPC_POS)
if (NOT _FPC_POS STREQUAL "-1")
list(APPEND PLATFORM_DEFS -DWITH_FPC_USART)
endif ()
# Extract non-standalone platform defs (remove -DWITH_ prefix and STANDALONE* entries)
string(REPLACE "-DWITH_" "" PLATFORM_DEFS_CLEAN "${PLATFORM_DEFS}")
separate_arguments(PLATFORM_DEFS_CLEAN)
# Filter out STANDALONE entries
set(PLATFORM_DEFS_INFO)
foreach (def ${PLATFORM_DEFS_CLEAN})
if (NOT def MATCHES "^STANDALONE_")
list(APPEND PLATFORM_DEFS_INFO ${def})
endif ()
endforeach ()
list(REMOVE_DUPLICATES PLATFORM_DEFS_INFO)
# Extract standalone mode (remove 'STANDALONE_' prefix)
message(STATUS "PLATFORM_DEFS_INFO = ${PLATFORM_DEFS_INFO}")
set(PLATFORM_DEFS_INFO_STANDALONE)
foreach (def ${PLATFORM_DEFS_CLEAN})
if (def MATCHES "^STANDALONE_(.+)")
list(APPEND PLATFORM_DEFS_INFO_STANDALONE "${CMAKE_MATCH_1}")
endif ()
endforeach ()
list(REMOVE_DUPLICATES PLATFORM_DEFS_INFO_STANDALONE)
# Check that only one Standalone mode is selected
list(LENGTH PLATFORM_DEFS_INFO_STANDALONE STANDALONE_COUNT)
if (STANDALONE_COUNT GREATER 1)
message(FATAL_ERROR "You must choose only one Standalone mode!: ${PLATFORM_DEFS_INFO_STANDALONE}")
endif ()
# Set extras info
set(PLATFORM_EXTRAS_INFO ${PLATFORM_EXTRAS})
if (NOT PLATFORM_EXTRAS_INFO)
set(PLATFORM_EXTRAS_INFO "No extra selected")
endif ()
message(STATUS "PLATFORM_DEFS_INFO_STANDALONE = ${PLATFORM_DEFS_INFO_STANDALONE}")
# Set standalone info
if (NOT PLATFORM_DEFS_INFO_STANDALONE)
set(PLATFORM_DEFS_INFO_STANDALONE "No standalone mode selected")
endif ()
# Default platform size
if (NOT PLATFORM_SIZE)
set(PLATFORM_SIZE 512)
endif ()
# Show some vars.
message(STATUS "===================================================================")
message(STATUS "Version info : ${VERSION_INFO} ")
message(STATUS "Platform name : ${PLTNAME} ")
message(STATUS "PLATFORM : ${PLATFORM} ")
message(STATUS "PLATFORM_FPGA : ${PLATFORM_FPGA} ")
message(STATUS "PLATFORM_SIZE : ${PLATFORM_SIZE} ")
message(STATUS "Platform extras : ${PLATFORM_EXTRAS_INFO} ")
message(STATUS "Included options : ${PLATFORM_DEFS_INFO} ")
message(STATUS "Standalone mode : ${PLATFORM_DEFS_INFO_STANDALONE} ")
message(STATUS "C Compiler Host : ${C_COMPILER_HOST}")
message(STATUS "===================================================================")
+6
View File
@@ -0,0 +1,6 @@
# ----------------------------------------------------------
# Fix error when 'compile a simple test program.'
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# ----------------------------------------------------------
+46
View File
@@ -0,0 +1,46 @@
if (NOT DEFINED PLATFORM)
message(FATAL_ERROR "Include this module after PLATFORM check.")
endif ()
#[[
Make All variables private(Exclude EXE)!!!
]]
# For get_exe_suffix function to detect the suffix of executable for current compiler, like '.exe' for Windows.
include(${CMAKE_CURRENT_LIST_DIR}/GetExeSuffixByCompiler.cmake)
set(_fc_MYINCLUDES -I${CMAKE_CURRENT_LIST_DIR}/../common_fpga)
set(_fc_MYCFLAGS -std=c99 -D_ISOC99_SOURCE)
if (PLATFORM STREQUAL PM3ICOPYX)
set(_fc_MYDEFS -DXC3)
else ()
set(_fc_MYDEFS)
endif ()
set(_fc_MYINCLUDES ${_fc_MYINCLUDES} -I${CMAKE_CURRENT_LIST_DIR}/../common/lz4)
set(_fc_MYCFLAGS ${_fc_MYCFLAGS} -DLZ4_MEMORY_USAGE=20 -Wno-redundant-decls -Wno-old-style-definition -Wno-missing-prototypes -Wno-missing-declarations)
set(_fc_MYSRCS ${_fc_MYSRCS}
${CMAKE_CURRENT_LIST_DIR}/fpga_compress/fpga_compress.c
${CMAKE_CURRENT_LIST_DIR}/../common/lz4/lz4hc.c
${CMAKE_CURRENT_LIST_DIR}/../common/lz4/lz4.c)
# The target name for fpga_compress
set(FPGA_COMPRESS fpga_compress)
get_exe_suffix(FPGA_COMPRESS_EXE_SUFFIX ${C_COMPILER_HOST})
get_filename_component(FPGA_COMPRESS_EXE "${CMAKE_CURRENT_LIST_DIR}/fpga_compress/${FPGA_COMPRESS}${FPGA_COMPRESS_EXE_SUFFIX}" ABSOLUTE) # executable filename + suffix
add_custom_command(OUTPUT ${FPGA_COMPRESS_EXE}
# COMMAND ${CMAKE_COMMAND} -E echo "[=] CC ${FPGA_COMPRESS} executable"
COMMAND ${C_COMPILER_HOST}
${_fc_MYCFLAGS}
${_fc_MYDEFS}
${_fc_MYINCLUDES}
${_fc_MYSRCS}
-o ${FPGA_COMPRESS_EXE}
DEPENDS ${_fc_MYSRCS} # if src update, this custom command will run. tips: only .c files watch now, you can add .h files watch if need.
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/fpga_compress
COMMENT "Build 'fpga_compress' executable for next step"
VERBATIM)
# add_custom_target always run if project build, but add_custom_command can cached output if no files update.
add_custom_target(${FPGA_COMPRESS} DEPENDS ${FPGA_COMPRESS_EXE})
+24
View File
@@ -0,0 +1,24 @@
function(get_exe_suffix OUTPUT_VAR GCC_COMPILER)
set(TEST_SRC ${CMAKE_CURRENT_BINARY_DIR}/detect_suffix.c)
set(TEST_EXE ${CMAKE_CURRENT_BINARY_DIR}/detect_suffix)
file(WRITE ${TEST_SRC} "int main(){return 0;}\n")
execute_process(
COMMAND ${GCC_COMPILER} ${TEST_SRC} -o ${TEST_EXE}
RESULT_VARIABLE RES
)
if (EXISTS "${TEST_EXE}.exe")
set(${OUTPUT_VAR} ".exe" PARENT_SCOPE)
else ()
set(${OUTPUT_VAR} "" PARENT_SCOPE)
endif ()
# Clear
file(REMOVE ${TEST_SRC} ${TEST_EXE} ${TEST_EXE}.exe ${TEST_EXE}.o)
endfunction()
# Usage:
# get_exe_suffix(${C_COMPILER_HOST} DETECTED_SUFFIX)
# message(STATUS "Detected suffix: '${DETECTED_SUFFIX}'")
+109
View File
@@ -0,0 +1,109 @@
# ------------------------------------------------------------------------
# Power by DXL
#
# Detect platform for run mkversion script
#
# Injection variable:
# MKVERSION_SCRIPT_FOUND - Is script found?
# MKVERSION_SCRIPT - The script full path
# MKVERSION_SCRIPT_TYPE - Script file type: "bat" or "sh"
# VERSION_INFO - Version info from mkversion.(bat|sh) --short
# MKVERSION_AVAILABLE - A boolean variable, tell me is script working and VERSION_INFO set.
# MKVERSION_CMD - The final command used to generate the source file version_pm3.c
# Only once run on setup(MKVERSION_AVAILABLE is a cached variable. Next reload will direct set and skip.)
if (DEFINED MKVERSION_AVAILABLE)
return()
endif ()
# Setup variable and export
set(MKVERSION_SCRIPT_FOUND FALSE)
set(MKVERSION_SCRIPT "")
set(MKVERSION_SCRIPT_TYPE "")
set(VERSION_INFO "unknown")
set(MKVERSION_AVAILABLE FALSE)
# The script for platform
set(MKVERSION_CANDIDATES_BAT "${CMAKE_CURRENT_LIST_DIR}/mkversion.bat")
set(MKVERSION_CANDIDATES_SH "${CMAKE_CURRENT_LIST_DIR}/mkversion.sh")
# We are running on the Windows?
set(MKVERSION_RUN_NATIVE_WINDOWS FALSE)
execute_process(COMMAND uname OUTPUT_VARIABLE uname)
if (uname MATCHES "^MSYS" OR uname MATCHES "^MINGW" OR uname MATCHES "^Lin" OR uname MATCHES "^Darwin")
message(STATUS "Not running on native Windows (uname is ${uname}).")
else ()
set(MKVERSION_RUN_NATIVE_WINDOWS TRUE)
endif ()
# First setup, we can run once '--short' for mkversion script to get like 'Iceman/master/b36b61feb-dirty'
if (MKVERSION_RUN_NATIVE_WINDOWS)
execute_process(
COMMAND cmd /c call "${MKVERSION_CANDIDATES_BAT}" --short
OUTPUT_VARIABLE _output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
RESULT_VARIABLE _result
)
if (${_result} EQUAL 0)
set(MKVERSION_SCRIPT "${MKVERSION_CANDIDATES_BAT}")
set(MKVERSION_SCRIPT_TYPE "bat")
set(VERSION_INFO "${_output}")
set(MKVERSION_SCRIPT_FOUND TRUE)
endif ()
else ()
# Is 'sh' available?
find_program(SH_COMMAND sh)
if (SH_COMMAND)
execute_process(
COMMAND "${SH_COMMAND}" "${MKVERSION_CANDIDATES_SH}" --short
OUTPUT_VARIABLE _output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
RESULT_VARIABLE _result
)
if (${_result} EQUAL 0)
set(MKVERSION_SCRIPT "${MKVERSION_CANDIDATES_SH}")
set(MKVERSION_SCRIPT_TYPE "sh")
set(VERSION_INFO "${_output}")
set(MKVERSION_SCRIPT_FOUND TRUE)
endif ()
endif ()
endif ()
# Finally, the script found and version info from '--short' available?
if (MKVERSION_SCRIPT_FOUND AND NOT "${VERSION_INFO}" STREQUAL "")
set(MKVERSION_AVAILABLE TRUE)
else ()
set(MKVERSION_AVAILABLE FALSE)
endif ()
# Export finally cmd for generate version_pm3.c
if (MKVERSION_SCRIPT_TYPE STREQUAL "sh") # What's shell type we are?
set(MKVERSION_CMD ${CMAKE_COMMAND} -E env bash ${MKVERSION_SCRIPT}) # Unix/Linux/macOS: call sh
elseif (MKVERSION_SCRIPT_TYPE STREQUAL "bat")
set(MKVERSION_CMD cmd /c ${MKVERSION_SCRIPT}) # Windows: call bat
else ()
message(FATAL_ERROR "MKVERSION_SCRIPT_TYPE must be 'sh' or 'bat', but got '${MKVERSION_SCRIPT_TYPE}'")
endif ()
# Set variables to cached level, next reload CmakeLists.txt will skip run this subscript(MKVersionScript.cmake).
set(MKVERSION_SCRIPT_FOUND ${MKVERSION_SCRIPT_FOUND} CACHE INTERNAL "Whether a mkversion script was found")
set(MKVERSION_SCRIPT ${MKVERSION_SCRIPT} CACHE INTERNAL "Full path to the mkversion script")
set(MKVERSION_SCRIPT_TYPE ${MKVERSION_SCRIPT_TYPE} CACHE INTERNAL "Type of script: 'bat' or 'sh'")
set(VERSION_INFO ${VERSION_INFO} CACHE INTERNAL "Version info string from --short")
set(MKVERSION_AVAILABLE ${MKVERSION_AVAILABLE} CACHE INTERNAL "Whether version info is available")
set(MKVERSION_CMD ${MKVERSION_CMD} CACHE INTERNAL "Command to generate version info")
# Debug info(Optional, can enable when debuging...)
if (FALSE)
message(STATUS "===================================================================")
message(STATUS "MKVERSION_SCRIPT_FOUND: ${MKVERSION_SCRIPT_FOUND}")
message(STATUS "MKVERSION_SCRIPT: ${MKVERSION_SCRIPT}")
message(STATUS "MKVERSION_SCRIPT_TYPE: ${MKVERSION_SCRIPT_TYPE}")
message(STATUS "VERSION_INFO: ${VERSION_INFO}")
message(STATUS "MKVERSION_CMD: ${MKVERSION_CMD}")
message(STATUS "===================================================================")
endif ()
+23
View File
@@ -0,0 +1,23 @@
# If it has already been found, there is no need to search again.
if(NOT DEFINED CMAKE_C_COMPILER)
set(TOOLCHAIN_PREFIX arm-none-eabi-)
# 1. Find the compiler
find_program(ARM_GCC_COMPILER ${TOOLCHAIN_PREFIX}gcc)
find_program(ARM_GXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
find_program(ARM_ASM_COMPILER ${TOOLCHAIN_PREFIX}gcc)
# 2. Check if the core C compiler is found
if(ARM_GCC_COMPILER)
message(STATUS "Found ARM GCC: ${ARM_GCC_COMPILER}")
# Set the found absolute paths (with or without .exe) directly to CMake
set(CMAKE_C_COMPILER ${ARM_GCC_COMPILER} CACHE PATH "C compiler")
set(CMAKE_CXX_COMPILER ${ARM_GXX_COMPILER} CACHE PATH "CXX compiler")
set(CMAKE_ASM_COMPILER ${ARM_ASM_COMPILER} CACHE PATH "ASM compiler")
else()
message(WARNING "ARM GCC (${TOOLCHAIN_PREFIX}gcc) not found in PATH!")
endif()
endif ()
+20
View File
@@ -0,0 +1,20 @@
@echo off
setlocal
:: Power by DXL
:: The mkversion.ps1 wrapper. why not mkversion.bat implement all function?
:: > Not good idea to call sha256 for arm src, so you known..
:: Did not output localization
set LC_ALL=C
set LANG=C
:: Where are this script?
set "SCRIPT_DIR=%~dp0"
:: Call PowerShell script, and send params
powershell -ExecutionPolicy Bypass -File "%SCRIPT_DIR%mkversion.ps1" %*
if %ERRORLEVEL% NEQ 0 (
exit /b %ERRORLEVEL%
)
+191
View File
@@ -0,0 +1,191 @@
<#
Power By DXL
The mkversion.sh same functions.
#>
param(
[string]$Destination,
[switch]$Short,
[switch]$Force,
[switch]$Undecided
)
# 默认 fork 名称(可自定义)
$fullgitinfo = "Iceman"
$clean = 2 # 2 = undecided, 1 = clean, 0 = dirty
# 获取脚本所在目录
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$pm3Root = Join-Path $ScriptDir ".."
# 检查是否在 Git 工作目录中
$inGit = $false
$gitDir = Join-Path $pm3Root ".git"
if (Test-Path $gitDir -PathType Container) {
# 尝试执行 git 命令
$result = $null
try {
$result = git -C $pm3Root rev-parse --is-inside-work-tree 2>$null
} catch { }
if ($result -eq "true") {
$inGit = $true
}
}
if ($inGit) {
try {
$gitVersion = (git -C $pm3Root describe --dirty --always).Trim()
$gitBranch = (git -C $pm3Root rev-parse --abbrev-ref HEAD).Trim()
if ($Undecided) {
if ($gitVersion -like "*-dirty") {
$clean = 0
} else {
$clean = 1
}
}
$fullgitinfo = "$fullgitinfo/$gitBranch/$gitVersion"
# 使用 FORCED_DATE 或当前时间
if ($env:FORCED_DATE -match '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$') {
$ctime = $env:FORCED_DATE
} else {
$ctime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
} catch {
$fullgitinfo = "$fullgitinfo/master/release (git_error)"
$ctime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
} else {
$fullgitinfo = "$fullgitinfo/master/release (no_git)"
$readmePath = Join-Path $pm3Root "README.md"
if (Test-Path $readmePath) {
$dl_time = (Get-Item $readmePath).LastWriteTime
$ctime = $dl_time.ToString("yyyy-MM-dd HH:mm:ss")
} else {
$ctime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
}
# --short 模式:只输出版本字符串
if ($Short) {
if ($fullgitinfo.Length -gt 49) {
$fullgitinfo = $fullgitinfo.Substring(0, 46) + "..."
}
Write-Output $fullgitinfo
exit 0
}
# 检查是否提供了输出文件路径
if (-not $Destination) {
Write-Error "Error: missing destination filename"
exit 1
}
# 计算 ARM 源码的 SHA256 哈希(前 9 位)
$armSrc = Join-Path $pm3Root "armsrc"
$commonArm = Join-Path $pm3Root "common_arm"
$files = @()
if (Test-Path $armSrc) {
$files += Get-ChildItem $armSrc | Where-Object {
($_.Extension -eq ".c" -or $_.Extension -eq ".h") -and
$_.Name -notmatch "^(disabled|version_pm3|fpga_version_info)"
}
}
if (Test-Path $commonArm) {
$files += Get-ChildItem $commonArm | Where-Object {
($_.Extension -eq ".c" -or $_.Extension -eq ".h") -and
$_.Name -notmatch "^(disabled|version_pm3|fpga_version_info)"
}
}
$sha = "no sha256"
if ($files.Count -gt 0) {
# 按文件名排序(确保一致性)
$sortedFiles = $files | Sort-Object Name
# 创建 SHA256 实例
$sha256 = New-Object System.Security.Cryptography.SHA256Managed
foreach ($file in $sortedFiles) {
try {
$content = [System.IO.File]::ReadAllBytes($file.FullName)
$sha256.TransformBlock($content, 0, $content.Length, $null, 0) | Out-Null
} catch {
Write-Warning "Failed to read file: $($file.FullName)"
}
}
# 完成哈希计算
$sha256.TransformFinalBlock([byte[]]@(), 0, 0)
$hashBytes = $sha256.Hash
$shaHex = -join ($hashBytes | ForEach-Object { $_.ToString("x2") })
$sha = $shaHex.Substring(0, 9)
}
# 截断 fullgitinfo 到最多 49 字符
if ($fullgitinfo.Length -gt 49) {
$fullgitinfo = $fullgitinfo.Substring(0, 46) + "..."
}
# 检查是否需要重新生成文件(避免无意义更新)
$regenerate = $true
if (-not $Force -and (Test-Path $Destination)) {
try {
$content = Get-Content $Destination -Raw
# 提取 clean 状态(第13行附近)
if ($content -match '^\s*(\d+)\s*$' -and $matches[1] -eq $clean) {
# 提取 fullgitinfo(第14行)
if ($content -match '^\s*"([^"]+)"\s*$' -and $matches[1] -eq $fullgitinfo) {
# 提取 sha(第16行)
if ($content -match '^\s*"([^"]+)"\s*$' -and $matches[1] -eq $sha) {
$regenerate = $false
}
}
}
} catch {
$regenerate = $true
}
}
# 仅当需要时才写入文件
if ($regenerate) {
$tmpFile = "$Destination.tmp"
$output = @"
#include "common.h"
/* Generated file, do not edit */
#ifndef ON_DEVICE
#define SECTVERSINFO
#else
#define SECTVERSINFO __attribute__((section(".version_information")))
#endif
const struct version_information_t SECTVERSINFO g_version_information = {
VERSION_INFORMATION_MAGIC,
1,
1,
$clean,
"$fullgitinfo",
"$ctime",
"$sha"
};
"@
try {
$output | Out-File -FilePath $tmpFile -Encoding ASCII -Force
Move-Item -Path $tmpFile -Destination $Destination -Force
} catch {
Write-Error "Failed to write version file: $_"
if (Test-Path $tmpFile) {
Remove-Item $tmpFile -Force
}
exit 1
}
}
exit 0