One of the secrets of the kernel: start_kernel () running process records

Source: Internet
Author: User

This article is original in itspy. If you copy or repost it, please indicate the original source at http://blog.csdn.net/yyplc/article/details/7030983,thank you!
How does one unlock the secrets of the Linux kernel? How does it do it? What is done, how to do it, how the process is, and so on, all need a clear process (because we need to give us a saying ~!), It is critical to have a better intimate, in-depth understanding of it and find a breakthrough point-'start from scratch '(starting from the Linux header ). This article analyzes the source code and verifies the running practices on the hardware platform.
Kernel version: linux-2.6.30.4
Hardware CPU: S3C2440 (arm920vt)
All programmers know that, in any case, all entry points start from the 'main' function (start_kernel ). Nonsense ~~
The 'head' in Linux is called a start_kernel function, which is the same as the main function.
The main process is as follows:

{... Printk (kern_notice "% s", linux_banner); // output the Linux version information setup_arch (& command_line); // set the environment related to the hardware system initialization and call // pageint_inig () -> devicemaps_init (mdesc); initialize the abnormal vector table, initialize zone Memory maps, and initialize the struct: sched_init () such as machine_start // initialize the scheduler... Printk (boot_command_line) before the start of the interrupt; // extract and analyze the core startup parameter process (transmitted from the bootloader) parse_early_param (); parse_argstrap_init (); // initialize the self-trapped entry function, for this version of arm, direct returnearly_irq_init (); // interrupt the initialization process .... Init_irq (); init_timers (); // initialize the timer, enable the timer Soft Interrupt Service, register the service program, and initialize init_timers ()-> run_timer_softirq () in each CPU () ->__ run_timers ().. timekeeping_init (); time_init (); // sets the timer and returns the current time lele_init () // preliminary initialization console. This console can only print some simple // startup information... Vmalloc_init (); // vfs_caches_init_early (); // mem_init (); // initialize the memory and calculate the available memory size kmem_cache_init (); // initialize slab cache distributor calibrate_delay (); // delayed calibration, Jiffy, records the number of beats of the system timer. Each change represents two consecutive interval of the system timer. Fork_init (num_physpages); // initialize max_threads. The init_task parameter is Fork (). For details, refer to buffer_init (); // initialize the block device read/write buffer vfs_caches_init (num_physpages ); // initialize the Virtual File System inode_init ()-> files_init ()-> mnt_init ()... signals_init (); // initialize the kernel signal queue .... Rest_init (); // finally enters the reset_init () function, including all the remaining hardware // drivers, thread initialization, and other processes... This completes the START process of // start_kernel .}

After entering reset_init (), first create the first thread kernel_init () of the system, thread pid = 1, and then create

PID = 2, kthreadadd () thread, start the task scheduling schedule (), and enter cpu_idle ()
The rest are all scheduled by the Job scheduler.
In the kenernel_init thread, the following functions are mainly completed: do_basic_setup () calls driver_init (), do_init_cils () (calls the functions whose attributes are _ init, complete related PCI and network and load the remaining device drivers.
Next, prepare_namespace (). An important task is to mount the root file system, which determines what the system needs to mount and where to mount it. After everything above is ready, the system enters the init_post () function:
Call free_initmem () in init_post () to release the space between _ init_begin and _ init_end. The following occurs:
Freed initmemory 92 K
Call sys_open () to open the console for the system. If the console cannot be found, the following error occurs:
Warning: unableto open an initial console.
Then, call the run_init_process (command) function. Command is the command_line parameter passed to the kernel by bootloader. Usually the embedded system parameter is mainly a linuxrc file, which is actually a soft connection to busybox.
If the command call fails, the system continues the following run_init_process () process:

run_init_process("/sbin/init");run_init_process("/etc/init");run_init_process("/bin/init");run_init_process("/bin/sh");

If the final call fails, the system will tell us:
Panic ("noinit found. Try passing init = option tokernel .");
OK. Familiar with the Startup Process of Linux kernel start_kernel (), compile a kernel and create a file system, and download it to the hardware:

Start Linux ...Copy linux kernel from 0x00200000 to 0x30008000, size = 0x00200000 ... Copy Kernel to SDRAM done,NOW, Booting Linux......Uncompressing Linux.............................................................................................................. done, booting the kernel.Linux version 2.6.30.4-itspy (root@wsn-Inspiron-1427) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203) ) #27 Thu Dec 1 14:15:49 CST 2011CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177CPU: VIVT data cache, VIVT instruction cacheMachine: s3c2440ATAG_INITRD is deprecated; please update your bootloader.Memory policy: ECC disabled, Data cache writebackCPU S3C2440A (id 0x32440001)S3C24XX Clocks, (c) 2004 Simtec ElectronicsS3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHzCLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL onBuilt 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256Kernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0NR_IRQS:85irq: clearing pending ext status 00080000irq: clearing subpending status 00000003irq: clearing subpending status 00000002PID hash table entries: 256 (order: 8, 1024 bytes)Console: colour dummy device 80x30console [ttySAC0] enabledDentry cache hash table entries: 8192 (order: 3, 32768 bytes)Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)Memory: 64MB = 64MB totalMemory: 61268KB available (3152K code, 349K data, 96K init, 0K highmem)SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)Mount-cache hash table entries: 512CPU: Testing write buffer coherency: oknet_namespace: 296 bytesNET: Registered protocol family 16S3C2440: Initialising architectureS3C2440: IRQ SupportS3C24XX DMA Driver, (c) 2003-2004,2006 Simtec ElectronicsDMA channel 0 at c4808000, irq 33DMA channel 1 at c4808040, irq 34DMA channel 2 at c4808080, irq 35DMA channel 3 at c48080c0, irq 36S3C244X: Clock Support, DVS offbio: create slab <bio-0> at 0SCSI subsystem initializedusbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbs3c2440-i2c s3c2440-i2c: slave address 0x10s3c2440-i2c s3c2440-i2c: bus frequency set to 97 KHzs3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adaptercfg80211: Calling CRDA to update world regulatory domainNET: Registered protocol family 2IP route cache hash table entries: 1024 (order: 0, 4096 bytes)TCP established hash table entries: 2048 (order: 2, 16384 bytes)TCP bind hash table entries: 2048 (order: 1, 8192 bytes)TCP: Hash tables configured (established 2048 bind 2048)TCP reno registeredNET: Registered protocol family 1yaffs Nov 30 2011 09:27:01 Installing. msgmni has been set to 119alg: No test for stdrng (krng)io scheduler noop registered (default)Console: switching to colour frame buffer device 60x17fb0: s3c2410fb frame buffer devicebacklight initializedGPIO-Control initializedPWM-Test initializedadc initializeds3c2440-uart.0: tq2440_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440s3c2440-uart.1: tq2440_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440s3c2440-uart.2: tq2440_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440loop: module loadeddm9000 Ethernet Driver, V1.31Now use the default MAC address: 10:23:45:67:89:abeth0 (dm9000): not using net_device_ops yeteth0: dm9000e at c4814000,c4818004 IRQ 51 MAC: 10:23:45:67:89:ab (chip)S3C24XX NAND Driver, (c) 2004 Simtec Electronicss3c2440-nand s3c2440-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30nsNAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)Scanning device for bad blocksCreating 3 MTD partitions on "NAND 256MiB 3,3V 8-bit":0x000000000000-0x000000040000 : "uboot1.1.6"0x000000200000-0x000000400000 : "linux-kernel"0x000000400000-0x00000ff80000 : "yaffs2"ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Drivers3c2410-ohci s3c2410-ohci: S3C24XX OHCIs3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000usb usb1: New USB device found, idVendor=1d6b, idProduct=0001usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1usb usb1: Product: S3C24XX OHCIusb usb1: Manufacturer: Linux 2.6.30.4-itspy ohci_hcdusb usb1: SerialNumber: s3c24xxusb usb1: configuration #1 chosen from 1 choicehub 1-0:1.0: USB hub foundhub 1-0:1.0: 2 ports detectedInitializing USB Mass Storage driver...usbcore: registered new interface driver usb-storageUSB Mass Storage support registered.usbcore: registered new interface driver usbserialusbserial: USB Serial Driver coreUSB Serial support registered for pl2303usbcore: registered new interface driver pl2303pl2303: Prolific PL2303 USB to serial adaptor drivers3c2410_udc: debugfs dir creation failed -19s3c2440-usbgadget s3c2440-usbgadget: S3C2440: increasing FIFO to 128 bytesmice: PS/2 mouse device common for all miceS3C24XX RTC, (c) 2004,2006 Simtec Electronicss3c2410-rtc s3c2410-rtc: rtc disabled, re-enablings3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0usbcore: registered new interface driver zc0301gspca: main v2.5.0 registeredusbcore: registered new interface driver zc3xxzc3xx: registeredusbcore: registered new interface driver uvcvideoUSB Video Class driver (v0.1.0)S3C2410 Watchdog Timer, (c) 2004 Simtec Electronicss3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabledmapped channel 0 to 0s3c2440-sdi s3c2440-sdi: powered down.s3c2440-sdi s3c2440-sdi: initialisation done.s3c2440-sdi s3c2440-sdi: powered down.usbcore: registered new interface driver usbhidusbhid: v2.6:USB HID core driverAdvanced Linux Sound Architecture Driver Version 1.0.18a.No device for DAI UDA134XNo device for DAI s3c24xx-i2sS3C24XX_UDA134X SoC Audio driverUDA134X SoC Audio Codecasoc: UDA134X <-> s3c24xx-i2s mapping okALSA device list:  #0: S3C24XX_UDA134X (UDA134X)TCP cubic registeredlib80211: common routines for IEEE802.11 driverss3c2410-rtc s3c2410-rtc: hctosys: invalid date/timeyaffs: dev is 32505858 name is "mtdblock2"yaffs: passed flags ""yaffs: Attempting MTD mount on 31.2, "mtdblock2"yaffs: auto selecting yaffs2yaffs: restored from checkpointyaffs_read_super: isCheckpointed 1VFS: Mounted root (yaffs filesystem) on device 31:2.Freeing init memory: 96KTry to bring eth0 interface up ...ifconfig eth0 hw ether 00:11:22:33:44:55Please press Enter to activate this console. eth0: link up, 100Mbps, full-duplex, lpa 0x45E1ifconfig eth0 192.168.2.209 netmask 255.255.254.0 upadd default gw 192.168.2.254Done[root@WSN /]# 

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.