From 722f185525a65943232b862addd9717252c1dc8a Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 12 Jul 2024 13:19:10 +0200 Subject: [PATCH] Add timer debug patch for OpenSBI --- JOURNAL.md | 9 ++++ lagarto-ox.nix | 7 ++- opensbi-timer-debug.patch | 100 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 opensbi-timer-debug.patch diff --git a/JOURNAL.md b/JOURNAL.md index 42a37b3..a8c1ddd 100644 --- a/JOURNAL.md +++ b/JOURNAL.md @@ -1614,3 +1614,12 @@ different branch, but "control" is never matched there. Still failing, the problem must be somewhere else. Let's try with openpiton configuration instead. + +Doesn't even start the UART: + + GGGGGGGGG + +These G's must be coming from the bootrom. + +So let's go back to the generic platform and place some `printf()` calls to +determine where it is failing. diff --git a/lagarto-ox.nix b/lagarto-ox.nix index 640140e..c9ab49c 100644 --- a/lagarto-ox.nix +++ b/lagarto-ox.nix @@ -310,7 +310,7 @@ }; #NIX_DEBUG=5; makeFlags = [ - "PLATFORM=fpga/openpiton" + "PLATFORM=generic" #"CONFIG_SBI_ECALL_RFENCE=n" #"PLATFORM_RISCV_ISA=rv64imafd" # No compressed instructions #"PLATFORM_RISCV_ISA=rv64g" # No compressed instructions @@ -318,7 +318,10 @@ "FW_PAYLOAD_PATH=${final.uboot}/u-boot-nodtb.bin" "FW_FDT_PATH=${final.ox-dtb}" ]; - #patches = [ ./ox-alveo-platform-plic.patch ]; + patches = [ + ./opensbi-timer-debug.patch + #./ox-alveo-platform-plic.patch + ]; }); # opensbi = prev.opensbi.overrideAttrs (old: { # #NIX_DEBUG=5; diff --git a/opensbi-timer-debug.patch b/opensbi-timer-debug.patch new file mode 100644 index 0000000..93e2df1 --- /dev/null +++ b/opensbi-timer-debug.patch @@ -0,0 +1,100 @@ +diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c +index 7b618de..65e42b0 100644 +--- a/lib/sbi/sbi_timer.c ++++ b/lib/sbi/sbi_timer.c +@@ -183,13 +183,17 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot) + u64 *time_delta; + const struct sbi_platform *plat = sbi_platform_ptr(scratch); + ++ sbi_printf("sbi_timer_init: begins\n"); ++ + if (cold_boot) { + time_delta_off = sbi_scratch_alloc_offset(sizeof(*time_delta)); + if (!time_delta_off) + return SBI_ENOMEM; + +- if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR)) ++ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR)) { ++ sbi_printf("sbi_timer_init: got Zicntr extension\n"); + get_time_val = get_ticks; ++ } + } else { + if (!time_delta_off) + return SBI_ENOMEM; +@@ -198,7 +202,10 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot) + time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off); + *time_delta = 0; + +- return sbi_platform_timer_init(plat, cold_boot); ++ int rc = sbi_platform_timer_init(plat, cold_boot); ++ if (rc) ++ sbi_printf("sbi_platform_timer: sbi_platform_timer_init failed (%d)\n", rc); ++ return rc; + } + + void sbi_timer_exit(struct sbi_scratch *scratch) +diff --git a/lib/utils/timer/fdt_timer.c b/lib/utils/timer/fdt_timer.c +index f468730..db20526 100644 +--- a/lib/utils/timer/fdt_timer.c ++++ b/lib/utils/timer/fdt_timer.c +@@ -7,6 +7,7 @@ + * Anup Patel + */ + ++#include + #include + #include + #include +@@ -39,19 +40,26 @@ static int fdt_timer_cold_init(void) + void *fdt = fdt_get_address(); + + for (pos = 0; pos < fdt_timer_drivers_size; pos++) { ++ sbi_printf("fdt_timer_cold_init: pos = %d\n", pos); + drv = fdt_timer_drivers[pos]; + + noff = -1; + while ((noff = fdt_find_match(fdt, noff, + drv->match_table, &match)) >= 0) { ++ ++ sbi_printf("fdt_timer_cold_init: got match, name = %s\n", match->compatible); + if (!fdt_node_is_enabled(fdt, noff)) + continue; + ++ sbi_printf("fdt_timer_cold_init: enabled\n"); ++ + /* drv->cold_init must not be NULL */ + if (drv->cold_init == NULL) + return SBI_EFAIL; + + rc = drv->cold_init(fdt, noff, match); ++ sbi_printf("fdt_timer_cold_init: drc->cold_init = %d\n", rc); ++ + if (rc == SBI_ENODEV) + continue; + if (rc) +@@ -69,6 +77,7 @@ static int fdt_timer_cold_init(void) + * We can't fail here since systems with Sstc might not provide + * mtimer/clint DT node in the device tree. + */ ++ sbi_printf("fdt_timer_cold_init: returns 0\n"); + return 0; + } + +@@ -78,9 +87,15 @@ int fdt_timer_init(bool cold_boot) + + if (cold_boot) { + rc = fdt_timer_cold_init(); +- if (rc) ++ if (rc) { ++ sbi_printf("fdt_timer_init: fdt_timer_cold_init failed (%d)\n", rc); + return rc; ++ } + } + +- return fdt_timer_warm_init(); ++ rc = fdt_timer_warm_init(); ++ if (rc) ++ sbi_printf("fdt_timer_init: fdt_timer_warm_init failed (%d)\n", rc); ++ ++ return rc; + }