Skip to content

Conversation

kaspar030
Copy link
Contributor

Contribution description

Currently, mulle has an extra call to xtimer_init() in its board_init(), as the following nvram init used by a boot counter needs it.
This does not work as is when xtimer is not needed / wanted. E.g., #11874 breaks due to this.

This PR moves the nvram initialization and boot counter stuff into its own function, which is then called in auto_init right after xtimer initialization. The mulle specific xtimer_init() call is removed.

I'm not happy to see board specific stuff in auto init, but more unhappy to have xtimer_init() called in board_init()...

Could we maybe just remove the boot counter and nvram init?

Testing procedure

  • flash on mulle, maybe ensure boot counter is still updated

Issues/PRs references

#11874

@kaspar030 kaspar030 added Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: boards Area: Board ports labels Jan 8, 2020
@@ -115,6 +115,10 @@ void auto_init(void)
DEBUG("Auto init xtimer module.\n");
xtimer_init();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not instead add a pseudomodulextimer_autonit and have:

DEFAULT_MODULE+=xtimer_autoinit

DISABLE_MODULE+=xtimer_autoinit

Copy link
Contributor

Choose a reason for hiding this comment

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

The init in the boardfile could be kept.

Copy link
Contributor

Choose a reason for hiding this comment

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

And an ifdef in sys/auto_init/auto_init.c around ximter_init

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I'd have to do the same thing with ztimer, and also guard that, and also add another pseudomodule. "ztimer" is a meta module pulling in ztimer_core and the ztimer auto init...

Maybe we should just replace the use of xtimer in nvram_spi. It is only used for "xtimer_spin(_ticks_to_usec(1))", which could be replaced with a simple spin loop.

Or just remove the boot counter. Or does mulle need that?

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 should just replace the use of xtimer in nvram_spi. It is only used for "xtimer_spin(_ticks_to_usec(1))", which could be replaced with a simple spin loop.

I think that would be the best fix, it would remove xtimer/ztimer as a dependency.

Or just remove the boot counter. Or does mulle need that?

I don't have a mulle, but there is one in Berlin.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I'd have to do the same thing with ztimer, and also guard that, and also add another pseudomodule. "ztimer" is a meta module pulling in ztimer_core and the ztimer auto init...

Lets do it with all auto-init functions then? I would find it very useful to be able to disable auto_init only for specific modules. No extra guard would be needed, only adding AUTO_INIT to the existing one.

diff --git a/makefiles/defaultmodules.inc.mk b/makefiles/defaultmodules.inc.mk
index 9d8331407c..973983ca8b 100644
--- a/makefiles/defaultmodules.inc.mk
+++ b/makefiles/defaultmodules.inc.mk
@@ -1,3 +1,5 @@
 DEFAULT_MODULE += board cpu core core_msg sys
 
 DEFAULT_MODULE += auto_init
+
+DEFAULT_MODULE += xtimer_auto_init
diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk
index e7f747a3ef..7f3efa5be3 100644
--- a/makefiles/pseudomodules.inc.mk
+++ b/makefiles/pseudomodules.inc.mk
@@ -197,4 +197,7 @@ PSEUDOMODULES += crypto_aes_precalculated
 # This pseudomodule causes a loop in AES to be unrolled (more flash, less CPU)
 PSEUDOMODULES += crypto_aes_unroll
 
+# All auto_init modules are pseudomodules
+PSEUDOMODULES += %_auto_init
+
 # Packages may also add modules to PSEUDOMODULES in their `Makefile.include`.
diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c
index b72b856875..6a69f2a357 100644
--- a/sys/auto_init/auto_init.c
+++ b/sys/auto_init/auto_init.c
@@ -24,7 +24,8 @@
 #include "diskio.h"
 #endif
 
-#ifdef MODULE_XTIMER
+#ifdef MODULE_XTIMER_AUTO_INIT
+#error
 #include "xtimer.h"
 #endif
 
@@ -111,7 +112,7 @@ void auto_init(void)
     void auto_init_random(void);
     auto_init_random();
 #endif
-#ifdef MODULE_XTIMER
+#ifdef MODULE_XTIMER_AUTO_INIT
     DEBUG("Auto init xtimer module.\n");
     xtimer_init();
 #endif

That being said removing the xtimer dependency is still the better fix IMO. This wold just be a nice feature :)

@basilfx
Copy link
Member

basilfx commented Jan 8, 2020

Can't we have something like a board_auto_init(), and move it over there?

The Silicon Labs SLTB001a does something similar (with a tuned while-loop), and I currently am writing a CPU-specific driver that I want to auto-init for SAUL (maybe cpu_auto_init() as well :-P), but not in the global auto-init.

@kaspar030
Copy link
Contributor Author

Can't we have something like a board_auto_init()?

I had that first (my name was 'board_init_late()`), but didn't know where to put it. First thing in auto-init doesn't make sense for this use case, it needs to be after xtimer. At the end seemed late. So I just went with a special case for mulle...

@fjmolinas
Copy link
Contributor

I had that first (my name was 'board_init_late()`), but didn't know where to put it. First thing in auto-init doesn't make sense for this use case, it needs to be after xtimer. At the end seemed late. So I just went with a special case for mulle...

Yes I think having a board_init that comes after all the auto_init stuff would be cool. But in that case It would be better for it to be generic, allowing to register init functions to be called after auto_init, doesn't need to be BOARD related.

@fjmolinas
Copy link
Contributor

This does not work as is when xtimer is not needed / wanted. E.g., #11874 breaks due to this

Thinking back on this, doesn't this mean you do not want xtimer at all? Why does this fix your issue, you still have xtimer? I think I'm missing something.

@kaspar030
Copy link
Contributor Author

Thinking back on this, doesn't this mean you do not want xtimer at all? Why does this fix your issue, you still have xtimer? I think I'm missing something.

This PR moves the xtimer dependent nvram initialization to after xtimer's initialization in auto_init, dropping the need for xtimer_init() in the board_init().

In the ztimer PR, if the xtimer module is used, ztimer provides the xtimer API using a wrapper, but there is no xtimer_init(), thus mulle fails to compile.

I could wrap ztimer_init() in xtimer_init() and keep mulle's early init, but that requires other hacks, as ztimer's init is not idempotent. (not sure xtimer still is after #9530).

TL;DR mulle's early xtimer_init() is a weird special case that would need more weird special handling with ztimer.

@fjmolinas
Copy link
Contributor

Can you use #13089 for this?

@stale
Copy link

stale bot commented Aug 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 15, 2020
@stale stale bot closed this Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants