Device registration comparison for old and new kernels

Source: Internet
Author: User

Transferred from: http://blog.chinaunix.net/uid-7332782-id-3268801.html

1. Version2.6 Kernel boot process

Start_kernel ()//board on power-up after entering Start_kernel (), equivalent to the main entrance of the program

--Setup_arch (&command_line) //command_line passed in by the kernel

--Mdesc = Setup_machine (machine_arch_type);

--list = Lookup_machine_type (NR); //assembly implement find machine code defined platform, find back MDESC structure

--init_machine = mdesc->init_machine; //struct MACHINE_DESC *MDESC;MACHINE_DESC structure is very important,

-Rest_init ()

-Kernel_thread (Kernel_init, NULL, CLONE_FS | Clone_sighand); //define Process Kernel_init,pid=1, dispatch run after Kthreadd process is created.

-Kernel_init ()

-Do_basic_setup ()

-Driver_init ()

-Devices_init ()

-Buses_init ()

-Classes_init ()

-Platform_bus_init ()

--do_initcalls () //This function is important to perform all functions in the Initcall table, including the Init_machine (Saar_init ()) function

-Saar_init ()

--Init_post () //Scheduling user space programs, such as Bash, to execute programs in user space dead loop

--pid = Kernel_thread (Kthreadd, NULL, CLONE_FS |  Clone_files); //define process Kthreadd

2. version3.x kernel boot process and 2.6 version in Init_machine load device resource difference comparison

    • In the 2.6 kernel , in Setup_arch (), for example IMX5,

-->init_machine=mdesc->init_machine; Init/main.c->start_kernel ()->setup_arch ()

-->.init_machine=mxc_board_init; Arch/arm/mach-mx5/mx50_arm2.c->machine_start (), macro instant initialization of MACHINE_DESC struct

--Mxc_register_device(&mxc_dma_device); Arch/arm/mach-mx5/mx50_arm2.c->mxc_board_init ()

-->mxc_register_device (&mxc_wdt_device); Mxc_wdt_device These equipment resources are also stated under mach-mx50

-->mxc_register_device (&mxci2c_devices[0]);

-->, .....

Of course the Init_machine is initialized in Setup_arch (), and at this point the Init_machine function is not called, but the Init_machine attribute is defined as Arch_initcalland then Do_ Initcalls () in the traversal call, see the above-mentioned startup process.

From the above can be seen in the system startup, device devices are already register to the bus, and 3.x has not been in the mach-** in the Declaration of equipment resources, the START process, see the next section.

    • In the 3.x kernel , the Setup_arch () is so handled, first parsing DTB

-->setup_arch ()//init/main.c->start_kernel ()->setup_arch ()

-->MDESC=SETUP_MACHINE_FDT ();

-->unflatten_device_tree ()

-->__unflatten_device_tree ()

-->unflatten_dt_node ()//to this basic completion of node-to-list operation in DTS

Device registration in the node (this is also done in init_machine, but not yet found, unlike in 2.6, Init_machine has arch_initcall properties --to solve : Actually and 2.6, in. The Arch_initcall attribute is also added to Init_machine in Arch/arm/kernel/setup.c. )

-->dt_machine_start//MACHINE_DESC Structure Assignment

-->.init_machine=imx6sx_init_machine

-->of_platform_populate (); Imx6sx_init_machine () call

-->of_platform_bus_create (); Called by For_each_child_of_node () to traverse each node in the device tree

-->of_platform_device_create_pdata ()

-->of_device_alloc ()//Request space for each device

-->platform_device_put ()

-->of_platform_bus_create ()

To complete the registration of the device.

in the 3.x setup.c , the invocation of init_machine is so defined.

1 Static int__init Customize_machine (void)2 {3     /*4 * Customizes platform devices, or adds new ones5 * on DT based machines, we fall back to populating the6 * Machine from the device tree, if no callback is provided,7 * Otherwise we would always need an init_machine callback.8      */9     if(machine_desc->init_machine)TenMachine_desc->init_machine (); One #ifdef config_of A     Else - of_platform_populate (NULL, of_default_bus_match_table, - null, NULL); the #endif -     return 0; -}

About whether Init_machine will be executed in the end, there is such a passage in Documentation/devicetree/usage-model.txt

The most interesting hookinchThe DT context is. Init_machine () which isPrimarily responsible forpopulating the Linux device model Withdata about the platform. Historically ThisHave been implemented onembedded platforms by defining aSetOfStaticclock structures,platform_devices, and other datainchthe Board support. c file, andregistering it en-masseinch. Init_machine (). When DT isused, theninstead of hard codingStaticDevices forEach platform, the list ofdevices can is obtained by parsing the DT, and allocating devicestructures. The simplest Case  isWhen. Init_machine () isOnly responsible forregistering a block of platform_devices. A Platform_device isa conceptused by Linux forMemory or i/O mapped devices which cannot be detectedby hardware, and for 'Composite'Or'Virtual'devices (more on thoselater). While there isNo'Platform Device'Terminology forThe dt,platform devices roughly correspond to device nodes on the root of Thetree and children of simple memory Mappe D bus nodes.

Device registration comparison for old and new kernels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.