updater: Check the return value from ApplyImagePatch / ApplyBSDiffPatch
Return NULL to abort the update process. Note that returning "" won't stop the script. Change-Id: Ifd108c1356f7c92a905c8776247a8842c6445319
This commit is contained in:
@@ -1107,6 +1107,7 @@ main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
if (status != INSTALL_SUCCESS) {
|
if (status != INSTALL_SUCCESS) {
|
||||||
ui->Print("Installation aborted.\n");
|
ui->Print("Installation aborted.\n");
|
||||||
|
ui->Print("OTA failed! Please power off the device to keep it in this state and file a bug report!\n");
|
||||||
|
|
||||||
// If this is an eng or userdebug build, then automatically
|
// If this is an eng or userdebug build, then automatically
|
||||||
// turn the text display on if the script fails so the error
|
// turn the text display on if the script fails so the error
|
||||||
|
|||||||
+28
-14
@@ -687,19 +687,26 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[]
|
|||||||
rss.p_remain = (tgt->pos[1] - tgt->pos[0]) * BLOCKSIZE;
|
rss.p_remain = (tgt->pos[1] - tgt->pos[0]) * BLOCKSIZE;
|
||||||
check_lseek(fd, (off64_t)tgt->pos[0] * BLOCKSIZE, SEEK_SET);
|
check_lseek(fd, (off64_t)tgt->pos[0] * BLOCKSIZE, SEEK_SET);
|
||||||
|
|
||||||
|
int ret;
|
||||||
if (style[0] == 'i') { // imgdiff
|
if (style[0] == 'i') { // imgdiff
|
||||||
ApplyImagePatch(buffer, src_blocks * BLOCKSIZE,
|
ret = ApplyImagePatch(buffer, src_blocks * BLOCKSIZE,
|
||||||
&patch_value,
|
&patch_value,
|
||||||
&RangeSinkWrite, &rss, NULL, NULL);
|
&RangeSinkWrite, &rss, NULL, NULL);
|
||||||
} else {
|
} else {
|
||||||
ApplyBSDiffPatch(buffer, src_blocks * BLOCKSIZE,
|
ret = ApplyBSDiffPatch(buffer, src_blocks * BLOCKSIZE,
|
||||||
&patch_value, 0,
|
&patch_value, 0,
|
||||||
&RangeSinkWrite, &rss, NULL);
|
&RangeSinkWrite, &rss, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
ErrorAbort(state, "patch failed\n");
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We expect the output of the patcher to fill the tgt ranges exactly.
|
// We expect the output of the patcher to fill the tgt ranges exactly.
|
||||||
if (rss.p_block != tgt->count || rss.p_remain != 0) {
|
if (rss.p_block != tgt->count || rss.p_remain != 0) {
|
||||||
fprintf(stderr, "range sink underrun?\n");
|
ErrorAbort(state, "range sink underrun?\n");
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks_so_far += tgt->size;
|
blocks_so_far += tgt->size;
|
||||||
@@ -723,7 +730,8 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[]
|
|||||||
range[1] = (tgt->pos[i*2+1] - tgt->pos[i*2]) * (uint64_t)BLOCKSIZE;
|
range[1] = (tgt->pos[i*2+1] - tgt->pos[i*2]) * (uint64_t)BLOCKSIZE;
|
||||||
|
|
||||||
if (ioctl(fd, BLKDISCARD, &range) < 0) {
|
if (ioctl(fd, BLKDISCARD, &range) < 0) {
|
||||||
printf(" blkdiscard failed: %s\n", strerror(errno));
|
ErrorAbort(state, " blkdiscard failed: %s\n", strerror(errno));
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -732,8 +740,8 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[]
|
|||||||
printf(" ignoring erase (not block device)\n");
|
printf(" ignoring erase (not block device)\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "unknown transfer style \"%s\"\n", style);
|
ErrorAbort(state, "unknown transfer style \"%s\"\n", style);
|
||||||
exit(1);
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,13 +752,19 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[]
|
|||||||
printf("wrote %d blocks; expected %d\n", blocks_so_far, total_blocks);
|
printf("wrote %d blocks; expected %d\n", blocks_so_far, total_blocks);
|
||||||
printf("max alloc needed was %zu\n", buffer_alloc);
|
printf("max alloc needed was %zu\n", buffer_alloc);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
free(transfer_list);
|
free(transfer_list);
|
||||||
FreeValue(blockdev_filename);
|
FreeValue(blockdev_filename);
|
||||||
FreeValue(transfer_list_value);
|
FreeValue(transfer_list_value);
|
||||||
FreeValue(new_data_fn);
|
FreeValue(new_data_fn);
|
||||||
FreeValue(patch_data_fn);
|
FreeValue(patch_data_fn);
|
||||||
return StringValue(success ? strdup("t") : strdup(""));
|
if (success) {
|
||||||
|
return StringValue(strdup("t"));
|
||||||
|
} else {
|
||||||
|
// NULL will be passed to its caller at Evaluate() and abort the OTA
|
||||||
|
// process.
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) {
|
Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) {
|
||||||
@@ -793,11 +807,11 @@ Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) {
|
|||||||
digest = SHA_final(&ctx);
|
digest = SHA_final(&ctx);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
FreeValue(blockdev_filename);
|
FreeValue(blockdev_filename);
|
||||||
FreeValue(ranges);
|
FreeValue(ranges);
|
||||||
if (digest == NULL) {
|
if (digest == NULL) {
|
||||||
return StringValue(strdup(""));
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
return StringValue(PrintSha1(digest));
|
return StringValue(PrintSha1(digest));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user