[RFC PATCH 3/8] utils: Add plugin_commands parameter

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue Dec 18 15:19:48 AEDT 2018


This points to an optional JSON file providing detailed command
examples. The format is an array of command objects which define a
platform name if appropriate, command name, command executable, argument
format string, and an array of arguments containing name and arguments.
At the moment three argument types are recognised: FieldString,
FieldInt, and FieldFloat (string, int64_t, and double respectively).
For example:

[
        {
                "platform":     "any",
                "name":         "Set NVRAM parameter",
                "cmd":          "nvram",
                "arg_fmt":      "-p {} --update-config {}={}",
                "args": [
                        {
                                "name":         "Partition",
                                "arg": { "FieldString": "common" }
                        },
                        {
                                "name":         "Parameter",
                                "arg": { "FieldString": "some" }
                        },
                        {
                                "name":         "Value",
                                "arg": { "FieldString": "value" }
                        }
                ],
                "help":         "Example: Set an NVRAM parameter"
        },
        {
                "platform":     "witherspoon",
                "name":         "Foo Memory Allocation",
                "cmd":          "nvram",
                "arg_fmt":      "-p {} --update-config foo_mem_amt={}",
                "args": [
                        {
                                "name":         "Partition",
                                "arg": { "FieldString": "ibm,skiboot" }
                        },
                        {
                                "name":         "Amount (MB)",
                                "arg": { "FieldInt": 0 }
                        }
                ],
                "help":         "Memory to be allocated for some feature"
        }
]

Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 discover/user-event.c | 2 ++
 utils/pb-plugin       | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/discover/user-event.c b/discover/user-event.c
index d3d4a5e8..cbbec1a0 100644
--- a/discover/user-event.c
+++ b/discover/user-event.c
@@ -601,6 +601,8 @@ static int user_event_plugin(struct user_event *uev, struct event *event)
 	opt->date = talloc_strdup(opt, event_get_param(event, "date"));
 	opt->plugin_file = talloc_strdup(opt,
 			event_get_param(event, "source_file"));
+	opt->command_file = talloc_strdup(opt,
+			event_get_param(event, "plugin_commands"));
 
 	executables = talloc_strdup(opt, event_get_param(event, "executables"));
 	if (!executables) {
diff --git a/utils/pb-plugin b/utils/pb-plugin
index a42d0515..b162f4b9 100755
--- a/utils/pb-plugin
+++ b/utils/pb-plugin
@@ -2,7 +2,7 @@
 
 __dest=/
 __pb_mount_dir=/var/petitboot/mnt/dev/
-plugin_abi=1
+plugin_abi=2
 plugin_ext=pb-plugin
 plugin_meta=pb-plugin.conf
 plugin_meta_dir=etc/preboot-plugins/
@@ -235,6 +235,7 @@ do_install()
 		name=$PLUGIN_NAME id=$PLUGIN_ID version=$PLUGIN_VERSION \
 		vendor=$PLUGIN_VENDOR vendor_id=$PLUGIN_VENDOR_ID \
 		date=$PLUGIN_DATE executables="$PLUGIN_EXECUTABLES" \
+		plugin_commands="${__dest}/${PLUGIN_COMMANDS}" \
 		source_file=$url installed="yes"
 
 	echo "Plugin installed"
@@ -364,6 +365,10 @@ shell environment (eg, /usr/bin/my-raid-config).
 If multiple executables are provided, separate with a space.
 EOF
 	read executables
+cat <<EOF
+Enter a command definition JSON file (optional)
+EOF
+	read plugin_commands
 
 	date=$(date +%Y-%m-%d)
 
@@ -379,6 +384,7 @@ PLUGIN_ID='$pluginshortname'
 PLUGIN_VERSION='$version'
 PLUGIN_DATE='$date'
 PLUGIN_EXECUTABLES='$executables'
+PLUGIN_COMMANDS='${plugin_commands}'
 EOF
 
 }
-- 
2.20.0



More information about the Petitboot mailing list