1idf_build_get_property(target IDF_TARGET)
2
3idf_component_register(SRCS "patches/esp_rom_crc.c"
4                            "patches/esp_rom_sys.c"
5                            "patches/esp_rom_uart.c"
6                       INCLUDE_DIRS include "${target}"
7                       PRIV_REQUIRES soc hal)
8
9# Append a target linker script at the target-specific path,
10# only the 'name' part is different for each script
11function(rom_linker_script name)
12    target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.rom.${name}.ld")
13endfunction()
14
15target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/ld/${target}.rom.ld")
16rom_linker_script("api")
17rom_linker_script("libgcc")
18
19if(BOOTLOADER_BUILD)
20    if(target STREQUAL "esp32")
21        rom_linker_script("newlib-funcs")
22        if(CONFIG_ESP32_REV_MIN_3)
23            rom_linker_script("eco3")
24        endif()
25
26    elseif(target STREQUAL "esp32s2")
27        rom_linker_script("newlib-funcs")
28        rom_linker_script("spiflash")
29
30    elseif(target STREQUAL "esp32s3")
31        rom_linker_script("newlib-funcs")
32        rom_linker_script("spiflash")
33
34    elseif(target STREQUAL "esp32c3")
35        rom_linker_script("newlib")
36    endif()
37
38else() # Regular app build
39    if(target STREQUAL "esp32")
40        rom_linker_script("newlib-data")
41        rom_linker_script("syscalls")
42
43        if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
44            rom_linker_script("newlib-funcs")
45            if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
46                # If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
47                # then all time functions from the ROM memory will not be linked.
48                # Instead, those functions can be used from the toolchain by ESP-IDF.
49                rom_linker_script("newlib-time")
50            endif()
51
52            # Include in newlib nano from ROM only if SPIRAM cache workaround is disabled
53            if(CONFIG_NEWLIB_NANO_FORMAT)
54                rom_linker_script("newlib-nano")
55            endif()
56
57        endif()
58
59        if(NOT CONFIG_SPI_FLASH_ROM_DRIVER_PATCH)
60            rom_linker_script("spiflash")
61        endif()
62
63        if(CONFIG_ESP32_REV_MIN_3)
64            rom_linker_script("eco3")
65        endif()
66
67    elseif(target STREQUAL "esp32s2")
68        rom_linker_script("newlib-funcs")
69        rom_linker_script("newlib-data")
70        rom_linker_script("spiflash")
71
72        if(CONFIG_NEWLIB_NANO_FORMAT)
73            rom_linker_script("newlib-nano")
74        endif()
75
76        # descirptors used by ROM code
77        target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c")
78
79    elseif(target STREQUAL "esp32s3")
80        rom_linker_script("newlib-funcs")
81        rom_linker_script("newlib-data")
82        rom_linker_script("spiflash")
83
84        if(CONFIG_NEWLIB_NANO_FORMAT)
85            rom_linker_script("newlib-nano")
86        endif()
87
88    elseif(target STREQUAL "esp32c3")
89        rom_linker_script("newlib")
90        rom_linker_script("version")
91
92        if(CONFIG_NEWLIB_NANO_FORMAT)
93            rom_linker_script("newlib-nano")
94        endif()
95
96        if(CONFIG_ESP32C3_REV_MIN_3)
97            rom_linker_script("eco3")
98        endif()
99    endif()
100
101endif()
102
103if(target STREQUAL "esp32s2")
104    target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c")
105endif()
106