Skip to content

Commit

Permalink
Auto detect flash drive length in cartesi-machine.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jul 11, 2023
1 parent de77e6a commit 6e8950a
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions src/cartesi-machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1097,14 +1097,6 @@ for _, a in ipairs(arg) do
end
end

local function get_file_length(filename)
local file = io.open(filename, "rb")
if not file then return nil end
local size = file:seek("end") -- get file size
file:close()
return size
end

local function print_root_hash(machine, print)
(print or stderr)("%u: %s\n", machine:read_mcycle(), util.hexhash(machine:get_root_hash()))
end
Expand Down Expand Up @@ -1246,35 +1238,6 @@ local function store_machine_config(config, output)
output("}\n")
end

local function resolve_flash_lengths(label_order, image_filename, length)
for _, label in ipairs(label_order) do
local filename = image_filename[label]
local len = length[label]
local filelen
if filename and filename ~= "" then
filelen = assert(
get_file_length(filename),
string.format("unable to find length of flash drive '%s' image file '%s'", label, filename)
)
if len and len ~= filelen then
error(
string.format(
"flash drive '%s' length (%u) and image file '%s' length (%u) do not match",
label,
len,
filename,
filelen
)
)
else
length[label] = filelen
end
elseif not len then
error(string.format("flash drive '%s' nas no length or image file", label))
end
end
end

local function resolve_flash_starts(label_order, start)
local auto_start = 1 << 55
if next(start) == nil then
Expand Down Expand Up @@ -1370,7 +1333,6 @@ elseif load_dir then
main_machine = create_machine(load_dir, runtime)
else
-- Resolve all device starts and lengths
resolve_flash_lengths(flash_label_order, flash_image_filename, flash_length)
resolve_flash_starts(flash_label_order, flash_start)

-- Build machine config
Expand Down Expand Up @@ -1404,7 +1366,7 @@ else
image_filename = flash_image_filename[label],
shared = flash_shared[label],
start = flash_start[label],
length = flash_length[label],
length = flash_length[label] or -1,
}
mtdparts[#mtdparts + 1] = string.format("flash.%d:-(%s)", i - 1, label)
end
Expand Down

0 comments on commit 6e8950a

Please sign in to comment.