return len;
}
+int pb_protocol_boot_len(const struct boot_command *boot)
+{
+ return 4 + optional_strlen(boot->option_id) +
+ 4 + optional_strlen(boot->boot_image_file) +
+ 4 + optional_strlen(boot->initrd_file) +
+ 4 + optional_strlen(boot->boot_args);
+}
+
int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len)
{
struct boot_option *opt;
return 0;
}
+int pb_protocol_serialise_boot_command(const struct boot_command *boot,
+ char *buf, int buf_len)
+{
+ char *pos = buf;
+
+ pos += pb_protocol_serialise_string(pos, boot->option_id);
+ pos += pb_protocol_serialise_string(pos, boot->boot_image_file);
+ pos += pb_protocol_serialise_string(pos, boot->initrd_file);
+ pos += pb_protocol_serialise_string(pos, boot->boot_args);
+
+ assert(pos <= buf + buf_len);
+ (void)buf_len;
+
+ return 0;
+}
+
int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
{
int total_len, rc;
void pb_protocol_dump_device(const struct device *dev, const char *text,
FILE *stream);
int pb_protocol_device_len(const struct device *dev);
+int pb_protocol_boot_len(const struct boot_command *boot);
int pb_protocol_device_cmp(const struct device *a, const struct device *b);
int pb_protocol_boot_option_cmp(const struct boot_option *a,
const struct pb_protocol_message *message);
int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len);
+int pb_protocol_serialise_boot_command(const struct boot_command *boot,
+ char *buf, int buf_len);
int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
return client->devices[index];
}
+
+static void create_boot_command(struct boot_command *command,
+ const struct device *device __attribute__((unused)),
+ const struct boot_option *boot_option,
+ const struct pb_boot_data *data)
+{
+
+ command->option_id = boot_option->id;
+ command->boot_image_file = data->image;
+ command->initrd_file = data->initrd;
+ command->boot_args = data->args;
+}
+
+int discover_client_boot(struct discover_client *client,
+ const struct device *device,
+ const struct boot_option *boot_option,
+ const struct pb_boot_data *data)
+{
+ struct pb_protocol_message *message;
+ struct boot_command boot_command;
+ int len, rc;
+
+ create_boot_command(&boot_command, device, boot_option, data);
+
+ len = pb_protocol_boot_len(&boot_command);
+
+ message = pb_protocol_create_message(client,
+ PB_PROTOCOL_ACTION_BOOT, len);
+
+ if (!message)
+ return -1;
+
+ pb_protocol_serialise_boot_command(&boot_command,
+ message->payload, len);
+
+ rc = pb_protocol_write_message(client->fd, message);
+
+ return rc;
+}
struct discover_client;
+struct pb_boot_data {
+ char *image;
+ char *initrd;
+ char *args;
+};
+
/**
* struct discover_client_ops - Application supplied client info.
* @device_add: PB_PROTOCOL_ACTION_ADD event callback.
*/
struct device *discover_client_get_device(struct discover_client *client,
int index);
+
+/* Tell the discover server to boot an image
+ * @param client A pointer to the discover client
+ * @param boot_command The command to boot
+ */
+int discover_client_boot(struct discover_client *client,
+ const struct device *device,
+ const struct boot_option *boot_option,
+ const struct pb_boot_data *data);
#endif
#include "system/system.h"
#include "types/types.h"
#include "ui/common/timer.h"
+#include "ui/common/discover-client.h"
#include <signal.h>
-struct pb_boot_data {
- char *image;
- char *initrd;
- char *args;
-};
-
int pb_boot(const struct pb_boot_data *bd, int dry_run);
int pb_start_daemon(void);