Skip to content

Conversation

@tejlmand
Copy link
Contributor

@tejlmand tejlmand commented Jun 27, 2024

Incremental builds for TF-M are not picked up by Zephyr linking stage. Code changes to tf-m repository results in a rebuild of TF-M and thus an updated tfm_s.hex (and other files), but not a re-link of Zephyr.

tfm_s.hex is merged together with the zephyr hex to form a final merged hex file for flashing. This is done as a post-build command, however such as step cannot take extra dependencies. The Zephyr target can have extra dependencies, however that will only ensure the dependency is brought up-to-date when Zephyr re-link, not re-linking Zephyr when the dependency changes.

Therefore an object dependency is placed on the interface.c file for Zephyr TF-M interface implementation, which ensures the tfm_api library is brought up-to-date whenever TF-M rebuilds, and this update again ensures the Zephyr itself is re-linked whenever TF-M rebuilds, and thus the Zephyr re-link ensures a new merge of the two images.

Incremental builds for TF-M are not picked up by Zephyr linking stage.
Code changes to tf-m repository results in a rebuild of TF-M and thus
an updated tfm_s.hex (and other files).

tfm_s.hex is merged together with the zephyr hex to form a final merged
hex file for flashing. This is done as a post-build command, however
such as step cannot take extra dependencies. The Zephyr target can have
extra dependencies, however that will only ensure the dependency is
brought up-to-date when Zephyr re-link, not re-linking Zephyr when the
dependency changes.

Therefore an object dependency is placed on the interface.c file for
Zephyr TF-M interface implementation, which ensures the tfm_api library
is brought up-to-date whenever TF-M rebuilds, and this update again
ensures the Zephyr itself is re-linked whenever TF-M rebuilds.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
@tejlmand tejlmand added this to the v3.7.0 milestone Jun 27, 2024
@tejlmand tejlmand added the bug The issue is a bug, or the PR is fixing a bug label Jun 27, 2024
@zephyrbot zephyrbot added the area: TF-M ARM Trusted Firmware-M (TF-M) label Jun 27, 2024
tejlmand added a commit to tejlmand/fw-nrfconnect-zephyr-1 that referenced this pull request Jun 27, 2024
Incremental builds for TF-M are not picked up by Zephyr linking stage.
Code changes to tf-m repository results in a rebuild of TF-M and thus
an updated tfm_s.hex (and other files).

tfm_s.hex is merged together with the zephyr hex to form a final merged
hex file for flashing. This is done as a post-build command, however
such as step cannot take extra dependencies. The Zephyr target can have
extra dependencies, however that will only ensure the dependency is
brought up-to-date when Zephyr re-link, not re-linking Zephyr when the
dependency changes.

Therefore an object dependency is placed on the interface.c file for
Zephyr TF-M interface implementation, which ensures the tfm_api library
is brought up-to-date whenever TF-M rebuilds, and this update again
ensures the Zephyr itself is re-linked whenever TF-M rebuilds.

Upstream PR: zephyrproject-rtos/zephyr#75090

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
anangl pushed a commit to nrfconnect/sdk-zephyr that referenced this pull request Jun 27, 2024
Incremental builds for TF-M are not picked up by Zephyr linking stage.
Code changes to tf-m repository results in a rebuild of TF-M and thus
an updated tfm_s.hex (and other files).

tfm_s.hex is merged together with the zephyr hex to form a final merged
hex file for flashing. This is done as a post-build command, however
such as step cannot take extra dependencies. The Zephyr target can have
extra dependencies, however that will only ensure the dependency is
brought up-to-date when Zephyr re-link, not re-linking Zephyr when the
dependency changes.

Therefore an object dependency is placed on the interface.c file for
Zephyr TF-M interface implementation, which ensures the tfm_api library
is brought up-to-date whenever TF-M rebuilds, and this update again
ensures the Zephyr itself is re-linked whenever TF-M rebuilds.

Upstream PR: zephyrproject-rtos/zephyr#75090

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
@ithinuel
Copy link
Contributor

Is there really a need for Zephyr to relink every time TF-M does so?
I’d expect it to only need to when shared/generated files are updated (eg s_veneers.o).

@adeaarm any advice?

@adeaarm
Copy link

adeaarm commented Jun 27, 2024

Is there really a need for Zephyr to relink every time TF-M does so? I’d expect it to only need to when shared/generated files are updated (eg s_veneers.o).

@adeaarm any advice?

You're correct, the NS world needs to relink only in case the veneers functions are updated, otherwise the two processing environments are completely indepedent.

@Vge0rge
Copy link
Contributor

Vge0rge commented Jun 28, 2024

Zephyr combines the non-secure and the secure image in a single hex named tfm_merged.hex (which is eventually used by sysbuild later to generate merged.hex).This is generated using the extra_post_build_commands of Zephyr here:

set_property(GLOBAL APPEND PROPERTY extra_post_build_commands

The reason that the relinking need to happen is that it will enforce this post_builds to execute every time that you update anything in TF-M even if you didn't update something in Zephyr. Without this we observed that a TF-M update will not update the tfm_merged.hex.

@tejlmand
Copy link
Contributor Author

Is there really a need for Zephyr to relink every time TF-M does so?

In principle not, but the problem is the merging of the tf-m hex together with the zephyr hex, and this step is only performed when a Zephyr re-link happens.

That was what I tried to describe here: #75090 (comment)

tfm_s.hex is merged together with the zephyr hex to form a final merged hex file for flashing. This is done as a post-build command, however such as step cannot take extra dependencies. The Zephyr target can have extra dependencies, however that will only ensure the dependency is brought up-to-date when Zephyr re-link, not re-linking Zephyr when the dependency changes.

Therefore an object dependency is placed on the interface.c file for Zephyr TF-M interface implementation, which ensures the tfm_api library is brought up-to-date whenever TF-M rebuilds, and this update again ensures the Zephyr itself is re-linked whenever TF-M rebuilds.

but guess I should have continued the sentence with additional to ensure a new merge of the two images.
(added to description).

@nashif nashif merged commit 2bfea20 into zephyrproject-rtos:main Jun 29, 2024
anangl pushed a commit to anangl/sdk-zephyr that referenced this pull request Jul 1, 2024
Incremental builds for TF-M are not picked up by Zephyr linking stage.
Code changes to tf-m repository results in a rebuild of TF-M and thus
an updated tfm_s.hex (and other files).

tfm_s.hex is merged together with the zephyr hex to form a final merged
hex file for flashing. This is done as a post-build command, however
such as step cannot take extra dependencies. The Zephyr target can have
extra dependencies, however that will only ensure the dependency is
brought up-to-date when Zephyr re-link, not re-linking Zephyr when the
dependency changes.

Therefore an object dependency is placed on the interface.c file for
Zephyr TF-M interface implementation, which ensures the tfm_api library
is brought up-to-date whenever TF-M rebuilds, and this update again
ensures the Zephyr itself is re-linked whenever TF-M rebuilds.

Upstream PR: zephyrproject-rtos/zephyr#75090

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
(cherry picked from commit 9a728d7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: TF-M ARM Trusted Firmware-M (TF-M) bug The issue is a bug, or the PR is fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants