Skip to contentSkip to conversation

arm: armv7: add us timer for bootstage

PATCH In review Patrick Delaunay 2 participants 2 messages Nov 22, 2016 – Dec 12, 2016 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: armv7: add us timer for bootstage

From: Patrick Delaunay <[email protected]>

solve issue when bootstage is used with armV7 generic timer first call of timer_get_boot_us() use the function get_timer() before timer initialization (arch.timer_rate_hz = 0) => div by 0

Commit-notes

When I activate bootstage on ARMV7 architecture with platform using the generic armv7 timer defined in file ./arch/arm/cpu/armv7m/timer.c

I have a issue because gd->arch.timer_rate_hz = 0

For me the get_timer() function should not used before timer_init (which initialize gd->arch.timer_rate_hz) at least for the ARMV7 timer.

But in the init sequence, the first bootstage fucntion is called before timer_init and this function use the timer function.

For me it is a error in the generic init sequence :
mark_bootstage is called before timer_init.

static init_fnc_t init_sequence_f[] = {
....
arch_cpu_init_dm,
mark_bootstage, /* need timer, go after init dm */
...
#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
defined(CONFIG_SPARC)
timer_init, /* initialize timer */
#endif
.......

To solve the issue for all the paltform, we can move timer_init() call just before mark_bootstage() in this array...

It should be ok for ARMV7 but I don't sure for other platform impacted
- the other ARM platform or ARMV7 wich don't use generic timer
- MIPS BLACKFIN NDS32 or SPARC

and I don't sure of impact for other function called (board_early_init_f for example....)

=> This patch solve issue only in timer armv7
get_boot_us() can be called everytime without div by 0 issue (gd->arch.timer_rate_hz is not used)

END

---

 arch/arm/cpu/armv7/arch_timer.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm/cpu/armv7/arch_timer.c +6 -1
index 0588e2b..30915d2 100644
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <asm/io.h>
 #include <div64.h>
+#include <bootstage.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -17,7 +18,6 @@ int timer_init(void)
 	gd->arch.tbu = 0;
 
 	gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ;
-
 	return 0;
 }
 
@@ -39,6 +39,11 @@ ulong get_timer(ulong base)
 	return lldiv(get_ticks(), gd->arch.timer_rate_hz) - base;
 }
 
+ulong timer_get_boot_us(void)
+{
+	return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / (CONFIG_SYS_HZ * 1000));
+}
+
 void __udelay(unsigned long usec)
 {
 	unsigned long long endtime;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 48 lines · Patrick Delaunay

From: Patrick Delaunay <[email protected]>

solve issue when bootstage is used with armV7 generic timer first call of timer_get_boot_us() use the function get_timer() before timer initialization (arch.timer_rate_hz = 0) => div by 0

Commit-notes

When I activate bootstage on ARMV7 architecture with platform using the generic armv7 timer defined in file ./arch/arm/cpu/armv7m/timer.c

I have a issue because gd->arch.timer_rate_hz = 0

For me the get_timer() function should not used before timer_init (which initialize gd->arch.timer_rate_hz) at least for the ARMV7 timer.

But in the init sequence, the first bootstage fucntion is called before timer_init and this function use the timer function.

For me it is a error in the generic init sequence :
mark_bootstage is called before timer_init.

static init_fnc_t init_sequence_f[] = {
....
arch_cpu_init_dm,
mark_bootstage, /* need timer, go after init dm */
...
#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
defined(CONFIG_SPARC)
timer_init, /* initialize timer */
#endif
.......

To solve the issue for all the paltform, we can move timer_init() call just before mark_bootstage() in this array...

It should be ok for ARMV7 but I don't sure for other platform impacted
- the other ARM platform or ARMV7 wich don't use generic timer
- MIPS BLACKFIN NDS32 or SPARC

and I don't sure of impact for other function called (board_early_init_f for example....)

Quoted 8 lines

=> This patch solve issue only in timer armv7
get_boot_us() can be called everytime without div by 0 issue (gd->arch.timer_rate_hz is not used)

END

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161212/388e4cdc/attachment.sig>