Skip to content

Commit 23860b7

Browse files
committed
generate macros using Makefile
1 parent 1d54dcf commit 23860b7

File tree

7 files changed

+73
-216
lines changed

7 files changed

+73
-216
lines changed

fuzzing/libs/glyphs.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_custom_command(
4141
OUTPUT ${GLYPHS_C} ${GLYPHS_H}
4242
COMMAND ${Python3_EXECUTABLE} ${GEN_GLYPHS_CMD} ${GLYPH_OPT} --glyphcheader
4343
${GLYPHS_H} --glyphcfile ${GLYPHS_C} ${GLYPH_FILES}
44+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/"
4445
DEPENDS ${GLYPH_FILES}
4546
COMMENT "Generating glyphs..."
4647
VERBATIM)

fuzzing/libs/lib_io.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ file(
2222
add_library(io ${LIB_IO_SOURCES})
2323
target_link_libraries(io PUBLIC nbgl cxng macros nfc)
2424
target_compile_options(io PUBLIC ${COMPILATION_FLAGS} -Wno-implicit-function-declaration)
25-
target_compile_definitions(io PUBLIC OS_IO_SEPH_BUFFER_SIZE=300)
2625
target_include_directories(
2726
io
2827
PUBLIC ${BOLOS_SDK}/include/

fuzzing/macros/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
##
2+
# Extract defines given the specified device
3+
#
4+
# @file
5+
# @version 0.1
6+
ifeq ($(BOLOS_SDK),)
7+
$(error Environment variable BOLOS_SDK is not set)
8+
endif
9+
10+
########################################
11+
# Mandatory configuration #
12+
########################################
13+
# Application name
14+
APPNAME = "Fuzzing"
15+
16+
# Application version
17+
APPVERSION_M = 1
18+
APPVERSION_N = 0
19+
APPVERSION_P = 0
20+
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"
21+
22+
# Application source files
23+
APP_SOURCE_PATH += src
24+
CURVE_APP_LOAD_PARAMS = secp256k1
25+
PATH_APP_LOAD_PARAMS = "44'/1'" # purpose=coin(44) / coin_type=Testnet(1)
26+
VARIANT_PARAM = COIN
27+
VARIANT_VALUES = BOL
28+
ENABLE_BLUETOOTH = 1
29+
ENABLE_NFC = 1
30+
ENABLE_NBGL_FOR_NANO_DEVICES = 1
31+
ENABLE_NBGL_QRCODE = 1
32+
33+
ifeq ($(APPNAME), "Fuzzing")
34+
ENABLE_TESTING_SWAP = 1
35+
endif
36+
37+
include $(BOLOS_SDK)/Makefile.standard_app
38+
39+
list-defines:
40+
@echo "$(DEFINES)"

fuzzing/macros/macros-flex.txt

Lines changed: 0 additions & 104 deletions
This file was deleted.

fuzzing/macros/macros-stax.txt

Lines changed: 0 additions & 102 deletions
This file was deleted.

fuzzing/macros/macros.cmake

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,35 @@ if(NOT "${BOLOS_SDK}/fuzzing" STREQUAL ${CMAKE_SOURCE_DIR})
1717

1818
# Building from SDK
1919
else()
20-
if("${TARGET_DEVICE}" STREQUAL "stax")
21-
message("${Blue}Importing macros from ${CMAKE_SOURCE_DIR}/macros/macros-stax.txt")
22-
file(STRINGS "${CMAKE_SOURCE_DIR}/macros/macros-stax.txt" MACRO_LIST)
23-
list(APPEND MACRO_LIST "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1")
24-
target_compile_definitions(macros INTERFACE ${MACRO_LIST})
25-
elseif("${TARGET_DEVICE}" STREQUAL "flex")
26-
message("${Blue}Importing macros from ${CMAKE_SOURCE_DIR}/macros/macros-flex.txt")
27-
file(STRINGS "${CMAKE_SOURCE_DIR}/macros/macros-flex.txt" MACRO_LIST)
20+
if(${TARGET_DEVICE} STREQUAL "stax" OR ${TARGET_DEVICE} STREQUAL "flex")
21+
# Run `make list-defines` and capture output
22+
execute_process(
23+
COMMAND ${CMAKE_COMMAND} -E env BOLOS_SDK=${BOLOS_SDK} TARGET=${TARGET_DEVICE} CC=${CMAKE_C_COMPILER} make list-defines
24+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/macros"
25+
OUTPUT_VARIABLE MACRO_OUTPUT
26+
OUTPUT_STRIP_TRAILING_WHITESPACE
27+
ERROR_QUIET
28+
)
29+
30+
31+
32+
33+
if(NOT MACRO_OUTPUT)
34+
message(FATAL_ERROR "Failed to extract macros via 'make list-defines'")
35+
endif()
36+
37+
string(REPLACE " " ";" MACRO_LIST "${MACRO_OUTPUT}")
38+
39+
# Append the special fuzzing macro
2840
list(APPEND MACRO_LIST "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1")
41+
list(REMOVE_ITEM MACRO_LIST "PRINTF\\(...\\)=")
42+
list(REMOVE_ITEM MACRO_LIST "USE_OS_IO_STACK")
43+
2944
target_compile_definitions(macros INTERFACE ${MACRO_LIST})
3045
endif()
31-
3246
endif()
47+
48+
message("${Blue}Loaded macros from 'make list-defines' (${CMAKE_SOURCE_DIR}/macros):")
49+
foreach(M ${MACRO_LIST})
50+
message(" - ${M}")
51+
endforeach()

fuzzing/mock/gen_mock.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ def generate_mock(signature):
6767
return mock[0] if 'noreturn' in signature else mock[1]
6868
return mock
6969

70+
def clean_duplicate_attributes(signature: str) -> str:
71+
return signature.replace("__attribute((weak))", "").strip()
72+
7073
def gen_mocks(c_code):
7174
global NUM_SKIPPED_MOCKS
7275
lines = c_code.splitlines()
7376
mocks, skipped = [], []
7477
i = 0
7578

7679
while i < len(lines):
80+
lines[i] = clean_duplicate_attributes(lines[i])
7781
line = lines[i]
7882

7983
if line.strip().startswith('#') or not line.strip():

0 commit comments

Comments
 (0)