summaryrefslogtreecommitdiffstats
path: root/fastboot/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'fastboot/engine.c')
-rw-r--r--fastboot/engine.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/fastboot/engine.c b/fastboot/engine.c
index 46b0828..93be3de 100644
--- a/fastboot/engine.c
+++ b/fastboot/engine.c
@@ -28,7 +28,6 @@
#include "fastboot.h"
#include "make_ext4fs.h"
-#include "ext4_utils.h"
#include <stdio.h>
#include <stdlib.h>
@@ -77,6 +76,7 @@ char *mkmsg(const char *fmt, ...)
#define OP_QUERY 3
#define OP_NOTICE 4
#define OP_FORMAT 5
+#define OP_DOWNLOAD_SPARSE 6
typedef struct Action Action;
@@ -111,6 +111,20 @@ struct image_data {
void generate_ext4_image(struct image_data *image);
void cleanup_image(struct image_data *image);
+int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...)
+{
+ char cmd[CMD_SIZE] = "getvar:";
+ int getvar_len = strlen(cmd);
+ va_list args;
+
+ response[FB_RESPONSE_SZ] = '\0';
+ va_start(args, fmt);
+ vsnprintf(cmd + getvar_len, sizeof(cmd) - getvar_len, fmt, args);
+ va_end(args);
+ cmd[CMD_SIZE - 1] = '\0';
+ return fb_command_response(usb, cmd, response);
+}
+
struct generator {
char *fs_type;
@@ -278,9 +292,7 @@ int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported)
unsigned i;
char cmd[CMD_SIZE];
- response[FB_RESPONSE_SZ] = '\0';
- snprintf(cmd, sizeof(cmd), "getvar:partition-type:%s", partition);
- status = fb_command_response(usb, cmd, response);
+ status = fb_getvar(usb, response, "partition-type:%s", partition);
if (status) {
if (skip_if_not_supported) {
fprintf(stderr,
@@ -312,9 +324,7 @@ int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported)
return -1;
}
- response[FB_RESPONSE_SZ] = '\0';
- snprintf(cmd, sizeof(cmd), "getvar:partition-size:%s", partition);
- status = fb_command_response(usb, cmd, response);
+ status = fb_getvar(usb, response, "partition-size:%s", partition);
if (status) {
if (skip_if_not_supported) {
fprintf(stderr,
@@ -372,6 +382,19 @@ void fb_queue_flash(const char *ptn, void *data, unsigned sz)
a->msg = mkmsg("writing '%s'", ptn);
}
+void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz)
+{
+ Action *a;
+
+ a = queue_action(OP_DOWNLOAD_SPARSE, "");
+ a->data = s;
+ a->size = 0;
+ a->msg = mkmsg("sending sparse '%s' (%d KB)", ptn, sz / 1024);
+
+ a = queue_action(OP_COMMAND, "flash:%s", ptn);
+ a->msg = mkmsg("writing '%s'", ptn);
+}
+
static int match(char *str, const char **value, unsigned count)
{
const char *val;
@@ -570,6 +593,10 @@ int fb_execute_queue(usb_handle *usb)
status = fb_format(a, usb, (int)a->data);
status = a->func(a, status, status ? fb_get_error() : "");
if (status) break;
+ } else if (a->op == OP_DOWNLOAD_SPARSE) {
+ status = fb_download_data_sparse(usb, a->data);
+ status = a->func(a, status, status ? fb_get_error() : "");
+ if (status) break;
} else {
die("bogus action");
}