]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
generic timer safeguard
authorVladimir Serbinenko <phcoder@gmail.com>
Sat, 20 Feb 2016 08:12:02 +0000 (09:12 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Sat, 20 Feb 2016 08:12:02 +0000 (09:12 +0100)
grub-core/kern/arm/coreboot/coreboot.S
grub-core/kern/arm/coreboot/init.c

index b056a2cbf04c60328e4967ea3dacccf6c236a30f..a1104526c154bd5a9dfd9e3680d8bb787c1088ef 100644 (file)
        .thumb
 #endif
 
+FUNCTION(grub_arm_pfr1)
+       mrc p15, 0, r0, c0, c1, 1
+       bx      lr
+
 FUNCTION(grub_armv7_get_timer_value)
        isb
        mrrc p15, 1, r0, r1, c14
index f65c36041d86d83858196a9ed9db1845421d0973..eb5068c0130c48eba20da8a166283e7cad525920 100644 (file)
@@ -42,6 +42,9 @@ grub_armv7_get_timer_value(void);
 grub_uint32_t
 grub_armv7_get_timer_frequency(void);
 
+grub_uint32_t
+grub_arm_pfr1(void);
+
 void  __attribute__ ((noreturn))
 grub_exit (void)
 {
@@ -93,6 +96,18 @@ get_time_ms (void)
   return grub_divmod64 (grub_armv7_get_timer_value(), timer_frequency_in_khz, 0);
 }
 
+static int
+try_generic_timer (void)
+{
+  if (((grub_arm_pfr1 () >> 16) & 0xf) != 1)
+    return 0;
+  timer_frequency_in_khz = grub_armv7_get_timer_frequency() / 1000;
+  if (timer_frequency_in_khz == 0)
+    return 0;
+  grub_install_get_time_ms (get_time_ms);
+  return 1;
+}
+
 void
 grub_machine_init (void)
 {
@@ -109,10 +124,8 @@ grub_machine_init (void)
   grub_font_init ();
   grub_gfxterm_init ();
 
-  timer_frequency_in_khz = grub_armv7_get_timer_frequency() / 1000;
-  if (timer_frequency_in_khz == 0)
+  if (!try_generic_timer ())
     grub_fatal ("No timer found");
-  grub_install_get_time_ms (get_time_ms);
 }
 
 void