Linux Kernel Source Analysis--Kernel boot (4) Image kernel boot (setup_arch function) (Linux-3.0 ARMv7) "Go"

Source: Internet
Author: User
Tags sprintf

Original address: Linux kernel source Code Analysis--Kernel boot (4) Image kernel boot (setup_arch function) (Linux-3.0 ARMv7) Tekkamanninja

Transferred from: http://blog.chinaunix.net/uid-25909619-id-4938393.html

In the analysis of the Start_kernel function, there are schema-related initialization function Setup_arch. This function varies according to the architecture and the detailed analysis of the ARM architecture is as follows:
  1. void __init Setup_arch (char **cmdline_p)
  2. {
  3. struct MACHINE_DESC *mdesc;

  4. Click (here) to collapse or open

    1. This is the device description structure, for any board has defined such a structure, my previous article has introduced:
    2. "Uncompressing Linux ... done, booting the kernel" 1, Machine Type mismatch
  5. Unwind_init ();
  6. Click (here) to collapse or open

    1. Initializes the BackTrace unwind system (stack fallback) based on arm Eabi, which is used primarily for address translation (ARCH/ARM/KERNEL/UNWIND.C)
  7. Setup_processor ();

    Click (here) to collapse or open

    1. The processor type is detected again and the underlying variable associated with the processor is initialized. The processor information (including the cache) that the kernel starts with is printed by this function, for example:
      1. Cpu:armv7 Processor [413fc082] revision 2 (ARMV7), cr=10c53c7f
      2. Cpu:vipt nonaliasing data cache, vipt aliasing instruction Cache
  8. Mdesc = SETUP_MACHINE_FDT (__atags_pointer);
  9. if (!MDESC)
  10. Mdesc = Setup_machine_tags (Machine_arch_type);

    Click (here) to collapse or open

    1. Match a struct MACHINE_DESC structure here with the device ID passed by bootloader.
    2. (This struct is the structure defined in ARCH/ARM/MACH-*/MACH-*.C: machine_start~machine_end)
    3. If there is no match on the dead loop.
    4. If a match is made, the machine name is printed and the tagged_list passed by bootloader is processed, and all tag information is saved to the corresponding global variable or struct.
    5. The machine information at the kernel startup is printed here, for example:
    6. Click (here) to collapse or open

      1. Machine:ti8168evm
    7. Finally, the struct pointer is returned.
  11. Machine_desc = Mdesc;
  12. Machine_Name = mdesc->name;

    Click (here) to collapse or open

    1. Initializes some global variables by matching struct MACHINE_DESC struct data
  13. if (mdesc->soft_reboot)
  14. Reboot_setup ("s");

    Click (here) to collapse or open

    1. To set the restart type through the soft_reboot data in the struct MACHINE_DESC:
    2. "S" if present: Softreset; "H" if it does not exist: Hardreset
  15. Init_mm.start_code = (unsigned long) _text;
  16. Init_mm.end_code = (unsigned long) _etext;
  17. Init_mm.end_data = (unsigned long) _edata;
  18. INIT_MM.BRK = (unsigned long) _end;

    Click (here) to collapse or open

    1. Here, you initialize some of the data in the MM_STRUCT structure init_mm by connecting the Linux code location data obtained in the script.
    2. PS: Each task has a MM_STRUCT structure to manage memory space, INIT_MM is the kernel itself mm_struct
  19. /* Fill Cmd_line for later use, protect boot_command_line data */
  20. strlcpy (Cmd_line, Boot_command_line, command_line_size);
  21. *cmdline_p = Cmd_line;

    Click (here) to collapse or open

    1. Copy the Boot_command_line into the cmd_line. The key here is to know how the CmdLine is delivered when the system starts.
  22. Parse_early_param ();

    Click (here) to collapse or open

    1. Handle the startup parameters defined as early in the struct Obs_kernel_param (mainly the parameters of the memory configuration section)
    2. which analyzes the [email protected] parameter initialization of the struct meminfo meminfo;
    3. Also initializes the Vmalloc=size parameter if it has a vmalloc_min
    4. Reference: Linux kernel high-low end Memory setup code tracking (ARM architecture)
    5. It is important to note that the parameters in the kernel cmdline are divided into early and non-early according to their required order.
    6. Include/linux/init.h:

      Click (here) to collapse or open

      1. struct Obs_kernel_param {
      2. const char *STR; The name of the corresponding parameter in the CmdLine.
      3. Int (*setup_func) (char *); For this parameter, the dedicated handler function
      4. int early; //is a parameter that needs to be processed earlier
      5. };
    7. Two different parameters are defined in the kernel with different macros:
    8. Early: #define EARLY_PARAM (str, fn) \
    9. __setup_param (str, FN, FN, 1)
    10. Non-early: #define __SETUP (str, fn) \
    11. __setup_param (str, FN, FN, 0)
    12. Using the parameters defined by these two macros is related to the schema, and some structures or boards can define their own specific parameters and processing functions. For the more important "men" parameter is the early parameter.
  23. Sanity_check_meminfo ();

    Click (here) to collapse or open

    1. Here you set the HIGHMEM variable in each bank in the struct Meminfo meminfo,
    2. Determine if memory in each bank belongs to high-end memory through Vmalloc_min
  24. Arm_memblock_init (&meminfo, Mdesc);

    Click (here) to collapse or open

    1. This is where data from the Meminfo is sorted by address data from small to large, and global memblock data is initialized.
  25. Paging_init (MDESC);

    Click (here) to collapse or open

    1. Sets the reference page table for the kernel.
    2. This page table is used not only for physical memory mapping, but also for managing the Vmalloc zone.
    3. One of the most important functions in this function is the initialization of the BOOTMEM allocator!
  26. Request_standard_resources (MDESC);

  27. Click (here) to collapse or open

    1. initializes the memory-related global struct-body variables by obtaining data from the device description struct (struct MACHINE_DESC) and the address data generated at compile time.
  28. Unflatten_device_tree ();

    Click (here) to collapse or open

    1. Get memory-related information by using the "non-flat device tree" information in the startup parameters (if any)
  29. #ifdef CONFIG_SMP
  30. if (IS_SMP ())
  31. Smp_init_cpus ();
  32. #endif

    Click (here) to collapse or open

    1. For SMP processors, initialize the possible CPU mappings-this describes the possible CPU
  33. Reserve_crashkernel ();

    Click (here) to collapse or open

    1. Reserved kernel for kernel crashes
    2. This feature preserves the export of kernel information when the main kernel crashes by "crashkernel=" in the kernel command line parameter.
  34. Cpu_init ();

    Click (here) to collapse or open

    1. Initialize a CPU and set up a PER-CPU stack
  35. Tcm_init ();

    Click (here) to collapse or open

    1. Initializes the TCM (tightly coupled memory) inside arm.
    2. Reference: "Understanding of ARM's compact memory TCM"
    3. ARM's official website also has the introduction document
  36. #ifdef Config_multi_irq_handler
  37. HANDLE_ARCH_IRQ = mdesc->handle_irq;
  38. #endif

  39. Click (here) to collapse or open

    1. The call device describes the MDESC->HANDLE_IRQ function in the struct, and the purpose is unknown.
  40. #ifdef CONFIG_VT
  41. #if defined (config_vga_console)
  42. CONSWITCHP = &vga_con;
  43. #elif defined (config_dummy_console)
  44. CONSWITCHP = &dummy_con;
  45. #endif
  46. #endif
  47. Early_trap_init ();

  48. Click (here) to collapse or open

    1. Early initialization of an interrupt vector table
  49. if (mdesc->init_early)
  50. Mdesc->init_early ();

    Click (here) to collapse or open

    1. It is called here if the device description struct defines the init_early function (which should be the meaning of an early initialization).
  51. }
This function mainly checks to see if the processor type matches, and obtains the processor information to set the processor's associated underlying parameters.
  1. static void __init setup_processor (void)
  2. {
  3. struct Proc_info_list *list;
  4. /*
  5. * Locate the processor in the list of supported processors
  6. * Connector for us to create this list, from * arch/arm/mm/proc-*. the entrance in S
  7. */
  8. List = Lookup_processor_type (read_cpuid_id ());
  9. if (!list) {
  10. PRINTK ("CPU configuration botched (ID%08x), unable"
  11. "To Continue.\n", read_cpuid_id ());
  12. while (1);
  13. }

    Click (here) to collapse or open

    1. Check the processor type again here, although this is already done in the assembly code.
  14. Cpu_name = list->cpu_name;
  15. #ifdef MULTI_CPU
  16. Processor = *list->proc;
  17. #endif
  18. #ifdef MULTI_TLB
  19. Cpu_tlb = *list->tlb;
  20. #endif
  21. #ifdef Multi_user
  22. Cpu_user = *list->user;
  23. #endif
  24. #ifdef Multi_cache
  25. Cpu_cache = *list->cache;
  26. #endif

  27. Click (here) to collapse or open

    1. Initialize CPU-related global variables by data obtained from struct proc_info_list
  28. PRINTK ("CPU:%s [%08x] revision%d (armv%s), cr=%08lx\n",
  29. Cpu_name, read_cpuid_id (), read_cpuid_id () & 15,
  30. Proc_arch[cpu_architecture ()], cr_alignment);

  31. Click (here) to collapse or open

    1. Processor information for the print kernel when it starts
  32. sprintf (Init_utsname ()->machine, "%s%c", List->arch_name, ENDIANNESS);
  33. sprintf (Elf_platform, "%s%c", List->elf_name, ENDIANNESS);
  34. Elf_hwcap = list->elf_hwcap;
  35. #ifndef Config_arm_thumb
  36. Elf_hwcap &= ~hwcap_thumb;
  37. #endif
  38. Feat_v6_fixup ();
  39. Click (here) to collapse or open

    1. Masking some features for specific arm core software
  40. Cacheid_init ();

    Click (here) to collapse or open

    1. Initializing the cache in the arm core
  41. Cpu_proc_init ();

    Click (here) to collapse or open

    1. Macro:
    2. #define Cpu_proc_init __glue (cpu_name,_proc_init)
    3. Intended to invoke processor-specific initialization functions.
  42. }

Linux Kernel Source Analysis--Kernel boot (4) Image kernel boot (setup_arch function) (Linux-3.0 ARMv7) "Go"

Related Article

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.