ro.serialno

本文深入探讨了Android系统中用于唯一标识设备的ro.serialno属性的生成过程及其在不同场景下的获取方式,包括通过fastboot命令和内核文件系统的直接读取。同时解释了ro.boot.serialno的来源及其在设备启动时的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://my.oschina.net/u/996206/blog/215960


1.ro.serialno不存在于任何属性文件,比如build.prop, default.prop等,而是在/system/core/init/init.c里由ro.boot.serialno 转换而来,见export_kernel_boot_props()。

2.而ro.boot.serialno的来源是/proc/cmdline,也就是linux kernel启动时被传入的cmdline, 由bootloader传入。 
bootloader传进来的是androidboot.serialno, 而不是ro.boot.serialno,因为还要解析过cmdline 
3.ro.serialno的用处是来保存唯一设备号,在settings->about->status里会显示,也会用在USB device name里。 
about->status 里获取serialno的流程: 
Build.SERIAL 
->getString(“ro.serialno”) 
->SystemProperties.get() 
->SystemProperties.native_get() 
->SystemProperties_getSS() in android_os_SystemProperties.cpp 
->property_get() in Properties.c 
->__system_property_get() in System_properties.c in bionic

获取到的前提是之前已经有设置好,也就是有调用property_set() in init.c

4.其他类似ro属性还有: 
ro.boot.mode 
ro.boot.baseband 
ro.boot.bootloader 
ro.boot.hardware

emmc has a unique serialno to mark the device/emmc.
there are 2 method to get the serialno for device/EMMC, this is useful to mark the device when doing stabilty tests.

1. boot your device to fastboot

yingangl@yingangl-work:~$ fastboot getvar serialno
serialno: aaa035df
finished. total time: 0.002s

2. in kernel 
   cd /sys/class/mmc_host/mmc0/mmc0:0001
   cat serial 
   0xaaa035df



The ro.serialno system property contains the product serial number. LK bootloader reads the "Product serial number (psn)" from the mmc card and add this to the kernel command line as a property "androidboot.serialno=<psn>". For more details check function target_serialno(), File: lk/target/msm952/init.c

The kernel command line will be further parsed by the "init" process and will set system property as ro.serialno=<psn>.

For code details check function: static void export_kernel_boot_props(void) (system/core/init/init.c)

kernel command line is parsed by : import_kernel_nv() in init.c

If you want to reset the ro.serialno system property temporarily, then you can reset in function export_kernel_boot_props() like shown below:

+ property_set("ro.serialno","<WRITE YOUR VALUE>");
ret = property_get("ro.boot.console", tmp);
if (ret)
strlcpy(console, tmp, sizeof(console)); 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值