diff options
Diffstat (limited to 'riscv')
-rw-r--r-- | riscv/sim.cc | 19 | ||||
-rw-r--r-- | riscv/sim.h | 5 |
2 files changed, 22 insertions, 2 deletions
diff --git a/riscv/sim.cc b/riscv/sim.cc index 0b29720..ac527a8 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -5,6 +5,7 @@ #include "dts.h" #include "remote_bitbang.h" #include "byteorder.h" +#include <fstream> #include <map> #include <iostream> #include <sstream> @@ -211,8 +212,22 @@ void sim_t::make_dtb() std::vector<char> rom((char*)reset_vec, (char*)reset_vec + sizeof(reset_vec)); - dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, initrd_start, initrd_end, procs, mems); - std::string dtb = dts_compile(dts); + std::string dtb; + if (!dtb_file.empty()) { + std::ifstream fin(dtb_file.c_str(), std::ios::binary); + if (!fin.good()) { + std::cerr << "can't find dtb file: " << dtb_file << std::endl; + exit(-1); + } + + std::stringstream strstream; + strstream << fin.rdbuf(); + + dtb = strstream.str(); + } else { + dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, initrd_start, initrd_end, procs, mems); + dtb = dts_compile(dts); + } rom.insert(rom.end(), dtb.begin(), dtb.end()); const int align = 0x1000; diff --git a/riscv/sim.h b/riscv/sim.h index 91aedab..0cf518d 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -49,6 +49,10 @@ public: void set_dtb_enabled(bool value) { this->dtb_enabled = value; } + void set_dtb_file(const char* value) { + if (value) + this->dtb_file = value; + } void set_remote_bitbang(remote_bitbang_t* remote_bitbang) { this->remote_bitbang = remote_bitbang; } @@ -68,6 +72,7 @@ private: reg_t initrd_end; reg_t start_pc; std::string dts; + std::string dtb_file; std::unique_ptr<rom_device_t> boot_rom; std::unique_ptr<clint_t> clint; bus_t bus; |