Skip to content

Commit 30ae580

Browse files
committed
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 <[email protected]>
1 parent 0e92b50 commit 30ae580

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

fastboot/engine.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ void generate_ext4_image(struct image_data *image)
255255
#else
256256
fd = fileno(tmpfile());
257257
#endif
258+
/* reset ext4fs info so we can be called multiple times */
258259
reset_ext4fs_info();
259260
info.len = image->partition_size;
260261
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)
266267
close(fd);
267268
}
268269

269-
int fb_format(Action *a, usb_handle *usb)
270+
int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported)
270271
{
271272
const char *partition = a->cmd;
272273
char response[FB_RESPONSE_SZ+1];
@@ -281,6 +282,13 @@ int fb_format(Action *a, usb_handle *usb)
281282
snprintf(cmd, sizeof(cmd), "getvar:partition-type:%s", partition);
282283
status = fb_command_response(usb, cmd, response);
283284
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+
}
284292
fprintf(stderr,"FAILED (%s)\n", fb_get_error());
285293
return status;
286294
}
@@ -292,6 +300,13 @@ int fb_format(Action *a, usb_handle *usb)
292300
}
293301
}
294302
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+
}
295310
fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n",
296311
response);
297312
return -1;
@@ -301,6 +316,12 @@ int fb_format(Action *a, usb_handle *usb)
301316
snprintf(cmd, sizeof(cmd), "getvar:partition-size:%s", partition);
302317
status = fb_command_response(usb, cmd, response);
303318
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+
}
304325
fprintf(stderr,"FAILED (%s)\n", fb_get_error());
305326
return status;
306327
}
@@ -329,11 +350,12 @@ int fb_format(Action *a, usb_handle *usb)
329350
return status;
330351
}
331352

332-
void fb_queue_format(const char *partition)
353+
void fb_queue_format(const char *partition, int skip_if_not_supported)
333354
{
334355
Action *a;
335356

336357
a = queue_action(OP_FORMAT, partition);
358+
a->data = (void*)skip_if_not_supported;
337359
a->msg = mkmsg("formatting '%s' partition", partition);
338360
}
339361

@@ -545,7 +567,7 @@ int fb_execute_queue(usb_handle *usb)
545567
} else if (a->op == OP_NOTICE) {
546568
fprintf(stderr,"%s\n",(char*)a->data);
547569
} else if (a->op == OP_FORMAT) {
548-
status = fb_format(a, usb);
570+
status = fb_format(a, usb, (int)a->data);
549571
status = a->func(a, status, status ? fb_get_error() : "");
550572
if (status) break;
551573
} else {

fastboot/fastboot.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ int main(int argc, char **argv)
640640
skip(2);
641641
} else if(!strcmp(*argv, "format")) {
642642
require(2);
643-
fb_queue_format(argv[1]);
643+
fb_queue_format(argv[1], 0);
644644
skip(2);
645645
} else if(!strcmp(*argv, "signature")) {
646646
require(2);
@@ -727,7 +727,9 @@ int main(int argc, char **argv)
727727

728728
if (wants_wipe) {
729729
fb_queue_erase("userdata");
730+
fb_queue_format("userdata", 1);
730731
fb_queue_erase("cache");
732+
fb_queue_format("cache", 1);
731733
}
732734
if (wants_reboot) {
733735
fb_queue_reboot();

fastboot/fastboot.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ char *fb_get_error(void);
4343
/* engine.c - high level command queue engine */
4444
void fb_queue_flash(const char *ptn, void *data, unsigned sz);;
4545
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);
4747
void fb_queue_require(const char *prod, const char *var, int invert,
4848
unsigned nvalues, const char **value);
4949
void fb_queue_display(const char *var, const char *prettyname);

0 commit comments

Comments
 (0)