diff --git a/lib/grpc-interfaces b/lib/grpc-interfaces index cba7c3f1c..4ec6e6620 160000 --- a/lib/grpc-interfaces +++ b/lib/grpc-interfaces @@ -1 +1 @@ -Subproject commit cba7c3f1c53b83bee83d8a1e5a1074591279220f +Subproject commit 4ec6e6620abce44048b9a8493124683ef15e0731 diff --git a/lib/machine-emulator-defines b/lib/machine-emulator-defines index fc2473ac7..c30dfb2bd 160000 --- a/lib/machine-emulator-defines +++ b/lib/machine-emulator-defines @@ -1 +1 @@ -Subproject commit fc2473ac74d485b40f53f45f874b67abcb6843af +Subproject commit c30dfb2bdfe994396f3e6d8f173b197c1b39785c diff --git a/src/Makefile b/src/Makefile index d41510f49..e08f55f12 100644 --- a/src/Makefile +++ b/src/Makefile @@ -314,7 +314,7 @@ LIBCARTESI_OBJS:= \ pma-driver.o \ clint.o \ clint-factory.o \ - rom.o \ + dtb.o \ tty.o \ htif.o \ htif-factory.o \ @@ -568,7 +568,7 @@ REMOTE_CARTESI_MACHINE_OBJS:= \ pma-driver.o \ clint.o \ clint-factory.o \ - rom.o \ + dtb.o \ tty.o \ htif.o \ htif-factory.o \ @@ -598,7 +598,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 a1b3702b6..d8192ddd3 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 a666619f5..d07840464 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-dtb-bootargs clear default bootargs. - --append-rom-bootargs= + --append-dtb-bootargs= append to bootargs. --no-root-flash-drive @@ -352,7 +352,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) @@ -401,8 +400,8 @@ 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/mtdblock0 rw quiet \z +local dtb_image_filename = nil +local dtb_bootargs = "console=hvc0 rootfstype=ext2 root=/dev/mtdblock0 rw quiet \z swiotlb=noforce init=/opt/cartesi/bin/init random.trust_bootloader=on" local rollup local uarch @@ -411,7 +410,7 @@ 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 append_dtb_bootargs = "" local htif_no_console_putchar = false local htif_console_getchar = false local htif_yield_automatic = false @@ -508,7 +507,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 @@ -524,26 +523,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%-dtb%-bootargs$", function(all) if not all then return false end - rom_bootargs = "" + dtb_bootargs = "" return true end, }, { - "^%-%-append%-rom%-bootargs%=(.*)$", + "^%-%-append%-dtb%-bootargs%=(.*)$", function(o) if not o or #o < 1 then return false end - append_rom_bootargs = o + append_dtb_bootargs = o return true end, }, @@ -825,7 +824,7 @@ local options = { flash_length.root = nil flash_shared.root = nil table.remove(flash_label_order, 1) - rom_bootargs = "console=hvc0" + dtb_bootargs = "console=hvc0" return true end, }, @@ -1163,12 +1162,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") @@ -1342,9 +1341,9 @@ else marchid = -1, mvendorid = -1, }, - rom = { - image_filename = rom_image_filename, - bootargs = rom_bootargs, + dtb = { + image_filename = dtb_image_filename, + bootargs = dtb_bootargs, }, ram = { image_filename = ram_image_filename, @@ -1370,13 +1369,13 @@ else mtdparts[#mtdparts + 1] = string.format("flash.%d:-(%s)", i - 1, label) end if #mtdparts > 0 then - config.rom.bootargs = append(config.rom.bootargs, "mtdparts=" .. table.concat(mtdparts, ";")) + config.dtb.bootargs = append(config.dtb.bootargs, "mtdparts=" .. table.concat(mtdparts, ";")) end - config.rom.bootargs = append(append(config.rom.bootargs, append_rom_bootargs), quiet and " splash=no" or "") + config.dtb.bootargs = append(append(config.dtb.bootargs, append_dtb_bootargs), quiet and " splash=no" or "") if #exec_arguments > 0 then - config.rom.bootargs = append(config.rom.bootargs, "-- " .. table.concat(exec_arguments, " ")) + config.dtb.bootargs = append(config.dtb.bootargs, "-- " .. table.concat(exec_arguments, " ")) end if load_config then diff --git a/src/clua-machine-util.cpp b/src/clua-machine-util.cpp index a49272e5f..76c3ff26e 100644 --- a/src/clua-machine-util.cpp +++ b/src/clua-machine-util.cpp @@ -770,10 +770,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); @@ -905,8 +905,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) { @@ -942,12 +942,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"); @@ -1206,7 +1206,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 cf1a800af..f09a6fb8a 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 88% rename from src/rom.cpp rename to src/dtb.cpp index 7104c0e73..c66b408da 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(); @@ -217,7 +203,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 268a29dd8..5bf0fa57e 100644 --- a/src/rom.h +++ b/src/dtb.h @@ -14,11 +14,11 @@ // with this program (see COPYING). If not, see . // -#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 04484088e..5cf5c18d3 100644 --- a/src/i-virtual-machine.h +++ b/src/i-virtual-machine.h @@ -631,8 +631,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 9b3fe8c29..048347e2a 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -5412,7 +5412,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 5ef64354e..e4ebd1215 100644 --- a/src/json-util.cpp +++ b/src/json-util.cpp @@ -780,7 +780,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; } @@ -790,10 +790,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 @@ -1012,7 +1012,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); @@ -1126,7 +1126,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}, {"image_filename", config.image_filename}, @@ -1191,7 +1191,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 3803a19c1..0d22c4efd 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 867c5360b..d13236f2b 100644 --- a/src/jsonrpc-discover.json +++ b/src/jsonrpc-discover.json @@ -1451,8 +1451,8 @@ ] }, - "ROMConfig": { - "title": "ROMConfig", + "DTBConfig": { + "title": "DTBConfig", "type": "object", "properties": { "bootargs": { @@ -1607,8 +1607,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 cc70975aa..0808d5b7b 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -184,21 +184,21 @@ 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.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.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.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.image_filename = convert_to_c(cpp_config.image_filename); + return new_c_dtb_config; } // ---------------------------------------------- @@ -383,7 +383,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); @@ -412,7 +412,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); @@ -702,8 +702,8 @@ 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->dtb.image_filename; + delete[] config->dtb.bootargs; 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 88e9c3682..7c411e89f 100644 --- a/src/machine-c-api.h +++ b/src/machine-c-api.h @@ -191,11 +191,11 @@ 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 *image_filename; ///< ROM image file -} cm_rom_config; +} cm_dtb_config; /// \brief Memory range configuration typedef struct { // NOLINT(modernize-use-using) @@ -264,7 +264,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 b75f26448..2eac08c05 100644 --- a/src/machine-config.cpp +++ b/src/machine-config.cpp @@ -43,7 +43,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 55e86371e..c05986fcd 100644 --- a/src/machine-config.h +++ b/src/machine-config.h @@ -73,10 +73,10 @@ struct ram_config final { // NOLINT(bugprone-exception-escape) std::string image_filename{}; ///< RAM image file name }; -/// \brief ROM state configuration -struct rom_config final { // NOLINT(bugprone-exception-escape) +/// \brief DTB state configuration +struct dtb_config final { std::string bootargs{}; ///< Bootargs to pass to kernel - std::string image_filename{}; ///< ROM image file + std::string image_filename{}; ///< DTB image file }; /// \brief Memory range configuration @@ -129,7 +129,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 50748e4d3..c48271340 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 2b913da3c..b2d1cb0df 100644 --- a/src/machine.h +++ b/src/machine.h @@ -59,7 +59,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 70091a660..06e5a05d1 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 65c37fc39..ba22f7818 100644 --- a/src/protobuf-util.cpp +++ b/src/protobuf-util.cpp @@ -44,9 +44,9 @@ 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_image_filename(c.rom.image_filename); + auto *proto_dtb = proto_c->mutable_dtb(); + proto_dtb->set_bootargs(c.dtb.bootargs); + 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); @@ -813,9 +813,9 @@ 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.image_filename = proto_c.rom().image_filename(); + if (proto_c.has_dtb()) { + c.dtb.bootargs = proto_c.dtb().bootargs(); + 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 1c0fdf67d..4749d3d63 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 3aa049589..ac9e21a0c 100644 --- a/src/test-machine-c-api.cpp +++ b/src/test-machine-c-api.cpp @@ -37,7 +37,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 @@ -215,8 +215,8 @@ 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.image_filename = new_cstr(source->rom.image_filename); + target->dtb.bootargs = new_cstr(source->dtb.bootargs); + 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]{}; @@ -240,17 +240,12 @@ 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->dtb.image_filename; + delete[] config->dtb.bootargs; 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; @@ -280,27 +275,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); @@ -312,43 +287,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); @@ -360,26 +322,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{}; @@ -393,7 +355,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; @@ -408,7 +370,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(); @@ -455,7 +417,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.image_filename, rhs.image_filename) == 0)); } @@ -473,7 +435,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)); } @@ -1473,7 +1435,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(); @@ -1522,7 +1484,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 @@ -1543,7 +1505,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 @@ -1909,7 +1871,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}; @@ -2534,7 +2496,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 74f2ccd92..f18b82fe8 100644 --- a/src/test-utils.h +++ b/src/test-utils.h @@ -339,7 +339,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]); @@ -350,41 +350,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 9d84198f3..7b89ee608 100755 --- a/src/tests/machine-bind.lua +++ b/src/tests/machine-bind.lua @@ -269,7 +269,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 @@ -432,7 +432,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 @@ -449,9 +449,9 @@ 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") + 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") 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 990ba59d9..51caf6bcc 100755 --- a/src/tests/machine-test.lua +++ b/src/tests/machine-test.lua @@ -153,7 +153,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 @@ -163,7 +163,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 @@ -509,7 +509,7 @@ test_util.make_do_test(build_machine, machine_type, { image_filename = linux_image, length = 0x4000000, }, - rom = { + dtb = { bootargs = "console=hvc0 rootfstype=ext2 root=/dev/mtdblock0 rw quiet swiotlb=noforce single=yes splash=no " .. "init=/opt/cartesi/bin/init " .. "mtdparts=flash.0:-(root);flash.1:-(input);flash.2:-(output) -- " @@ -533,9 +533,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 3dddba074..0677adfec 100644 --- a/src/tests/util.lua +++ b/src/tests/util.lua @@ -327,7 +327,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 @@ -351,7 +351,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]) @@ -360,16 +360,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( @@ -380,20 +380,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 67698058a..f05d7b7d7 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/mtdblock0 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