1idf_build_get_property(target IDF_TARGET)
2
3if(CONFIG_EFUSE_VIRTUAL)
4    message(STATUS "Efuse virtual mode is enabled. If Secure boot or Flash encryption is on"
5        " it does not provide any security. FOR TESTING ONLY!")
6endif()
7
8if(EXISTS "${COMPONENT_DIR}/${target}")
9    include(${COMPONENT_DIR}/${target}/sources.cmake)
10    spaces2list(EFUSE_SOC_SRCS)
11    set(include_dirs include ${target}/include)
12    set(private_include private_include ${target}/private_include)
13    add_prefix(srcs "${target}/" ${EFUSE_SOC_SRCS})
14endif()
15
16if(CONFIG_SOC_EFUSE_KEY_PURPOSE_FIELD)
17    set(type "with_key_purposes")
18else()
19    if(CONFIG_SOC_EFUSE_CONSISTS_OF_ONE_KEY_BLOCK)
20        set(type "without_key_purposes/one_key_block")
21    else()
22        set(type "without_key_purposes/three_key_blocks")
23    endif()
24endif()
25
26list(APPEND srcs "src/esp_efuse_api.c"
27                 "src/esp_efuse_fields.c"
28                 "src/esp_efuse_utility.c"
29                 "src/efuse_controller/keys/${type}/esp_efuse_api_key.c")
30
31idf_component_register(SRCS "${srcs}"
32                    PRIV_REQUIRES bootloader_support soc spi_flash
33                    INCLUDE_DIRS "${include_dirs}"
34                    PRIV_INCLUDE_DIRS "${private_include}")
35
36if(target)
37    set(TOOL_TARGET -t ${target})
38endif()
39
40set(GEN_EFUSE_TABLE_ARG ${TOOL_TARGET} --max_blk_len ${CONFIG_EFUSE_MAX_BLK_LEN})
41
42idf_build_get_property(python PYTHON)
43
44###################
45# Make common files esp_efuse_table.c and include/esp_efuse_table.h files.
46set(EFUSE_COMMON_TABLE_CSV_PATH "${COMPONENT_DIR}/${target}/esp_efuse_table.csv")
47
48add_custom_target(efuse-common-table COMMAND "${python}"
49                 "${CMAKE_CURRENT_SOURCE_DIR}/efuse_table_gen.py"
50                 ${EFUSE_COMMON_TABLE_CSV_PATH} ${GEN_EFUSE_TABLE_ARG})
51add_deprecated_target_alias(efuse_common_table efuse-common-table)
52
53###################
54# Make custom files project/main/esp_efuse_custom_table.c and project/main/include/esp_efuse_custom_table.h files.
55# Path to CSV file is relative to project path for custom CSV files.
56if(${CONFIG_EFUSE_CUSTOM_TABLE})
57    # Custom filename expands any path relative to the project
58    idf_build_get_property(project_dir PROJECT_DIR)
59    get_filename_component(EFUSE_CUSTOM_TABLE_CSV_PATH "${CONFIG_EFUSE_CUSTOM_TABLE_FILENAME}"
60                           ABSOLUTE BASE_DIR "${project_dir}")
61    add_custom_target(efuse-custom-table COMMAND "${python}" "${CMAKE_CURRENT_SOURCE_DIR}/efuse_table_gen.py"
62                           ${EFUSE_COMMON_TABLE_CSV_PATH} ${EFUSE_CUSTOM_TABLE_CSV_PATH} ${GEN_EFUSE_TABLE_ARG})
63    add_deprecated_target_alias(efuse_custom_table efuse-custom-table)
64else()
65    add_custom_target(efuse-custom-table COMMAND)
66    add_deprecated_target_alias(efuse_custom_table efuse-custom-table)
67endif()#if(${CONFIG_EFUSE_CUSTOM_TABLE})
68
69add_custom_target(show-efuse-table COMMAND "${python}"
70                  "${CMAKE_CURRENT_SOURCE_DIR}/efuse_table_gen.py"
71                  ${EFUSE_COMMON_TABLE_CSV_PATH} ${EFUSE_CUSTOM_TABLE_CSV_PATH} ${GEN_EFUSE_TABLE_ARG} "--info")
72add_deprecated_target_alias(show_efuse_table show-efuse-table)
73
74###################
75# Generates files for unit test. This command is run manually.
76set(EFUSE_TEST_TABLE_CSV_PATH "${COMPONENT_DIR}/test/esp_efuse_test_table.csv")
77add_custom_target(efuse_test_table COMMAND "${python}"
78                  "${CMAKE_CURRENT_SOURCE_DIR}/efuse_table_gen.py"
79                  ${EFUSE_TEST_TABLE_CSV_PATH} ${GEN_EFUSE_TABLE_ARG})
80