diff options
author | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-02-18 11:50:54 +0000 |
---|---|---|
committer | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-02-18 11:53:10 +0000 |
commit | 106e3eba38979e3cbfec333e3badbeebb4da717d (patch) | |
tree | 074cdf3b85d76130cb38bc52e4d41958ce41bd3c | |
parent | ab15a795061c1ecafea765dc46b499d713e87810 (diff) | |
download | spike-106e3eba38979e3cbfec333e3badbeebb4da717d.zip spike-106e3eba38979e3cbfec333e3badbeebb4da717d.tar.gz spike-106e3eba38979e3cbfec333e3badbeebb4da717d.tar.bz2 |
Add simple error checking to DTB parsing code
This catches silly mistakes like accidentally passing a DTS file when
it should have been a DTB.
Now, you get something like this:
$ /opt/spike/latest/bin/spike --dtb=bogus.dtb -l obj.o
Failed to read DTB from `bogus.dtb': FDT_ERR_BADMAGIC.
-rw-r--r-- | riscv/sim.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/riscv/sim.cc b/riscv/sim.cc index 97b3746..2ee05d6 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -6,6 +6,7 @@ #include "remote_bitbang.h" #include "byteorder.h" #include "platform.h" +#include "libfdt.h" #include <fstream> #include <map> #include <iostream> @@ -296,6 +297,18 @@ void sim_t::make_dtb() dts = make_dts(INSNS_PER_RTC_TICK, CPU_HZ, initrd_start, initrd_end, bootargs, 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.empty()) { + 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() |