diff --git a/plugins/dfu/dfu-chunked.c b/plugins/dfu/dfu-chunked.c index 5cec92c7a..e2abe8c85 100644 --- a/plugins/dfu/dfu-chunked.c +++ b/plugins/dfu/dfu-chunked.c @@ -183,3 +183,27 @@ dfu_chunked_new (const guint8 *data, } return segments; } + +/** + * dfu_chunked_new_from_bytes: + * @blob: a #GBytes + * @addr_start: the hardware address offset, or 0 + * @page_sz: the hardware page size, or 0 + * @packet_sz: the transfer size, or 0 + * + * Chunks a linear blob of memory into packets, ensuring each packet does not + * cross a package boundary and is less that a specific transfer size. + * + * Return value: (element-type DfuChunkedPacket): array of packets + **/ +GPtrArray * +dfu_chunked_new_from_bytes (GBytes *blob, + guint32 addr_start, + guint32 page_sz, + guint32 packet_sz) +{ + gsize sz; + const guint8 *data = g_bytes_get_data (blob, &sz); + return dfu_chunked_new (data, (guint32) sz, + addr_start, page_sz, packet_sz); +} diff --git a/plugins/dfu/dfu-chunked.h b/plugins/dfu/dfu-chunked.h index e99a9f68d..7d03373bc 100644 --- a/plugins/dfu/dfu-chunked.h +++ b/plugins/dfu/dfu-chunked.h @@ -48,6 +48,10 @@ GPtrArray *dfu_chunked_new (const guint8 *data, guint32 addr_start, guint32 page_sz, guint32 packet_sz); +GPtrArray *dfu_chunked_new_from_bytes (GBytes *blob, + guint32 addr_start, + guint32 page_sz, + guint32 packet_sz); G_END_DECLS