Skip to content

Conversation

@giansta
Copy link
Contributor

@giansta giansta commented Jan 6, 2023

  • Different initialization modes of Control Block
  • Safer INIT() like in SystemView V352a
  • Made _aTerminalId const like in SystemView V352a

Fixes #53544.

@giansta
Copy link
Contributor Author

giansta commented Jan 6, 2023

Expected to fix Issue #53544 with PR #53569 in Zephyr repo

#endif
#endif

#ifndef SEGGER_RTT_MEMCMP
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this a new segger version or your modifications?
I'm afraid that those changes may get lost if someone updates with new version of segger_rtt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's my modifications. I was assuming that Segger people follow this repo and approve these changes so that they become they also take them.
If not, what do you suggest? Contact them through their official website?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I look in previous commits, they don't seem to be done by Segger, like my one. Are there some additional rules to coordinate with Segger?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how to push it to segger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe @sigvartmh or @carlescufi can help?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Segger is not part of the zephyrproject-rtos Git-Repo.
However, we will review the changes and extend the official RTT sources if we
come to the conclusion that it is a good addition to the current RTT state.
I will keep you posted.

I got this reply after opening a ticket in Segger support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After opening a ticket in support.segger.com, they proposed the update V7.86h that gives equivalent changes and improved initialization. I tried to leave the SEGGER_RTT.c untouched and follow their suggestion to not call at all SEGGER_RTT_Init() in the chained application, but, even if working, I saw that the APIs using use INIT() aren't used in Zephyr log backend. So I added a change only in SEGGER_RTT_Init(), using the configuration I'm aware of that distinguish the cases when we want to to a forced init of CB or just check if it's already done.


#ifndef SEGGER_RTT_MEMSET
#ifdef MEMSET
#define SEGGER_RTT_MEMSET(pDest, FillChar, NumBytes) MEMCPY((pDest), (FillChar), (NumBytes))
Copy link
Collaborator

Choose a reason for hiding this comment

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

copy paste error. MEMCPY -> MEMSET

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for spotting this, fixed.

#endif
#endif

#ifndef SEGGER_RTT_MEMCMP
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how to push it to segger.

@giansta giansta force-pushed the fix/rtt-cb-common-addr branch from 71e53e6 to 5c21108 Compare March 27, 2023 14:09
@giansta giansta force-pushed the fix/rtt-cb-common-addr branch from 5c21108 to 76a9690 Compare April 14, 2023 13:27
@giansta giansta changed the title Zero-init RTT control block fields if not in BSS, don't init it twice Zero-init RTT control block if not in BSS, don't init it twice Apr 14, 2023
@MarcianoPreciado
Copy link

Can we get this reviewed? This is causing me issues also

@carlescufi
Copy link
Member

@sigvartmh please review this as part of this change
@giansta please rebase since we've updated to RTT 3.40

* Segger code using _DoInit() is used. For applications started by
* bootloader, Segger recommends not calling this function, as all the
* recommended APIs use INIT(). Unfortunately Zephyr log backend uses
* SEGGER_RTT_WriteSkipNoLock() that doesn't call INT(), so we need
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: INIT

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could add a dedicated Kconfig option to let user decide if Zephyr application should actually force overwrite of the RTT structures during initialization. The current approach cannot support e.g. other bootloaders.
That would also allow to preserve RTT content during e.g. software reboot that does not clear RAM content.

Copy link
Contributor

@MarekPieta MarekPieta May 23, 2023

Choose a reason for hiding this comment

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

I also wonder if it wouldn't be reasonable to check whole acID right before initialization (instead of checking just the first byte) to ensure no false positives in case RAM content is not zero-initialized (with current implementation chance of false positive when checking if structure is initialized is quite high - ~1/255).
Actually after we improve the check, we may event consider to always call INIT here

Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going to rely on bootloader to initialize the RTT structures, we need to ensure backwards compatibility of the initialization operation (many embedded applications rely on immutable bootloader that cannot be updated once flashed).

Copy link
Contributor Author

@giansta giansta Jun 9, 2023

Choose a reason for hiding this comment

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

Thanks for your suggestions. Unfortunately I was too busy and I'll be out now for a couple of weeks, but afterwards I'll try to follow them.
The Kconfig option is a good idea, I was not very satisfied with my #ifdefs that are less general. I just have to figure out where such a Kconfig can be placed.
I also agree on the whole acID check, the INIT() macro can be used like it is only for other functions than SEGGER_RTT_Init(). I tried not to touch the SEGGER module, then trying with minimal change, but this is indeed reasonable.
I'll even rebase to RTT 3.40.

Copy link
Contributor Author

@giansta giansta Aug 29, 2023

Choose a reason for hiding this comment

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

With latest release I tried to take account of all above suggestions:

  • Rebased to SystemView V340
  • Managed dedicated CONFIG_SEGGER_RTT_INIT_MODE to have different init behaviours

The second change gives more flexibility: application level configs can force initialization of control block without condition or have a complete or partial check on acID to have a contitional init. Yet this requires some more changes in Segger code.

The SystemView V340 code misses some minor changes (safer INIT(), const _aTerminalId) tht are provided by latest SystemView V352a: I've added them, as in previous version.

The CONFIG_SEGGER_RTT_INIT_MODE is defined in PR #53569 in Zephyr repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for all your changes looks good :) I've done similar modifications but haven't pushed changes to Zephyr due to having it interop with other parts of downstream Nordic Fork, which I couldn't figure out how to handle in a nice way. However having this upstream would definitely be a good addition.

@giansta giansta force-pushed the fix/rtt-cb-common-addr branch from fc79836 to 7194d9b Compare August 29, 2023 22:14
@giansta giansta changed the title Zero-init RTT control block if not in BSS, don't init it twice Segger RTT: support CONFIG_SEGGER_RTT_INIT_MODE and optimizations Aug 29, 2023
@giansta giansta force-pushed the fix/rtt-cb-common-addr branch from 44e7b52 to 0a02f8b Compare April 17, 2024 10:27
Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

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

I generally think this looks good, but it could benefit from either a more elaborate Git commit message describing the changes in detail, or more code comments - or both.

@giansta giansta force-pushed the fix/rtt-cb-common-addr branch from 0a02f8b to 0ff9539 Compare April 26, 2024 10:56
@giansta
Copy link
Contributor Author

giansta commented Apr 26, 2024

I generally think this looks good, but it could benefit from either a more elaborate Git commit message describing the changes in detail, or more code comments - or both.

I tried to have the commit messages clearer.
With regard to comments, I believe that most code changes are taken from Segger code and they should be quite clear.
The key point is in SEGGER_RTT_Init(), where I wrote a comment explaining the reason of changes.
If you feel that something else could be enhanced, please let me know.

volatile SEGGER_RTT_CB* p;
p = (volatile SEGGER_RTT_CB*)((char*)&_SEGGER_RTT + SEGGER_RTT_UNCACHED_OFF);
unsigned i;
bool DoInit = false;
Copy link
Member

@cfriedt cfriedt Jul 25, 2024

Choose a reason for hiding this comment

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

I needed to include <stdbool.h> at the top of this file to avoid this error when building against v3.6-branch

SEGGER/SEGGER_RTT.c:1906:3: error: unknown type name 'bool'
 1906 |   bool DoInit = false;

Copy link
Contributor Author

@giansta giansta Aug 12, 2024

Choose a reason for hiding this comment

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

Thanks @cfriedt, for signalling this issue. It probably depends on the toolchain, as I didn't have it.
Yet, looking at Seger code, they seem not to use boolean, so I changed it to int without using false/true values.

RTT__DMB(); // Force order of memory accesses for cores that may perform out-of-order memory accesses
for (i = 0; i < sizeof(_aInitStr) - 1; ++i) {
if (p->acID[i] != _aInitStr[sizeof(_aInitStr) - 2 - i]) { // Skip terminating \0 at the end of the array
DoInit = true;
Copy link
Member

Choose a reason for hiding this comment

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

Similar error / need for <stdbool.h>

SEGGER/SEGGER_RTT.c:1913:16: error: 'true' undeclared (first use in this function)
 1913 |       DoInit = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

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

LGTM

@brycewilkins
Copy link
Contributor

@giansta I tried to get the Zephyr repo west.yml updated to have this pull request merged (zephyrproject-rtos/zephyr#81425), but this PR needs to be rebased. Could you do that? Would love to have this in!

Support Zephyr "RTT Initialization mode" config choice, allowing
Control Block initialization to be retained from another program
(e.g. bootloader).
It includes conditional CB init with full check on Control Block ID or
partial one that checks only the first byte, yet improving its logic.
Minor optimizations with static const added.

Signed-off-by: Giancarlo Stasi <[email protected]>
Allow to define the name of custom RTT section both when it's configured
to be placed at RAM start and when its address is defined by a memory
region in DTS.

Signed-off-by: Giancarlo Stasi <[email protected]>
@giansta giansta force-pushed the fix/rtt-cb-common-addr branch from fe8fb43 to 4cb1239 Compare November 15, 2024 21:04
@cfriedt
Copy link
Member

cfriedt commented Nov 15, 2024

We should really have a rule that source code should be checked in with UNIX line endings. The sources in this repository are somewhat difficult to work with because they have DOS line endings.

@brycewilkins
Copy link
Contributor

We should really have a rule that source code should be checked in with UNIX line endings. The sources in this repository are somewhat difficult to work with because they have DOS line endings.

Agree; let's address that in a new PR; I can do it.

@brycewilkins
Copy link
Contributor

brycewilkins commented Nov 15, 2024

@giansta Thanks for rebase!

@cfriedt @nordic-krch @nordicjm Could this be reviewed so we can get it over the line?

Copy link
Contributor

@brycewilkins brycewilkins left a comment

Choose a reason for hiding this comment

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

lgtm! This will be great to have merged!

@cfriedt cfriedt merged commit 1a607e8 into zephyrproject-rtos:master Nov 18, 2024
@brycewilkins brycewilkins mentioned this pull request Nov 29, 2024
2 tasks
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.

9 participants