X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fpb-protocol%2Fpb-protocol.c;h=681b250e20135ee334c0822a500eae0ea50f2973;hp=2792bf832c7ea2866a6accbe3b82b191eaa406f4;hb=7b793150f96a6fe6033ac1390a663b1b62be2df6;hpb=6b87c9c7776796c766e3dcbdb32f5d292f7125d5 diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index 2792bf8..681b250 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,7 @@ * action = 0x1: device add message * payload: * 4-byte len, id + * 1-byte type * 4-byte len, name * 4-byte len, description * 4-byte len, icon_file @@ -33,6 +35,7 @@ * 4-byte len, icon_file * 4-byte len, boot_image_file * 4-byte len, initrd_file + * 4-byte len, dtb_file * 4-byte len, boot_args * * action = 0x2: device remove message @@ -44,6 +47,7 @@ * 4-byte len, boot option id * 4-byte len, boot_image_file * 4-byte len, initrd_file + * 4-byte len, dtb_file * 4-byte len, boot_args * */ @@ -66,6 +70,7 @@ void pb_protocol_dump_device(const struct device *dev, const char *text, fprintf(stream, "%s\t\ticon: %s\n", text, opt->icon_file); fprintf(stream, "%s\t\tboot: %s\n", text, opt->boot_image_file); fprintf(stream, "%s\t\tinit: %s\n", text, opt->initrd_file); + fprintf(stream, "%s\t\tdtb: %s\n", text, opt->dtb_file); fprintf(stream, "%s\t\targs: %s\n", text, opt->boot_args); } } @@ -162,6 +167,7 @@ static int optional_strlen(const char *str) int pb_protocol_device_len(const struct device *dev) { return 4 + optional_strlen(dev->id) + + sizeof(dev->type) + 4 + optional_strlen(dev->name) + 4 + optional_strlen(dev->description) + 4 + optional_strlen(dev->icon_file); @@ -177,7 +183,9 @@ int pb_protocol_boot_option_len(const struct boot_option *opt) 4 + optional_strlen(opt->icon_file) + 4 + optional_strlen(opt->boot_image_file) + 4 + optional_strlen(opt->initrd_file) + - 4 + optional_strlen(opt->boot_args); + 4 + optional_strlen(opt->dtb_file) + + 4 + optional_strlen(opt->boot_args) + + sizeof(opt->is_default); } int pb_protocol_boot_len(const struct boot_command *boot) @@ -185,6 +193,7 @@ 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->dtb_file) + 4 + optional_strlen(boot->boot_args); } @@ -202,6 +211,8 @@ int pb_protocol_serialise_device(const struct device *dev, char *pos = buf; pos += pb_protocol_serialise_string(pos, dev->id); + *(enum device_type *)pos = dev->type; + pos += sizeof(enum device_type); pos += pb_protocol_serialise_string(pos, dev->name); pos += pb_protocol_serialise_string(pos, dev->description); pos += pb_protocol_serialise_string(pos, dev->icon_file); @@ -224,8 +235,12 @@ int pb_protocol_serialise_boot_option(const struct boot_option *opt, pos += pb_protocol_serialise_string(pos, opt->icon_file); pos += pb_protocol_serialise_string(pos, opt->boot_image_file); pos += pb_protocol_serialise_string(pos, opt->initrd_file); + pos += pb_protocol_serialise_string(pos, opt->dtb_file); pos += pb_protocol_serialise_string(pos, opt->boot_args); + *(bool *)pos = opt->is_default; + pos += sizeof(bool); + assert(pos <= buf + buf_len); (void)buf_len; @@ -240,6 +255,7 @@ int pb_protocol_serialise_boot_command(const struct boot_command *boot, 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->dtb_file); pos += pb_protocol_serialise_string(pos, boot->boot_args); assert(pos <= buf + buf_len); @@ -372,6 +388,12 @@ int pb_protocol_deserialise_device(struct device *dev, if (read_string(dev, &pos, &len, &dev->id)) goto out; + if (len < sizeof(enum device_type)) + goto out; + dev->type = *(enum device_type *)(pos); + pos += sizeof(enum device_type); + len -= sizeof(enum device_type); + if (read_string(dev, &pos, &len, &dev->name)) goto out; @@ -418,9 +440,16 @@ int pb_protocol_deserialise_boot_option(struct boot_option *opt, if (read_string(opt, &pos, &len, &opt->initrd_file)) goto out; + if (read_string(opt, &pos, &len, &opt->dtb_file)) + goto out; + if (read_string(opt, &pos, &len, &opt->boot_args)) goto out; + if (len < sizeof(bool)) + goto out; + opt->is_default = *(bool *)(pos); + rc = 0; out: @@ -446,6 +475,9 @@ int pb_protocol_deserialise_boot_command(struct boot_command *cmd, if (read_string(cmd, &pos, &len, &cmd->initrd_file)) goto out; + if (read_string(cmd, &pos, &len, &cmd->dtb_file)) + goto out; + if (read_string(cmd, &pos, &len, &cmd->boot_args)) goto out;