Android cpu信息获取/修改

这篇具有很好参考价值的文章主要介绍了Android cpu信息获取/修改。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

CPU信息查看

通过 cat proc/cpuinfo 查看

processor       : 7
BogoMIPS        : 38.40
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x51
CPU architecture: 8
CPU variant     : 0xa
CPU part        : 0x800
CPU revision    : 2

Hardware        : 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;
		/*
		 * glibc reads /proc/cpuinfo to determine the number of
		 * online processors, looking for lines beginning with
		 * "processor".  Give glibc what it expects.
		 */
		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);
		/*
		 * Dump out the common processor features in a single line.
		 * Userspace should read the hwcaps with getauxval(AT_HWCAP)
		 * rather than attempting to parse this, but there's a body of
		 * software which does already (at least for 32-bit).
		 */
		seq_puts(m, "Features\t:");
		if (compat) {
#ifdef CONFIG_COMPAT
			for (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 /* CONFIG_COMPAT */
		} 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);
	else
		seq_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"},
	/* 8960 IDs */
	[87] = {MSM_CPU_8960, "MSM8960"},
	/* 8064 IDs */
	[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 = <xxx 0x10000>, <xxx 0x10000>;

注意:

高Android版本,修改 cpu_of_id 可能会影响CTS testConfigHardwareMitigations 此项。相关源码cts/hostsidetests/security/src/android/security/cts/KernelConfigTest.java

    private Map<String, String[]> hardwareMitigations = new HashMap<String, String[]>() {
    {
        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());
    }
    /**
     * Test that the kernel has Spectre/Meltdown mitigations for architectures and kernel versions
     * that support it. Exempt platforms which are known to not be vulnerable.
     *
     * @throws Exception
     */
    @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://www.toymoban.com/news/detail-516821.html

到了这里,关于Android cpu信息获取/修改的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • android adb 获取电池信息以及设置

    android adb 获取电池信息以及设置

    本文主要包含 1、设置adb 无线调试桥连接步骤 2、打印设备电池状态(当前电量、充电状态、充放电电流大小、电池种类等) 3、更改电池充电状态、电量百分比、电池还原命令 4、断开adb 远程调试桥 -------------------------------------------------------------------------------- 详细步骤如下

    2024年02月14日
    浏览(4)
  • Android 手机来电 获取来电信息,接听/挂断电话

    目录 1.需求描述 2.实现原理 第一个:手机来电状态 第二个:获取手机来电号码 第三个:接听和挂断电话 1.需求描述 监听用户手机来电,弹起App内自定义的来电展示,并且展示来电电话,用户可以接通和挂断。 2.实现原理 这儿我就总结下手机来电、获取手机号码和接听/挂断

    2024年02月12日
    浏览(6)
  • android开发获取手机麦克风设备信息

    android开发获取手机麦克风设备信息

    之前为了测试蓝牙耳机的麦克,想从蓝牙耳机的麦克录音。尝试发现三星、小米自带的录音机并不能从蓝牙录音。看了网上一篇文章,提供了一个特定的录音APP,才支持开启蓝牙录音功能。 非常令人疑惑。想到现在的手机,有不只一个麦克风,是否能开发一个可选择录音源的

    2024年04月16日
    浏览(11)
  • 【Android开发基础】蓝牙信息的获取(Bluetooth)

    【Android开发基础】蓝牙信息的获取(Bluetooth)

    描述:蓝牙技术是一种无线数据和语音通信开放的全球规范,它是基于低成本的近距离无线连接,为固定和移动设备建立通信环境的一种特殊的近距离无线技术连接。蓝牙使当前的一些便携移动设备和计算机设备能够不需要电缆就能连接到互联网,并且可以无线接入互联网。

    2024年02月09日
    浏览(11)
  • Android项目获取网页信息的三种方法

    Android项目获取网页信息的三种方法

    具体操作可以参考我的另一篇文章eclipse创建Android项目调用jsoup获取网页信息 进入想要获取信息的网页,点击F12进入开发者模式,选择网络,刷新页面,点击标头,参考对应字条,没有的字条就不修改。

    2024年02月15日
    浏览(8)
  • 【Android开发基础】手机传感器信息的获取

    【Android开发基础】手机传感器信息的获取

    描述:关于传感器的使用,我在同栏目下发了一篇关于传感器(方向传感器、加速度传感器)的使用,这篇博客主要以获取不同手机所支持的传感器信息为主,具体如何使用这些传感器,需要自己进行查阅和学习,也可以私聊我。 博客:传感器(方向传感器、加速度传感器)

    2024年02月10日
    浏览(11)
  • Android中获取手机SIM卡的各种信息

     通过以下工具类方法可以获取到手机SIM的各种信息数据!!!

    2024年02月10日
    浏览(12)
  • Android 获取手机通讯录联系人信息

    Android 获取手机通讯录联系人信息

    近日在项目开发过程中发现,华为手机HarmonyOS 3.0系统,设置隐私 里面可以查看各个应用访问隐私权限的次数,发现应用程序访问手机通讯录的次数异常的高,针对访问通讯录频次高的问题做了研究和优化 问题分析: 分析代码发现只要通过ContentProvider 访问通讯录一次,统计

    2024年02月12日
    浏览(15)
  • 基于scrcpy的Android群控项目重构,获取Android屏幕元素信息并编写自动化事件

    基于scrcpy的Android群控项目重构,获取Android屏幕元素信息并编写自动化事件

    基于scrcpy的远程调试方案 基于scrcpy的Android群控项目重构 基于scrcpy的Android群控项目重构 进阶版 基于scrcpy的Android群控项目重构,获取Android屏幕元素信息并编写自动化事件(视频) 基于scrcpy的Android群控项目重构,获取Android屏幕元素信息并编写自动化事件(博客) 基于scrcpy的

    2024年02月16日
    浏览(27)
  • Android查看签名信息系列 · 使用逆向分析工具JadxGUI获取签名

    Android查看签名信息系列 · 使用逆向分析工具JadxGUI获取签名

    前言 Android查看签名信息系列之使用逆向分析工具JadxGUI获取签名,通过这种方式,可以获取到的签名信息包括:MD5、SHA1、SHA-256、公钥(模数)等信息 实现方法 1、进入JadxGUI目录下的lib文件夹内,找到jadx-gui-1.4.7.jar文件 2、双击jadx-gui-1.4.7.jar进入图形界面,或者cmd进入lib所在路径

    2024年02月03日
    浏览(8)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包