Thanks Thomas,
OK. So the issue is that the prepressing is correct but saves “include”, using the suggested command line parameters.
It looks like a different behavior of IAR tools.
From: Thomas Törnblom <thomas.tornblom@iar.com>
Sent: Thursday, July 9, 2020 11:05 AM
To: Andrej Butok <andrey.butok@nxp.com>
Cc: tf-m@lists.trustedfirmware.org
Subject: Re: C preprocessor directives issue for IAR linker
Yes, it includes that line, but the resulting file after preprocessing doesn't.
In my first reply I showed two of the build steps, the first preprocesses the .icf file, which contains an #include line, and it produces an .icf.i file, which doesn't contain an #include line, and it is this file you use in the Option->Linker->Config->Override
default box instead of the .icf file.
Basically you run the C-processor on the .icf file to produce an icf.i file which is what you use to link the image. It becomes a two step process.
Hope this clears thing up :)
Cheers,
Thomas
Den 2020-07-09 kl. 10:55, skrev Andrej Butok:
Hi Thomas,
But your version of icf contains the #include "region_defs.h" too (line 21).
I am using the original TFM, just trying to compile it in the IAR IDE v8.50.5.
So should be a missing step which will convert region_defs.h definitions to a linker format.
From: Thomas Törnblom <thomas.tornblom@iar.com>
Sent: Thursday, July 9, 2020 10:46 AM
To: Andrej Butok <andrey.butok@nxp.com>
Cc: tf-m@lists.trustedfirmware.org
Subject: Re: C preprocessor directives issue for IAR linker
I am using a fork with some of my not-yet merged patches, but it should not affect this. It does have different .icf files though.
You can pull this from https://review.trustedfirmware.org/c/TF-M/trusted-firmware-m/+/4438
git pull "https://review.trustedfirmware.org/TF-M/trusted-firmware-m" refs/changes/38/4438/23
If you can share your workspace I would be glad to have a look.
Cheers,
ThomasDen 2020-07-09 kl. 10:35, skrev Andrej Butok:
Hi Thomas,
> The .icf files in the tf-m projects contain no such line.
It’s strange. The “trusted-firmware-m/platform/ext/common/iar/tfm_common_s.icf” IAR linker file contains:
line 21
#include "region_defs.h"
After the preprocessing it is converted to :
Line 22:
include "region_defs.h";
Are you using a different or forked TFM? Could you reference to it?
Thank you,
Andrej
From: Thomas Törnblom <thomas.tornblom@iar.com>
Sent: Thursday, July 9, 2020 10:25 AM
To: Andrej Butok <andrey.butok@nxp.com>
Cc: tf-m@lists.trustedfirmware.org
Subject: Re: C preprocessor directives issue for IAR linker
Hi Andrej,
There should be no "include" line in the final icf.i file, unless the .icf file contains this.
Perhaps you added that in an attempt at fixing the first issue?
The .icf files in the tf-m projects contain no such line.
Cheers,
ThomasDen 2020-07-09 kl. 10:05, skrev Andrej Butok:
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
--
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
--
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
--
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