Hi Thomas,

 

Thank you, the command helped to preprocess the .icf linker file and eliminate C preprocessor directives inside it.

 

But still there is the issue, as the final .icf.i includes the region_defs.h C header file:

include "region_defs.h";

 

So it is causing the error in "region_defs.h":

Error[Lc003]: expected ""check", "define", "do", "export", "if", "include", "initialize", "keep", "place", "reserve", or a placement label,"

 

Guess, it should be an additional step which is missed. Right?

 

Thank you,

Andrej

 

From: Thomas Törnblom <thomas.tornblom@iar.com>
Sent: Wednesday, July 8, 2020 10:11 AM
To: Andrej Butok <andrey.butok@nxp.com>
Cc: tf-m@lists.trustedfirmware.org
Subject: Re: C preprocessor directives issue for IAR linker

 

Hello Andrej,

This is part of the cmake build chain. One of the steps runs the C-preprocessor on the .icf files to generate a new .icf file that is what is really used in the linking step.

This is the same with armclang and gcc as well.

I think you could use the Options->Build Actions->Pre-build command line option to run this step before executing the other build steps.

Here is how it is done for the secure image through cmake, it is done similarly for the bl2 and non-secure images:
---
cd C:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/cmake_build_iar/secure_fw && D:/apps/ewarm-8.50.5/arm/bin/iccarm.exe --cpu Cortex-M33.no_dsp -DTFM_PARTITION_TEST_SECURE_SERVICES -DTFM_PARTITION_INITIAL_ATTESTATION -DTFM_PARTITION_PROTECTED_STORAGE -DTFM_PARTITION_CRYPTO -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE -DTFM_PARTITION_PLATFORM -DTFM_LVL=1 -DTFM_PARTITION_TEST_CORE -DTFM_PARTITION_TEST_CORE_IPC -DTFM_PARTITION_TEST_PS -DTEST_FRAMEWORK_S -DTEST_FRAMEWORK_NS -DTFM_PSA_API -DTFM_PARTITION_TEST_CORE -DTFM_ENABLE_IRQ_TEST -IC:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/platform/ext/target/nxp/lpcxpresso55s69/partition C:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/platform/ext/common/iar/tfm_common_s.icf --silent --preprocess=ns C:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/cmake_build_iar/secure_fw/tfm_s.icf.i
---

and the link step:
---
cd C:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/cmake_build_iar/secure_fw && D:/apps/ewarm-8.50.5/arm/bin/ilinkarm.exe     --cpu Cortex-M33.no_dsp  --import_cmse_lib_out=C:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/cmake_build_iar/secure_fw/s_veneers.o --silent --semihosting --redirect __write=__write_buffered  --config=C:/Users/thomasto/Projects/tf-m1/trusted-firmware-m/cmake_build_iar/secure_fw/tfm_s.icf.i ../test/secure_test/tfm_secure_tests.a partitions/initial_attestation/tfm_attest.a partitions/protected_storage/tfm_storage.a partitions/crypto/tfm_crypto.a partitions/internal_trusted_storage/tfm_internal_trusted_storage.a partitions/platform/tfm_platform.a partitions/lib/sprt/libtfmsprt.a  -f CMakeFiles/tfm_s.dir/objects1.rsp -o ../unit_test/tfm_s.axf --map ../unit_test/tfm_s.map
---
Good luck!

Cheers,
Thomas

Den 2020-07-08 kl. 09:30, skrev Andrej Butok:

Hello Tomas,

 

I am trying to port TFM to IAR Embedded Workbench v8.50.5 IDE (NOT cmake) for LPC55S69.

And have an error during linking in tfm\platform\ext\common\iar\tfm_common_s.icf on #include "region_defs.h":

Error[Lc003]: expected ""check", "define", "do", "export", "if", "include", "initialize", "keep", "place", "reserve", or a placement label

 

It can be fixed by changing: #include "region_defs.h" to: include "region_defs.h";

but it creates 44 Errors [Lc003] in region_defs.h,

 

The IAR linker does not understand the C preprocessor directives like #ifndef, #ifdef, #endif etc.

How did you solve this IAR issue?

As we have to use IAR IDE (not cmake), what is your suggestion? Maybe a special IAR Linker preprocessing parameter/option?

 

Thank you,

Andrej Butok

 

 

--

Thomas Törnblom, Product Engineer
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
Mobile: +46 76 180 17 80 Fax: +46 18 16 78 01
E-mail:
thomas.tornblom@iar.com Website: www.iar.com
Twitter:
www.twitter.com/iarsystems