]> git.ozlabs.org Git - petitboot/commitdiff
pb-event: Add 'boot' user event
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Fri, 22 Apr 2016 04:20:49 +0000 (14:20 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Fri, 6 May 2016 03:57:30 +0000 (13:57 +1000)
Add a user event to send a boot command to the discover server.
The format of the boot command is similar to the add command, eg:

pb-event boot@eth0 image="http://host/image" initrd="http://host/initrd"

and also recognises "id", "dtb", and "args" arguments.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/event.c
discover/event.h
discover/user-event.c
utils/pb-event.c

index 79323788368d8c20b5f4f67702bd68337a9fe371..8b3a1ab8b344ca2662a97649b5113c71d173047c 100644 (file)
@@ -53,6 +53,8 @@ static int event_parse_ad_header(char *buf, int len, enum event_action *action,
                *action = EVENT_ACTION_CONF;
        else if (streq(buf, "dhcp"))
                *action = EVENT_ACTION_DHCP;
+       else if (streq(buf, "boot"))
+               *action = EVENT_ACTION_BOOT;
        else {
                pb_log("%s: unknown action: %s\n", __func__, buf);
                return -1;
index 8dee13b560f689cacc46aeb3cbe5cdcc1da233b9..35c07679db17eeb31bd75d533ef4b1ac9bf896ab 100644 (file)
@@ -13,6 +13,7 @@ enum event_action {
        EVENT_ACTION_URL,
        EVENT_ACTION_CONF,
        EVENT_ACTION_DHCP,
+       EVENT_ACTION_BOOT,
        EVENT_ACTION_MAX,
 };
 
index 8926458905ef2b076b965270b31a5adefbb6fa77..15d9c87bebc2213a1cb265b532999921f0e92925 100644 (file)
@@ -58,6 +58,8 @@ static const char *event_action_name(enum event_action action)
                return "url";
        case EVENT_ACTION_DHCP:
                return "dhcp";
+       case EVENT_ACTION_BOOT:
+               return "boot";
        default:
                break;
        }
@@ -444,6 +446,24 @@ static int user_event_url(struct user_event *uev, struct event *event)
        return 0;
 }
 
+static int user_event_boot(struct user_event *uev, struct event *event)
+{
+       struct device_handler *handler = uev->handler;
+       struct boot_command *cmd = talloc(handler, struct boot_command);
+
+       cmd->option_id = talloc_strdup(cmd, event_get_param(event, "id"));
+       cmd->boot_image_file = talloc_strdup(cmd, event_get_param(event, "image"));
+       cmd->initrd_file = talloc_strdup(cmd, event_get_param(event, "initrd"));
+       cmd->dtb_file = talloc_strdup(cmd, event_get_param(event, "dtb"));
+       cmd->boot_args = talloc_strdup(cmd, event_get_param(event, "args"));
+
+       device_handler_boot(handler, cmd);
+
+       talloc_free(cmd);
+
+       return 0;
+}
+
 static void user_event_handle_message(struct user_event *uev, char *buf,
        int len)
 {
@@ -476,6 +496,9 @@ static void user_event_handle_message(struct user_event *uev, char *buf,
        case EVENT_ACTION_DHCP:
                result = user_event_dhcp(uev, event);
                break;
+       case EVENT_ACTION_BOOT:
+               result = user_event_boot(uev, event);
+               break;
        default:
                break;
        }
index a1affe5243cc4bf270bef92b87fb7595fb97b3d5..572eb16c36be36d1302bfc7ccfbec5d2d3de0f41 100644 (file)
@@ -55,7 +55,7 @@ static void print_usage(void)
 "       Events can be read from stdin, or provided on the command line.\n"
 "       User events must have the following format:\n"
 "\n"
-"         (add|remove)@device-id [name=value] [image=value] [args=value]\n"
+"         (add|remove|boot)@device-id [name=value] [image=value] [args=value]\n"
 "\n"
 "       When read from stdin, components are separated by NUL chars\n"
 "\n"