diff --git a/b2g_product.mk b/b2g_product.mk index 7d524244ff5fd03e53669819fd89ec01ce30a9dd..f17e35f18dd2d27cd314dc3859484988f0761fbd 100644 --- a/b2g_product.mk +++ b/b2g_product.mk @@ -31,7 +31,6 @@ include gonk-misc/b2g.mk include external/moztt/fonts.mk TARGET_PROVIDES_INIT_RC := PRODUCT_PACKAGES := $(filter-out fakeappops rilproxy oom-msg-logger,$(PRODUCT_PACKAGES)) -PRODUCT_PACKAGES += librecovery_updater_qcom PRODUCT_PROPERTY_OVERRIDES += \ ro.display.colorfill=1 \ diff --git a/updater/Android.mk b/updater/Android.mk deleted file mode 100644 index 824b0b287be2edd0c1c672297b3be67eca8db10d..0000000000000000000000000000000000000000 --- a/updater/Android.mk +++ /dev/null @@ -1,19 +0,0 @@ -ifneq ($(TARGET_SIMULATOR),true) -ifeq ($(TARGET_ARCH),arm) - -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -# librecovery_update_qcom is a set of edify extension functions for -# doing radio update on QCOM devices. - -LOCAL_MODULE_TAGS := optional - -LOCAL_SRC_FILES := recovery_updater.c firmware.c bootloader.c -LOCAL_STATIC_LIBRARIES += libmtdutils -LOCAL_C_INCLUDES += bootable/recovery -LOCAL_MODULE := librecovery_updater_qcom -include $(BUILD_STATIC_LIBRARY) - -endif # TARGET_ARCH == arm -endif # !TARGET_SIMULATOR diff --git a/updater/MODULE_LICENSE_APACHE2 b/updater/MODULE_LICENSE_APACHE2 deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/updater/NOTICE b/updater/NOTICE deleted file mode 100644 index 64aaa8dbd68e6917b35c02655ba2f8d763165368..0000000000000000000000000000000000000000 --- a/updater/NOTICE +++ /dev/null @@ -1,190 +0,0 @@ - - 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. - - 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. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/updater/bootloader.c b/updater/bootloader.c deleted file mode 100644 index 2c2aee9d8d7526b1dca3f8efea87610bf2abad5e..0000000000000000000000000000000000000000 --- a/updater/bootloader.c +++ /dev/null @@ -1,311 +0,0 @@ -/* Copyright (C) 2008 The Android Open Source Project - * Copyright (c) 2012, The Linux Foundation. All rights reserved. - * - * 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 "bootloader.h" -#include "common.h" -#include "mtdutils/mtdutils.h" -#include "roots.h" - -#include <errno.h> -#include <stdio.h> -#include <string.h> - -static const int MISC_PAGES = 3; // number of pages to save -static const int MISC_COMMAND_PAGE = 1; // bootloader command is this page - -#undef LOGE -#define LOGE(...) fprintf(stderr, "E:" __VA_ARGS__) - -#ifdef LOG_VERBOSE -static void dump_data(const char *data, int len) { - int pos; - for (pos = 0; pos < len; ) { - printf("%05x: %02x", pos, data[pos]); - for (++pos; pos < len && (pos % 24) != 0; ++pos) { - printf(" %02x", data[pos]); - } - printf("\n"); - } -} -#endif - -int get_bootloader_message_emmc(struct bootloader_message *out, Volume *v) { - FILE* f = fopen(v->device, "rb"); - if (f == NULL) { - LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno)); - return -1; - } - struct bootloader_message temp; - int count = fread(&temp, sizeof(temp), 1, f); - if (count != 1) { - LOGE("Failed reading %s\n(%s)\n", v->device, strerror(errno)); - return -1; - } - if (fclose(f) != 0) { - LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno)); - return -1; - } - memcpy(out, &temp, sizeof(temp)); - return 0; -} - -int set_bootloader_message_emmc(const struct bootloader_message *in, Volume *v) { - FILE* f = fopen(v->device, "wb"); - if (f == NULL) { - LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno)); - return -1; - } - int count = fwrite(in, sizeof(*in), 1, f); - if (count != 1) { - LOGE("Failed writing %s\n(%s)\n", v->device, strerror(errno)); - return -1; - } - if (fclose(f) != 0) { - LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno)); - return -1; - } - return 0; -} - -int get_bootloader_message(struct bootloader_message *out) { - size_t write_size; - const MtdPartition *part = mtd_find_partition_by_name(MISC_NAME); - if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) { - LOGE("Can't find %s\n", MISC_NAME); - return -1; - } - - MtdReadContext *read = mtd_read_partition(part); - if (read == NULL) { - LOGE("Can't open %s\n(%s)\n", MISC_NAME, strerror(errno)); - return -1; - } - - const ssize_t size = write_size * MISC_PAGES; - char data[size]; - ssize_t r = mtd_read_data(read, data, size); - if (r != size) LOGE("Can't read %s\n(%s)\n", MISC_NAME, strerror(errno)); - mtd_read_close(read); - if (r != size) return -1; - -#ifdef LOG_VERBOSE - printf("\n--- get_bootloader_message ---\n"); - dump_data(data, size); - printf("\n"); -#endif - - memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out)); - return 0; -} - -int set_bootloader_message(const struct bootloader_message *in) { - size_t write_size; - const MtdPartition *part = mtd_find_partition_by_name(MISC_NAME); - if (part == NULL || mtd_partition_info(part, NULL, NULL, &write_size)) { - LOGE("Can't find %s\n", MISC_NAME); - return -1; - } - - MtdReadContext *read = mtd_read_partition(part); - if (read == NULL) { - LOGE("Can't open %s\n(%s)\n", MISC_NAME, strerror(errno)); - return -1; - } - - ssize_t size = write_size * MISC_PAGES; - char data[size]; - ssize_t r = mtd_read_data(read, data, size); - if (r != size) LOGE("Can't read %s\n(%s)\n", MISC_NAME, strerror(errno)); - mtd_read_close(read); - if (r != size) return -1; - - memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in)); - -#ifdef LOG_VERBOSE - printf("\n--- set_bootloader_message ---\n"); - dump_data(data, size); - printf("\n"); -#endif - - MtdWriteContext *write = mtd_write_partition(part); - if (write == NULL) { - LOGE("Can't open %s\n(%s)\n", MISC_NAME, strerror(errno)); - return -1; - } - if (mtd_write_data(write, data, size) != size) { - LOGE("Can't write %s\n(%s)\n", MISC_NAME, strerror(errno)); - mtd_write_close(write); - return -1; - } - if (mtd_write_close(write)) { - LOGE("Can't finish %s\n(%s)\n", MISC_NAME, strerror(errno)); - return -1; - } - - LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : ""); - return 0; -} - -/* Update Image - * - * - will be stored in the "cache" partition - * - bad blocks will be ignored, like boot.img and recovery.img - * - the first block will be the image header (described below) - * - the size is in BYTES, inclusive of the header - * - offsets are in BYTES from the start of the update header - */ - -struct update_header { - unsigned char MAGIC[UPDATE_MAGIC_SIZE]; - - unsigned version; - unsigned size; - - unsigned image_offset; - unsigned image_length; -}; - -int write_update_for_bootloader( - const char *update, int update_length, - const char *log_filename) { - const MtdPartition *part = mtd_find_partition_by_name(CACHE_NAME); - if (part == NULL) { - LOGE("Can't find %s\n", CACHE_NAME); - return -1; - } - - MtdWriteContext *write = mtd_write_partition(part); - if (write == NULL) { - LOGE("Can't open %s\n(%s)\n", CACHE_NAME, strerror(errno)); - return -1; - } - - /* Write an invalid (zero) header first, to disable any previous - * update and any other structured contents (like a filesystem), - * and as a placeholder for the amount of space required. - */ - - struct update_header header; - memset(&header, 0, sizeof(header)); - const ssize_t header_size = sizeof(header); - if (mtd_write_data(write, (char*) &header, header_size) != header_size) { - LOGE("Can't write header to %s\n(%s)\n", CACHE_NAME, strerror(errno)); - mtd_write_close(write); - return -1; - } - - /* Write each section individually block-aligned, so we can write - * each block independently without complicated buffering. - */ - - memcpy(&header.MAGIC, UPDATE_MAGIC, UPDATE_MAGIC_SIZE); - header.version = UPDATE_VERSION; - header.size = header_size; - - if (log_filename != NULL) { - // Write 1 byte into the following block, then fill to the end - // in order to reserve that block. We'll use the block to - // send a copy of the log through to the next invocation of - // recovery. We write the log as late as possible in order to - // capture any messages emitted by this function. - mtd_erase_blocks(write, 0); - if (mtd_write_data(write, (char*) &header, 1) != 1) { - LOGE("Can't write log block to %s\n(%s)\n", - CACHE_NAME, strerror(errno)); - mtd_write_close(write); - return -1; - } - } - - off_t image_start_pos = mtd_erase_blocks(write, 0); - header.image_length = update_length; - if ((int) header.image_offset == -1 || - mtd_write_data(write, update, update_length) != update_length) { - LOGE("Can't write update to %s\n(%s)\n", CACHE_NAME, strerror(errno)); - mtd_write_close(write); - return -1; - } - mtd_erase_blocks(write, 0); - /* Sending image offset as it is.Apps bootloader will take care of bad blocks */ - header.image_offset = 0x80000; - - /* Write the header last, after all the blocks it refers to, so that - * when the magic number is installed everything is valid. - */ - - if (mtd_write_close(write)) { - LOGE("Can't finish writing %s\n(%s)\n", CACHE_NAME, strerror(errno)); - return -1; - } - - write = mtd_write_partition(part); - if (write == NULL) { - LOGE("Can't reopen %s\n(%s)\n", CACHE_NAME, strerror(errno)); - return -1; - } - - if (mtd_write_data(write, (char*) &header, header_size) != header_size) { - LOGE("Can't rewrite header to %s\n(%s)\n", CACHE_NAME, strerror(errno)); - mtd_write_close(write); - return -1; - } - - if (log_filename != NULL) { - LOGE("writing log\n"); - size_t erase_size; - if (mtd_partition_info(part, NULL, &erase_size, NULL) != 0) { - LOGE("Error reading block size\n(%s)\n", strerror(errno)); - mtd_write_close(write); - return -1; - } - mtd_erase_blocks(write, 0); - - if (erase_size > 0) { - char* log = malloc(erase_size); - FILE* f = fopen(log_filename, "rb"); - // The fseek() may fail if it tries to go before the - // beginning of the log, but that's okay because we want - // to be positioned at the start anyway. - fseek(f, -(erase_size-sizeof(size_t)-LOG_MAGIC_SIZE), SEEK_END); - memcpy(log, LOG_MAGIC, LOG_MAGIC_SIZE); - size_t read = fread(log+sizeof(size_t)+LOG_MAGIC_SIZE, - 1, erase_size-sizeof(size_t)-LOG_MAGIC_SIZE, f); - LOGI("read %d bytes from log\n", (int)read); - *(size_t *)(log + LOG_MAGIC_SIZE) = read; - fclose(f); - if (mtd_write_data(write, log, erase_size) != erase_size) { - LOGE("failed to store log in cache partition\n(%s)\n", - strerror(errno)); - mtd_write_close(write); - } - free(log); - } - } - - if (mtd_erase_blocks(write, 0) != image_start_pos) { - LOGE("Misalignment rewriting %s\n(%s)\n", CACHE_NAME, strerror(errno)); - mtd_write_close(write); - return -1; - } - - LOGE("closing partition\n"); - if (mtd_write_close(write)) { - LOGE("Can't finish header of %s\n(%s)\n", CACHE_NAME, strerror(errno)); - return -1; - } - - return 0; -} diff --git a/updater/bootloader.h b/updater/bootloader.h deleted file mode 100644 index bc80a258eb08343e068d8b933423b225971b7104..0000000000000000000000000000000000000000 --- a/updater/bootloader.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -#ifndef _RECOVERY_BOOTLOADER_H -#define _RECOVERY_BOOTLOADER_H - -/* Bootloader Message - * - * This structure describes the content of a block in flash - * that is used for recovery and the bootloader to talk to - * each other. - * - * The command field is updated by linux when it wants to - * reboot into recovery or to update radio or bootloader firmware. - * It is also updated by the bootloader when firmware update - * is complete (to boot into recovery for any final cleanup) - * - * The status field is written by the bootloader after the - * completion of an "update-radio" command. - * - * The recovery field is only written by linux and used - * for the system to send a message to recovery or the - * other way around. - */ -struct bootloader_message { - char command[32]; - char status[32]; - char recovery[1024]; -}; - -/* Read and write the bootloader command from the "misc" partition. - * These return zero on success. - */ -int get_bootloader_message(struct bootloader_message *out); -int set_bootloader_message(const struct bootloader_message *in); - -/* Write an update to the cache partition for update-radio. - * Note, this destroys any filesystem on the cache partition! - */ -int write_update_for_bootloader( - const char *update, int update_len, - const char *log_filename); - -/* Look for a log stored in the cache partition in the block after the - * firmware update header. If we can read such a log, copy it to - * stdout (ie, the current log). - */ -void recover_firmware_update_log(); - -#define CACHE_NAME "cache" -#define MISC_NAME "misc" - -#define UPDATE_MAGIC "MSM-RADIO-UPDATE" -#define UPDATE_MAGIC_SIZE 16 -#define UPDATE_VERSION 0x00010000 - -#define LOG_MAGIC "LOGmagic" -#define LOG_MAGIC_SIZE 8 - - - -#endif diff --git a/updater/firmware.c b/updater/firmware.c deleted file mode 100644 index 9fc673ab0f27caf051055a8d952c6bc3f087ce2d..0000000000000000000000000000000000000000 --- a/updater/firmware.c +++ /dev/null @@ -1,251 +0,0 @@ -/* Copyright (C) 2008 The Android Open Source Project - * Copyright (c) 2012, The Linux Foundation. All rights reserved. - * - * 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 "bootloader.h" -#include "common.h" -#include "firmware.h" -#include "mtdutils/mtdutils.h" - -#include <errno.h> -#include <string.h> -#include <sys/reboot.h> -#include <sys/mount.h> - -/* Bootloader / Recovery Flow - * - * On every boot, the bootloader will read the bootloader_message - * from flash and check the command field. The bootloader should - * deal with the command field not having a 0 terminator correctly - * (so as to not crash if the block is invalid or corrupt). - * - * The bootloader will have to publish the partition that contains - * the bootloader_message to the linux kernel so it can update it. - * - * if command == "boot-recovery" -> boot recovery.img - * else if command == "update-radio" -> update radio image (below) - * else -> boot boot.img (normal boot) - * - * Radio Update Flow - * 1. the bootloader will attempt to load and validate the header - * 2. if the header is invalid, status="invalid-update", goto #8 - * 3. display the busy image on-screen - * 4. if the update image is invalid, status="invalid-radio-image", goto #8 - * 5. attempt to update the firmware (depending on the command) - * 6. if successful, status="okay", goto #8 - * 7. if failed, and the old image can still boot, status="failed-update" - * 8. write the bootloader_message, leaving the recovery field - * unchanged, updating status, and setting command to - * "boot-recovery" - * 9. reboot - * - * The bootloader will not modify or erase the cache partition. - * It is recovery's responsibility to clean up the mess afterwards. - */ - -#undef LOGE -#define LOGE(...) fprintf(stderr, "E:" __VA_ARGS__) - -static int num_volumes = 0; -static Volume* device_volumes = NULL; - -int install_firmware_update(const char *update_type, - const char *update_data, - size_t update_length, - const char *log_filename) { - if (update_data == NULL || update_length == 0) return 0; - - mtd_scan_partitions(); - - /* We destroy the cache partition to pass the update image to the - * bootloader, so all we can really do afterwards is wipe cache and reboot. - * Set up this instruction now, in case we're interrupted while writing. - */ - - struct bootloader_message boot; - memset(&boot, 0, sizeof(boot)); - strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); - strlcpy(boot.recovery, "recovery\n--wipe_cache\n", sizeof(boot.command)); - if (set_bootloader_message(&boot)) return -1; - - if (write_update_for_bootloader( - update_data, update_length, - log_filename)) { - LOGE("Can't write %s image\n(%s)\n", update_type, strerror(errno)); - return -1; - } - - /* The update image is fully written, so now we can instruct the bootloader - * to install it. (After doing so, it will come back here, and we will - * wipe the cache and reboot into the system.) - */ - snprintf(boot.command, sizeof(boot.command), "update-%s", update_type); - if (set_bootloader_message(&boot)) { - return -1; - } - - reboot(RB_AUTOBOOT); - - LOGE("Can't reboot\n"); - return -1; -} - -static void load_volume_table() { - int alloc = 2; - device_volumes = malloc(alloc * sizeof(Volume)); - - // Insert an entry for /tmp, which is the ramdisk and is always mounted. - device_volumes[0].mount_point = "/tmp"; - device_volumes[0].fs_type = "ramdisk"; - device_volumes[0].device = NULL; - device_volumes[0].device2 = NULL; - num_volumes = 1; - - FILE* fstab; - fstab = fopen("/etc/recovery_mmc.fstab", "r"); - - if (fstab == NULL) { - LOGE("failed to open /etc/recovery.fstab (%s)\n", strerror(errno)); - return; - } - - char buffer[1024]; - int i; - while (fgets(buffer, sizeof(buffer)-1, fstab)) { - for (i = 0; buffer[i] && isspace(buffer[i]); ++i); - if (buffer[i] == '\0' || buffer[i] == '#') continue; - - char* original = strdup(buffer); - - char* mount_point = strtok(buffer+i, " \t\n"); - char* fs_type = strtok(NULL, " \t\n"); - char* device = strtok(NULL, " \t\n"); - // lines may optionally have a second device, to use if - // mounting the first one fails. - char* device2 = strtok(NULL, " \t\n"); - - if (mount_point && fs_type && device) { - while (num_volumes >= alloc) { - alloc *= 2; - device_volumes = realloc(device_volumes, alloc*sizeof(Volume)); - } - device_volumes[num_volumes].mount_point = strdup(mount_point); - device_volumes[num_volumes].fs_type = strdup(fs_type); - device_volumes[num_volumes].device = strdup(device); - device_volumes[num_volumes].device2 = - device2 ? strdup(device2) : NULL; - ++num_volumes; - } else { - LOGE("skipping malformed recovery.fstab line: %s\n", original); - } - free(original); - } - - fclose(fstab); -} - -static Volume* volume_for_path(const char* path) { - int i; - for (i = 0; i < num_volumes; ++i) { - Volume* v = device_volumes+i; - int len = strlen(v->mount_point); - if (strncmp(path, v->mount_point, len) == 0 && - (path[len] == '\0' || path[len] == '/')) { - return v; - } - } - return NULL; -} - -int start_firmware_update(char *update_type, char *part_type) -{ - int result; - struct bootloader_message boot; - - memset(&boot, 0, sizeof(boot)); - - if(!strcmp(part_type, "mtd")) - { - mtd_scan_partitions(); - - strlcpy(boot.recovery, "recovery\n--radio_status\n", sizeof(boot.command)); - snprintf(boot.command, sizeof(boot.command), "update-%s", update_type); - if (set_bootloader_message(&boot)) { - return -1; - } - } - else if(!strcmp(part_type, "emmc")) - { - Volume *v = NULL; - - load_volume_table(); - - v = volume_for_path("/sys_boot"); - if (strcmp(v->fs_type, "vfat")) - { - LOGE("Error in fs_type for sys_boot partition\n"); - return -1; - } - - mkdir("/sys_boot", 777); - - /* Try mounting device first */ - result = mount(v->device, v->mount_point, v->fs_type, - MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); - if(result) - { - /* Try mounting device2 next */ - result = mount(v->device2, v->mount_point, v->fs_type, - MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); - } - if(result == 0) - { - /* Creating cookie file for radio update */ - FILE *fp = fopen("/sys_boot/upcookie.txt", "w"); - fclose(fp); - - /* Unmount the sdcard now */ - if(umount(v->mount_point)) - { - LOGE("Error in unmounting %s\n",v->mount_point); - return -1; - } - else - LOGI("Created cookie file for eMMC radio update\n"); - } - else - { - LOGE("Error in mounting %s\n",v->mount_point); - return -1; - } - memset(&boot, 0, sizeof(boot)); - v = volume_for_path("/misc"); - if (set_bootloader_message_emmc(&boot, v)) { - return -1; - } - } - else - { - LOGE("Error in part_type %s\n",part_type); - return -1; - } - - sync(); - reboot(RB_AUTOBOOT); - - // Can't reboot? WTF? - LOGE("Can't reboot\n"); - return -1; -} diff --git a/updater/firmware.h b/updater/firmware.h deleted file mode 100644 index bb319bf6075eb1d7266e522b4ab99c6673ffd99c..0000000000000000000000000000000000000000 --- a/updater/firmware.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -#ifndef _RECOVERY_FIRMWARE_H -#define _RECOVERY_FIRMWARE_H - -/* Reboot into the bootloader to install the given update. - * Returns 0 if no radio image was defined, nonzero on error, - * doesn't return at all on success... - */ -int install_firmware_update(const char *update_type, - const char *update_data, - size_t update_length, - const char *log_filename); - -#endif diff --git a/updater/recovery_updater.c b/updater/recovery_updater.c deleted file mode 100644 index f5804908acce40ec141c73580288cb672b287849..0000000000000000000000000000000000000000 --- a/updater/recovery_updater.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Copyright (C) 2009 The Android Open Source Project - * Copyright (c) 2012, The Linux Foundation. All rights reserved. - * - * 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 <stdio.h> -#include <errno.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> - -#include "edify/expr.h" -#include "firmware.h" - -Value* UpdateFn(const char* name, State* state, int argc, Expr* argv[]) { - if (argc != 1) { - return ErrorAbort(state, "%s() expects 6 args, got %d", name, argc); - } - - char* type = strrchr(name, '_'); - if (type == NULL || *(type+1) == '\0') { - return ErrorAbort(state, "%s() couldn't get type from function name", - name); - } - ++type; - - Value* image; - - if (ReadValueArgs(state, argv, 1, &image) <0) { - return NULL; - } - - if (image->type != VAL_BLOB) { - printf("image argument is not blob (is type %d)\n", image->type); - goto done; - } - - install_firmware_update(type, image->data, image->size, "/tmp/recovery.log"); - printf("%s: install_firmware_update returned!\n", name); - - done: - FreeValue(image); - // install_firmware_update should reboot. If it returns, it failed. - return StringValue(strdup("")); -} - -Value* SetRadioFn(const char* name, State* state, int argc, Expr* argv[]) { - char *part_type; - - if (argc != 1) { - return ErrorAbort(state, "%s() expects arg, got %d", name, argc); - } - - char* type = strrchr(name, '_'); - if (type == NULL || *(type+1) == '\0') { - return ErrorAbort(state, "%s() couldn't get type from function name", - name); - } - ++type; - - if (ReadArgs(state, argv, 1, &part_type) <0) { - return NULL; - } - - start_firmware_update(type,part_type); - - return StringValue(strdup("")); -} - -void Register_librecovery_updater_qcom() { - fprintf(stderr, "installing QCOM updater extensions\n"); - - RegisterFunction("qcom.install_radio", UpdateFn); - RegisterFunction("qcom.set_radio", SetRadioFn); -}