当前位置:网站首页>aliases node analysis
aliases node analysis
2022-08-10 05:10:00 【Four Seasons Sail】
There is a node called aliases in the device tree:
/{#address-cells = <1>;#size-cells = <1>;aliases {fimc0 = &fimc0;fimc1 = &fimc1;fimc2 = &fimc2;i2c0 = &i2c0;i2c1 = &i2c1;i2c2 = &i2c2; };......};
This node will be parsed when the Linux kernel starts:
start_kernelsetup_archunflatten_device_treeof_alias_scanvoid of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)){struct property *pp;/* Find the device_node corresponding to the /aliases node */of_aliases = of_find_node_by_path("/aliases");/* Find the device_node corresponding to the /chosen node */of_chosen = of_find_node_by_path("/chosen");/* If there is no /chosen, find the /[email protected] node */if (of_chosen == NULL)of_chosen = of_find_node_by_path("/[email protected]");/* Traverse the properties of the /aliases node */for_each_property_of_node(of_aliases, pp) {const char *start = pp->name; // the name of the propertyconst char *end = start + strlen(start); // end of name, *end is '\0'struct device_node *np;struct alias_prop *ap;int id, len;/* Skip those we do not want to proceed *//* Ignore attributes whose names are name, phandle, linux, phandle */if (!strcmp(pp->name, "name") ||!strcmp(pp->name, "phandle") ||!strcmp(pp->name, "linux,phandle"))continue;/* Get the node corresponding to this value according to the value of the attribute *//* For example, this property, fimc2 = "/soc/camera/[email protected]" to find the node through the path */np = of_find_node_by_path(pp->value);if (!np)continue;/* Normally an attribute name is fimc1, i2c0, so, here is to point the end pointer to the position in front of the number,* Such as the address of the c character of fimc2 */while (isdigit(*(end-1)) && end > start)end--;len = end - start; /* this len is the length of the name minus numbers *//* Convert the number after the end string into a number and copy it to the id, such as fimc2, number 2 */if (kstrtoint(end, 10, &id) < 0)continue;/* Allocate an alias_prop with enough space for the stem *//* Allocate memory, the multi-allocated "len+1" is used to store the name of stem */ap = dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap));if (!ap)continue;memset(ap, 0, sizeof(*ap) + len + 1);ap->alias = start; /* ap->alias points to the string "fimc2 */of_alias_add(ap, np, id, start, len);}}static void of_alias_add(struct alias_prop *ap, struct device_node *np,int id, const char *stem, int stem_len){ap->np = np; // np is the node device_node corresponding to "/soc/camera/[email protected]";"ap->id = id; // The value of id is 2, which represents the device serial number, which is used when using//Since stem_len is the length of the name minus the number, ap->stem is assigned the value "fimc"strncpy(ap->stem, stem, stem_len);ap->stem[stem_len] = 0;list_add_tail(&ap->link, &aliases_lookup); //Add this ap to the global aliases_lookup listpr_debug("adding DT alias:%s: stem=%s id=%i node=%pOF\n",ap->alias, ap->stem, ap->id, np);}
When registering the i2c controller:
int i2c_add_adapter(struct i2c_adapter *adapter){struct device *dev = &adapter->dev;int id;if (dev->of_node) {//Get the id of alias_prop corresponding to this device_node.If i2c2 = &i2c2; node is used as an example, the id obtained here is 2id = of_alias_get_id(dev->of_node, "i2c");if (id >= 0) {adapter->nr = id;return __i2c_add_numbered_adapter(adapter);}}id = idr_alloc(&i2c_adapter_idr, adapter,__i2c_first_dynamic_bus_num, 0, GFP_KERNEL);adapter->nr = id;return i2c_register_adapter(adapter);}int of_alias_get_id(struct device_node *np, const char *stem){struct alias_prop *app;int id = -ENODEV;mutex_lock(&of_mutex);/* Traverse the global linked list aliases_lookup */list_for_each_entry(app, &aliases_lookup, link) {/* find alias_prop whose stem is "i2c" */if (strcmp(app->stem, stem) != 0)continue;/* All i2c-controlled stems are called "i2c", so make sure the device nodes are consistent */if (np == app->np) {id = app->id; /* Finally return the number name found */break;}}mutex_unlock(&of_mutex);return id;}
From the above analysis, we can see the role of the alias node:
For example, there are multiple i2c controllers on the SoC, and alias is equivalent to assigning a unique number to each i2c controller. For example, the alias corresponding to i2c2 above is i2c2, then this number is 2, and it will be available in /dev in the futureBelow you see a device node named i2c-2.
Reference documents:
边栏推荐
- Stacks and Queues | Valid parentheses, delete all adjacent elements in a string, reverse Polish expression evaluation, maximum sliding window, top K high frequency elements | leecode brush questions
- curl命令介绍
- canvas 画布绘制时钟
- 看了几十篇轻量化目标检测论文扫盲做的摘抄笔记
- FPGA工程师面试试题集锦21~30
- 如何从代码层提高产品质量
- Stacks and Queues | Implementing Queues with Stacks | Implementing Stacks with Queues | Basic Theory and Code Principles
- Ueditor editor arbitrary file upload vulnerability
- `id` bigint(20) unsigned NOT NULL COMMENT 'Database primary key',
- ThreadPoolExecutor线程池原理
猜你喜欢
How Current Probes Set Oscilloscope Parameters
Hezhou ESP32C3 +1.8"tft network clock under Arduino framework
openvino 安装(01)
Flutter开发:报错The following assertion was thrown resolving an image codec:Unable to…的解决方法
2022G3 Boiler Water Treatment Exam Mock 100 Questions and Mock Exam
Become a language that hackers have to learn. Do you think it's okay after reading it?
看了几十篇轻量化目标检测论文扫盲做的摘抄笔记
LeetCode 301. Remove Invalid Parentheses BFS
What are the common commands of mysql
How to choose the right oscilloscope probe in different scenarios
随机推荐
leetcode每天5题-Day10
mysql常用命令有什么
The sword refers to Offer 033. Variation array
From entry to mastery of PHPCMS imitation station, Xiaobai is enough to watch this set of courses
剑指Offer 033.变位数组
重要转型升级
leetcode每天5题-Day11
aliases节点分析
FPGA engineer interview questions collection 1~10
LeetCode 6138. 最长理想子序列 动态规划
oracle cdc时,设置并行度2插槽数1,最终任务只有一个tm,是不是因为oracle不支持并发
Flutter development: error The following assertion was thrown resolving an image codec: Solution for Unable to...
Why are negative numbers in binary represented in two's complement form - binary addition and subtraction
线程(中):线程安全
并发工具类——CountDownLatch、CyclicBarrier、Semaphore、Exchanger的介绍与使用
FPGA工程师面试试题集锦1~10
Introduction to curl command
线性模型中的高级特征选择技术——基于R
【u-boot】u-boot驱动模型分析(02)
ORA-16018 异常处理记录