Skip to content

Commit

Permalink
feat(override flash): support override flash from dut
Browse files Browse the repository at this point in the history
Signed-off-by: jiaxiaoyu <[email protected]>
  • Loading branch information
xyyy1420 committed Dec 25, 2024
1 parent ed34b7a commit 169f88d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion difftest/difftest-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

#define CONFIG_MEMORY_SIZE (16 * 1024 * 1024 * 1024UL)
#define CONFIG_FLASH_BASE 0x10000000UL
#define CONFIG_FLASH_SIZE 0x100000UL
#define CONFIG_FLASH_SIZE 0x10000000UL
#define CONFIG_PMP_NUM 16
#define CONFIG_PMP_MAX_NUM 16
#define CONFIG_PMP_GRAN 12
Expand Down
11 changes: 8 additions & 3 deletions difftest/difftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ void DifftestRef::memcpy_from_dut(reg_t dest, void* src, size_t n) {
}
}

void DifftestRef::flash_cpy_from_dut(const uint8_t* src, size_t n) {
sim->set_mmio(CONFIG_FLASH_BASE, n, src);
p->get_mmu()->flush_icache();
}

void DifftestRef::debug_memcpy_from_dut(reg_t dest, void* src, size_t n) {
#ifdef CONFIG_DIFF_DEBUG_MODE
// addr is absolute physical addr
Expand Down Expand Up @@ -486,7 +491,7 @@ const std::vector<std::pair<reg_t, abstract_device_t*>> DifftestRef::create_devi
std::make_pair(reg_t(DM_BASE_ADDR), new dummy_debug_t),
#endif
#if defined(CONFIG_FLASH_BASE) && defined(CONFIG_FLASH_SIZE)
std::make_pair(reg_t(CONFIG_FLASH_BASE), new rom_device_t(rom_data)),
std::make_pair(reg_t(CONFIG_FLASH_BASE), new custom_rom_device_t(rom_data)),
#endif
};
}
Expand Down Expand Up @@ -638,8 +643,8 @@ void debug_mem_sync(reg_t addr, void* buf, size_t n) {
ref->debug_memcpy_from_dut(addr, buf, n);
}

void difftest_load_flash(void *flash_bin, size_t size) {

void difftest_load_flash(const uint8_t *flash_bin, size_t size) {
ref->flash_cpy_from_dut(flash_bin, size);
}

void difftest_set_mhartid(int mhartid) {
Expand Down
12 changes: 12 additions & 0 deletions difftest/difftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ class DifftestNonRegInterruptPending {
bool lcofi_req = false;
};

class custom_rom_device_t : public rom_device_t {
public:
custom_rom_device_t(std::vector<char> data) : rom_device_t(data) {}
// support full override flash only
bool store(reg_t addr, size_t len, const uint8_t* bytes) override {
auto &rom_data = get_data();
rom_data.assign(bytes, bytes + len);
return true;
}
};

class DifftestRef {
public:
DifftestRef();
Expand All @@ -141,6 +152,7 @@ class DifftestRef {
void get_regs(diff_context_t *ctx);
void set_regs(diff_context_t *ctx, bool on_demand);
void memcpy_from_dut(reg_t dest, void* src, size_t n);
void flash_cpy_from_dut(const uint8_t* src, size_t n);
void debug_memcpy_from_dut(reg_t dest, void* src, size_t n);
int store_commit(uint64_t *addr, uint64_t *data, uint8_t *mask);
void raise_intr(uint64_t no);
Expand Down
4 changes: 4 additions & 0 deletions riscv/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class rom_device_t : public abstract_device_t {
bool load(reg_t addr, size_t len, uint8_t* bytes) override;
bool store(reg_t addr, size_t len, const uint8_t* bytes) override;
const std::vector<char>& contents() { return data; }

// 提供访问器
std::vector<char>& get_data() { return data; }

private:
std::vector<char> data;
};
Expand Down
5 changes: 5 additions & 0 deletions riscv/sim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ bool sim_t::mmio_store(reg_t paddr, size_t len, const uint8_t* bytes)
return bus.store(paddr, len, bytes);
}

bool sim_t::set_mmio(reg_t paddr, size_t len, const uint8_t* bytes)
{
return mmio_store(paddr, len, bytes);
}

void sim_t::set_rom()
{
const int reset_vec_size = 8;
Expand Down
2 changes: 2 additions & 0 deletions riscv/sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class sim_t : public htif_t, public simif_t
public:
#endif
virtual char* addr_to_mem(reg_t paddr) override;
virtual bool set_mmio(reg_t paddr, size_t len, const uint8_t* bytes);

#if defined(DIFFTEST)
private:
#endif
Expand Down

0 comments on commit 169f88d

Please sign in to comment.