summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--riscv/platform_impl.ml17
-rw-r--r--riscv/platform_main.ml5
2 files changed, 19 insertions, 3 deletions
diff --git a/riscv/platform_impl.ml b/riscv/platform_impl.ml
index 5c238a1e..e593dce9 100644
--- a/riscv/platform_impl.ml
+++ b/riscv/platform_impl.ml
@@ -113,10 +113,23 @@ let dts = spike_dts "rv64imac" cpu_hz insns_per_tick mems;;
let bytes_to_string bytes =
String.init (List.length bytes) (fun i -> Char.chr (List.nth bytes i))
+let dtc_path = ref "/usr/bin/dtc"
+
+let set_dtc path =
+ try let st = Unix.stat path in
+ if st.Unix.st_kind = Unix.S_REG && st.Unix.st_perm != 0
+ then dtc_path := path
+ else ( Printf.eprintf "%s doesn't seem like a valid executable.\n%!" path;
+ exit 1)
+ with Unix.Unix_error (e, _, _) ->
+ ( Printf.eprintf "Error accessing %s: %s\n%!" path (Unix.error_message e);
+ exit 1)
+
let make_dtb dts = (* Call the dtc compiler, assumed to be at /usr/bin/dtc *)
try
+ let cmd = Printf.sprintf "%s -I dts" !dtc_path in
let (cfrom, cto, cerr) =
- Unix.open_process_full "/usr/bin/dtc -I dts" [||]
+ Unix.open_process_full cmd [||]
in (
output_string cto dts;
(* print_endline " sent dts to dtc ..."; *)
@@ -136,7 +149,7 @@ let make_dtb dts = (* Call the dtc compiler, assumed to be at /usr/bin/dtc *)
let emsg = bytes_to_string (accum_bytes cerr []) in
match Unix.close_process_full (cfrom, cto, cerr) with
| Unix.WEXITED 0 -> dtb
- | _ -> (Printf.printf "%s\n" ("Error executing dtc: " ^ emsg);
+ | _ -> (Printf.printf "%s\n%!" ("Error executing dtc: " ^ emsg);
exit 1)
)
with Unix.Unix_error (e, fn, _) ->
diff --git a/riscv/platform_main.ml b/riscv/platform_main.ml
index 4c33e24d..e204daee 100644
--- a/riscv/platform_main.ml
+++ b/riscv/platform_main.ml
@@ -72,7 +72,10 @@ let options = Arg.align ([("-dump-dts",
" enable dirty-bit update during page-table walks");
("-enable-misaligned-access",
Arg.Set P.config_enable_misaligned_access,
- " enable misaligned accesses without M-mode traps")
+ " enable misaligned accesses without M-mode traps");
+ ("-with-dtc",
+ Arg.String PI.set_dtc,
+ " full path to dtc to use")
])
let usage_msg = "RISC-V platform options:"