diff options
author | Andrew Waterman <andrew@sifive.com> | 2024-08-01 17:26:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-01 17:26:30 -0700 |
commit | 2890ea72125b69eb96bb0458a5bbc00ce26e8872 (patch) | |
tree | 285a22b2f02221ae9db1df5d79cc70db13b0deaf | |
parent | fdd2570fc4d93ebdc07551988fe5ccab519d281c (diff) | |
parent | b9ecc1d4e5b9cc4e4c3e6793516e1809aec76762 (diff) | |
download | riscv-isa-sim-master.zip riscv-isa-sim-master.tar.gz riscv-isa-sim-master.tar.bz2 |
Improve dts <-> dtb API
-rw-r--r-- | riscv/dts.cc | 21 | ||||
-rw-r--r-- | riscv/dts.h | 3 | ||||
-rw-r--r-- | riscv/sim.cc | 4 |
3 files changed, 18 insertions, 10 deletions
diff --git a/riscv/dts.cc b/riscv/dts.cc index 7ca7c4e..9751ffe 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -99,13 +99,10 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, return s.str(); } -std::string dtc_compile(const std::string& dtc_input, const std::string& input_type, const std::string& output_type) +static std::string dtc_compile(const std::string& dtc_input, bool compile) { - if (input_type == output_type) - std::cerr << "Must have differing {in,out}put types for running " DTC << std::endl; - - if (!((input_type == "dts" && output_type == "dtb") || (input_type == "dtb" && output_type == "dts"))) - std::cerr << "Invalid {in,out}put types for running " DTC ": Must convert from 'dts' to 'dtb' (or vice versa)" << std::endl; + const char* input_type = compile ? "dts" : "dtb"; + const char* output_type = compile ? "dtb" : "dts"; int dtc_input_pipe[2]; pid_t dtc_input_pid; @@ -147,7 +144,7 @@ std::string dtc_compile(const std::string& dtc_input, const std::string& input_t close(dtc_input_pipe[1]); close(dtc_output_pipe[0]); close(dtc_output_pipe[1]); - execlp(DTC, DTC, "-O", output_type.c_str(), "-I", input_type.c_str(), (char *)0); + execlp(DTC, DTC, "-O", output_type, "-I", input_type, nullptr); std::cerr << "Failed to run " DTC ": " << strerror(errno) << std::endl; exit(1); } @@ -186,6 +183,16 @@ std::string dtc_compile(const std::string& dtc_input, const std::string& input_t return dtc_output.str(); } +std::string dtb_to_dts(const std::string& dtc_input) +{ + return dtc_compile(dtc_input, false); +} + +std::string dts_to_dtb(const std::string& dtc_input) +{ + return dtc_compile(dtc_input, true); +} + int fdt_get_node_addr_size(const void *fdt, int node, reg_t *addr, unsigned long *size, const char *field) { diff --git a/riscv/dts.h b/riscv/dts.h index 987f269..730dea7 100644 --- a/riscv/dts.h +++ b/riscv/dts.h @@ -11,7 +11,8 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, std::vector<std::pair<reg_t, abstract_mem_t*>> mems, std::string device_nodes); -std::string dtc_compile(const std::string& dtc_input, const std::string& input_type, const std::string& output_type); +std::string dts_to_dtb(const std::string& dtc_input); +std::string dtb_to_dts(const std::string& dtc_input); int fdt_get_node_addr_size(const void *fdt, int node, reg_t *addr, unsigned long *size, const char *field); diff --git a/riscv/sim.cc b/riscv/sim.cc index e9928f5..0e27171 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -133,7 +133,7 @@ sim_t::sim_t(const cfg_t *cfg, bool halted, std::stringstream strstream; strstream << fin.rdbuf(); dtb = strstream.str(); - dts = dtc_compile(dtb, "dtb", "dts"); + dts = dtb_to_dts(dtb); } else { std::pair<reg_t, reg_t> initrd_bounds = cfg->initrd_bounds; std::string device_nodes; @@ -143,7 +143,7 @@ sim_t::sim_t(const cfg_t *cfg, bool halted, device_nodes.append(factory->generate_dts(this, sargs)); } dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, cfg, mems, device_nodes); - dtb = dtc_compile(dts, "dts", "dtb"); + dtb = dts_to_dtb(dts); } int fdt_code = fdt_check_header(dtb.c_str()); |