run amend scripts from the command line

This commit is contained in:
Koushik K. Dutta 2010-03-07 13:39:21 -08:00
parent 2bda3e9fa0
commit f68aaaf20c
3 changed files with 70 additions and 13 deletions

View File

@ -30,6 +30,9 @@
#include "roots.h"
#include "recovery_ui.h"
#include "commands.h"
#include "amend/amend.h"
int signature_check_enabled = 1;
int script_assert_enabled = 1;
static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip";
@ -383,3 +386,56 @@ void do_mount_usb_storage()
system("echo '' > /sys/devices/platform/usb_mass_storage/lun0/file");
system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable");
}
int amend_main(int argc, char** argv)
{
if (argc != 2)
{
printf("Usage: amend <script>\n");
return 0;
}
RecoveryCommandContext ctx = { NULL };
if (register_update_commands(&ctx)) {
LOGE("Can't install update commands\n");
}
struct stat file_info;
if (0 != stat(argv[1], &file_info)) {
printf("Error executing stat on file: %s\n", argv[1]);
return 1;
}
int script_len = file_info.st_size;
char* script_data = (char*)malloc(script_len);
FILE *file = fopen(argv[1], "rb");
fread(script_data, script_len, 1, file);
fclose(file);
/* Parse the script. Note that the script and parse tree are never freed.
*/
const AmCommandList *commands = parseAmendScript(script_data, script_len);
if (commands == NULL) {
printf("Syntax error in update script\n");
return 1;
} else {
printf("Parsed %.*s\n", script_len, argv[1]);
}
/* Execute the script.
*/
int ret = execCommandList((ExecContext *)1, commands);
if (ret != 0) {
int num = ret;
char *line, *next = script_data;
while (next != NULL && ret-- > 0) {
line = next;
next = memchr(line, '\n', script_data + script_len - line);
if (next != NULL) *next++ = '\0';
}
printf("Failure at line %d:\n%s\n", num, next ? line : "(not found)");
return 1;
}
return 0;
}

View File

@ -34,24 +34,23 @@ LOCAL_MODULE := libflash_image
LOCAL_CFLAGS += -Dmain=flash_image_main
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := flash_image.c
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE := recovery_flash_image
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_STEM := flash_image
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_EXECUTABLES_UNSTRIPPED)
LOCAL_MODULE_PATH := $(TARGET_OUT)/utilities
LOCAL_STATIC_LIBRARIES := libmtdutils libcutils libc
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := dump_image.c
LOCAL_MODULE := libdump_image
LOCAL_CFLAGS += -Dmain=dump_image_main
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := driver.c
LOCAL_MODULE_CLASS := RECOVERY_EXECUTABLES
LOCAL_MODULE := recovery_tools
LOCAL_MODULE_TAGS := eng
LOCAL_STATIC_LIBRARIES := libmkyaffs2image libunyaffs libdump_image libflash_image libmtdutils libcutils libc
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_EXECUTABLES_UNSTRIPPED)
ADDITIONAL_RECOVERY_EXECUTABLES += recovery_tools
#include $(BUILD_EXECUTABLE)
endif # TARGET_ARCH == arm
endif # !TARGET_SIMULATOR

View File

@ -482,6 +482,8 @@ main(int argc, char **argv)
return mkyaffs2image_main(argc, argv);
if (strstr(argv[0], "unyaffs") != NULL)
return unyaffs_main(argc, argv);
if (strstr(argv[0], "amend"))
return amend_main(argc, argv);
return busybox_driver(argc, argv);
}
int is_user_initiated_recovery = 0;