diff options
author | JP Abgrall | 2012-05-07 22:25:24 -0500 |
---|---|---|
committer | JP Abgrall | 2012-05-07 22:25:24 -0500 |
commit | 30ae5806e920cb824d019defd856068f09dd0db6 (patch) | |
tree | 634b3da5e3379fd3a8f14d878e9c4983c5ad28d8 | |
parent | 0e92b50f0fb432c45b26863394e473916b0ab4ef (diff) | |
download | platform-system-core-30ae5806e920cb824d019defd856068f09dd0db6.tar.gz platform-system-core-30ae5806e920cb824d019defd856068f09dd0db6.tar.xz platform-system-core-30ae5806e920cb824d019defd856068f09dd0db6.zip |
fastboot: Change -w to format after the erase of userdata & cache
If the bootloader doesn't support formatting of those partitions
(either because it doesn't support the getvar commands needed or
the partition type is not supported), the errors are printed but
doesn't halt processing of subsequent commands.
Change-Id: I816ac2e5e7593846fcb4fd39c793a8dbdd996f6f
Signed-off-by: Mike J. Chen <mjchen@google.com>
-rw-r--r-- | fastboot/engine.c | 28 | ||||
-rw-r--r-- | fastboot/fastboot.c | 4 | ||||
-rw-r--r-- | fastboot/fastboot.h | 2 |
3 files changed, 29 insertions, 5 deletions
diff --git a/fastboot/engine.c b/fastboot/engine.c index 994eeae23..46b082806 100644 --- a/fastboot/engine.c +++ b/fastboot/engine.c | |||
@@ -255,6 +255,7 @@ void generate_ext4_image(struct image_data *image) | |||
255 | #else | 255 | #else |
256 | fd = fileno(tmpfile()); | 256 | fd = fileno(tmpfile()); |
257 | #endif | 257 | #endif |
258 | /* reset ext4fs info so we can be called multiple times */ | ||
258 | reset_ext4fs_info(); | 259 | reset_ext4fs_info(); |
259 | info.len = image->partition_size; | 260 | info.len = image->partition_size; |
260 | make_ext4fs_internal(fd, NULL, NULL, NULL, 0, 1, 0, 0, 0, NULL); | 261 | make_ext4fs_internal(fd, NULL, NULL, NULL, 0, 1, 0, 0, 0, NULL); |
@@ -266,7 +267,7 @@ void generate_ext4_image(struct image_data *image) | |||
266 | close(fd); | 267 | close(fd); |
267 | } | 268 | } |
268 | 269 | ||
269 | int fb_format(Action *a, usb_handle *usb) | 270 | int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported) |
270 | { | 271 | { |
271 | const char *partition = a->cmd; | 272 | const char *partition = a->cmd; |
272 | char response[FB_RESPONSE_SZ+1]; | 273 | char response[FB_RESPONSE_SZ+1]; |
@@ -281,6 +282,13 @@ int fb_format(Action *a, usb_handle *usb) | |||
281 | snprintf(cmd, sizeof(cmd), "getvar:partition-type:%s", partition); | 282 | snprintf(cmd, sizeof(cmd), "getvar:partition-type:%s", partition); |
282 | status = fb_command_response(usb, cmd, response); | 283 | status = fb_command_response(usb, cmd, response); |
283 | if (status) { | 284 | if (status) { |
285 | if (skip_if_not_supported) { | ||
286 | fprintf(stderr, | ||
287 | "Erase successful, but not automatically formatting.\n"); | ||
288 | fprintf(stderr, | ||
289 | "Can't determine partition type.\n"); | ||
290 | return 0; | ||
291 | } | ||
284 | fprintf(stderr,"FAILED (%s)\n", fb_get_error()); | 292 | fprintf(stderr,"FAILED (%s)\n", fb_get_error()); |
285 | return status; | 293 | return status; |
286 | } | 294 | } |
@@ -292,6 +300,13 @@ int fb_format(Action *a, usb_handle *usb) | |||
292 | } | 300 | } |
293 | } | 301 | } |
294 | if (!generator) { | 302 | if (!generator) { |
303 | if (skip_if_not_supported) { | ||
304 | fprintf(stderr, | ||
305 | "Erase successful, but not automatically formatting.\n"); | ||
306 | fprintf(stderr, | ||
307 | "File system type %s not supported.\n", response); | ||
308 | return 0; | ||
309 | } | ||
295 | fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n", | 310 | fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n", |
296 | response); | 311 | response); |
297 | return -1; | 312 | return -1; |
@@ -301,6 +316,12 @@ int fb_format(Action *a, usb_handle *usb) | |||
301 | snprintf(cmd, sizeof(cmd), "getvar:partition-size:%s", partition); | 316 | snprintf(cmd, sizeof(cmd), "getvar:partition-size:%s", partition); |
302 | status = fb_command_response(usb, cmd, response); | 317 | status = fb_command_response(usb, cmd, response); |
303 | if (status) { | 318 | if (status) { |
319 | if (skip_if_not_supported) { | ||
320 | fprintf(stderr, | ||
321 | "Erase successful, but not automatically formatting.\n"); | ||
322 | fprintf(stderr, "Unable to get partition size\n."); | ||
323 | return 0; | ||
324 | } | ||
304 | fprintf(stderr,"FAILED (%s)\n", fb_get_error()); | 325 | fprintf(stderr,"FAILED (%s)\n", fb_get_error()); |
305 | return status; | 326 | return status; |
306 | } | 327 | } |
@@ -329,11 +350,12 @@ cleanup: | |||
329 | return status; | 350 | return status; |
330 | } | 351 | } |
331 | 352 | ||
332 | void fb_queue_format(const char *partition) | 353 | void fb_queue_format(const char *partition, int skip_if_not_supported) |
333 | { | 354 | { |
334 | Action *a; | 355 | Action *a; |
335 | 356 | ||
336 | a = queue_action(OP_FORMAT, partition); | 357 | a = queue_action(OP_FORMAT, partition); |
358 | a->data = (void*)skip_if_not_supported; | ||
337 | a->msg = mkmsg("formatting '%s' partition", partition); | 359 | a->msg = mkmsg("formatting '%s' partition", partition); |
338 | } | 360 | } |
339 | 361 | ||
@@ -545,7 +567,7 @@ int fb_execute_queue(usb_handle *usb) | |||
545 | } else if (a->op == OP_NOTICE) { | 567 | } else if (a->op == OP_NOTICE) { |
546 | fprintf(stderr,"%s\n",(char*)a->data); | 568 | fprintf(stderr,"%s\n",(char*)a->data); |
547 | } else if (a->op == OP_FORMAT) { | 569 | } else if (a->op == OP_FORMAT) { |
548 | status = fb_format(a, usb); | 570 | status = fb_format(a, usb, (int)a->data); |
549 | status = a->func(a, status, status ? fb_get_error() : ""); | 571 | status = a->func(a, status, status ? fb_get_error() : ""); |
550 | if (status) break; | 572 | if (status) break; |
551 | } else { | 573 | } else { |
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c index af61f888f..848cea377 100644 --- a/fastboot/fastboot.c +++ b/fastboot/fastboot.c | |||
@@ -640,7 +640,7 @@ int main(int argc, char **argv) | |||
640 | skip(2); | 640 | skip(2); |
641 | } else if(!strcmp(*argv, "format")) { | 641 | } else if(!strcmp(*argv, "format")) { |
642 | require(2); | 642 | require(2); |
643 | fb_queue_format(argv[1]); | 643 | fb_queue_format(argv[1], 0); |
644 | skip(2); | 644 | skip(2); |
645 | } else if(!strcmp(*argv, "signature")) { | 645 | } else if(!strcmp(*argv, "signature")) { |
646 | require(2); | 646 | require(2); |
@@ -727,7 +727,9 @@ int main(int argc, char **argv) | |||
727 | 727 | ||
728 | if (wants_wipe) { | 728 | if (wants_wipe) { |
729 | fb_queue_erase("userdata"); | 729 | fb_queue_erase("userdata"); |
730 | fb_queue_format("userdata", 1); | ||
730 | fb_queue_erase("cache"); | 731 | fb_queue_erase("cache"); |
732 | fb_queue_format("cache", 1); | ||
731 | } | 733 | } |
732 | if (wants_reboot) { | 734 | if (wants_reboot) { |
733 | fb_queue_reboot(); | 735 | fb_queue_reboot(); |
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index 7d56ecbbe..1d3e2b824 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h | |||
@@ -43,7 +43,7 @@ char *fb_get_error(void); | |||
43 | /* engine.c - high level command queue engine */ | 43 | /* engine.c - high level command queue engine */ |
44 | void fb_queue_flash(const char *ptn, void *data, unsigned sz);; | 44 | void fb_queue_flash(const char *ptn, void *data, unsigned sz);; |
45 | void fb_queue_erase(const char *ptn); | 45 | void fb_queue_erase(const char *ptn); |
46 | void fb_queue_format(const char *ptn); | 46 | void fb_queue_format(const char *ptn, int skip_if_not_supported); |
47 | void fb_queue_require(const char *prod, const char *var, int invert, | 47 | void fb_queue_require(const char *prod, const char *var, int invert, |
48 | unsigned nvalues, const char **value); | 48 | unsigned nvalues, const char **value); |
49 | void fb_queue_display(const char *var, const char *prettyname); | 49 | void fb_queue_display(const char *var, const char *prettyname); |