Skip to content

Commit

Permalink
cancro: deprecate kitkat base
Browse files Browse the repository at this point in the history
- force eveyone to upgrade to xiaomi mm stuffs for better
  compatibilty using baseband assertion

- update fingerprint to match lastest public stock build

- switch to full_config instead of mini, anyone
  with mm baseband will have 1.2GB of system

- if installtion fails due to old baseband, the recovery
  will prompt user to visit a webpage with instruction
  to update baseband and other minor things

Baseband assertion based on:
CyanogenMod/android_device_lge_d855@db17ee7

Change-Id: I3da5bdab7889339b32e70b11d4c877f8af07ce67
Signed-off-by: jrizzoli <[email protected]>
  • Loading branch information
jrizzoli committed May 16, 2016
1 parent 3999ff9 commit c8b5468
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 16 deletions.
1 change: 1 addition & 0 deletions board-info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require version-baseband=MPSS.DI.4.0
5 changes: 5 additions & 0 deletions board/releasetools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ReleaseTools
TARGET_RELEASETOOLS_EXTENSIONS := $(DEVICE_PATH)/releasetools
TARGET_RECOVERY_UPDATER_LIBS := librecovery_updater_cancro

TARGET_BOARD_INFO_FILE ?= $(DEVICE_PATH)/board-info.txt
13 changes: 2 additions & 11 deletions cancro.mk
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
ebtables \
ethertypes \
curl \
libnl_2 \
libbson

Expand All @@ -220,16 +219,8 @@ PRODUCT_PACKAGES += \
com.dsi.ant.antradio_library \
libantradio

# System properties
PRODUCT_PROPERTY_OVERRIDES += \

# Zip
PRODUCT_PACKAGES += \
zip

# SoundRecorder
PRODUCT_PACKAGES += \
SoundRecorder
# Baseband assertion
PRODUCT_PACKAGES += librecovery_updater_cancro

# Permissions
PRODUCT_COPY_FILES += \
Expand Down
6 changes: 3 additions & 3 deletions cm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ TARGET_SCREEN_WIDTH := 1080
# Inherit from those products. Most specific first.
$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base_telephony.mk)

# Inherit some common CM stuff.
$(call inherit-product, vendor/cm/config/common_full_phone.mk)

# Inherit from cancro device
$(call inherit-product, device/xiaomi/cancro/cancro.mk)

# Enhanced NFC
$(call inherit-product, vendor/cm/config/nfc_enhanced.mk)

# Inherit some common CM stuff.
$(call inherit-product, vendor/cm/config/common_mini_phone.mk)

PRODUCT_NAME := cm_cancro
PRODUCT_DEVICE := cancro
PRODUCT_BRAND := Xiaomi
Expand Down
4 changes: 2 additions & 2 deletions init/init_cancro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void init_msm_properties(unsigned long msm_id, unsigned long msm_ver, char *boar
}

property_set("ro.product.device", "cancro");
property_set("ro.build.fingerprint", "Xiaomi/cancro/cancro:6.0.1/MMB29M/6.1.21:userdebug/test-keys");
property_set("ro.build.description", "cancro-userdebug 6.0.1 MMB29M 6.1.21 test-keys");
property_set("ro.build.fingerprint", "Xiaomi/cancro/cancro:6.0.1/MMB29M/6.5.12:userdebug/test-keys");
property_set("ro.build.description", "cancro-userdebug 6.0.1 MMB29M 6.5.12 test-keys");

switch (raw_id) {
case 1978:
Expand Down
8 changes: 8 additions & 0 deletions recovery/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES := bootable/recovery
LOCAL_SRC_FILES := recovery_updater.c
LOCAL_MODULE := librecovery_updater_cancro
LOCAL_MODULE_TAGS := eng
include $(BUILD_STATIC_LIBRARY)
189 changes: 189 additions & 0 deletions recovery/recovery_updater.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* Copyright (C) 2016, The CyanogenMod 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 <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "edify/expr.h"

#define MAX(a, b) (((a) > (b)) ? (a) : (b))

#define ALPHABET_LEN 256
#define KB 1024

#define BASEBAND_PART_PATH "/dev/block/platform/msm_sdcc.1/by-name/modem"
#define BASEBAND_VER_STR_START "MPSS.DI."
#define BASEBAND_VER_STR_START_LEN 8
#define BASEBAND_VER_BUF_LEN 255
#define BASEBAND_SZ 64000 * KB /* MMAP 64M of BASEBAND, BASEBAND partition is 64M */

/* Boyer-Moore string search implementation from Wikipedia */

/* Return longest suffix length of suffix ending at str[p] */
static int max_suffix_len(const char *str, size_t str_len, size_t p) {
uint32_t i;

for (i = 0; (str[p - i] == str[str_len - 1 - i]) && (i < p); ) {
i++;
}

return i;
}

/* Generate table of distance between last character of pat and rightmost
* occurrence of character c in pat
*/
static void bm_make_delta1(int *delta1, const char *pat, size_t pat_len) {
uint32_t i;
for (i = 0; i < ALPHABET_LEN; i++) {
delta1[i] = pat_len;
}
for (i = 0; i < pat_len - 1; i++) {
uint8_t idx = (uint8_t) pat[i];
delta1[idx] = pat_len - 1 - i;
}
}

/* Generate table of next possible full match from mismatch at pat[p] */
static void bm_make_delta2(int *delta2, const char *pat, size_t pat_len) {
int p;
uint32_t last_prefix = pat_len - 1;

for (p = pat_len - 1; p >= 0; p--) {
/* Compare whether pat[p-pat_len] is suffix of pat */
if (strncmp(pat + p, pat, pat_len - p) == 0) {
last_prefix = p + 1;
}
delta2[p] = last_prefix + (pat_len - 1 - p);
}

for (p = 0; p < (int) pat_len - 1; p++) {
/* Get longest suffix of pattern ending on character pat[p] */
int suf_len = max_suffix_len(pat, pat_len, p);
if (pat[p - suf_len] != pat[pat_len - 1 - suf_len]) {
delta2[pat_len - 1 - suf_len] = pat_len - 1 - p + suf_len;
}
}
}

static char * bm_search(const char *str, size_t str_len, const char *pat,
size_t pat_len) {
int delta1[ALPHABET_LEN];
int delta2[pat_len];
int i;

bm_make_delta1(delta1, pat, pat_len);
bm_make_delta2(delta2, pat, pat_len);

if (pat_len == 0) {
return (char *) str;
}

i = pat_len - 1;
while (i < (int) str_len) {
int j = pat_len - 1;
while (j >= 0 && (str[i] == pat[j])) {
i--;
j--;
}
if (j < 0) {
return (char *) (str + i + 1);
}
i += MAX(delta1[(uint8_t) str[i]], delta2[j]);
}

return NULL;
}

static int get_baseband_version(char *ver_str, size_t len) {
int ret = 0;
int fd;
char *baseband_data = NULL;
char *offset = NULL;

fd = open(BASEBAND_PART_PATH, O_RDONLY);
if (fd < 0) {
ret = errno;
goto err_ret;
}

baseband_data = (char *) mmap(NULL, BASEBAND_SZ, PROT_READ, MAP_PRIVATE, fd, 0);
if (baseband_data == (char *)-1) {
ret = errno;
goto err_fd_close;
}

/* Do Boyer-Moore search across BASEBAND data */
offset = bm_search(baseband_data, BASEBAND_SZ, BASEBAND_VER_STR_START, BASEBAND_VER_STR_START_LEN);
if (offset != NULL) {
strncpy(ver_str, offset, len);
} else {
ret = -ENOENT;
}

munmap(baseband_data, BASEBAND_SZ);
err_fd_close:
close(fd);
err_ret:
return ret;
}

/* verify_baseband("BASEBAND_VERSION", "BASEBAND_VERSION", ...) */
Value * VerifyBasebandFn(const char *name, State *state, int argc, Expr *argv[]) {
char current_baseband_version[BASEBAND_VER_BUF_LEN];
char *baseband_version;
int i, ret;

ret = get_baseband_version(current_baseband_version, BASEBAND_VER_BUF_LEN);
if (ret) {
return ErrorAbort(state, "%s() failed to read current BASEBAND version: %d",
name, ret);
}

for (i = 0; i < argc; i++) {
baseband_version = Evaluate(state, argv[i]);
if (baseband_version < 0) {
return ErrorAbort(state, "%s() error parsing arguments: %d",
name, baseband_version);
}

uiPrintf(state, "Checking for BASEBAND version %s", baseband_version);

/**
* @param count is hardcoded to 11 to check "MPSS.DI.?.0" value only
* because xiaomi changes the other 8 chars every weekly update
* and we just need a MPSS.DI.4.0 baseband
*/
if (strncmp(baseband_version, current_baseband_version, 11) == 0) {
return StringValue(strdup("1"));
}
}

uiPrintf(state, "ERROR: It appears you are running an unsupported baseband. Please visit http://bit.ly/cancroCMBaseband to learn how to update.");
return StringValue(strdup("0"));
}

void Register_librecovery_updater_cancro() {
RegisterFunction("cancro.verify_baseband", VerifyBasebandFn);
}
23 changes: 23 additions & 0 deletions releasetools/releasetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@
# limitations under the License.
#

import hashlib
import common
import re

def FullOTA_Assertions(info):
AddBasebandAssertion(info)
return

def IncrementalOTA_Assertions(info):
AddBasebandAssertion(info)
return

def AddBasebandAssertion(info):
android_info = info.input_zip.read("OTA/android-info.txt")
m = re.search(r'require\s+version-baseband\s*=\s*(\S+)', android_info)
if m:
versions = m.group(1).split('|')
if len(versions) and '*' not in versions:
cmd = 'assert(cancro.verify_baseband(' + ','.join(['"%s"' % baseband for baseband in versions]) + ') == "1");'
info.script.AppendExtra(cmd)
return


def FullOTA_PostValidate(info):
info.script.AppendExtra('run_program("/sbin/e2fsck", "-fy", "/dev/block/platform/msm_sdcc.1/by-name/system");');
info.script.AppendExtra('run_program("/tmp/install/bin/resize2fs_static", "/dev/block/platform/msm_sdcc.1/by-name/system");');
Expand Down

0 comments on commit c8b5468

Please sign in to comment.