Skip to content

Conversation

@stgloorious
Copy link
Contributor

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

cc @jaccoo01

@tomi-font tomi-font changed the base branch from main to zephyr_tf-m_v2.2.2 December 3, 2025 09:02
@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 19 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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(cherry picked from commit 5188b1e)
Follows the same logic as in
ac7219e.

Change-Id: I211cb321d442bac74fc62c966e2330f75ad91271
Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(cherry picked from commit af54602)
Replace the existing implementation which used printf.

Change-Id: Ie3e37eb905583c8793578bc138e6cc11222f378e
Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(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 <nicola.mazzucato@arm.com>
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 <jackson.cooper-driver@arm.com>
(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 <jackson.cooper-driver@arm.com>
(cherry picked from commit 2b9877121c1e84d2ff1d98c1ec9bdca3d1e205b5)
@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.

Now had a look at your PRs. I think we can do with just #157, if the log cherry-picks are for supporting the added platform it makes sense (and is simpler) to have everything in a single PR.

@stgloorious
Copy link
Contributor Author

Fine for me. Closing this in favor of #157

@stgloorious stgloorious closed this Dec 5, 2025
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.

4 participants