From e53eea6426da49dfb542929d5aa686667f4d416f Mon Sep 17 00:00:00 2001 From: Ziyan Date: Sun, 3 Jan 2016 04:12:26 +0100 Subject: Remove bootloader and radio updaters We're not going to create OTA packages with these images. samsung.fs_size_fix also got removed: nobody is going to install this to a factory (never installed any factory image, bootloader or ota package), encrypted maguro device. Change-Id: Iae292f4fce48eede0d5ac34e90096c0258552b53 --- BoardConfig.mk | 4 - recovery/Android.mk | 17 -- recovery/bootloader.c | 367 -------------------------------------------- recovery/bootloader.h | 25 --- recovery/recovery_updater.c | 127 --------------- releasetools.py | 121 --------------- 6 files changed, 661 deletions(-) delete mode 100644 recovery/Android.mk delete mode 100644 recovery/bootloader.c delete mode 100644 recovery/bootloader.h delete mode 100644 recovery/recovery_updater.c delete mode 100644 releasetools.py diff --git a/BoardConfig.mk b/BoardConfig.mk index cedb0bc..07917c3 100755 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -69,10 +69,6 @@ BOARD_CREATE_TUNA_HDCP_KEYS_SYMLINK := true # set if the target supports FBIO_WAITFORVSYNC TARGET_HAS_WAITFORVSYNC := true -# device-specific extensions to the updater binary -TARGET_RECOVERY_UPDATER_LIBS += librecovery_updater_tuna -TARGET_RELEASETOOLS_EXTENSIONS := $(DEVICE_FOLDER) - # Filesystem TARGET_USERIMAGES_USE_EXT4 := true TARGET_USERIMAGES_USE_F2FS := true diff --git a/recovery/Android.mk b/recovery/Android.mk deleted file mode 100644 index bb6aa45..0000000 --- a/recovery/Android.mk +++ /dev/null @@ -1,17 +0,0 @@ -ifneq (,$(findstring $(TARGET_DEVICE),tuna toro toroplus maguro)) - -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -# Edify extension functions for doing bootloader updates on Tuna devices. - -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES += bootable/recovery system/vold external/openssl/include -LOCAL_SRC_FILES := recovery_updater.c bootloader.c - -# should match TARGET_RECOVERY_UPDATER_LIBS set in BoardConfig.mk -LOCAL_MODULE := librecovery_updater_tuna - -include $(BUILD_STATIC_LIBRARY) - -endif diff --git a/recovery/bootloader.c b/recovery/bootloader.c deleted file mode 100644 index afe13a7..0000000 --- a/recovery/bootloader.c +++ /dev/null @@ -1,367 +0,0 @@ -/* - * Copyright (C) 2011 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 -#include -#include -#include -#include -#include - -#include "bootloader.h" - -#define SECTOR_SIZE 512 -#define NUM_SECONDARY_GPT_SECTORS 34 -#define PIT_PARTITION_TABLE_SIZE 0x1000 // 4KB -#define BOOT_PART_LEN 0x20000 // 128KB -#define SBL_OFFSET (PIT_PARTITION_TABLE_SIZE + (BOOT_PART_LEN * 4)) - -#define SMALL_BUFFER_SIZE 0x20 - -// A combination of these defines the specification of the device. -#define OMAP4460 0x1 -#define OMAP4430 0x2 -#define CHIP_HS 0x4 -#define CHIP_EMU 0x8 -#define MSV_PROD 0x10 - -// Location of the PIT partition table in EMMC -#define PIT_PARTITION_TABLE_LOCATION 0x4400 - -static const char* FAMILY_LOCATION = "/sys/board_properties/soc/family"; -static const char* TYPE_LOCATION = "/sys/board_properties/soc/type"; -static const char* MSV_LOCATION = "/sys/board_properties/soc/msv"; - -static const char* MMC_LOCATION = "/dev/block/mmcblk0"; - -/* pit structure = header + (pit partition info * n) */ -struct pit_header { - unsigned int magic; - int count; /* onenand + mmc partitions */ - int dummy[5]; -} __attribute__((packed)); - -struct pit_partinfo { - int binary; /* BINARY_TYPE_ */ - int device; /* PARTITION_DEV_TYPE_ */ - int id; /* partition id */ - int attribute; /* PARTITION_ATTR_ */ - int update; /* PARTITION_UPDATE_ATTR_ - dedicated. */ - unsigned int blksize; /* mmc start sector */ - unsigned int blklen; /* sector count */ - unsigned int offset; /* file offset (in TAR) */ - unsigned int filesize; /* file size */ - char name[32]; /* partition name */ - char filename[32]; /* file name */ - char deltaname[32]; /* delta file name - dedicated. */ -} __attribute__((packed)); - -unsigned int read_whole_file(const char* fname, char* buffer, - int buffer_size) { - memset(buffer, 0, buffer_size); - - FILE* f = fopen(fname, "rb"); - if (f == NULL) { - fprintf(stderr, "Cannot open %s!\n", fname); - return -1; - } - - int read_byte_count = fread(buffer, 1, buffer_size - 1, f); - fclose(f); - if (read_byte_count < 0) { - fprintf(stderr, "Couldn't read %s\n", fname); - return -1; - } - - // Remove any newlines at the end. - while (buffer[read_byte_count - 1] == '\n') { - buffer[--read_byte_count] = 0; - } - - return 0; -} - -// Get the specifications for this device -int get_specification() { - int spec = 0; - - char file_data[SMALL_BUFFER_SIZE]; - - if (read_whole_file(FAMILY_LOCATION, file_data, SMALL_BUFFER_SIZE) == 0) { - if (strcmp(file_data, "OMAP4430") == 0) { - spec |= OMAP4430; - } else if (strcmp(file_data, "OMAP4460") == 0) { - spec |= OMAP4460; - } else { - fprintf(stderr, "Unknown family: %s\n", file_data); - return -1; - } - } else { - fprintf(stderr, "No family\n"); - return -1; - } - - if (read_whole_file(TYPE_LOCATION, file_data, SMALL_BUFFER_SIZE) == 0) { - if (strcmp(file_data, "HS") == 0) { - spec |= CHIP_HS; - } else if (strcmp(file_data, "EMU") == 0) { - spec |= CHIP_EMU; - } else { - fprintf(stderr, "Unknown chip type: %s\n", file_data); - return -1; - } - } else { - fprintf(stderr, "No chip type\n"); - return -1; - } - - // MSV is either prod (non-zero) or eng (zero). Default to eng. - if (read_whole_file(MSV_LOCATION, file_data, SMALL_BUFFER_SIZE) == 0) { - if (strtoul(file_data, NULL, 16) != 0) { - spec |= MSV_PROD; - } - } else { - fprintf(stderr, "No msv\n"); - } - - return spec; -} - - -// Four different xloaders are supported by bootloader.img: -// 4460 EMU, 4460 HS (eng), 4460 HS (prod), 4430 HS. -// The layout of the bootloader.img is: -// -// PIT Partition table (4KB) -// 4460 EMU xloader (128KB) -// 4460 HS (eng) xloader (128KB) -// 4460 HS (prod) xloader (128KB) -// 4430 HS xloader(128KB) -// sbl (the rest) -int get_xloader_offset() { - int spec = get_specification(); - - if (spec < 0) { - return -1; - } - - if (spec & OMAP4460 && - spec & CHIP_EMU) { - return 0; - } else if (spec & OMAP4460 && - spec & CHIP_HS && - !(spec & MSV_PROD)) { - return BOOT_PART_LEN; - } else if (spec & OMAP4460 && - spec & CHIP_HS && - spec & MSV_PROD) { - return BOOT_PART_LEN * 2; - } else if (spec & OMAP4430 && - spec & CHIP_HS) { - return BOOT_PART_LEN * 3; - } - - fprintf(stderr, "Unsupported spec for bootloader.img: %d", spec); - return -1; -} - -int write_pit_partition_table(const char* image_data, - size_t image_size) { - int written = 0; - int close_status = 0; - int to_write; - const char* curr; - - - int mmcfd = open(MMC_LOCATION, O_RDWR); - if (mmcfd < 0) { - fprintf(stderr, "Could not open %s\n", MMC_LOCATION); - return -1; - } - - // zero out gpt magic field - if (lseek(mmcfd, SECTOR_SIZE, SEEK_SET) < 0) { - fprintf(stderr, "Couldn't seek to the start of sector 1\n"); - close(mmcfd); - return -1; - } - - char buf[SECTOR_SIZE]; - if (read(mmcfd, buf, SECTOR_SIZE) != SECTOR_SIZE) { - fprintf(stderr, "Failed to read sector 1\n"); - close(mmcfd); - return -1; - } - - memset(buf, 0, 8); - - if (lseek(mmcfd, SECTOR_SIZE, SEEK_SET) < 0) { - fprintf(stderr, "Couldn't seek to the start of sector 1, part 2\n"); - close(mmcfd); - return -1; - } - - to_write = SECTOR_SIZE; - curr = buf; - while (to_write > 0) { - written = write(mmcfd, curr, to_write); - if (written < 0 && errno != EINTR) { - fprintf(stderr, "Couldn't overwrite sector 1\n"); - close(mmcfd); - return -1; - } - if (written > 0) { - to_write -= written; - curr += written; - } - } - - // modify the pit partition info to reflect userdata size - // before writing the pit partition table - char pit_partition_copy[PIT_PARTITION_TABLE_SIZE]; - memcpy(pit_partition_copy, image_data, PIT_PARTITION_TABLE_SIZE); - - struct pit_header* hd = (struct pit_header*) pit_partition_copy; - int i; - for (i = 0; i < hd->count; i++) { - struct pit_partinfo* pi = (struct pit_partinfo*) - (pit_partition_copy + sizeof(*hd) + sizeof(*pi) * i); - if (strcmp(pi->name, "userdata") == 0) { - unsigned int num_sectors; - if (ioctl(mmcfd, BLKGETSIZE, &num_sectors) < 0) { - fprintf(stderr, "Couldn't get sector count\n"); - close(mmcfd); - return -1; - } - - // There are NUM_SECONDARY_GPT_SECTORS sectors reserved at the end of the - // device to hold a backup copy of the GPT, so we subtract that number. - pi->blklen = num_sectors - pi->blksize - NUM_SECONDARY_GPT_SECTORS; - break; - } - } - - if (i == hd->count) { - fprintf(stderr, "No userdata partition found\n"); - close(mmcfd); - return -1; - } - - // copy the modified pit partition table data to the correct location - if (lseek(mmcfd, PIT_PARTITION_TABLE_LOCATION, SEEK_SET) < 0) { - fprintf(stderr, "Couldn't seek to the pit partition table location\n"); - close(mmcfd); - return -1; - } - - to_write = PIT_PARTITION_TABLE_SIZE; - curr = pit_partition_copy; - while (to_write > 0) { - written = write(mmcfd, curr, to_write); - if (written < 0 && errno != EINTR) { - fprintf(stderr, "Failed writing pit partition table\n"); - close(mmcfd); - return -1; - } - if (written > 0) { - to_write -= written; - curr += written; - } - } - - if (close(mmcfd) != 0) { - fprintf(stderr, "Failed to close file\n"); - return -1; - } - - return 0; -} - -int write_xloader(const char* image_data, - size_t image_size, - const char* xloader_loc) { - int xloader_offset = get_xloader_offset(); - - if (xloader_offset < 0) { - return -1; - } - - // The offsets into xloader part of the bootloader image - xloader_offset += PIT_PARTITION_TABLE_SIZE; - - FILE* xloader = fopen(xloader_loc, "r+b"); - if (xloader == NULL) { - fprintf(stderr, "Could not open %s\n", xloader_loc); - return -1; - } - - // index into the correct xloader offset - int written = fwrite(image_data+xloader_offset, 1, BOOT_PART_LEN, xloader); - int close_status = fclose(xloader); - if (written != BOOT_PART_LEN || close_status != 0) { - fprintf(stderr, "Failed writing to /xloader\n"); - return -1; - } - - return 0; -} - -int write_sbl(const char* image_data, - size_t image_size, - const char* sbl_loc) { - unsigned int sbl_size = image_size - SBL_OFFSET; - FILE* sbl = fopen(sbl_loc, "r+b"); - if (sbl == NULL) { - fprintf(stderr, "Could not open %s\n", sbl_loc); - return -1; - } - - int written = fwrite(image_data+SBL_OFFSET, 1, sbl_size, sbl); - int close_status = fclose(sbl); - if (written != sbl_size || close_status != 0) { - fprintf(stderr, "Failed writing to /sbl\n"); - return -1; - } - - return 0; -} - -int update_bootloader(const char* image_data, - size_t image_size, - const char* xloader_loc, - const char* sbl_loc) { - if (image_size < SBL_OFFSET) { - fprintf(stderr, "image size %d is too small\n", image_size); - return -1; - } - - if (write_pit_partition_table(image_data, image_size) < 0) { - return -1; - } - - if (write_xloader(image_data, image_size, xloader_loc) < 0) { - return -1; - } - - if (write_sbl(image_data, image_size, sbl_loc) < 0) { - return -1; - } - - return 0; -} diff --git a/recovery/bootloader.h b/recovery/bootloader.h deleted file mode 100644 index f7f7f26..0000000 --- a/recovery/bootloader.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2011 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 __BOOTLOADER_H__ -#define __BOOTLOADER_H__ - -int update_bootloader(const char* image_data, - size_t image_size, - const char* xloader_loc, - const char* sbl_loc); - -#endif diff --git a/recovery/recovery_updater.c b/recovery/recovery_updater.c deleted file mode 100644 index 0c49f9a..0000000 --- a/recovery/recovery_updater.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2011 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 -#include -#include -#include -#include -#include -#include - -#include "edify/expr.h" -#include "bootloader.h" - -Value* WriteBootloaderFn(const char* name, State* state, int argc, Expr* argv[]) -{ - int result = -1; - Value* img; - Value* xloader_loc; - Value* sbl_loc; - - if (argc != 3) { - return ErrorAbort(state, "%s() expects 3 args, got %d", name, argc); - } - - if (ReadValueArgs(state, argv, 3, &img, &xloader_loc, &sbl_loc) < 0) { - return NULL; - } - - if(img->type != VAL_BLOB || - xloader_loc->type != VAL_STRING || - sbl_loc->type != VAL_STRING) { - FreeValue(img); - FreeValue(xloader_loc); - FreeValue(sbl_loc); - return ErrorAbort(state, "%s(): argument types are incorrect", name); - } - - result = update_bootloader(img->data, img->size, - xloader_loc->data, sbl_loc->data); - FreeValue(img); - FreeValue(xloader_loc); - FreeValue(sbl_loc); - return StringValue(strdup(result == 0 ? "t" : "")); -} - -/* - * The size of the userdata partition for HSPA Galaxy Nexus devices is incorrect - * in the partition as it comes from the factory. Updating the bootloader fixes - * the partition table, and makes the size of the userdata partition 1 sector - * smaller. However, if the user had encrypted their device with the original - * incorrect size of the partition table, the crypto footer has saved that - * size, and tries to map that much data when decrypting. However, with the - * new partition table, that size is too big to be mapped, and the kernel - * throws an error, and the user can't decrypt and boot the device after the - * OTA is installed. Oops! - * - * The fix here is to recognize a crypto footer that has the wrong size, and - * update it to the new correct size. This program should be run as part of - * the recovery script for HSPA Galaxy Nexus devices. - */ - -#define BAD_SIZE 0x01b14fdfULL -#define GOOD_SIZE 0x01b14fdeULL - -#define HSPA_PRIME_KEY_PARTITION "/dev/block/platform/omap/omap_hsmmc.0/by-name/metadata" - -Value* FsSizeFixFn(const char* name, State* state, int argc, Expr* argv[]) -{ - struct crypt_mnt_ftr ftr; - int fd; - - if (argc != 0) { - return ErrorAbort(state, "%s() expects 0 args, got %d", name, argc); - } - - if ((fd = open(HSPA_PRIME_KEY_PARTITION, O_RDWR)) == -1) { - return ErrorAbort(state, "%s() Cannot open %s\n", name, HSPA_PRIME_KEY_PARTITION); - } - - if (read(fd, &ftr, sizeof(ftr)) != sizeof(ftr)) { - close(fd); - return ErrorAbort(state, "%s() Cannot read crypto footer %s\n", name, HSPA_PRIME_KEY_PARTITION); - } - - if ((ftr.magic == CRYPT_MNT_MAGIC) && (ftr.fs_size == BAD_SIZE)) { - ftr.fs_size = GOOD_SIZE; - if (lseek(fd, 0, SEEK_SET) == 0) { - if (write(fd, &ftr, sizeof(ftr)) == sizeof(ftr)) { - fsync(fd); /* Make sure it gets to the disk */ - fprintf(stderr, "Footer updated\n"); - close(fd); - return StringValue(strdup("t")); - } - } - close(fd); - return ErrorAbort(state, "%s() Cannot seek or write crypto footer %s\n", name, HSPA_PRIME_KEY_PARTITION); - } - - /* Nothing to do */ - fprintf(stderr, "Footer doesn't need updating\n"); - close(fd); - return StringValue(strdup("t")); -} - -void Register_librecovery_updater_tuna() { - fprintf(stderr, "installing samsung updater extensions\n"); - - RegisterFunction("samsung.write_bootloader", WriteBootloaderFn); - RegisterFunction("samsung.fs_size_fix", FsSizeFixFn); -} diff --git a/releasetools.py b/releasetools.py deleted file mode 100644 index b9dabdb..0000000 --- a/releasetools.py +++ /dev/null @@ -1,121 +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. -# 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. - -"""Emit commands needed for Prime during OTA installation -(installing the bootloader and radio images).""" - -import common - -def FullOTA_InstallEnd(info): - try: - bootloader_img = info.input_zip.read("RADIO/bootloader.img") - except KeyError: - print "no bootloader.img in target_files; skipping install" - else: - WriteBootloader(info, bootloader_img) - - try: - radio_img = info.input_zip.read("RADIO/radio.img") - except KeyError: - print "no radio.img in target_files; skipping install" - else: - WriteRadio(info, radio_img) - - FsSizeFix(info) - -def IncrementalOTA_VerifyEnd(info): - try: - target_radio_img = info.target_zip.read("RADIO/radio.img") - source_radio_img = info.source_zip.read("RADIO/radio.img") - except KeyError: - # No source or target radio. Nothing to verify - pass - else: - if source_radio_img != target_radio_img: - info.script.CacheFreeSpaceCheck(len(source_radio_img)) - radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) - info.script.PatchCheck("%s:%s:%d:%s:%d:%s" % ( - radio_type, radio_device, - len(source_radio_img), common.sha1(source_radio_img).hexdigest(), - len(target_radio_img), common.sha1(target_radio_img).hexdigest())) - -def IncrementalOTA_InstallEnd(info): - try: - target_bootloader_img = info.target_zip.read("RADIO/bootloader.img") - try: - source_bootloader_img = info.source_zip.read("RADIO/bootloader.img") - except KeyError: - source_bootloader_img = None - - if source_bootloader_img == target_bootloader_img: - print "bootloader unchanged; skipping" - else: - WriteBootloader(info, target_bootloader_img) - except KeyError: - print "no bootloader.img in target target_files; skipping install" - - try: - target_radio_img = info.target_zip.read("RADIO/radio.img") - try: - source_radio_img = info.source_zip.read("RADIO/radio.img") - except KeyError: - source_radio_img = None - - WriteRadio(info, target_radio_img, source_radio_img) - except KeyError: - print "no radio.img in target target_files; skipping install" - - FsSizeFix(info) - -def FsSizeFix(info): - info.script.Print("Fixing fs_size in crypto footer...") - info.script.AppendExtra('''assert(samsung.fs_size_fix());''') - -def WriteBootloader(info, bootloader_img): - common.ZipWriteStr(info.output_zip, "bootloader.img", bootloader_img) - fstab = info.info_dict["fstab"] - - info.script.Print("Writing bootloader...") - info.script.AppendExtra('''assert(samsung.write_bootloader( - package_extract_file("bootloader.img"), "%s", "%s"));''' % \ - (fstab["/xloader"].device, fstab["/sbl"].device)) - -def WriteRadio(info, target_radio_img, source_radio_img=None): - tf = common.File("radio.img", target_radio_img) - if source_radio_img is None: - tf.AddToZip(info.output_zip) - info.script.Print("Writing radio...") - info.script.WriteRawImage("/radio", tf.name) - else: - sf = common.File("radio.img", source_radio_img); - if tf.sha1 == sf.sha1: - print "radio image unchanged; skipping" - else: - diff = common.Difference(tf, sf, diff_program="bsdiff") - common.ComputeDifferences([diff]) - _, _, d = diff.GetPatch() - if d is None or len(d) > tf.size * common.OPTIONS.patch_threshold: - # computing difference failed, or difference is nearly as - # big as the target: simply send the target. - tf.AddToZip(info.output_zip) - info.script.Print("Writing radio...") - info.script.WriteRawImage("/radio", tf.name) - else: - common.ZipWriteStr(info.output_zip, "radio.img.p", d) - info.script.Print("Patching radio...") - radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) - info.script.ApplyPatch( - "%s:%s:%d:%s:%d:%s" % (radio_type, radio_device, - sf.size, sf.sha1, tf.size, tf.sha1), - "-", tf.size, tf.sha1, sf.sha1, "radio.img.p") -- cgit v1.1