Skip to content

Conversation

@stgloorious
Copy link
Contributor

@stgloorious stgloorious commented Nov 21, 2025

Support for NXP FRDM-MCXN947 board.

Cherry-pick commits from upstream to introduce new log macros.
Prerequisite to also pull in new board support, e.g., NXP FRDM-MCXN947.

Cherry-picked from https://review.trustedfirmware.org/c/TF-M/trusted-firmware-m/+/44162
cc @waqar-tahir

No conflicts occured.

Some changes are necessary to Zephyr as well. With these changes, I can build and boot TF-M successfully:

Booting TF-M v2.2.0+55ca99f00
[WRN] This device was provisioned with dummy keys. This device is NOT SECURE
[Sec Thread] Secure image initializing!
[INF] [PS] Encryption alg: 0x5500200
[INF] [Crypto] Provision entropy seed...
[INF] [Crypto] Provision entropy seed... complete.
*** Booting Zephyr OS build v4.3.0-7-g7efb4a3be3e9 ***
Hello World! frdm_mcxn947/mcxn947/cpu0/ns

@stgloorious stgloorious marked this pull request as draft November 21, 2025 14:11
@stgloorious stgloorious marked this pull request as ready for review November 24, 2025 08:53
@waqar-tahir
Copy link
Contributor

Hi @stgloorious. May I ask, if this PR will be merged for #154.
Or, if something else needs to be done, to make it part of zephyr tf-m 2.2.2, please let me know.
Thanks.

@stgloorious
Copy link
Contributor Author

Hi @stgloorious. May I ask, if this PR will be merged for #154. Or, if something else needs to be done, to make it part of zephyr tf-m 2.2.2, please let me know. Thanks.

@waqar-tahir It would be nice to merge it into Zephyr tf-m 2.2.2 if possible. The prerequisite for this, #159, was already cherry-picked into #154. What is the plan/policy here, @tomi-font ?

@tomi-font
Copy link
Collaborator

Hey, I am not gonna include this as part of the 2.2.2 update as this is purely adding support for a new platform. #159, on the other hand, fixed something that we already had in-tree so I cherry-picked it to be able to get rid of 5a5eea0.
Once #154 is merged zephyr_tf-m_v2.2.2 will be set as the new default branch of the repository and the currently open PRs will have to be rebased and their base branch updated accordingly.
See https://github.com/zephyrproject-rtos/mbedtls?tab=readme-ov-file#version-bumping for more information on the process (I will link to this from this repo's readme as part of the update).

@stgloorious
Copy link
Contributor Author

Makes sense @tomi-font, thanks.

@tomi-font tomi-font changed the base branch from main to zephyr_tf-m_v2.2.2 December 3, 2025 09:03
@tomi-font
Copy link
Collaborator

The default branch of this repository is being changed to zephyr_tf-m_v2.2.2 which will replace main shortly.
Please rebase your branch atop zephyr_tf-m_v2.2.2 and force-push it.
I have already changed your PR's base branch to zephyr_tf-m_v2.2.2.
Also, make sure to follow the new commit guidelines documented here.

jackson-cooperd and others added 20 commits December 3, 2025 10:18
Add support to the vprintf implementation for left formatting. This
applies to both integer format specifiers and strings. The
implementation also allows us to tidy up the existing integer format
specifier parser.

Change-Id: If7bcc07712a14de76294b9a7a1f6f637380ed714
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 44a5153)
Make use of the new tfm_log library for logging from BL2. We achieve
this by redefining the MCUBOOT_LOG_ macros in TF-M to use the tfm_log
macros instead of printf. The log level is mapped from the configured
MCUBoot value to the value used by tfm_log and we add a CPP check to
ensure that the two match correctly.

Change-Id: I6dd24bd53008a779ab5fa282153a8c8d5c4e5741
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit a6a90c3)
These macros allow for printing raw strings without any prefix (such as
[DGB] etc.). They are useful for porting existing logging library usage
to the new logging API.

Change-Id: I90acbfb3fb0c9bbe8fc3938b7ac79a82d2151138
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 5188b1e)
Follows the same logic as in
ac7219e.

Change-Id: I211cb321d442bac74fc62c966e2330f75ad91271
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit a054b3f)
Remove these to ensure that these interface targets only provide the
tfm_log.c and tfm_log_unpriv.c source files and nothing else. This
allows targets to individually link the tfm_vprintf.c source file.

Change-Id: I5c00665d361ff9fab5b6316104d5a743336b8917
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit e74fa6f)
Previously, the tfm_log_unpriv implementation dropped strings that could
not fit in the 32 byte buffer. Rework the implementation to instead
output them directly to the SVC call, without using the buffer.

Change-Id: Ib976bef538d7efdf30a64e3a2091ca1ebfd15764
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 8eb243c)
Add the implementation of vprintf for unprivileged logging. This
function follows the same signature as the standard library vprintf.

Change-Id: I512e1835c0c93e72be46f06508c1b66d67587dbf
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 4d5ce0e)
Make use of the new unprivileged logging API throughout the secure
partitions. This mainly does drop in replacements for the existing
macros to the new LOG_UNPRIV macros.

Note that as part of this change, we replace the existing remove
tfm_sp_log_raw.c which implemented the vprintf standard library
function. This function is still by some platforms and external
libraries in TF-M and therefore we add a new implementation which makes
use of the implementation in the new unpriv logging library.

Change-Id: I58c7f71fabab0984fe42560c6c20ca313bd5aa60
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 1f2c7fd)
Replace the existing SPM log library with the new tfm_log library. This
patch aims to maintain existing behaviour by using a format specifier
which matches the existing implementation.

Change-Id: I5871b5429e4f051fdede87063bfe3ebbe49847f9
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit af54602)
Replace the existing implementation which used printf.

Change-Id: Ie3e37eb905583c8793578bc138e6cc11222f378e
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 182bcbf)
Instead of verifying that the LOG_LEVEL matches the MCUBOOT_LOG_LEVEL,
completely ignore the definition of LOG_LEVEL for MCUBoot logging and
ensure that instead we only use the MCUBOOT_LOG_LEVEL macro to determine
the level to log at.

We achieve this by setting the LOG_LEVEL to LOG_LEVEL_VERBOSE which
compiles in all logging macros and allow the MCUBOOT_LOG_LEVEL to set
which level to log at.

Change-Id: I343774306734499b691fde04cd87626ff6d13add
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 1fe05e9)
The vprintf implementation in crt_vprintf.c should return the number of
characters printed (as that is the standard signature of vprintf).
Rework the tfm_vprintf_unpriv implementation to count the number of
characters printed to the UART and return them.

Change-Id: I26f9f4efdede685c1e82294859ef3ce1fcf45fcd
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit b311830)
This function should not be accessed outside of the tfm_log and
tfm_log_unpriv libraries and therefore does not need to be exposed in
the public header. Add a new private header which is then included by
the logging source files.

Change-Id: Ic6ca5d4ad753b6e6abaedaf27d0b17b9ebe6f1b3
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit ccf42f2)
The underlying tfm_vprintf function can now be called
tfm_vprintf_unpriv, which is called from the runtime FW vprintf
implementation. This function will be called without a marker character
at the beginning of the string and therefore will cause an assertion to
be triggered within the vprintf implementation. Add a new argument which
specifies whether or not there is a marker character.

Change-Id: I58bc8cfa44f348766408d6e1fcf3fa995c3f6131
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit b59d3fb)
Completely replace the MCUBOOT_LOG_LEVEL with TFM_BL2_LOG_LEVEL, which
specifies the log level to use for all of BL2.

Change-Id: I2e454c6709d32d283454730d11b4b22d7c550071
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit aa09e6f)
Link this target which provides the tfm_vprintf headers to each of the
logging library header targets. This prevents users of the logging
libraries from having to explicitly link both of the header targets.

Change-Id: I043e51cdb1567fcb971e480474dfebf46c7688a8
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 79aa055)
Although %d is already present, extend with %i so it is
easier to introduce work-in-progress patches.

Signed-off-by: Nicola Mazzucato <[email protected]>
Change-Id: I9637c514f44bf78c9a4acb3b3a4934fc72c01c8f
(cherry picked from commit 18c84d7)
In tfm_vprintf.c, if the calculate_length flag is set and the string
passed to output_str is NULL, then the program would dereference the
NULL pointer as per the following warning:

warning: potential null pointer dereference [-Wnull-dereference]
   64 |         while (*str_ptr++ != '\0') {
      |                ^~~~~~~~~~

Fix this by adding an assertion that the string is non-NULL and
returning from the function in the case of release builds.

Change-Id: Ibc9fe50a19c8255298ea69b22770f8a255ad9266
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 3e369bd)
Add support for printing hex values in capitals when using the %X format
specifier.

Change-Id: I5f914164963b704689e388b14c9d96c5c59ee552
Signed-off-by: Jackson Cooper-Driver <[email protected]>
(cherry picked from commit 2b9877121c1e84d2ff1d98c1ec9bdca3d1e205b5)
The commit adds support for the ARM Cortext-M33
based NXP frdmmcxn947 development board to
Trusted Firmware-M (TF-M). This includes:
- Native peripheral driver for Flash and LPUART
- System, Flash and RAM configuration files for
  dual-core CM33 architecture
- Platform Native drivers from MCUX SDK
- TF-M target configuration for secure/non-secure
  domains
- s/ns board configuration for FRDM-MCXN947
- Platform documentation added
- updates in common hal files to be re-used
  by multiple NXP platforms. This imporoves code
  reusability and standardization across NXP
  MCU platforms

Change-Id: I6ad23001d1e79dda786ff858c686465cd89f6b5b
Signed-off-by: Waqar Tahir <[email protected]>
(cherry picked from commit 90a6a81d6ec12519927dc16c84688d65a88273f3)
@stgloorious
Copy link
Contributor Author

Thanks; rebased and renamed commits.

Copy link
Collaborator

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a Zephyr PR which pulls this in?

@stgloorious
Copy link
Contributor Author

No, the Zephyr integration is not ready to be upstreamed yet. We are working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants