Browse Source

Inline make_dtb into sim_t constructor

make_dtb is only called here, this simplifies later work
towards refactoring device DTS node generation
pull/1374/head
Jerry Zhao 3 years ago
parent
commit
b9275b7ce2
  1. 64
      riscv/sim.cc
  2. 1
      riscv/sim.h

64
riscv/sim.cc

@ -109,7 +109,35 @@ sim_t::sim_t(const cfg_t *cfg, bool halted,
if (!dtb_enabled) return;
// Load dtb_file if provided, otherwise self-generate a dts/dtb
make_dtb(dtb_file);
if (dtb_file) {
std::ifstream fin(dtb_file, 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 {
std::pair<reg_t, reg_t> initrd_bounds = cfg->initrd_bounds();
dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ,
initrd_bounds.first, initrd_bounds.second,
cfg->bootargs(), cfg->pmpregions, procs, mems);
dtb = dts_compile(dts);
}
int fdt_code = fdt_check_header(dtb.c_str());
if (fdt_code) {
std::cerr << "Failed to read DTB from ";
if (!dtb_file) {
std::cerr << "auto-generated DTS string";
} else {
std::cerr << "`" << dtb_file << "'";
}
std::cerr << ": " << fdt_strerror(fdt_code) << ".\n";
exit(-1);
}
void *fdt = (void *)dtb.c_str();
@ -303,40 +331,6 @@ bool sim_t::mmio_store(reg_t paddr, size_t len, const uint8_t* bytes)
return bus.store(paddr, len, bytes);
}
void sim_t::make_dtb(const char* dtb_file)
{
if (dtb_file) {
std::ifstream fin(dtb_file, 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 {
std::pair<reg_t, reg_t> initrd_bounds = cfg->initrd_bounds();
dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ,
initrd_bounds.first, initrd_bounds.second,
cfg->bootargs(), cfg->pmpregions, procs, mems);
dtb = dts_compile(dts);
}
int fdt_code = fdt_check_header(dtb.c_str());
if (fdt_code) {
std::cerr << "Failed to read DTB from ";
if (!dtb_file) {
std::cerr << "auto-generated DTS string";
} else {
std::cerr << "`" << dtb_file << "'";
}
std::cerr << ": " << fdt_strerror(fdt_code) << ".\n";
exit(-1);
}
}
void sim_t::set_rom()
{
const int reset_vec_size = 8;

1
riscv/sim.h

@ -98,7 +98,6 @@ private:
virtual char* addr_to_mem(reg_t paddr) override;
virtual bool mmio_load(reg_t paddr, size_t len, uint8_t* bytes) override;
virtual bool mmio_store(reg_t paddr, size_t len, const uint8_t* bytes) override;
void make_dtb(const char* dtb_file);
void set_rom();
virtual const char* get_symbol(uint64_t paddr) override;

Loading…
Cancel
Save