[CMake] Linking twice for CRC32

Vincent van Beveren v.van.beveren at nikhef.nl
Fri Oct 11 02:10:54 EDT 2019


Hello  everyone,

For integrating the CRC to an ELF I believe I will need to link twice. 
First to create a binary on which to caclulate the CRC, and using a 
second pass to actually put the CRC into a the symbol at the last part 
of the RAM. Using the pointers by Eric  Noulard I have constructed the 
following CMake code, which links the file, exports a binary BIN file 
(the actual ROM image, and then calculates the CRC into a file called 
$<TARGET_FILE:clb_v2_dom.elf>.crc32.

# Exprimental CRC32 support
add_library(clb_v2_dom.objs OBJECT ${F_GEN} ${F__DOM})
target_compile_definitions(clb_v2_dom.objs PUBLIC -DDOM -DCLBV2 )
add_executable(clb_v2_dom.elf $<TARGET_OBJECTS:clb_v2_dom.objs>)
add_custom_command(TARGET clb_v2_dom.elf POST_BUILD
     COMMAND ${CMAKE_OBJCOPY} $<TARGET_FILE:clb_v2_dom.elf> ${SECTIONS} 
-O binary $<TARGET_FILE:clb_v2_dom.elf>.bin
     COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/crc32.py 
$<TARGET_FILE:clb_v2_dom.elf>.bin > $<TARGET_FILE:clb_v2_dom.elf>.crc32
)

with linker flags defined as

# Bring up the linker
add_link_options(
     -nostartfiles
     -nodefaultlibs
     -Wl,--gc-sections
     -nostdlib
     -T ${CMAKE_SOURCE_DIR}/${P_SRC}/romram.ld
     -Wl,--defsym=CRC_VALUE=0
     -Wl,--defsym=_start=0
     )

However, the last part is to link the file again with *exactly* the same 
invocation as the original linking, except for the 
'-Wl,--defsym=CRC_VALUE=<<content of .crc32 file>>' instead of 0.

Can anyone give me points on how to achieve this goal?

Kind regards,
Vincent

-- 
National Institute for Subatomic Physics Nikhef
Department of Computer Technology
Science Park 105
1098 XG AMSTERDAM

tel.  : +31 (0)20 592 2032
e-mail: v.van.beveren at nikhef.nl
site  : http://www.nikhef.nl/~vincentb



More information about the CMake mailing list