From de2d551035b73637fa7215cec7ee7b5cd8c506d0 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 18 Dec 2024 10:44:25 +0100 Subject: [PATCH] Start adding infrastructure for reading bitstream --- himbaechel/uarch/gatemate/bitstream.cc | 8 ++++++++ himbaechel/uarch/gatemate/gatemate.cc | 9 +++++++++ himbaechel/uarch/gatemate/gatemate.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/himbaechel/uarch/gatemate/bitstream.cc b/himbaechel/uarch/gatemate/bitstream.cc index a80b643a..1d1ec90c 100644 --- a/himbaechel/uarch/gatemate/bitstream.cc +++ b/himbaechel/uarch/gatemate/bitstream.cc @@ -148,4 +148,12 @@ void GateMateImpl::write_bitstream(const std::string &device, const std::string be.write_bitstream(); } +bool GateMateImpl::read_bitstream(const std::string &device, const std::string &filename) +{ + std::ifstream in(filename); + if (!in) + log_error("failed to open file %s for reading (%s)\n", filename.c_str(), strerror(errno)); + return false; +} + NEXTPNR_NAMESPACE_END diff --git a/himbaechel/uarch/gatemate/gatemate.cc b/himbaechel/uarch/gatemate/gatemate.cc index 356222d6..17661f28 100644 --- a/himbaechel/uarch/gatemate/gatemate.cc +++ b/himbaechel/uarch/gatemate/gatemate.cc @@ -56,6 +56,15 @@ void GateMateImpl::postRoute() } } +void GateMateImpl::setupArchContext() +{ + const ArchArgs &args = ctx->args; + if (args.options.count("read")) { + if (!read_bitstream(args.device, args.options.at("read"))) + log_error("Loading bitstream failed.\n"); + } +} + struct GateMateArch : HimbaechelArch { GateMateArch() : HimbaechelArch("gatemate") {}; diff --git a/himbaechel/uarch/gatemate/gatemate.h b/himbaechel/uarch/gatemate/gatemate.h index 9da903e6..d6c15995 100644 --- a/himbaechel/uarch/gatemate/gatemate.h +++ b/himbaechel/uarch/gatemate/gatemate.h @@ -36,6 +36,7 @@ struct GateMateImpl : HimbaechelAPI void init_database(Arch *arch) override; void init(Context *ctx) override; + void setupArchContext() override; void pack() override; @@ -46,6 +47,8 @@ struct GateMateImpl : HimbaechelAPI void drawBel(std::vector &g, GraphicElement::style_t style, IdString bel_type, Loc loc) override; void write_bitstream(const std::string &device, const std::string &filename); + bool read_bitstream(const std::string &device, const std::string &filename); + void parse_ccf(const std::string &filename); };