diff --git a/riscv/dts.cc b/riscv/dts.cc index 7ca7c4e3fc..48e538247c 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 std::string input_type = compile ? "dts" : "dtb"; + const std::string output_type = compile ? "dtb" : "dts"; int dtc_input_pipe[2]; pid_t dtc_input_pid; @@ -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 987f2698af..730dea7765 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> 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 e9928f5c2a..0e2717110b 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 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());