本文主要是介绍MTK cpuid 的总结,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- cpuid原理
- 实现
- adb shell "getprop ro.boot.cpuid"
- fastboot getvar cpuid
- 验证结果
- cmdline
- adb
- fastboot
- MTK原始
cpuid原理
cpuid是由cpu 的chip id 和ufs/mmc id组合而成是由MTK平台CPUID,是由chipid和ufs特征信息拼接而成;
安全使用的CPUID在preloader中获取,在传给安全(TEE);
Android侧获取的CPUID是从lk获取,通过命令行传给Linux Kernel的;
CPUSN和EMMCID连起来两种情况:
CPUID=chipid(32位)+ufsid_hash(前24位)
CPUID=chipid(32位)+ufsid(前12)
实现
adb shell “getprop ro.boot.cpuid”
路径:alps/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c
#define CPUID_SIZE 80
char chip_id_num[CPUID_SIZE];
static void set_chip_cpu_id(void)
{u32 hrid_size, i;u32 hrid[4] = {0};char serial_num[CPUID_SIZE];u32 ufs_id0 = 0, ufs_id1 = 0, ufs_id2 = 0;/* read hrid */hrid_size = get_hrid_size();for (i = 0; i < hrid_size; i++) {hrid[i] = get_devinfo_with_index(12 + i);}/* get ufs sn */if (ufs_get_sha256_uid(&ufs_id0, &ufs_id1, &ufs_id2)) {dprintf(CRITICAL, "get unique id failed\n");}/* set chip id cmdline */snprintf(serial_num, CPUID_SIZE, "%s%08x%08x%08x%08x","androidboot.chipid=0x",hrid[0], hrid[1], hrid[2], hrid[3]);cmdline_append(serial_num);dprintf(CRITICAL, "set_chip_cpu_id, chipid=%s\n", serial_num);/* set cpu id cmdline */snprintf(chip_id_num, CPUID_SIZE, "%08x%08x%08x%08x%08x%08x%08x",hrid[0], hrid[1], hrid[2], hrid[3], ufs_id0, ufs_id1, ufs_id2);snprintf(serial_num, CPUID_SIZE, "%s%08x%08x%08x%08x%08x%08x%08x","androidboot.cpuid=0x",hrid[0], hrid[1], hrid[2], hrid[3], ufs_id0, ufs_id1, ufs_id2);cmdline_append(serial_num);dprintf(CRITICAL, "set_chip_cpu_id, cpuid=%s\n", serial_num);
}
//接口
set_chip_cpu_id();
路径:alps/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/common/storage/ufs/ufs_aio_interface.c
#include "sha256_export.h"int ufs_get_sha256_uid(u32 *id0, u32 *id1, u32 *id2)
{struct ufs_unique_id ufs_id;int err = 0;uint8_t hash[SHA256_HASH_SZ] = {0};u32 *pword = (u32 *) hash;/* get ufs sn */err = ufs_get_unique_id(&ufs_id);if (err) {dprintf(CRITICAL, "get ufs id failed, %d\n", err);return err;}err = sha256((unsigned char*)ufs_id.sn, strlen(ufs_id.sn), hash);if (err) {dprintf(CRITICAL, "hash ufs sn fail, %d\n", err);return err;}*id0 = pword[0];*id1 = pword[1];*id2 = pword[2];return err;
}
fastboot getvar cpuid
路径:alps/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/fastboot.c
......
extern char chip_id_num[];
......
fastboot_publish("cpuid", chip_id_num);
验证结果
cmdline
adb root
adb shell cat /proc/cmdline
adb
adb shell "getprop ro.boot.cpuid"
fastboot
fastboot getvar cpuid
//————————————————————华丽分割线————————————————————
MTK原始
//1,获取HRID
File: flashtoolex_api.h
LIBEX_EXPORT status_t LIB_API flashtool_get_hrid(HSESSION hs, uint8* hrid_buf, uint32 hrid_buflen, bool log = false);
//2,获取UFS SN
File: flashtoolex_api.h
LIBEX_EXPORT status_t LIB_API flashtool_get_device_info(HSESSION hs, /*IN OUT*/struct device_info_t* info);typedef struct device_info_t
{union{char8 STUB[8192];struct{struct mmc_info_struct mmc;struct nand_info_struct nand;struct nor_info_struct nor;struct ufs_info_struct ufs;struct ram_info_struct ram;struct chip_id_struct chip_id;unsigned int random_id[4];//add more info here if needed.};};
}device_info_t;struct ufs_info_struct
{uint32 type; //ufs or none.uint32 block_size;uint64 lu0_size;uint64 lu1_size;uint64 lu2_size;uint16 vendor_id;uint8 cid[16+4];uint8 fwver[4+4];uint8 sn[128+4];uint8 pre_eol_info;uint8 life_time_est_a;uint8 life_time_est_b;uint8 stub1;uint32 life_time_status;
};
这两个就是需要调用的接口(Connect DA 之后调用)
File: flashtoolex_api.h
LIBEX_EXPORT status_t LIB_API flashtool_get_hrid(HSESSION hs, uint8* hrid_buf, uint32 hrid_buflen, bool log = false);LIBEX_EXPORT status_t LIB_API flashtool_get_device_info(HSESSION hs, /*IN OUT*/struct device_info_t* info);
这篇关于MTK cpuid 的总结的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!