[PATCH 1/9] clocksource: make available in PBL

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Apr 21 22:26:27 PDT 2025


We currently have some adhoc early_udelay implementations in PBL.
As the clocksource framework is already very lightweight, let's port it
to allow dropping early_udelay in future.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/Makefile | 1 +
 common/clock.c  | 5 ++++-
 include/sched.h | 2 +-
 pbl/Kconfig     | 3 +++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/common/Makefile b/common/Makefile
index 9b67187561bf..e12eef4691fe 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -5,6 +5,7 @@ obj-y				+= memory.o
 obj-y				+= memory_display.o
 pbl-$(CONFIG_PBL_CONSOLE)	+= memory_display.o
 obj-y				+= clock.o
+pbl-$(CONFIG_PBL_CLOCKSOURCE)	+= clock.o
 obj-y				+= console_common.o
 obj-$(CONFIG_OFDEVICE)		+= deep-probe.o
 obj-y				+= startup.o
diff --git a/common/clock.c b/common/clock.c
index b300e5798a16..15e26c67c887 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -34,7 +34,7 @@ static struct clocksource dummy_cs = {
 	.priority = -1,
 };
 
-static struct clocksource *current_clock = &dummy_cs;
+static struct clocksource *current_clock = IN_PROPER ? &dummy_cs : NULL;
 
 static int dummy_csrc_warn(void)
 {
@@ -55,6 +55,9 @@ uint64_t get_time_ns(void)
 	uint64_t cycle_now, cycle_delta;
 	uint64_t ns_offset;
 
+	if (IN_PBL && !cs)
+		panic("No PBL clocksource has been initialized\n");
+
 	/* read clocksource: */
 	cycle_now = cs->read() & cs->mask;
 
diff --git a/include/sched.h b/include/sched.h
index 4dadff20696e..0b5e91f0be44 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -2,7 +2,7 @@
 #ifndef __BAREBOX_SCHED_H_
 #define __BAREBOX_SCHED_H_
 
-#ifdef CONFIG_HAS_SCHED
+#if defined CONFIG_HAS_SCHED && IN_PROPER
 void resched(void);
 #else
 static inline void resched(void)
diff --git a/pbl/Kconfig b/pbl/Kconfig
index 98d71791454b..6e3581829d58 100644
--- a/pbl/Kconfig
+++ b/pbl/Kconfig
@@ -57,6 +57,9 @@ config PBL_VERIFY_PIGGY
 	depends on ARM || MIPS || RISCV
 	bool "Verify barebox proper hash before decompression" if COMPILE_TEST
 
+config PBL_CLOCKSOURCE
+	bool
+
 config BOARD_GENERIC_DT
 	bool
 	select LIBFDT
-- 
2.39.5




More information about the barebox mailing list