Android cpu信息获取/修改
CPU信息查看
通过 cat proc/cpuinfo 查看
processor : 7BogoMIPS : 38.40Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuidCPU implementer : 0x51CPU architecture: 8CPU variant : 0xaCPU part : 0x800CPU revision : 2Hardware : Qualcomm Technologies, Inc
应用端,类似某兔兔中CPU信息应该也是从这里获取的
CPU信息修改
cpuinfo 文件内容是在 kernel/msm-4.19/arch/arm64/kernel/cpuinfo.c 中 c_show 函数中写入的
static int c_show(struct seq_file *m, void *v){int i, j;bool compat = personality(current->personality) == PER_LINUX32;seq_printf(m, "Processor\t: AArch64 Processor rev %d (%s)\n",read_cpuid_id() & 15, ELF_PLATFORM);for_each_present_cpu(i) {struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, i);u32 midr = cpuinfo->reg_midr;seq_printf(m, "processor\t: %d\n", i);if (compat)seq_printf(m, "model name\t: ARMv8 Processor rev %d (%s)\n", MIDR_REVISION(midr), COMPAT_ELF_PLATFORM);seq_printf(m, "BogoMIPS\t: %lu.%02lu\n", loops_per_jiffy / (500000UL/HZ), loops_per_jiffy / (5000UL/HZ) % 100);seq_puts(m, "Features\t:");if (compat) {#ifdef CONFIG_COMPATfor (j = 0; compat_hwcap_str[j]; j++)if (compat_elf_hwcap & (1 << j))seq_printf(m, " %s", compat_hwcap_str[j]);for (j = 0; compat_hwcap2_str[j]; j++)if (compat_elf_hwcap2 & (1 << j))seq_printf(m, " %s", compat_hwcap2_str[j]);#endif } else {for (j = 0; hwcap_str[j]; j++)if (elf_hwcap & (1 << j))seq_printf(m, " %s", hwcap_str[j]);}seq_puts(m, "\n");seq_printf(m, "CPU implementer\t: 0x%02x\n", MIDR_IMPLEMENTOR(midr));seq_printf(m, "CPU architecture: 8\n");seq_printf(m, "CPU variant\t: 0x%x\n", MIDR_VARIANT(midr));seq_printf(m, "CPU part\t: 0x%03x\n", MIDR_PARTNUM(midr));seq_printf(m, "CPU revision\t: %d\n\n", MIDR_REVISION(midr));}if (!arch_read_hardware_id)seq_printf(m, "Hardware\t: %s\n", machine_name);elseseq_printf(m, "Hardware\t: %s\n", arch_read_hardware_id());return 0;}
注:上面 arch_read_hardware_id 函数,高通平台是在 kernel/msm-4.19/drivers/soc/qcom/socinfo.c 文件中,等于 msm_read_hardware_id 函数
static char *msm_read_hardware_id(void){static char msm_soc_str[256] = "Qualcomm Technologies, Inc ";static bool string_generated;int ret = 0;if (string_generated)return msm_soc_str;if (!socinfo)goto err_path;if (!cpu_of_id[socinfo->v0_1.id].soc_id_string)goto err_path;ret = strlcat(msm_soc_str, cpu_of_id[socinfo->v0_1.id].soc_id_string,sizeof(msm_soc_str));if (ret > sizeof(msm_soc_str))goto err_path;string_generated = true;return msm_soc_str;err_path:return "UNKNOWN SOC TYPE";}
这里就是将高通和芯片名称 soc_id_string 进行拼接下。上面 msm_soc_info cpu_of_id[] 中枚举了相关芯片信息
static struct msm_soc_info cpu_of_id[] = {[0] = {MSM_CPU_UNKNOWN, "Unknown CPU"},[87] = {MSM_CPU_8960, "MSM8960"},[109] = {MSM_CPU_8064, "APQ8064"},[122] = {MSM_CPU_8960, "MSM8960"},... ...
根据 socinfo->v0_1.id 进行匹配,这个 id 等于项目的 dtsi 中配置的 qcom,msm-id
/ {model = "Qualcomm Technologies, Inc. xxx";compatible = "xxx";qcom,msm-id = , ;
注意:
高Android版本,修改 cpu_of_id 可能会影响CTS testConfigHardwareMitigations 此项。相关源码cts/hostsidetests/security/class="lazy" data-src/android/security/cts/KernelConfigTest.java
private Map hardwareMitigations = new HashMap() { { put("EXYNOS990", null); put("EXYNOS980", null); put("EXYNOS850", null); put("EXYNOS3830", null); put("EXYNOS9630", null); put("EXYNOS9830", null); put("EXYNOS7870", null); put("EXYNOS7880", null); put("EXYNOS7570", null); put("EXYNOS7872", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("EXYNOS7885", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("EXYNOS9610", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("Kirin980", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("Kirin970", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("Kirin810", null); put("Kirin710", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("SDMMAGPIE", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("SM6150", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("SM7150", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("LITO", null); put("SM8150", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("SM8150P", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("KONA", null); put("SDM429", null); put("SDM439", null); put("QM215", null); put("BENGAL", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y"}); put("DEFAULT", new String[]{"CONFIG_HARDEN_BRANCH_PREDICTOR=y", "CONFIG_UNMAP_KERNEL_AT_EL0=y"}); }}; private String[] lookupMitigations() throws Exception { return hardwareMitigations.get(getHardware()); } @CddTest(requirement="9.7") public void testConfigHardwareMitigations() throws Exception { String mitigations[]; if (PropertyUtil.getFirstApiLevel(mDevice) < 28) { return; } if (CpuFeatures.isArm64(mDevice) && !CpuFeatures.kernelVersionLessThan(mDevice, 4, 4)) { mitigations = lookupMitigations(); if (mitigations != null) { for (String mitigation : mitigations) { assertTrue("Linux kernel must have " + mitigation + " enabled.",configSet.contains(mitigation)); } } } else if (CpuFeatures.isX86(mDevice)) { assertTrue("Linux kernel must have KPTI enabled: CONFIG_PAGE_TABLE_ISOLATION=y", configSet.contains("CONFIG_PAGE_TABLE_ISOLATION=y")); } }
测试会根据 hardwareMitigations 中CPU型号,确认需要开启的宏,所以修改CPU名称后需要确认相关宏是否开启。
来源地址:https://blog.csdn.net/tq501501/article/details/131514655
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341