From 9931f7f3c1288171319e9ff7d053ebaad07db720 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 10 Jun 2009 14:11:53 -0700 Subject: edify extensions for OTA package installation, part 1 Adds the following edify functions: mount unmount format show_progress delete delete_recursive package_extract symlink set_perm set_perm_recursive This set is enough to extract and install the system part of a (full) OTA package. Adds the updater binary that extracts an edify script from the OTA package and then executes it. Minor changes to the edify core (adds a sleep() builtin for debugging, adds "." to the set of characters that can appear in an unquoted string). --- updater/updater.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 updater/updater.c (limited to 'updater/updater.c') diff --git a/updater/updater.c b/updater/updater.c new file mode 100644 index 000000000..aa03803a8 --- /dev/null +++ b/updater/updater.c @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "edify/expr.h" +#include "updater.h" +#include "install.h" +#include "minzip/Zip.h" + +// Where in the package we expect to find the edify script to execute. +// (Note it's "updateR-script", not the older "update-script".) +#define SCRIPT_NAME "META-INF/com/google/android/updater-script" + +int main(int argc, char** argv) { + if (argc != 4) { + fprintf(stderr, "unexpected number of arguments (%d)\n", argc); + return 1; + } + + char* version = argv[1]; + if (version[0] != '1' || version[1] != '\0') { + fprintf(stderr, "wrong updater binary API; expected 1, got %s\n", + version); + return 2; + } + + // Set up the pipe for sending commands back to the parent process. + + int fd = atoi(argv[2]); + FILE* cmd_pipe = fdopen(fd, "wb"); + setlinebuf(cmd_pipe); + + // Extract the script from the package. + + char* package_data = argv[3]; + ZipArchive za; + int err; + err = mzOpenZipArchive(package_data, &za); + if (err != 0) { + fprintf(stderr, "failed to open package %s: %s\n", + package_data, strerror(err)); + return 3; + } + + const ZipEntry* script_entry = mzFindZipEntry(&za, SCRIPT_NAME); + if (script_entry == NULL) { + fprintf(stderr, "failed to find %s in %s\n", SCRIPT_NAME, package_data); + return 4; + } + + char* script = malloc(script_entry->uncompLen+1); + if (!mzReadZipEntry(&za, script_entry, script, script_entry->uncompLen)) { + fprintf(stderr, "failed to read script from package\n"); + return 5; + } + script[script_entry->uncompLen] = '\0'; + + // Configure edify's functions. + + RegisterBuiltins(); + RegisterInstallFunctions(); + FinishRegistration(); + + // Parse the script. + + Expr* root; + yy_scan_string(script); + int error = yyparse(&root); + if (error != 0) { + fprintf(stderr, "%d parse errors\n", error); + return 6; + } + + // Evaluate the parsed script. + + UpdaterInfo updater_info; + updater_info.cmd_pipe = cmd_pipe; + updater_info.package_zip = &za; + + char* result = Evaluate(&updater_info, root); + if (result == NULL) { + const char* errmsg = GetError(); + fprintf(stderr, "script aborted with error: %s\n", + errmsg == NULL ? "(none)" : errmsg); + ClearError(); + return 7; + } else { + fprintf(stderr, "script result was [%s]\n", result); + free(result); + } + + mzCloseZipArchive(&za); + + return 0; +} -- cgit v1.2.3 From 8edb00c990e563e6f91b278a212f2edf877cf763 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Thu, 11 Jun 2009 17:21:44 -0700 Subject: edify extensions for OTA package installation, part 2 Adds more edify functions for OTAs: is_mounted getprop apply_patch apply_patch_check apply_patch_space write_raw_image write_firmware_image package_extract_file This allows us to install radios, hboots, boot images, and install incremental OTA packages. Fixes a couple of dumb bugs in edify itself: - we were doubling the size of the function table each time it was *not* full, rather than each time it was full - "no such function" errors weren't visible to the parser, so they didn't prevent execution of the script. --- updater/updater.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'updater/updater.c') diff --git a/updater/updater.c b/updater/updater.c index aa03803a8..09776256b 100644 --- a/updater/updater.c +++ b/updater/updater.c @@ -80,10 +80,11 @@ int main(int argc, char** argv) { // Parse the script. Expr* root; + int error_count = 0; yy_scan_string(script); - int error = yyparse(&root); - if (error != 0) { - fprintf(stderr, "%d parse errors\n", error); + int error = yyparse(&root, &error_count); + if (error != 0 || error_count > 0) { + fprintf(stderr, "%d parse errors\n", error_count); return 6; } -- cgit v1.2.3 From d9c9d10d9da76f067d3955bea71f7bb39e859fa5 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Fri, 12 Jun 2009 12:24:39 -0700 Subject: fixes to edify and updater script A few more changes to edify: - fix write_raw_image(); my last change neglected to close the write context, so the written image was corrupt. - each expression tracks the span of the source code from which it was compiled, so that assert()'s error message can include the source of the expression that failed. - the 'cookie' argument to each Function is replaced with a State object, which contains the cookie, the source script (for use with the above spans), and the current error message (replacing the global variables that were used for this purpose). - in the recovery image, a new command "ui_print" can be sent back through the command pipe to cause text to appear on the screen. Add a new ui_print() function to print things from scripts. Rename existing "print" function to "stdout". --- updater/updater.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'updater/updater.c') diff --git a/updater/updater.c b/updater/updater.c index 09776256b..5a2ed2ccf 100644 --- a/updater/updater.c +++ b/updater/updater.c @@ -94,12 +94,26 @@ int main(int argc, char** argv) { updater_info.cmd_pipe = cmd_pipe; updater_info.package_zip = &za; - char* result = Evaluate(&updater_info, root); + State state; + state.cookie = &updater_info; + state.script = script; + state.errmsg = NULL; + + char* result = Evaluate(&state, root); if (result == NULL) { - const char* errmsg = GetError(); - fprintf(stderr, "script aborted with error: %s\n", - errmsg == NULL ? "(none)" : errmsg); - ClearError(); + if (state.errmsg == NULL) { + fprintf(stderr, "script aborted (no error message)\n"); + fprintf(cmd_pipe, "ui_print script aborted (no error message)\n"); + } else { + fprintf(stderr, "script aborted: %s\n", state.errmsg); + char* line = strtok(state.errmsg, "\n"); + while (line) { + fprintf(cmd_pipe, "ui_print %s\n", line); + line = strtok(NULL, "\n"); + } + fprintf(cmd_pipe, "ui_print\n"); + } + free(state.errmsg); return 7; } else { fprintf(stderr, "script result was [%s]\n", result); @@ -107,6 +121,7 @@ int main(int argc, char** argv) { } mzCloseZipArchive(&za); + free(script); return 0; } -- cgit v1.2.3 From fb2e3af3f915c0e3f2b4b027ef26777267ad46dc Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 17 Jun 2009 17:29:40 -0700 Subject: let the "firmware" command take the file straight from the package To do a firmware-install-on-reboot, the update binary tells recovery what file to install before rebooting. Let this file be specified as "PACKAGE:" to indicate taking the file out of the OTA package, avoiding an extra copy to /tmp. Bump the API version number to reflect this change. --- updater/updater.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'updater/updater.c') diff --git a/updater/updater.c b/updater/updater.c index 5a2ed2ccf..31d93ae96 100644 --- a/updater/updater.c +++ b/updater/updater.c @@ -34,9 +34,10 @@ int main(int argc, char** argv) { } char* version = argv[1]; - if (version[0] != '1' || version[1] != '\0') { - fprintf(stderr, "wrong updater binary API; expected 1, got %s\n", - version); + if ((version[0] != '1' && version[0] != '2') || version[1] != '\0') { + // We support version "1" or "2". + fprintf(stderr, "wrong updater binary API; expected 1 or 2, got %s\n", + argv[1]); return 2; } -- cgit v1.2.3