<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi Eric,</p>
<p>Thanks for your prompt reply. <br>
</p>
<p>I have been able to follow your steps up until the item, so
thanks!<br>
</p>
<p> COMMAND
${CMAKE_C_COMPILER} $<TARGET_OBJECTS:clb_v2_dom.objs>
--symbol $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>>.crc32
$<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>></p>
<p>I ran into two challenges:<br>
- The argument '$<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>>.crc32' should
be the actual content of the file, and not the file itself, i.e.
the calculated CRC value. How to do this?<br>
- As far as I can see, non of the previously defined linker flags
are added to this command. Of course I can do this, but it would
mean I need to define things twice.</p>
<p>Cheers,<br>
Vincent</p>
<div class="moz-cite-prefix">On 7-10-2019 at 15:55 wrote Eric
Noulard:<br>
</div>
<blockquote type="cite"
cite="mid:CAPASGLokRMnQwkxaSs0kZps6_y2DVk0Krudvwpm+neWKXVqXEw@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Le lun. 7 oct. 2019 à 14:41,
Vincent van Beveren <<a
href="mailto:v.van.beveren@nikhef.nl"
moz-do-not-send="true">v.van.beveren@nikhef.nl</a>> a
écrit :<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">Hello everyone,<br>
<br>
I'm setting up a new build targeting an embedded platform
(LM32) and <br>
trying to integrate a CRC32 into the resulting ELF. I have
previously <br>
done this using plain Makefiles with the following steps
(pseudo code):<br>
<br>
target.elf: <obj-files><br>
link <obj-files> --symbol CRC_VALUE=0
intermediate.elf<br>
objcopy --binary intermediate.elf intermediate.bin<br>
link <obj-files> --symbol CRC_VALUE=`crc32
intermediate.bin` target.elf<br>
rm intermediate.bin<br>
<br>
Now I would like to achieve the same thing with CMake. I'm
using <br>
add_executable with multiple targets. The end of my
CMakeLists.txt looks <br>
like this, where F_GEN contains generic source files and
F__* source <br>
files specific for that variant of the build:<br>
<br>
# [...defining of cross compiler, and source files, some
compile flags, <br>
etc...]<br>
# Educate the linker<br>
add_link_options(<br>
-nostartfiles<br>
-nodefaultlibs<br>
-nostdlib<br>
-Wl,--gc-sections<br>
-T ${CMAKE_SOURCE_DIR}/${P_SRC}/romram.ld<br>
-Wl,--defsym=CRC_VALUE=0<br>
-Wl,--defsym=_start=0<br>
)<br>
<br>
# DOM v2 target<br>
add_executable( clb_v2_dom.elf ${F_GEN} ${F__DOM} )<br>
target_compile_definitions(clb_v2_dom.elf PUBLIC -DDOM
-DCLBV2 )<br>
<br>
# BASE v2 target<br>
add_executable( clb_v2_base.elf ${F_GEN} ${F__BASE} )<br>
# TODO migrate define 'DUBASE' -> 'BASE'<br>
target_compile_definitions(clb_v2_base.elf PUBLIC -DDUBASE
-DBASE -DCLBV2)<br>
<br>
# Golden v2 target<br>
add_executable( clb_v2_golden.elf ${F_GEN} ${F__GLD} )<br>
target_compile_definitions( clb_v2_golden.elf PUBLIC
-DGOLDEN -DCLBV2 )<br>
<br>
==<br>
<br>
As you can see CRC_VALUE is now simply defined 0 for every
target. Which <br>
works well for compiling but during runtime poses a problem
to the ROM <br>
verification procedure. What would a 'proper' way be of
adding a CRC to <br>
an ELF file be using CMake, and be different for each
target. Any help <br>
is welcome!<br>
</blockquote>
<div><br>
</div>
<div>I would try to add a set of custom command as POST_BUILD
event.</div>
<div><a
href="https://cmake.org/cmake/help/v3.15/command/add_custom_command.html#build-events"
moz-do-not-send="true">https://cmake.org/cmake/help/v3.15/command/add_custom_command.html#build-events</a><br>
</div>
<div><br>
</div>
<div>add_custom_command(TARGET clb_v2_base.elf POST_BUILD<br>
</div>
<div>
COMMAND crc32 $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_base.elf">FILE:clb_v2_base.elf</a>>
> $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_base.elf">FILE:clb_v2_base.elf</a>>.crc32</div>
<div> COMMAND
${CMAKE_C_COMPILER}
--symbol $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_base.elf">FILE:clb_v2_base.elf</a>>.crc32
$<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_base.elf">FILE:clb_v2_base.elf</a>></div>
<div> )</div>
<div><br>
</div>
<div>I don't know if the linker can read the computed crc32
from the previously generated file but you get the idea.</div>
<div>Moreover if you want to easily collect objects used for
linking a target you may need to use an intermediate</div>
<div>OBJECT library in order to be able to
retrieve $<TARGET_OBJECTS:objlib> </div>
<div>see: <a
href="https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries"
moz-do-not-send="true">https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries</a><br>
</div>
<div>i.e. replace: </div>
<div>add_executable( clb_v2_dom.elf ${F_GEN} ${F__DOM} )<br>
</div>
<div><br>
</div>
<div>by</div>
<div>add_library(clb_v2_dom.objs OBJECT ${F_GEN} ${F__DOM})</div>
<div>add_executable(clb_v2_dom.elf
$<TARGET_OBJECTS:clb_v2_dom.objs>)<br>
</div>
<div><br>
</div>
<div>and then:</div>
<div><br>
</div>
<div>add_custom_command(TARGET clb_v2_dom.elf POST_BUILD<br>
COMMAND crc32 $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>>
> $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>>.crc32<br>
COMMAND
${CMAKE_C_COMPILER} $<TARGET_OBJECTS:clb_v2_dom.objs>
--symbol $<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>>.crc32
$<TARGET_<a class="moz-txt-link-freetext" href="FILE:clb_v2_dom.elf">FILE:clb_v2_dom.elf</a>><br>
)<br>
</div>
<div><br>
</div>
<div>If this looks ok to you I would then write my own</div>
<div><br>
</div>
<div>lm32_add_executable that would wraps this up in order to
be called as:</div>
<div><br>
</div>
<div>lm32_add_executable(EXECUTABLE clb_v2_dom.elf<br>
</div>
<div> SOURCES ${F_GEN}
${F__DOM})</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<br>
Kind regards,<br>
Vincent<br>
<br>
<br>
<br>
-- <br>
National Institute for Subatomic Physics Nikhef<br>
Department of Computer Technology<br>
Science Park 105<br>
1098 XG AMSTERDAM<br>
<br>
tel. : +31 (0)20 592 2032<br>
e-mail: <a href="mailto:v.van.beveren@nikhef.nl"
target="_blank" moz-do-not-send="true">v.van.beveren@nikhef.nl</a><br>
site : <a href="http://www.nikhef.nl/~vincentb"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.nikhef.nl/~vincentb</a><br>
<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com"
rel="noreferrer" target="_blank" moz-do-not-send="true">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a
href="http://www.cmake.org/Wiki/CMake_FAQ"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake
community. For more information on each offering, please
visit:<br>
<br>
CMake Support: <a
href="http://cmake.org/cmake/help/support.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a
href="http://cmake.org/cmake/help/consulting.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a
href="http://cmake.org/cmake/help/training.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a
href="http://www.kitware.com/opensource/opensource.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>Eric<br>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
National Institute for Subatomic Physics Nikhef
Department of Computer Technology
Science Park 105
1098 XG AMSTERDAM
tel. : +31 (0)20 592 2032
e-mail: <a class="moz-txt-link-abbreviated" href="mailto:v.van.beveren@nikhef.nl">v.van.beveren@nikhef.nl</a>
site : <a class="moz-txt-link-freetext" href="http://www.nikhef.nl/~vincentb">http://www.nikhef.nl/~vincentb</a></pre>
</body>
</html>