From 444606c79993f4b7c44eafc398c0165c6233e649 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 25 Jul 2023 16:10:27 -0300 Subject: [PATCH] refactor!: rename ROM to DTB --- lib/machine-emulator-defines | 2 +- src/Makefile | 6 +- src/cartesi-machine-tests.lua | 4 +- src/cartesi-machine.lua | 61 +++++++------ src/clua-machine-util.cpp | 18 ++-- src/clua-machine-util.h | 4 +- src/{rom.cpp => dtb.cpp} | 32 ++----- src/{rom.h => dtb.h} | 20 ++--- src/i-virtual-machine.h | 4 +- src/interpret.cpp | 2 +- src/json-util.cpp | 12 +-- src/json-util.h | 10 +-- src/jsonrpc-discover.json | 8 +- src/machine-c-api.cpp | 42 ++++----- src/machine-c-api.h | 8 +- src/machine-config.cpp | 2 +- src/machine-config.h | 8 +- src/machine.cpp | 38 ++++----- src/machine.h | 2 +- src/pma-constants.h | 4 +- src/protobuf-util.cpp | 20 ++--- src/riscv-constants.h | 2 +- src/test-machine-c-api.cpp | 108 ++++++++---------------- src/test-utils.h | 34 ++++---- src/tests/log-with-mtime-transition.lua | 2 +- src/tests/machine-bind.lua | 14 +-- src/tests/machine-test.lua | 17 ++-- src/tests/util.lua | 28 +++--- tools/benchmarks/run-benchmarks.lua | 2 +- tools/gdb/gdb.md | 4 +- 30 files changed, 228 insertions(+), 290 deletions(-) rename src/{rom.cpp => dtb.cpp} (87%) rename src/{rom.h => dtb.h} (60%) diff --git a/lib/machine-emulator-defines b/lib/machine-emulator-defines index 4f164a788..250330354 160000 --- a/lib/machine-emulator-defines +++ b/lib/machine-emulator-defines @@ -1 +1 @@ -Subproject commit 4f164a788ff34b43c6c070fdc14204cd69110440 +Subproject commit 2503303544a146997d9a00e8e32df99af0e06884 diff --git a/src/Makefile b/src/Makefile index 2099014db..37507a8fa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -303,7 +303,7 @@ CARTESI_OBJS:= \ pma-driver.o \ clint.o \ clint-factory.o \ - rom.o \ + dtb.o \ tty.o \ htif.o \ htif-factory.o \ @@ -559,7 +559,7 @@ REMOTE_CARTESI_MACHINE_OBJS:= \ pma-driver.o \ clint.o \ clint-factory.o \ - rom.o \ + dtb.o \ tty.o \ htif.o \ htif-factory.o \ @@ -588,7 +588,7 @@ JSONRPC_REMOTE_CARTESI_MACHINE_OBJS:= \ pma-driver.o \ clint.o \ clint-factory.o \ - rom.o \ + dtb.o \ tty.o \ htif.o \ htif-factory.o \ diff --git a/src/cartesi-machine-tests.lua b/src/cartesi-machine-tests.lua index 685507ec8..08ef718e7 100755 --- a/src/cartesi-machine-tests.lua +++ b/src/cartesi-machine-tests.lua @@ -668,7 +668,7 @@ local function print_machine(test_name, expected_cycles) "./cartesi-machine.lua \ --ram-length=32Mi\ --ram-image='%s'\ - --no-rom-bootargs\ + --no-dtb-bootargs\ --max-mcycle=%d ", test_path .. "/" .. test_name, 2 * expected_cycles @@ -679,7 +679,7 @@ local function print_machine(test_name, expected_cycles) "./cartesi-machine.lua \ --ram-length=32Mi\ --ram-image='%s'\ - --no-rom-bootargs\ + --no-dtb-bootargs\ --uarch-ram-length=%d\ --uarch-ram-image=%s\ --max-mcycle=%d ", diff --git a/src/cartesi-machine.lua b/src/cartesi-machine.lua index e5e130c76..d541c1604 100755 --- a/src/cartesi-machine.lua +++ b/src/cartesi-machine.lua @@ -75,13 +75,13 @@ where options are: --ram-length= set RAM length. - --rom-image= - name of file containing ROM image (default: auto generated flattened device tree). + --dtb-image= + name of file containing DTB image (default: auto generated flattened device tree). - --no-rom-bootargs + --no-bootargs clear default bootargs. - --append-rom-bootargs= + --append-bootargs= append to bootargs. --no-root-flash-drive @@ -359,7 +359,6 @@ where options are: elf (optional) the binary elf file with symbols and debugging information to be debugged, such as: - vmlinux (for kernel debugging) - - ROM elf (for debugging the ROM) - BBL elf (for debugging the BBL boot loader) - a test elf (for debugging tests) @@ -428,10 +427,11 @@ local flash_length = {} local memory_range_replace = {} local ram_image_filename = images_path .. "linux.bin" local ram_length = 64 << 20 -local rom_image_filename = nil -local rom_bootargs = "console=hvc0 rootfstype=ext2 root=/dev/pmem0 rw quiet \z +local dtb_image_filename = nil +local bootargs = "console=hvc0 rootfstype=ext2 root=/dev/pmem0 rw quiet \z swiotlb=noforce random.trust_bootloader=on" local init_splash = true +local append_bootargs = "" local append_init = "" local append_entrypoint = "" local rollup @@ -441,7 +441,6 @@ local rollup_inspect local concurrency_update_merkle_tree = 0 local skip_root_hash_check = false local skip_version_check = false -local append_rom_bootargs local htif_no_console_putchar = false local htif_console_getchar = false local htif_yield_automatic = false @@ -537,7 +536,7 @@ local options = { local ok, stdlib = pcall(require, "posix.stdlib") if ok and stdlib then -- use realpath to get images real filenames, - -- tools could use this information to detect rom/linux/rootfs versions + -- tools could use this information to detect linux/rootfs versions local ram_image = stdlib.realpath(images_path .. "linux.bin") local rootfs_image = stdlib.realpath(images_path .. "rootfs.ext2") if ram_image then print(string.format(' "default_ram_image": "%s",', ram_image)) end @@ -553,26 +552,26 @@ local options = { end, }, { - "^%-%-rom%-image%=(.*)$", + "^%-%-dtb%-image%=(.*)$", function(o) if not o or #o < 1 then return false end - rom_image_filename = o + dtb_image_filename = o return true end, }, { - "^%-%-no%-rom%-bootargs$", + "^%-%-no%-bootargs$", function(all) if not all then return false end - rom_bootargs = "" + bootargs = "" return true end, }, { - "^%-%-append%-rom%-bootargs%=(.*)$", + "^%-%-append%-bootargs%=(.*)$", function(o) if not o or #o < 1 then return false end - append_rom_bootargs = o + append_bootargs = o return true end, }, @@ -866,7 +865,7 @@ local options = { flash_length.root = nil flash_shared.root = nil table.remove(flash_label_order, 1) - rom_bootargs = "console=hvc0" + bootargs = "console=hvc0" return true end, }, @@ -1250,12 +1249,12 @@ local function store_machine_config(config, output) output(" image_filename = %q,", ram.image_filename or def.ram.image_filename) comment_default(ram.image_filename, def.ram.image_filename) output(" },\n") - local rom = config.rom or {} - output(" rom = {\n") - output(" image_filename = %q,", rom.image_filename or def.rom.image_filename) - comment_default(rom.image_filename, def.rom.image_filename) - output(" bootargs = %q,", rom.bootargs or def.rom.bootargs) - comment_default(rom.bootargs, def.rom.bootargs) + local dtb = config.dtb or {} + output(" dtb = {\n") + output(" image_filename = %q,", dtb.image_filename or def.dtb.image_filename) + comment_default(dtb.image_filename, def.dtb.image_filename) + output(" bootargs = %q,", dtb.bootargs or def.dtb.bootargs) + comment_default(dtb.bootargs, def.dtb.bootargs) output(" },\n") local tlb = config.tlb or {} output(" tlb = {\n") @@ -1421,9 +1420,9 @@ else marchid = -1, mvendorid = -1, }, - rom = { - image_filename = rom_image_filename, - bootargs = rom_bootargs, + dtb = { + image_filename = dtb_image_filename, + bootargs = bootargs, init = "", entrypoint = "", }, @@ -1443,7 +1442,7 @@ else -- show splash on init if init_splash then - config.rom.init = config.rom.init + config.dtb.init = config.dtb.init .. ([[ echo " . @@ -1468,20 +1467,20 @@ echo " length = flash_length[label] or -1, } if label ~= "root" and flash_mount[label] then - config.rom.init = config.rom.init + config.dtb.init = config.dtb.init .. ([[ busybox mkdir "/mnt/LABEL" && busybox mount "/dev/DEVNAME" "/mnt/LABEL" ]]):gsub("LABEL", label):gsub("DEVNAME", devname) end end - if #append_init > 0 then config.rom.init = config.rom.init .. append_init end + if #append_init > 0 then config.dtb.init = config.dtb.init .. append_init end - if append_rom_bootargs then config.rom.bootargs = config.rom.bootargs .. " " .. append_rom_bootargs end + if #append_bootargs > 0 then config.dtb.bootargs = config.dtb.bootargs .. " " .. append_bootargs end - if #append_entrypoint > 0 then config.rom.entrypoint = config.rom.entrypoint .. append_entrypoint end + if #append_entrypoint > 0 then config.dtb.entrypoint = config.dtb.entrypoint .. append_entrypoint end - if #exec_arguments > 0 then config.rom.entrypoint = config.rom.entrypoint .. table.concat(exec_arguments, " ") end + if #exec_arguments > 0 then config.dtb.entrypoint = config.dtb.entrypoint .. table.concat(exec_arguments, " ") end if load_config then local env = {} diff --git a/src/clua-machine-util.cpp b/src/clua-machine-util.cpp index c9c94dc3f..cf85eab71 100644 --- a/src/clua-machine-util.cpp +++ b/src/clua-machine-util.cpp @@ -768,10 +768,10 @@ static void push_cm_ram_config(lua_State *L, const cm_ram_config *r) { } } -/// \brief Pushes a cm_rom_config to the Lua stack +/// \brief Pushes a cm_dtb_config to the Lua stack /// \param L Lua state. /// \param r Ram configuration to be pushed. -static void push_cm_rom_config(lua_State *L, const cm_rom_config *r) { +static void push_cm_dtb_config(lua_State *L, const cm_dtb_config *r) { lua_newtable(L); if (r->bootargs != nullptr) { clua_setstringfield(L, r->bootargs, "bootargs", -1); @@ -909,8 +909,8 @@ void clua_push_cm_machine_config(lua_State *L, const cm_machine_config *c) { lua_setfield(L, -2, "flash_drive"); // config push_cm_ram_config(L, &c->ram); // config ram lua_setfield(L, -2, "ram"); // config - push_cm_rom_config(L, &c->rom); // config rom - lua_setfield(L, -2, "rom"); // config + push_cm_dtb_config(L, &c->dtb); // config dtb + lua_setfield(L, -2, "dtb"); // config push_cm_uarch_config(L, &c->uarch); // uarch lua_setfield(L, -2, "uarch"); // config if (c->rollup.has_value) { @@ -946,12 +946,12 @@ static void check_cm_ram_config(lua_State *L, int tabidx, cm_ram_config *r) { lua_pop(L, 1); } -/// \brief Loads ROM config from Lua to cm_rom_config +/// \brief Loads DTB config from Lua to cm_dtb_config /// \param L Lua state /// \param tabidx Config stack index -/// \param r C api ROM config structure to receive results -static void check_cm_rom_config(lua_State *L, int tabidx, cm_rom_config *r) { - if (!opt_table_field(L, tabidx, "rom")) { +/// \param r C api DTB config structure to receive results +static void check_cm_dtb_config(lua_State *L, int tabidx, cm_dtb_config *r) { + if (!opt_table_field(L, tabidx, "dtb")) { return; } r->image_filename = opt_copy_string_field(L, -1, "image_filename"); @@ -1212,7 +1212,7 @@ cm_machine_config *clua_check_cm_machine_config(lua_State *L, int tabidx, int ct config->processor = get_default_processor_config(L); check_cm_processor_config(L, tabidx, &config->processor, &config->processor); check_cm_ram_config(L, tabidx, &config->ram); - check_cm_rom_config(L, tabidx, &config->rom); + check_cm_dtb_config(L, tabidx, &config->dtb); check_cm_tlb_config(L, tabidx, &config->tlb); check_cm_htif_config(L, tabidx, &config->htif); check_cm_clint_config(L, tabidx, &config->clint); diff --git a/src/clua-machine-util.h b/src/clua-machine-util.h index ee122b17b..218ac12b1 100644 --- a/src/clua-machine-util.h +++ b/src/clua-machine-util.h @@ -76,9 +76,9 @@ void cm_delete(cm_machine_runtime_config *ptr); template <> void cm_delete(cm_ram_config *p); -/// \brief Deleter for C api rom config +/// \brief Deleter for C api dtb config template <> -void cm_delete(cm_rom_config *p); +void cm_delete(cm_dtb_config *p); /// \brief Deleter for C api access log template <> diff --git a/src/rom.cpp b/src/dtb.cpp similarity index 87% rename from src/rom.cpp rename to src/dtb.cpp index 0855bf3a5..5f6a0193f 100644 --- a/src/rom.cpp +++ b/src/dtb.cpp @@ -20,14 +20,14 @@ #include /// \file -/// \brief Bootstrap and device tree in ROM +/// \brief Device Tree Blob +#include "dtb.h" #include "fdt-builder.h" #include "machine-c-version.h" #include "pma-constants.h" #include "riscv-constants.h" #include "rng-seed.h" -#include "rom.h" #include "rtc.h" namespace cartesi { @@ -43,29 +43,15 @@ static std::string misa_to_isa_string(uint64_t misa) { return ss.str(); } -void rom_init(const machine_config &c, unsigned char *rom_start, uint64_t length) { - if (length < PMA_ROM_EXTRASPACE_LENGTH_DEF) { - throw std::runtime_error{"not enough space on ROM for bootargs"}; - } - - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - char *bootargs = reinterpret_cast(rom_start + length - PMA_ROM_EXTRASPACE_LENGTH_DEF); - - if (!c.rom.bootargs.empty()) { - strncpy(bootargs, c.rom.bootargs.c_str(), PMA_BOOTARGS_LENGTH_DEF); - bootargs[PMA_BOOTARGS_LENGTH_DEF - 1] = '\0'; - } -} - -void rom_init_device_tree(const machine_config &c, unsigned char *rom_start, uint64_t length) { +void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_length) { using namespace std::string_literals; constexpr uint32_t INTC_PHANDLE = 1; constexpr uint32_t X_HOST = 13; constexpr uint32_t BOOTARGS_MAX_LEN = 4096; // Check if bootargs length is not too large - if (c.rom.bootargs.length() > BOOTARGS_MAX_LEN) { - throw std::runtime_error{"ROM bootargs is is above maximum length of 4096"}; + if (c.dtb.bootargs.length() > BOOTARGS_MAX_LEN) { + throw std::runtime_error{"DTB bootargs is is above maximum length of 4096"}; } FDTBuilder fdt; @@ -80,7 +66,7 @@ void rom_init_device_tree(const machine_config &c, unsigned char *rom_start, uin { // chosen fdt.begin_node("chosen"); - fdt.prop_string("bootargs", c.rom.bootargs); + fdt.prop_string("bootargs", c.dtb.bootargs); // ??(edubart): make this configurable in machine config? fdt.prop("rng-seed", FDT_RNG_SEED, sizeof(FDT_RNG_SEED)); fdt.end_node(); @@ -90,8 +76,8 @@ void rom_init_device_tree(const machine_config &c, unsigned char *rom_start, uin fdt.begin_node("cartesi"); // We add emulator version, so can inspect it from inside the machine by reading the FDT fdt.prop_string_data("version", CM_VERSION); - fdt.prop_string_data("init", c.rom.init); - fdt.prop_string_data("entrypoint", c.rom.entrypoint); + fdt.prop_string_data("init", c.dtb.init); + fdt.prop_string_data("entrypoint", c.dtb.entrypoint); fdt.end_node(); } @@ -216,7 +202,7 @@ void rom_init_device_tree(const machine_config &c, unsigned char *rom_start, uin } fdt.end(); - fdt.finish(rom_start, length); + fdt.finish(dtb_start, dtb_length); } } // namespace cartesi diff --git a/src/rom.h b/src/dtb.h similarity index 60% rename from src/rom.h rename to src/dtb.h index 737c147d2..eec3f4d31 100644 --- a/src/rom.h +++ b/src/dtb.h @@ -14,11 +14,11 @@ // along with the machine-emulator. If not, see http://www.gnu.org/licenses/. // -#ifndef ROM_H -#define ROM_H +#ifndef DTB_H +#define DTB_H /// \file -/// \brief Bootstrap and device tree in ROM +/// \brief Device Tree Blob #include @@ -29,17 +29,11 @@ namespace cartesi { // Forward declarations struct machine_config; -/// \brief Initializes PMA extension metadata on ROM +/// \brief Initializes flattened device tree from machine config on DTB /// \param c Machine configuration. -/// \param rom_start Pointer to start of ROM contiguous range in host memory -/// \param length Maximum amount of ROM to use from start. -void rom_init(const machine_config &c, unsigned char *rom_start, uint64_t length); - -/// \brief Initializes FDT metadata on ROM -/// \param c Machine configuration. -/// \param rom_start Pointer to start of ROM contiguous range in host memory -/// \param length Maximum amount of ROM to use from start. -void rom_init_device_tree(const machine_config &c, unsigned char *rom_start, uint64_t length); +/// \param dtb_start Pointer to start of DTB contiguous range in host memory +/// \param dtb_length Maximum amount of DTB to use from start. +void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_length); } // namespace cartesi diff --git a/src/i-virtual-machine.h b/src/i-virtual-machine.h index eef915e23..a29d13c21 100644 --- a/src/i-virtual-machine.h +++ b/src/i-virtual-machine.h @@ -630,8 +630,8 @@ class i_virtual_machine { return do_reset_uarch_state(); } - /// \brief Reads the value of the microarchitecture ROM length - /// \returns The value of microarchitecture ROM length + /// \brief Reads the value of the microarchitecture RAM length + /// \returns The value of microarchitecture RAM length uint64_t read_uarch_ram_length(void) const { return do_read_uarch_ram_length(); } diff --git a/src/interpret.cpp b/src/interpret.cpp index 8ab0b0ea2..11308f519 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -5413,7 +5413,7 @@ static FORCE_INLINE fetch_status fetch_translate_pc_slow(STATE_ACCESS &a, uint64 } // Walk memory map to find the range that contains the physical address auto &pma = a.template find_pma_entry(paddr); - // We only execute directly from RAM (as in "random access memory", which includes ROM) + // We only execute directly from RAM (as in "random access memory") // If the range is not memory or not executable, this as a PMA violation if (unlikely(!pma.get_istart_M() || !pma.get_istart_X())) { pc = raise_exception(a, pc, MCAUSE_INSN_ACCESS_FAULT, vaddr); diff --git a/src/json-util.cpp b/src/json-util.cpp index 658a9e377..628828ff8 100644 --- a/src/json-util.cpp +++ b/src/json-util.cpp @@ -786,7 +786,7 @@ template void ju_get_opt_field(const nlohmann::json &j, const std:: const std::string &path); template -void ju_get_opt_field(const nlohmann::json &j, const K &key, rom_config &value, const std::string &path) { +void ju_get_opt_field(const nlohmann::json &j, const K &key, dtb_config &value, const std::string &path) { if (!contains(j, key)) { return; } @@ -798,10 +798,10 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, rom_config &value, ju_get_opt_field(jconfig, "image_filename"s, value.image_filename, new_path); } -template void ju_get_opt_field(const nlohmann::json &j, const uint64_t &key, rom_config &value, +template void ju_get_opt_field(const nlohmann::json &j, const uint64_t &key, dtb_config &value, const std::string &path); -template void ju_get_opt_field(const nlohmann::json &j, const std::string &key, rom_config &value, +template void ju_get_opt_field(const nlohmann::json &j, const std::string &key, dtb_config &value, const std::string &path); template @@ -1020,7 +1020,7 @@ void ju_get_opt_field(const nlohmann::json &j, const K &key, machine_config &val const auto new_path = path + to_string(key) + "/"; ju_get_opt_field(config, "processor"s, value.processor, new_path); ju_get_opt_field(config, "ram"s, value.ram, new_path); - ju_get_opt_field(config, "rom"s, value.rom, new_path); + ju_get_opt_field(config, "dtb"s, value.dtb, new_path); ju_get_opt_field(config, "flash_drive"s, value.flash_drive, new_path); ju_get_opt_field(config, "tlb"s, value.tlb, new_path); ju_get_opt_field(config, "clint"s, value.clint, new_path); @@ -1134,7 +1134,7 @@ void to_json(nlohmann::json &j, const ram_config &config) { }; } -void to_json(nlohmann::json &j, const rom_config &config) { +void to_json(nlohmann::json &j, const dtb_config &config) { j = nlohmann::json{ {"bootargs", config.bootargs}, {"init", config.init}, @@ -1201,7 +1201,7 @@ void to_json(nlohmann::json &j, const machine_config &config) { j = nlohmann::json{ {"processor", config.processor}, {"ram", config.ram}, - {"rom", config.rom}, + {"dtb", config.dtb}, {"flash_drive", config.flash_drive}, {"tlb", config.tlb}, {"clint", config.clint}, diff --git a/src/json-util.h b/src/json-util.h index 021015631..fae24e904 100644 --- a/src/json-util.h +++ b/src/json-util.h @@ -271,14 +271,14 @@ template void ju_get_opt_field(const nlohmann::json &j, const K &key, processor_config &value, const std::string &path = "params/"); -/// \brief Attempts to load a rom_config object from a field in a JSON object +/// \brief Attempts to load a dtb_config object from a field in a JSON object /// \tparam K Key type (explicit extern declarations for uint64_t and std::string are provided) /// \param j JSON object to load from /// \param key Key to load value from /// \param value Object to store value /// \param path Path to j template -void ju_get_opt_field(const nlohmann::json &j, const K &key, rom_config &value, const std::string &path = "params/"); +void ju_get_opt_field(const nlohmann::json &j, const K &key, dtb_config &value, const std::string &path = "params/"); /// \brief Attempts to load a ram_config object from a field in a JSON object /// \tparam K Key type (explicit extern declarations for uint64_t and std::string are provided) @@ -541,7 +541,7 @@ void to_json(nlohmann::json &j, const memory_range_config &config); void to_json(nlohmann::json &j, const processor_config &config); void to_json(nlohmann::json &j, const flash_drive_configs &fs); void to_json(nlohmann::json &j, const ram_config &config); -void to_json(nlohmann::json &j, const rom_config &config); +void to_json(nlohmann::json &j, const dtb_config &config); void to_json(nlohmann::json &j, const tlb_config &config); void to_json(nlohmann::json &j, const clint_config &config); void to_json(nlohmann::json &j, const htif_config &config); @@ -640,9 +640,9 @@ extern template void ju_get_opt_field(const nlohmann::json &j, const uint64_t &k const std::string &base = "params/"); extern template void ju_get_opt_field(const nlohmann::json &j, const std::string &key, processor_config &value, const std::string &base = "params/"); -extern template void ju_get_opt_field(const nlohmann::json &j, const uint64_t &key, rom_config &value, +extern template void ju_get_opt_field(const nlohmann::json &j, const uint64_t &key, dtb_config &value, const std::string &base = "params/"); -extern template void ju_get_opt_field(const nlohmann::json &j, const std::string &key, rom_config &value, +extern template void ju_get_opt_field(const nlohmann::json &j, const std::string &key, dtb_config &value, const std::string &base = "params/"); extern template void ju_get_opt_field(const nlohmann::json &j, const uint64_t &key, ram_config &value, const std::string &base = "params/"); diff --git a/src/jsonrpc-discover.json b/src/jsonrpc-discover.json index c03bbd325..4cddd8182 100644 --- a/src/jsonrpc-discover.json +++ b/src/jsonrpc-discover.json @@ -1453,8 +1453,8 @@ ] }, - "ROMConfig": { - "title": "ROMConfig", + "DTBConfig": { + "title": "DTBConfig", "type": "object", "properties": { "bootargs": { @@ -1615,8 +1615,8 @@ "ram": { "$ref": "#/components/schemas/RAMConfig" }, - "rom": { - "$ref": "#/components/schemas/ROMConfig" + "dtb": { + "$ref": "#/components/schemas/DTBConfig" }, "flash_drive": { "$ref": "#/components/schemas/FlashDriveConfigs" diff --git a/src/machine-c-api.cpp b/src/machine-c-api.cpp index bd2149c8d..b50926cce 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -184,25 +184,25 @@ static cm_ram_config convert_to_c(const cartesi::ram_config &cpp_config) { } // -------------------------------------------- -// Rom configuration conversion functions +// DTB configuration conversion functions // -------------------------------------------- -static cartesi::rom_config convert_from_c(const cm_rom_config *c_config) { - cartesi::rom_config new_cpp_rom_config{}; - new_cpp_rom_config.bootargs = null_to_empty(c_config->bootargs); - new_cpp_rom_config.init = null_to_empty(c_config->init); - new_cpp_rom_config.entrypoint = null_to_empty(c_config->entrypoint); - new_cpp_rom_config.image_filename = null_to_empty(c_config->image_filename); - return new_cpp_rom_config; +static cartesi::dtb_config convert_from_c(const cm_dtb_config *c_config) { + cartesi::dtb_config new_cpp_dtb_config{}; + new_cpp_dtb_config.bootargs = null_to_empty(c_config->bootargs); + new_cpp_dtb_config.init = null_to_empty(c_config->init); + new_cpp_dtb_config.entrypoint = null_to_empty(c_config->entrypoint); + new_cpp_dtb_config.image_filename = null_to_empty(c_config->image_filename); + return new_cpp_dtb_config; } -static cm_rom_config convert_to_c(const cartesi::rom_config &cpp_config) { - cm_rom_config new_c_rom_config{}; - new_c_rom_config.bootargs = convert_to_c(cpp_config.bootargs); - new_c_rom_config.init = convert_to_c(cpp_config.init); - new_c_rom_config.entrypoint = convert_to_c(cpp_config.entrypoint); - new_c_rom_config.image_filename = convert_to_c(cpp_config.image_filename); - return new_c_rom_config; +static cm_dtb_config convert_to_c(const cartesi::dtb_config &cpp_config) { + cm_dtb_config new_c_dtb_config{}; + new_c_dtb_config.bootargs = convert_to_c(cpp_config.bootargs); + new_c_dtb_config.init = convert_to_c(cpp_config.init); + new_c_dtb_config.entrypoint = convert_to_c(cpp_config.entrypoint); + new_c_dtb_config.image_filename = convert_to_c(cpp_config.image_filename); + return new_c_dtb_config; } // ---------------------------------------------- @@ -387,7 +387,7 @@ cartesi::machine_config convert_from_c(const cm_machine_config *c_config) { cartesi::machine_config new_cpp_machine_config{}; new_cpp_machine_config.processor = convert_from_c(&c_config->processor); new_cpp_machine_config.ram = convert_from_c(&c_config->ram); - new_cpp_machine_config.rom = convert_from_c(&c_config->rom); + new_cpp_machine_config.dtb = convert_from_c(&c_config->dtb); new_cpp_machine_config.tlb = convert_from_c(&c_config->tlb); new_cpp_machine_config.clint = convert_from_c(&c_config->clint); new_cpp_machine_config.htif = convert_from_c(&c_config->htif); @@ -416,7 +416,7 @@ cm_machine_config *convert_to_c(const cartesi::machine_config &cpp_config) { auto *new_machine_config = new cm_machine_config{}; new_machine_config->processor = convert_to_c(cpp_config.processor); new_machine_config->ram = convert_to_c(cpp_config.ram); - new_machine_config->rom = convert_to_c(cpp_config.rom); + new_machine_config->dtb = convert_to_c(cpp_config.dtb); new_machine_config->flash_drive = convert_to_c(cpp_config.flash_drive); new_machine_config->tlb = convert_to_c(cpp_config.tlb); new_machine_config->clint = convert_to_c(cpp_config.clint); @@ -705,10 +705,10 @@ void cm_delete_machine_config(const cm_machine_config *config) { delete[] config->flash_drive.entry[i].image_filename; } delete[] config->flash_drive.entry; - delete[] config->rom.image_filename; - delete[] config->rom.bootargs; - delete[] config->rom.init; - delete[] config->rom.entrypoint; + delete[] config->dtb.image_filename; + delete[] config->dtb.bootargs; + delete[] config->dtb.init; + delete[] config->dtb.entrypoint; delete[] config->ram.image_filename; delete[] config->tlb.image_filename; delete[] config->rollup.rx_buffer.image_filename; diff --git a/src/machine-c-api.h b/src/machine-c-api.h index f757b6bf3..e97155a05 100644 --- a/src/machine-c-api.h +++ b/src/machine-c-api.h @@ -196,13 +196,13 @@ typedef struct { // NOLINT(modernize-use-using) const char *image_filename; ///< RAM image file name } cm_ram_config; -/// \brief ROM state configuration +/// \brief DTB state configuration typedef struct { // NOLINT(modernize-use-using) const char *bootargs; ///< Bootargs to pass to kernel const char *init; ///< Initialization commands to be executed as root on boot const char *entrypoint; ///< Commands to execute the main application - const char *image_filename; ///< ROM image file -} cm_rom_config; + const char *image_filename; ///< DTB image file +} cm_dtb_config; /// \brief Memory range configuration typedef struct { // NOLINT(modernize-use-using) @@ -271,7 +271,7 @@ typedef struct { // NOLINT(modernize-use-using) typedef struct { // NOLINT(modernize-use-using) cm_processor_config processor; cm_ram_config ram; - cm_rom_config rom; + cm_dtb_config dtb; cm_memory_range_config_array flash_drive; cm_tlb_config tlb; cm_clint_config clint; diff --git a/src/machine-config.cpp b/src/machine-config.cpp index c8618558f..68f20c18b 100644 --- a/src/machine-config.cpp +++ b/src/machine-config.cpp @@ -45,7 +45,7 @@ std::string machine_config::get_config_filename(const std::string &dir) { } static void adjust_image_filenames(machine_config &c, const std::string &dir) { - c.rom.image_filename = c.get_image_filename(dir, PMA_ROM_START, PMA_ROM_LENGTH); + c.dtb.image_filename = c.get_image_filename(dir, PMA_DTB_START, PMA_DTB_LENGTH); c.ram.image_filename = c.get_image_filename(dir, PMA_RAM_START, c.ram.length); c.tlb.image_filename = c.get_image_filename(dir, PMA_SHADOW_TLB_START, PMA_SHADOW_TLB_LENGTH); for (auto &f : c.flash_drive) { diff --git a/src/machine-config.h b/src/machine-config.h index 0176d8519..3df0f64d3 100644 --- a/src/machine-config.h +++ b/src/machine-config.h @@ -73,12 +73,12 @@ struct ram_config final { std::string image_filename{}; ///< RAM image file name }; -/// \brief ROM state configuration -struct rom_config final { +/// \brief DTB state configuration +struct dtb_config final { std::string bootargs{}; ///< Bootargs to pass to kernel std::string init{}; ///< Initialization commands to be executed as root on boot std::string entrypoint{}; ///< Commands to execute the main application - std::string image_filename{}; ///< ROM image file + std::string image_filename{}; ///< DTB image file }; /// \brief Memory range configuration @@ -131,7 +131,7 @@ struct machine_config final { processor_config processor{}; ///< Processor state ram_config ram{}; ///< RAM state - rom_config rom{}; ///< ROM state + dtb_config dtb{}; ///< DTB state flash_drive_configs flash_drive{}; ///< Flash drives state tlb_config tlb{}; ///< TLB device state clint_config clint{}; ///< CLINT device state diff --git a/src/machine.cpp b/src/machine.cpp index 84003da0a..26c44435d 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -28,11 +28,11 @@ #include #include "clint-factory.h" +#include "dtb.h" #include "htif-factory.h" #include "interpret.h" #include "machine.h" #include "riscv-constants.h" -#include "rom.h" #include "rtc.h" #include "shadow-pmas-factory.h" #include "shadow-state-factory.h" @@ -64,11 +64,10 @@ const pma_entry::flags machine::m_ram_flags{ PMA_ISTART_DID::memory // DID }; -// The ROM is not really read-only, this might seem counter-intuitive at first. -// When we pass a RNG seed in a FDT stored in ROM, +// When we pass a RNG seed in a FDT stored in DTB, // Linux will wipe out its contents as a security measure, -// therefore we need to make ROM writable, otherwise boot will hang. -const pma_entry::flags machine::m_rom_flags{ +// therefore we need to make DTB writable, otherwise boot will hang. +const pma_entry::flags machine::m_dtb_flags{ true, // R true, // W true, // X @@ -356,11 +355,11 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) : .set_flags(m_ram_flags)); } - // Register ROM - pma_entry &rom = register_pma_entry((m_c.rom.image_filename.empty() ? - make_callocd_memory_pma_entry("ROM"s, PMA_ROM_START, PMA_ROM_LENGTH) : - make_callocd_memory_pma_entry("ROM"s, PMA_ROM_START, PMA_ROM_LENGTH, m_c.rom.image_filename)) - .set_flags(m_rom_flags)); + // Register DTB + pma_entry &dtb = register_pma_entry((m_c.dtb.image_filename.empty() ? + make_callocd_memory_pma_entry("DTB"s, PMA_DTB_START, PMA_DTB_LENGTH) : + make_callocd_memory_pma_entry("DTB"s, PMA_DTB_START, PMA_DTB_LENGTH, m_c.dtb.image_filename)) + .set_flags(m_dtb_flags)); // Register all flash drives int i = 0; @@ -424,13 +423,10 @@ machine::machine(const machine_config &c, const machine_runtime_config &r) : // Register pma board shadow device register_pma_entry(make_shadow_pmas_pma_entry(PMA_SHADOW_PMAS_START, PMA_SHADOW_PMAS_LENGTH)); - // Initialize ROM - if (m_c.rom.image_filename.empty()) { - // Write the FDT (flattened device tree) into ROM - rom_init_device_tree(m_c, rom.get_memory().get_host_memory(), PMA_ROM_LENGTH); - } else { - // Initialize PMA extension metadata on ROM - rom_init(m_c, rom.get_memory().get_host_memory(), PMA_ROM_LENGTH); + // Initialize DTB + if (m_c.dtb.image_filename.empty()) { + // Write the FDT (flattened device tree) into DTB + dtb_init(m_c, dtb.get_memory().get_host_memory(), PMA_DTB_LENGTH); } // Add sentinel to PMA vector @@ -547,12 +543,12 @@ machine_config machine::get_serialization_config(void) const { c.htif.console_getchar = static_cast(read_htif_iconsole() & (1 << HTIF_CONSOLE_GETCHAR)); c.htif.yield_manual = static_cast(read_htif_iyield() & (1 << HTIF_YIELD_MANUAL)); c.htif.yield_automatic = static_cast(read_htif_iyield() & (1 << HTIF_YIELD_AUTOMATIC)); - // Ensure we don't mess with ROM by writing the original bootargs + // Ensure we don't mess with DTB by writing the original bootargs // over the potentially modified memory region we serialize - c.rom.bootargs.clear(); + c.dtb.bootargs.clear(); // Remove image filenames from serialization // (they will be ignored by save and load for security reasons) - c.rom.image_filename.clear(); + c.dtb.image_filename.clear(); c.ram.image_filename.clear(); c.uarch.ram.image_filename.clear(); c.tlb.image_filename.clear(); @@ -658,7 +654,7 @@ static inline T &deref(T *t) { } void machine::store_pmas(const machine_config &c, const std::string &dir) const { - store_memory_pma(find_pma_entry(PMA_ROM_START), dir); + store_memory_pma(find_pma_entry(PMA_DTB_START), dir); store_memory_pma(find_pma_entry(PMA_RAM_START), dir); store_device_pma(*this, find_pma_entry(PMA_SHADOW_TLB_START), dir); // Could iterate over PMAs checking for those with a drive DID diff --git a/src/machine.h b/src/machine.h index 181872ef6..f7b895bcb 100644 --- a/src/machine.h +++ b/src/machine.h @@ -51,7 +51,7 @@ class machine final { uarch_machine m_uarch; ///< Microarchitecture machine machine_runtime_config m_r; ///< Copy of initialization runtime config - static const pma_entry::flags m_rom_flags; ///< PMA flags used for ROM + static const pma_entry::flags m_dtb_flags; ///< PMA flags used for DTB static const pma_entry::flags m_ram_flags; ///< PMA flags used for RAM static const pma_entry::flags m_flash_drive_flags; ///< PMA flags used for flash drives static const pma_entry::flags m_rollup_rx_buffer_flags; ///< PMA flags used for rollup rx buffer diff --git a/src/pma-constants.h b/src/pma-constants.h index a78d0cbb5..2483630bb 100644 --- a/src/pma-constants.h +++ b/src/pma-constants.h @@ -32,8 +32,8 @@ enum PMA_ranges : uint64_t { PMA_SHADOW_STATE_LENGTH = EXPAND_UINT64_C(PMA_SHADOW_STATE_LENGTH_DEF), ///< Length of processor shadow range PMA_SHADOW_PMAS_START = EXPAND_UINT64_C(PMA_SHADOW_PMAS_START_DEF), ///< Start of pma board shadow range PMA_SHADOW_PMAS_LENGTH = EXPAND_UINT64_C(PMA_SHADOW_PMAS_LENGTH_DEF), ///< Length of pma board shadow range - PMA_ROM_START = EXPAND_UINT64_C(PMA_ROM_START_DEF), ///< Start of ROM range - PMA_ROM_LENGTH = EXPAND_UINT64_C(PMA_ROM_LENGTH_DEF), ///< Length of ROM range + PMA_DTB_START = EXPAND_UINT64_C(PMA_DTB_START_DEF), ///< Start of DTB range + PMA_DTB_LENGTH = EXPAND_UINT64_C(PMA_DTB_LENGTH_DEF), ///< Length of DTB range PMA_SHADOW_TLB_START = EXPAND_UINT64_C(PMA_SHADOW_TLB_START_DEF), ///< Start of TLB shadow range PMA_SHADOW_TLB_LENGTH = EXPAND_UINT64_C(PMA_SHADOW_TLB_LENGTH_DEF), ///< Length of TLB shadow range PMA_CLINT_START = EXPAND_UINT64_C(PMA_CLINT_START_DEF), ///< Start of CLINT range diff --git a/src/protobuf-util.cpp b/src/protobuf-util.cpp index ccfe0c593..fcaba45ae 100644 --- a/src/protobuf-util.cpp +++ b/src/protobuf-util.cpp @@ -44,11 +44,11 @@ void set_proto_rollup(const rollup_config &r, CartesiMachine::RollupConfig *prot } void set_proto_machine_config(const machine_config &c, CartesiMachine::MachineConfig *proto_c) { - auto *proto_rom = proto_c->mutable_rom(); - proto_rom->set_bootargs(c.rom.bootargs); - proto_rom->set_init(c.rom.init); - proto_rom->set_entrypoint(c.rom.entrypoint); - proto_rom->set_image_filename(c.rom.image_filename); + auto *proto_dtb = proto_c->mutable_dtb(); + proto_dtb->set_bootargs(c.dtb.bootargs); + proto_dtb->set_init(c.dtb.init); + proto_dtb->set_entrypoint(c.dtb.entrypoint); + proto_dtb->set_image_filename(c.dtb.image_filename); auto *proto_ram = proto_c->mutable_ram(); proto_ram->set_length(c.ram.length); proto_ram->set_image_filename(c.ram.image_filename); @@ -814,11 +814,11 @@ machine_config get_proto_machine_config(const CartesiMachine::MachineConfig &pro if (proto_c.has_uarch()) { c.uarch = get_proto_uarch_config(proto_c.uarch()); } - if (proto_c.has_rom()) { - c.rom.bootargs = proto_c.rom().bootargs(); - c.rom.init = proto_c.rom().init(); - c.rom.entrypoint = proto_c.rom().entrypoint(); - c.rom.image_filename = proto_c.rom().image_filename(); + if (proto_c.has_dtb()) { + c.dtb.bootargs = proto_c.dtb().bootargs(); + c.dtb.init = proto_c.dtb().init(); + c.dtb.entrypoint = proto_c.dtb().entrypoint(); + c.dtb.image_filename = proto_c.dtb().image_filename(); } if (proto_c.has_ram()) { c.ram.length = proto_c.ram().length(); diff --git a/src/riscv-constants.h b/src/riscv-constants.h index 6132aec56..ad1a99046 100644 --- a/src/riscv-constants.h +++ b/src/riscv-constants.h @@ -470,7 +470,7 @@ enum CARTESI_init : uint64_t { UARCH_PC_INIT = UINT64_C(0x70000000), ///< Initial value for microarchitecture pc UARCH_CYCLE_INIT = UINT64_C(0), ///< Initial value for microarchitecture cycle MHARTID_INIT = UINT64_C(0), ///< Initial mhartid - FDTADDR_INIT = PMA_ROM_START, ///< Initial FDT address + FDTADDR_INIT = PMA_DTB_START, ///< Initial FDT address // Registers REG_X0 = UINT64_C(0), //< zero - hardwired zero diff --git a/src/test-machine-c-api.cpp b/src/test-machine-c-api.cpp index 6b58a80de..4c52befd9 100644 --- a/src/test-machine-c-api.cpp +++ b/src/test-machine-c-api.cpp @@ -43,7 +43,7 @@ static hash_type get_verification_root_hash(cm_machine *machine) { std::vector dump_list{ "0000000000000000--0000000000001000.bin", // shadow state - "0000000000001000--000000000000f000.bin", // rom + "0000000000001000--000000000000f000.bin", // dtb "0000000000010000--0000000000001000.bin", // shadow pmas "0000000000020000--0000000000006000.bin", // shadow tlb "0000000002000000--00000000000c0000.bin", // clint @@ -221,10 +221,10 @@ class incomplete_machine_fixture : public default_machine_fixture { target->ram.length = source->ram.length; target->ram.image_filename = new_cstr(source->ram.image_filename); - target->rom.bootargs = new_cstr(source->rom.bootargs); - target->rom.init = new_cstr(source->rom.init); - target->rom.entrypoint = new_cstr(source->rom.entrypoint); - target->rom.image_filename = new_cstr(source->rom.image_filename); + target->dtb.bootargs = new_cstr(source->dtb.bootargs); + target->dtb.init = new_cstr(source->dtb.init); + target->dtb.entrypoint = new_cstr(source->dtb.entrypoint); + target->dtb.image_filename = new_cstr(source->dtb.image_filename); target->flash_drive.count = source->flash_drive.count; target->flash_drive.entry = new cm_memory_range_config[source->flash_drive.count]{}; @@ -248,19 +248,14 @@ class incomplete_machine_fixture : public default_machine_fixture { } delete[] config->tlb.image_filename; delete[] config->flash_drive.entry; - delete[] config->rom.image_filename; - delete[] config->rom.bootargs; - delete[] config->rom.init; - delete[] config->rom.entrypoint; + delete[] config->dtb.image_filename; + delete[] config->dtb.bootargs; + delete[] config->dtb.init; + delete[] config->dtb.entrypoint; delete[] config->ram.image_filename; delete[] config->uarch.ram.image_filename; } - void _set_rom_image(const std::string &image_name) { - delete[] _machine_config.rom.image_filename; - _machine_config.rom.image_filename = new_cstr(image_name.c_str()); - } - void _setup_flash(std::list &&configs) { _machine_config.flash_drive.count = configs.size(); delete[] _machine_config.flash_drive.entry; @@ -290,27 +285,7 @@ class incomplete_machine_fixture : public default_machine_fixture { } }; -class machine_rom_fixture : public incomplete_machine_fixture { -public: - machine_rom_fixture() { - std::ofstream output(_rom_path); - output.close(); - _set_rom_image(_rom_path); - } - ~machine_rom_fixture() { - std::filesystem::remove(_rom_path); - } - - machine_rom_fixture(const machine_rom_fixture &other) = delete; - machine_rom_fixture(machine_rom_fixture &&other) noexcept = delete; - machine_rom_fixture &operator=(const machine_rom_fixture &other) = delete; - machine_rom_fixture &operator=(machine_rom_fixture &&other) noexcept = delete; - -protected: - const std::string _rom_path = "./empty-rom.bin"; -}; - -BOOST_FIXTURE_TEST_CASE_NOLINT(create_machine_null_machine_test, machine_rom_fixture) { +BOOST_FIXTURE_TEST_CASE_NOLINT(create_machine_null_machine_test, incomplete_machine_fixture) { char *err_msg{}; int error_code = cm_create_machine(&_machine_config, &_runtime_config, nullptr, &err_msg); BOOST_CHECK_EQUAL(error_code, CM_ERROR_INVALID_ARGUMENT); @@ -322,43 +297,30 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(create_machine_null_machine_test, machine_rom_fix cm_delete_cstring(err_msg); } -BOOST_FIXTURE_TEST_CASE_NOLINT(create_machine_unknown_rom_file_test, incomplete_machine_fixture) { - _set_rom_image("/unknown/file.bin"); - char *err_msg{}; - int error_code = cm_create_machine(&_machine_config, &_runtime_config, &_machine, &err_msg); - BOOST_CHECK_EQUAL(error_code, CM_ERROR_RUNTIME_ERROR); - - std::string result = err_msg; - std::string origin("error opening image file '/unknown/file.bin' when initializing ROM: No such file or directory"); - BOOST_CHECK_EQUAL(origin, result); - - cm_delete_cstring(err_msg); -} - -class machine_rom_flash_fixture : public machine_rom_fixture { +class machine_flash_fixture : public incomplete_machine_fixture { public: - machine_rom_flash_fixture() { + machine_flash_fixture() { cm_memory_range_config flash1_cfg = {0x80000000000000, 0x3c00000, true, _flash1_path.c_str()}; cm_memory_range_config flash2_cfg = {0x7ffffffffff000, 0x2000, true, _flash2_path.c_str()}; _setup_flash({flash1_cfg, flash2_cfg}); } - ~machine_rom_flash_fixture() { + ~machine_flash_fixture() { std::filesystem::remove(_flash1_path); std::filesystem::remove(_flash2_path); } - machine_rom_flash_fixture(const machine_rom_flash_fixture &other) = delete; - machine_rom_flash_fixture(machine_rom_flash_fixture &&other) noexcept = delete; - machine_rom_flash_fixture &operator=(const machine_rom_flash_fixture &other) = delete; - machine_rom_flash_fixture &operator=(machine_rom_flash_fixture &&other) noexcept = delete; + machine_flash_fixture(const machine_flash_fixture &other) = delete; + machine_flash_fixture(machine_flash_fixture &&other) noexcept = delete; + machine_flash_fixture &operator=(const machine_flash_fixture &other) = delete; + machine_flash_fixture &operator=(machine_flash_fixture &&other) noexcept = delete; private: const std::string _flash1_path = "./flash1.bin"; const std::string _flash2_path = "./flash2.bin"; }; -BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_pma_overlapping_test, machine_rom_flash_fixture) { +BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_pma_overlapping_test, machine_flash_fixture) { char *err_msg{}; int error_code = cm_create_machine(&_machine_config, &_runtime_config, &_machine, &err_msg); BOOST_CHECK_EQUAL(error_code, CM_ERROR_INVALID_ARGUMENT); @@ -370,26 +332,26 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_pma_overlapping_test, machin cm_delete_cstring(err_msg); } -class machine_rom_flash_simple_fixture : public machine_rom_fixture { +class machine_flash_simple_fixture : public incomplete_machine_fixture { public: - machine_rom_flash_simple_fixture() { + machine_flash_simple_fixture() { _setup_flash(_flash_path); } - ~machine_rom_flash_simple_fixture() { + ~machine_flash_simple_fixture() { std::filesystem::remove(_flash_path); } - machine_rom_flash_simple_fixture(const machine_rom_flash_simple_fixture &other) = delete; - machine_rom_flash_simple_fixture(machine_rom_flash_simple_fixture &&other) noexcept = delete; - machine_rom_flash_simple_fixture &operator=(const machine_rom_flash_simple_fixture &other) = delete; - machine_rom_flash_simple_fixture &operator=(machine_rom_flash_simple_fixture &&other) noexcept = delete; + machine_flash_simple_fixture(const machine_flash_simple_fixture &other) = delete; + machine_flash_simple_fixture(machine_flash_simple_fixture &&other) noexcept = delete; + machine_flash_simple_fixture &operator=(const machine_flash_simple_fixture &other) = delete; + machine_flash_simple_fixture &operator=(machine_flash_simple_fixture &&other) noexcept = delete; protected: const std::string _flash_path = "./flash.bin"; }; -BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_invalid_alignment_test, machine_rom_flash_simple_fixture) { +BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_invalid_alignment_test, machine_flash_simple_fixture) { _machine_config.flash_drive.entry[0].start -= 1; char *err_msg{}; @@ -403,7 +365,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_invalid_alignment_test, mach cm_delete_cstring(err_msg); } -BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_not_addressable_test, machine_rom_flash_simple_fixture) { +BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_not_addressable_test, machine_flash_simple_fixture) { _machine_config.flash_drive.entry[0].start = 0x100000000000000 - 0x3c00000 + 4096; _machine_config.flash_drive.entry[0].length = 0x3c00000; @@ -418,7 +380,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_not_addressable_test, machin cm_delete_cstring(err_msg); } -class ordinary_machine_fixture : public machine_rom_fixture { +class ordinary_machine_fixture : public incomplete_machine_fixture { public: ordinary_machine_fixture() { _machine_dir_path = (std::filesystem::temp_directory_path() / "661b6096c377cdc07756df488059f4407c8f4").string(); @@ -465,7 +427,7 @@ bool operator==(const cm_ram_config &lhs, const cm_ram_config &rhs) { return (lhs.length == rhs.length && (strcmp(lhs.image_filename, rhs.image_filename) == 0)); } -bool operator==(const cm_rom_config &lhs, const cm_rom_config &rhs) { +bool operator==(const cm_dtb_config &lhs, const cm_dtb_config &rhs) { return ((strcmp(lhs.bootargs, rhs.bootargs) == 0) && (strcmp(lhs.init, rhs.init) == 0) && (strcmp(lhs.entrypoint, rhs.entrypoint) == 0) && (strcmp(lhs.image_filename, rhs.image_filename) == 0)); } @@ -484,7 +446,7 @@ bool operator==(const cm_htif_config &lhs, const cm_htif_config &rhs) { } bool operator==(const cm_machine_config &lhs, const cm_machine_config &rhs) { - return ((lhs.processor == rhs.processor) && (lhs.rom == rhs.rom) && (lhs.ram == rhs.ram) && (lhs.tlb == rhs.tlb) && + return ((lhs.processor == rhs.processor) && (lhs.dtb == rhs.dtb) && (lhs.ram == rhs.ram) && (lhs.tlb == rhs.tlb) && (lhs.clint == rhs.clint) && (lhs.htif == rhs.htif)); } @@ -1485,7 +1447,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(replace_memory_range_null_flash_config_test, ordi cm_delete_cstring(err_msg); } -class flash_drive_machine_fixture : public machine_rom_flash_simple_fixture { +class flash_drive_machine_fixture : public machine_flash_simple_fixture { public: flash_drive_machine_fixture() : _flash_config{}, _flash_data{"test data 1234567890"} { _machine_dir_path = (std::filesystem::temp_directory_path() / "661b6096c377cdc07756df488059f4407c8f4").string(); @@ -1534,7 +1496,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(get_initial_config_flash_drive_test, flash_drive_ BOOST_FIXTURE_TEST_CASE_NOLINT(dump_pmas_null_placeholder_test, flash_drive_machine_fixture) { std::array dump_list{ "0000000000000000--0000000000001000.bin", // shadow state - "0000000000001000--000000000000f000.bin", // rom + "0000000000001000--000000000000f000.bin", // dtb "0000000000010000--0000000000001000.bin", // shadow pmas "0000000000020000--0000000000006000.bin", // shadow tlb "0000000002000000--00000000000c0000.bin", // clint @@ -1555,7 +1517,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(dump_pmas_null_placeholder_test, flash_drive_mach BOOST_FIXTURE_TEST_CASE_NOLINT(dump_pmas_basic_test, flash_drive_machine_fixture) { std::array dump_list{ "0000000000000000--0000000000001000.bin", // shadow state - "0000000000001000--000000000000f000.bin", // rom + "0000000000001000--000000000000f000.bin", // dtb "0000000000010000--0000000000001000.bin", // shadow pmas "0000000000020000--0000000000006000.bin", // shadow tlb "0000000002000000--00000000000c0000.bin", // clint @@ -1921,7 +1883,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(verify_access_log_null_log_test, default_machine_ cm_delete_cstring(err_msg); } -class access_log_machine_fixture : public machine_rom_fixture { +class access_log_machine_fixture : public incomplete_machine_fixture { public: access_log_machine_fixture() { _log_type = {true, true}; @@ -2546,7 +2508,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(machine_verify_merkle_tree_proof_updates_test, or // GRPC machine tests -class grpc_machine_fixture : public machine_rom_flash_simple_fixture { +class grpc_machine_fixture : public machine_flash_simple_fixture { public: grpc_machine_fixture() : m_stub{} { char *err_msg{}; diff --git a/src/test-utils.h b/src/test-utils.h index 3a17c239c..0138a1339 100644 --- a/src/test-utils.h +++ b/src/test-utils.h @@ -338,7 +338,7 @@ static hash_type calculate_emulator_hash(const std::vector &pmas_f using namespace cartesi; cartesi::keccak_256_hasher h; auto shadow_state = parse_pma_file(pmas_files[0]); - auto rom = parse_pma_file(pmas_files[1]); + auto dtb = parse_pma_file(pmas_files[1]); auto shadow_pmas = parse_pma_file(pmas_files[2]); auto shadow_tlb = parse_pma_file(pmas_files[3]); auto clint = parse_pma_file(pmas_files[4]); @@ -349,41 +349,41 @@ static hash_type calculate_emulator_hash(const std::vector &pmas_f uarch_ram = parse_pma_file(pmas_files[7]); } - std::vector shadow_rom; - shadow_rom.reserve(shadow_state.size() + rom.size() + shadow_pmas.size()); - shadow_rom.insert(shadow_rom.end(), shadow_state.begin(), shadow_state.end()); - shadow_rom.insert(shadow_rom.end(), rom.begin(), rom.end()); - shadow_rom.insert(shadow_rom.end(), shadow_pmas.begin(), shadow_pmas.end()); + std::vector shadow_dtb; + shadow_dtb.reserve(shadow_state.size() + dtb.size() + shadow_pmas.size()); + shadow_dtb.insert(shadow_dtb.end(), shadow_state.begin(), shadow_state.end()); + shadow_dtb.insert(shadow_dtb.end(), dtb.begin(), dtb.end()); + shadow_dtb.insert(shadow_dtb.end(), shadow_pmas.begin(), shadow_pmas.end()); - hash_type shadow_rom_tlb_space_hash; - hash_type shadow_rom_tlb_clint_hash; + hash_type shadow_dtb_tlb_space_hash; + hash_type shadow_dtb_tlb_clint_hash; hash_type left; hash_type used_space_hash; - int shadow_rom_hash_size_log2 = ceil_log2(PMA_SHADOW_STATE_LENGTH + PMA_ROM_LENGTH + PMA_SHADOW_PMAS_LENGTH); - auto shadow_rom_space_hash = calculate_region_hash(shadow_rom, - (shadow_rom.size() + PMA_PAGE_SIZE - 1) / PMA_PAGE_SIZE, PMA_PAGE_SIZE_LOG2, shadow_rom_hash_size_log2); - shadow_rom_space_hash = extend_region_hash(shadow_rom_space_hash, 0, shadow_rom_hash_size_log2, 17); + int shadow_dtb_hash_size_log2 = ceil_log2(PMA_SHADOW_STATE_LENGTH + PMA_DTB_LENGTH + PMA_SHADOW_PMAS_LENGTH); + auto shadow_dtb_space_hash = calculate_region_hash(shadow_dtb, + (shadow_dtb.size() + PMA_PAGE_SIZE - 1) / PMA_PAGE_SIZE, PMA_PAGE_SIZE_LOG2, shadow_dtb_hash_size_log2); + shadow_dtb_space_hash = extend_region_hash(shadow_dtb_space_hash, 0, shadow_dtb_hash_size_log2, 17); auto tlb_size_log2 = ceil_log2(PMA_SHADOW_TLB_LENGTH); auto tlb_space_hash = calculate_region_hash(shadow_tlb, (shadow_tlb.size() + PMA_PAGE_SIZE - 1) / PMA_PAGE_SIZE, PMA_PAGE_SIZE_LOG2, tlb_size_log2); tlb_space_hash = extend_region_hash(tlb_space_hash, PMA_SHADOW_TLB_START, tlb_size_log2, 17); - get_concat_hash(h, shadow_rom_space_hash, tlb_space_hash, shadow_rom_tlb_space_hash); // 18 - shadow_rom_tlb_space_hash = extend_region_hash(shadow_rom_tlb_space_hash, 0, 18, 25); + get_concat_hash(h, shadow_dtb_space_hash, tlb_space_hash, shadow_dtb_tlb_space_hash); // 18 + shadow_dtb_tlb_space_hash = extend_region_hash(shadow_dtb_tlb_space_hash, 0, 18, 25); auto clint_size_log2 = ceil_log2(PMA_CLINT_LENGTH); auto clint_space_hash = calculate_region_hash(clint, (clint.size() + PMA_PAGE_SIZE - 1) / PMA_PAGE_SIZE, PMA_PAGE_SIZE_LOG2, clint_size_log2); clint_space_hash = extend_region_hash(clint_space_hash, PMA_CLINT_START, clint_size_log2, 25); - get_concat_hash(h, shadow_rom_tlb_space_hash, clint_space_hash, shadow_rom_tlb_clint_hash); // 26 - shadow_rom_tlb_clint_hash = extend_region_hash(shadow_rom_tlb_clint_hash, 0, 26, 29); + get_concat_hash(h, shadow_dtb_tlb_space_hash, clint_space_hash, shadow_dtb_tlb_clint_hash); // 26 + shadow_dtb_tlb_clint_hash = extend_region_hash(shadow_dtb_tlb_clint_hash, 0, 26, 29); uint64_t htif_size_log2 = ceil_log2(htif.size()); auto htif_space_hash = calculate_region_hash_2(PMA_HTIF_START, htif, htif_size_log2, 29); - get_concat_hash(h, shadow_rom_tlb_clint_hash, htif_space_hash, left); // 30 + get_concat_hash(h, shadow_dtb_tlb_clint_hash, htif_space_hash, left); // 30 auto uarch_ram_space_hash = zero_keccak_hash_table[30]; if (uarch_ram.size() > 0) { diff --git a/src/tests/log-with-mtime-transition.lua b/src/tests/log-with-mtime-transition.lua index a7f4e91d7..00ac5dfff 100644 --- a/src/tests/log-with-mtime-transition.lua +++ b/src/tests/log-with-mtime-transition.lua @@ -13,7 +13,7 @@ local config = { ram = { length = 1 << 12, }, - rom = { + dtb = { image_filename = "", }, uarch = { diff --git a/src/tests/machine-bind.lua b/src/tests/machine-bind.lua index fa71922ac..b2c512139 100755 --- a/src/tests/machine-bind.lua +++ b/src/tests/machine-bind.lua @@ -248,7 +248,7 @@ end local pmas_file_names = { "0000000000000000--0000000000001000.bin", -- shadow state - "0000000000001000--000000000000f000.bin", -- rom + "0000000000001000--000000000000f000.bin", -- dtb "0000000000010000--0000000000001000.bin", -- shadow pmas "0000000000020000--0000000000006000.bin", -- shadow tlb "0000000002000000--00000000000c0000.bin", -- clint @@ -406,7 +406,7 @@ end local function test_config(config) assert(type(config) == "table", "config not a table") - for _, field in ipairs({ "processor", "htif", "clint", "flash_drive", "ram", "rom" }) do + for _, field in ipairs({ "processor", "htif", "clint", "flash_drive", "ram", "dtb" }) do assert(config[field] and type(config[field]) == "table", "invalid field " .. field) end for i = 1, 31 do @@ -423,11 +423,11 @@ local function test_config(config) local ram = config.ram assert(type(ram.length) == "number", "invalid ram.length") assert(ram.image_filename == nil or type(ram.image_filename) == "string", "invalid ram.image_filename") - local rom = config.rom - assert(rom.image_filename == nil or type(rom.image_filename) == "string", "invalid rom.image_filename") - assert(rom.bootargs == nil or type(rom.bootargs) == "string", "invalid rom.bootargs") - assert(rom.init == nil or type(rom.init) == "string", "invalid rom.init") - assert(rom.entrypoint == nil or type(rom.entrypoint) == "string", "invalid rom.entrypoint") + local dtb = config.dtb + assert(dtb.image_filename == nil or type(dtb.image_filename) == "string", "invalid dtb.image_filename") + assert(dtb.bootargs == nil or type(dtb.bootargs) == "string", "invalid dtb.bootargs") + assert(dtb.init == nil or type(dtb.init) == "string", "invalid dtb.init") + assert(dtb.entrypoint == nil or type(dtb.entrypoint) == "string", "invalid dtb.entrypoint") local tlb = config.tlb assert(tlb.image_filename == nil or type(tlb.image_filename) == "string", "invalid tlb.image_filename") for _, f in ipairs(config.flash_drive) do diff --git a/src/tests/machine-test.lua b/src/tests/machine-test.lua index c028b66c1..77ee8148d 100755 --- a/src/tests/machine-test.lua +++ b/src/tests/machine-test.lua @@ -152,7 +152,7 @@ end local pmas_file_names = { "0000000000000000--0000000000001000.bin", -- shadow state - "0000000000001000--000000000000f000.bin", -- rom + "0000000000001000--000000000000f000.bin", -- dtb "0000000000010000--0000000000001000.bin", -- shadow pmas "0000000000020000--0000000000006000.bin", -- shadow tlb "0000000002000000--00000000000c0000.bin", -- clint @@ -162,7 +162,7 @@ local pmas_file_names = { local pmas_file_names_with_uarch = { "0000000000000000--0000000000001000.bin", -- shadow state - "0000000000001000--000000000000f000.bin", -- rom + "0000000000001000--000000000000f000.bin", -- dtb "0000000000010000--0000000000001000.bin", -- shadow pmas "0000000000020000--0000000000006000.bin", -- shadow tlb "0000000002000000--00000000000c0000.bin", -- clint @@ -508,9 +508,10 @@ test_util.make_do_test(build_machine, machine_type, { image_filename = linux_image, length = 0x4000000, }, - rom = { - bootargs = "console=hvc0 rootfstype=ext2 root=/dev/pmem0 rw quiet swiotlb=noforce single=yes splash=no " - .. "-- mount /dev/pmem1 /mnt && cat /mnt/etc/issue | dd status=none of=/dev/pmem2", + dtb = { + bootargs = "console=hvc0 rootfstype=ext2 root=/dev/pmem0 rw quiet swiotlb=noforce single=yes splash=no", + init = "mount /dev/pmem1 /mnt", + entrypoint = "cat /proc/device-tree/cartesi/name | dd status=none of=/dev/pmem2", }, flash_drive = { { @@ -530,9 +531,9 @@ test_util.make_do_test(build_machine, machine_type, { machine:run(MAX_MCYCLE) assert(machine:read_iflags_H(), "machine should be halted") - local expected_issue = "Welcome to Cartesi" - local flash_data = machine:read_memory(0xa0000000000000, #expected_issue) - assert(flash_data == expected_issue, "unexpected flash drive output") + local expected_data = "cartesi" + local flash_data = machine:read_memory(0xa0000000000000, #expected_data) + assert(flash_data == expected_data, "unexpected flash drive output") end) print("\n\n check for relevant register values after step 1") diff --git a/src/tests/util.lua b/src/tests/util.lua index 29a6ede90..77385bdd5 100644 --- a/src/tests/util.lua +++ b/src/tests/util.lua @@ -314,7 +314,7 @@ end -- PMA defs local PMA_SHADOW_STATE_LENGTH = 0x1000 local PMA_SHADOW_PMAS_LENGTH = 0x1000 -local PMA_ROM_LENGTH = 0xF000 +local PMA_DTB_LENGTH = 0xF000 local PMA_SHADOW_TLB_START = 0x20000 local PMA_SHADOW_TLB_LENGTH = 0x6000 local PMA_CLINT_START = 0x2000000 @@ -338,7 +338,7 @@ local calculate_region_hash_2 = test_util.calculate_region_hash_2 -- and calculate root hash of the machine function test_util.calculate_emulator_hash(test_path, pmas_files) local shadow_state = test_util.parse_pma_file(test_path .. pmas_files[1]) - local rom = test_util.parse_pma_file(test_path .. pmas_files[2]) + local dtb = test_util.parse_pma_file(test_path .. pmas_files[2]) local shadow_pmas = test_util.parse_pma_file(test_path .. pmas_files[3]) local shadow_tlb = test_util.parse_pma_file(test_path .. pmas_files[4]) local clint = test_util.parse_pma_file(test_path .. pmas_files[5]) @@ -347,16 +347,16 @@ function test_util.calculate_emulator_hash(test_path, pmas_files) local uarch_ram = "" if pmas_files[8] then uarch_ram = test_util.parse_pma_file(test_path .. pmas_files[8]) end - local shadow_rom = shadow_state .. rom .. shadow_pmas + local shadow_dtb = shadow_state .. dtb .. shadow_pmas - local shadow_rom_hash_size_log2 = ceil_log2(PMA_SHADOW_STATE_LENGTH + PMA_ROM_LENGTH + PMA_SHADOW_PMAS_LENGTH) - local shadow_rom_space_hash = calculate_region_hash( - shadow_rom, - (#shadow_rom + PMA_PAGE_SIZE - 1) // PMA_PAGE_SIZE, + local shadow_dtb_hash_size_log2 = ceil_log2(PMA_SHADOW_STATE_LENGTH + PMA_DTB_LENGTH + PMA_SHADOW_PMAS_LENGTH) + local shadow_dtb_space_hash = calculate_region_hash( + shadow_dtb, + (#shadow_dtb + PMA_PAGE_SIZE - 1) // PMA_PAGE_SIZE, PMA_PAGE_SIZE_LOG2, - shadow_rom_hash_size_log2 + shadow_dtb_hash_size_log2 ) - shadow_rom_space_hash = extend_region_hash(shadow_rom_space_hash, 0, shadow_rom_hash_size_log2, 17) + shadow_dtb_space_hash = extend_region_hash(shadow_dtb_space_hash, 0, shadow_dtb_hash_size_log2, 17) local tlb_size_log2 = ceil_log2(PMA_SHADOW_TLB_LENGTH) local tlb_space_hash = calculate_region_hash( @@ -367,20 +367,20 @@ function test_util.calculate_emulator_hash(test_path, pmas_files) ) tlb_space_hash = extend_region_hash(tlb_space_hash, PMA_SHADOW_TLB_START, tlb_size_log2, 17) - local shadow_rom_tlb_space_hash = cartesi.keccak(shadow_rom_space_hash, tlb_space_hash) -- 18 - shadow_rom_tlb_space_hash = extend_region_hash(shadow_rom_tlb_space_hash, 0, 18, 25) + local shadow_dtb_tlb_space_hash = cartesi.keccak(shadow_dtb_space_hash, tlb_space_hash) -- 18 + shadow_dtb_tlb_space_hash = extend_region_hash(shadow_dtb_tlb_space_hash, 0, 18, 25) local clint_size_log2 = ceil_log2(PMA_CLINT_LENGTH) local clint_space_hash = calculate_region_hash(clint, (#clint + PMA_PAGE_SIZE - 1) // PMA_PAGE_SIZE, PMA_PAGE_SIZE_LOG2, clint_size_log2) clint_space_hash = extend_region_hash(clint_space_hash, PMA_CLINT_START, clint_size_log2, 25) - local shadow_rom_tlb_clint_hash = cartesi.keccak(shadow_rom_tlb_space_hash, clint_space_hash) -- 26 - shadow_rom_tlb_clint_hash = extend_region_hash(shadow_rom_tlb_clint_hash, 0, 26, 29) + local shadow_dtb_tlb_clint_hash = cartesi.keccak(shadow_dtb_tlb_space_hash, clint_space_hash) -- 26 + shadow_dtb_tlb_clint_hash = extend_region_hash(shadow_dtb_tlb_clint_hash, 0, 26, 29) local htif_size_log2 = ceil_log2(#htif) local htif_space_hash = calculate_region_hash_2(PMA_HTIF_START, htif, htif_size_log2, 29) - local left = cartesi.keccak(shadow_rom_tlb_clint_hash, htif_space_hash) -- 30 + local left = cartesi.keccak(shadow_dtb_tlb_clint_hash, htif_space_hash) -- 30 local uarch_ram_space_hash = test_util.fromhex(zero_keccak_hash_table[30]) if #uarch_ram > 0 then local uarch_ram_size_log2 = ceil_log2(#uarch_ram) diff --git a/tools/benchmarks/run-benchmarks.lua b/tools/benchmarks/run-benchmarks.lua index 18489cc21..40bb856d3 100755 --- a/tools/benchmarks/run-benchmarks.lua +++ b/tools/benchmarks/run-benchmarks.lua @@ -88,7 +88,7 @@ local function build_machine(exec_args) marchid = -1, mvendorid = -1, }, - rom = { + dtb = { bootargs = ( "console=hvc0 rootfstype=ext2 root=/dev/pmem0 rw " .. "quiet mtdparts=flash.0:-(root) -- " diff --git a/tools/gdb/gdb.md b/tools/gdb/gdb.md index 4cae641bb..c45c040b5 100644 --- a/tools/gdb/gdb.md +++ b/tools/gdb/gdb.md @@ -11,9 +11,9 @@ This is a documentation on how to use GDB to debug privileged code with the Cart ## How to get debug information to work -1. You need to compile your rom, kernel or test that you would like to debug with +1. You need to compile your kernel or test that you would like to debug with debug information into a binary ELF file (using `.bin` will not work). -2. Connect GDB with `riscv64-cartesi-linux-gnu-gdb -ex "set arch riscv:rv64" -ex "target remote 127.0.0.1:1234" ` where `` is your rom, kernel or test ELF file compiled with debug information. +2. Connect GDB with `riscv64-cartesi-linux-gnu-gdb -ex "set arch riscv:rv64" -ex "target remote 127.0.0.1:1234" ` where `` is your kernel or test ELF file compiled with debug information. 3. To view C/C++ code, make sure you run GDB client in a directory that is able to access the source files relative to the ELF binary being debugged. ## GDB commands