From ca4b54393e7e63b00faf8011d4559734b8b8af05 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 9 Oct 2024 16:02:52 -0300 Subject: [PATCH] feat: add new shorthands in cartesi machine cli -m shorthand for --ram-length -k shorthand for --ram-image -q shorthand for --quiet --no-init-splash -r/--rootfs shorthand for --flash-drive=label:root,filename: -S/--shared-rootfs shorthand for setting rootfs as shared --- src/cartesi-machine.lua | 159 +++++++++++++++++++++++++++++----------- 1 file changed, 116 insertions(+), 43 deletions(-) diff --git a/src/cartesi-machine.lua b/src/cartesi-machine.lua index 1e4e8c908..8d74e3118 100755 --- a/src/cartesi-machine.lua +++ b/src/cartesi-machine.lua @@ -71,13 +71,13 @@ where options are: DON'T USE THIS OPTION IN PRODUCTION - --ram-image= + -k= or --ram-image= name of file containing RAM image (default: "linux.bin"). --no-ram-image forget settings for RAM image. - --ram-length= + -m= or --ram-length= set RAM length. --dtb-image= @@ -93,6 +93,13 @@ where options are: --no-root-flash-drive clear default root flash drive and associated bootargs parameters. + -r= or --rootfs= + shorthand for --flash-drive=label:root,filename: + + -S or --shared-rootfs + target modifications to root flash drive modify image file as well. + by default, image files are not modified and changes are lost. + --flash-drive=:[,:[,...]...] defines a new flash drive, or modify an existing flash drive definition. flash drives appear as /dev/pmem[0-7]. @@ -297,7 +304,7 @@ where options are: NON REPRODUCIBLE OPTION, DON'T USE THIS OPTION IN PRODUCTION - -v or --volume=: + -v=... or --volume=: like --virtio-9p, but also appends init commands to auto mount the host directory in the guest directory. mount tags are incrementally set to "vfs0", "vfs1", ... @@ -478,6 +485,9 @@ where options are: --no-init-splash don't show cartesi machine splash on boot. + -q + shorthand for --quiet --no-init-splash. + -u= or --user= appends to init the user who should execute the entrypoint command. when omitted, the user is set to "dapp" by rootfs init script. @@ -808,6 +818,40 @@ local function handle_interactive(all) return true end +local function handle_flashdrive(all, f) + assert(f.label, "missing flash drive label in " .. all) + f.image_filename = f.filename + f.filename = nil + if f.image_filename == true then f.image_filename = "" end + assert(not f.shared or f.shared == true, "invalid flash drive shared value in " .. all) + if f.mount == nil then + -- mount only if there is a file backing + if f.image_filename and f.image_filename ~= "" then + f.mount = "/mnt/" .. f.label + else + f.mount = false + end + elseif f.mount == "true" then + f.mount = "/mnt/" .. f.label + elseif f.mount == "false" then + f.mount = false + end + if f.start then f.start = assert(util.parse_number(f.start), "invalid flash drive start in " .. all) end + if f.length then f.length = assert(util.parse_number(f.length), "invalid flash drive length in " .. all) end + local d = f.label + if not flash_image_filename[d] then + flash_label_order[#flash_label_order + 1] = d + flash_image_filename[d] = "" + end + flash_image_filename[d] = f.image_filename or flash_image_filename[d] + flash_start[d] = f.start or flash_start[d] + flash_length[d] = f.length or flash_length[d] + flash_shared[d] = f.shared or flash_shared[d] + flash_mount[d] = f.mount or flash_mount[d] + flash_user[d] = f.user or flash_user[d] + return true +end + -- List of supported options -- Options are processed in order -- For each option, @@ -906,6 +950,14 @@ local options = { return true end, }, + { + "^%-m%=(.+)$", + function(n) + if not n then return false end + ram_length = assert(util.parse_number(n), "invalid RAM length " .. n) + return true + end, + }, { "^%-%-ram%-length%=(.+)$", function(n) @@ -914,6 +966,14 @@ local options = { return true end, }, + { + "^%-k%=(.*)$", + function(o) + if not o or #o < 1 then return false end + ram_image_filename = o + return true + end, + }, { "^%-%-ram%-image%=(.*)$", function(o) @@ -1016,50 +1076,54 @@ local options = { return true end, }, + { + "^(%-r%=(.+))$", + function(all, o) + if not o then return false end + return handle_flashdrive(all, { label = "root", filename = o }) + end, + }, + { + "^(%-%-rootfs%=(.+))$", + function(all, o) + if not o then return false end + return handle_flashdrive(all, { label = "root", filename = o, shared = flash_shared.root }) + end, + }, + { + "^%-S$", + function(all) + if not all then return false end + assert(flash_image_filename.root and flash_label_order[1] == "root", "no root flash drive to be shared") + flash_shared.root = true + return true + end, + }, + { + "^%-%-shared%-rootfs$", + function(all) + if not all then return false end + assert(flash_image_filename.root and flash_label_order[1] == "root", "no root flash drive to be shared") + flash_shared.root = true + return true + end, + }, { "^(%-%-flash%-drive%=(.+))$", function(all, opts) if not opts then return false end - local f = util.parse_options(opts, { - label = true, - filename = true, - shared = true, - mount = true, - user = true, - length = true, - start = true, - }) - assert(f.label, "missing flash drive label in " .. all) - f.image_filename = f.filename - f.filename = nil - if f.image_filename == true then f.image_filename = "" end - assert(not f.shared or f.shared == true, "invalid flash drive shared value in " .. all) - if f.mount == nil then - -- mount only if there is a file backing - if f.image_filename and f.image_filename ~= "" then - f.mount = "/mnt/" .. f.label - else - f.mount = false - end - elseif f.mount == "true" then - f.mount = "/mnt/" .. f.label - elseif f.mount == "false" then - f.mount = false - end - if f.start then f.start = assert(util.parse_number(f.start), "invalid flash drive start in " .. all) end - if f.length then f.length = assert(util.parse_number(f.length), "invalid flash drive length in " .. all) end - local d = f.label - if not flash_image_filename[d] then - flash_label_order[#flash_label_order + 1] = d - flash_image_filename[d] = "" - end - flash_image_filename[d] = f.image_filename or flash_image_filename[d] - flash_start[d] = f.start or flash_start[d] - flash_length[d] = f.length or flash_length[d] - flash_shared[d] = f.shared or flash_shared[d] - flash_mount[d] = f.mount or flash_mount[d] - flash_user[d] = f.user or flash_user[d] - return true + return handle_flashdrive( + all, + util.parse_options(opts, { + label = true, + filename = true, + shared = true, + mount = true, + user = true, + length = true, + start = true, + }) + ) end, }, { @@ -1248,6 +1312,15 @@ local options = { return true end, }, + { + "%-q", + function(all) + if not all then return false end + stderr = function() end + init_splash = false + return true + end, + }, { "^%-%-log%-step%-uarch$", function(all)