linux4.10.8 kernel porting (i)---environment and suitable for single board.

Source: Internet
Author: User

First, Environment construction

SOURCE package Download: Git clone https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.10.8.tar.gz

Or go directly to kernel.org to download it.

Cross-compilation tool chain production:

This has already been done in the u-boot transplant: http://www.cnblogs.com/kele-dad/p/6910040.html

Second, the kernel boot process 2.1 Windows and Linux system startup difference

  

The bootloader determines which single board to start.

2.2 Modifying Makefile

The following line is commented out:

  

Modify Arch:

  

To modify the cross-compilation tool chain:

  

2.3 Select default configuration

Locate the default configuration:

  

  

Into the ARM architecture:

  

You can see that there is a mini2440 architecture in our architecture, as well as a s3c2410 configuration file.

Enter the kernel root directory, configured as 2410:

  

Open a. config file

  

Looking at the CPU, you can see that there are 2440 CPUs:

  

It also supports mini2440 's veneer:

  

2.4 Compiling

Execution: Make Uimage

To compile:

  

Compile prompt error, that is because the U-boot dependency package is not installed.

  

Prompt to install a new package

  

To perform the compilation again:

  

Compilation succeeded.

2.5 Burn Write

Burn-Write via NFS, NFS configuration such as documentation: Http://www.cnblogs.com/kele-dad/p/7082765.html

  

Boot kernel: Bootm 32000000

  

Look at the printing information, there is an error, the machine ID is not recognized. A lot of machine IDs are printed below.

Now we have to look at the code of the boot kernel according to our machine ID to u-boot source.

Go to CMD_BOOTM.C (common), search Bootm, find the following line of code:

  

The above code calls the DO_BOOTM function and goes into the function to see:

1 U_boot_cmd2 Do_bootm3 Do_bootm_subcommand4 Do_bootm_subcommand5 do_bootm_states6BOOT_OS_FN *Boot_fn;7 Bootm_start8 Bootm_find_os9 Bootm_find_otherTen Bootm_load_os OneBOOT_FN = Bootm_os_get_boot_func (images->Os.os); ADo_bootm_states

There is a structure in do_bootm_states, BOOT_OS_FN:

1 StaticBOOT_OS_FN *boot_os[] = {2[Ih_os_u_boot] =Do_bootm_standalone,3 #ifdef config_bootm_linux 4     [Ih_os_linux] = Do_bootm_linux,5 #endif6 #ifdef CONFIG_BOOTM_NETBSD7[Ih_os_netbsd] =Do_bootm_netbsd,8 #endif9 #ifdef Config_lynxkdiTen[Ih_os_lynxos] =Do_bootm_lynxkdi, One #endif A #ifdef Config_bootm_rtems -[Ih_os_rtems] =Do_bootm_rtems, - #endif the #ifDefined (config_bootm_ose) -[Ih_os_ose] =Do_bootm_ose, - #endif - #ifDefined (CONFIG_BOOTM_PLAN9) +[Ih_os_plan9] =Do_bootm_plan9, - #endif + #ifDefined (config_bootm_vxworks) && A(Defined (CONFIG_PPC) | |defined (config_arm)) at[Ih_os_vxworks] =Do_bootm_vxworks, - #endif - #ifDefined (config_cmd_elf) -[IH_OS_QNX] =Do_bootm_qnxelf, - #endif - #ifdef config_integrity in[Ih_os_integrity] =do_bootm_integrity, - #endif to #ifdef Config_bootm_openrtos +[Ih_os_openrtos] =Do_bootm_openrtos, - #endif the};

The Do_bootm_linux function is called in this struct and goes to view BOOTM.C (Arch\arm\lib)

1 intDo_bootm_linux (intFlagintargcChar*Constargv[],2bootm_headers_t *images)3 {4     /*No need for those on ARM*/5     if(Flag & bootm_state_os_bd_t | | Flag &bootm_state_os_cmdline)6         return-1;7 8     if(Flag &bootm_state_os_prep) {9 boot_prep_linux (images);Ten         return 0; One     } A  -     if(Flag & (Bootm_state_os_go |Bootm_state_os_fake_go)) { - boot_jump_linux (images, flag); the         return 0; -     } -  - boot_prep_linux (images); + boot_jump_linux (images, flag); -     return 0; +}

In the last sentence, execute the Boot_jump_linux function:

1 /*Subcommand:go*/2 Static voidBoot_jump_linux (bootm_headers_t *images,intflag)3 {4UnsignedLong Machid = gd->bd->bi_arch_number;5     Char*s;6     void(*kernel_entry) (intZerointArchUINT params);7UnsignedLongR2;8     intFake = (Flag &bootm_state_os_fake_go);9 TenKernel_entry = (void(*) (int,int,UINT)) images->EP; One  A     s = getenv ("Machid"); -     if(s) { -         if(Strict_strtoul (s), -, &machid) <0) { theDebug"Strict_strtoul failed!\n"); -             return; -         } -printf"Using Machid 0x%lx from environment\n", Machid); +     } - Bootstage_mark (bootstage_id_run_os); + announce_and_cleanup (fake); A  at     if(Image_enable_of_libfdt && images->Ft_len) -r2 = (unsignedLong) images->ft_addr; -     Else -r2 = gd->bd->Bi_boot_params; -  -     if(!fake) { in             kernel_entry (0, Machid, r2); -     } to}

Get the mach_id from the environment variable and enter kernel. If you do not get from an environment variable, the default value is used, and the first sentence of this function is the default value. See what the default value is.

  Machid = gd->bd->bi_arch_number;

in the The default ID is set in jz2440.c (board\samsung\jz2440):

1 intBoard_init (void)2 {3     /*Arch number of JZ2440 board*/4     gd->bd->bi_arch_number = mach_type_jz2440;5 6     /*adress of boot parameters*/7Gd->bd->bi_boot_params =0x30000100;8 9 icache_enable ();Ten dcache_enable (); One  A     return 0; -}

There are also set IDs in the setup_machine of BOARD_F.C (Common):

  1   Static  int  setup_machine (void  Span style= "COLOR: #000000" >)  2  { Span style= "COLOR: #008080" >3   #ifdef config_mach_type  4  gd->bd->bi_arch_number = Config_mach_type;  /*   board ID for Linux  */  5   #endif  6  return  0< /span> 7 }   

CONFIG_MACH_TYPE This macro we did not set.

Then our previous Set ID function is valid.

The ID set in Mach-types.h (ARCH\ARM\INCLUDE\ASM) is 194.

  

Then in the kernel, into the arch/arm/s3c24x0/directory, there are many of our support s3c24x0 board, into the smdk2440 single board file mach-smdk2440.c:

Machine_start (s3c2440, "SMDK2440")/    * Maintainer:ben dooks <[email protected]> */    . Atag_offset    = 0x100,    . Init_irq    = S3c2440_init_irq,    . Map_io        = Smdk2440_map_io,    . Init_machine    = Smdk2440_machine_init,    . Init_time    = Smdk2440_init_time,machine_end

In Machine_start, a single board file is found based on the Mchine ID. Machine_start is defined as follows:

  

After you expand,. NR = mach_type_s3c2440, look for this macro.

  

Generated is a file directory that is temporarily generated. Take a look at the mach-types.h:

This is smdk2440 's machine code.

  

This is mini2440 's machine code.

  

Can be seen against our u-boot print:

  

16 binary conversion to 10 binary can be calculated.

Based on the above, we can set our MACH_ID environment variable in u-boot to start the kernel, or we can directly modify the default ID value of U-boot and the machine ID match here.

Change the machine ID into mini2440. Directly modify the U-boot source code:

Change the mini2440 to the following:

  

JZ2440 changed to the following:

  

The two defined machine codes were swapped.

Set the startup parameters in the Include/configs/jz2440.h, to add the baud rate setting, otherwise there will be garbled. The baud rate set in the mini2440 kernel file is 115200,smdk2440 16M.

  

Then compile burn write U-boot.

Enter U-boot remember print to check the environment variables and reset them if the baud rate doesn't change:

  

Save it for a moment. and burn it into the kernel.

Boot kernel:

  

There is already a print message.

linux4.10.8 kernel porting (i)---environment and suitable for single board.

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.