U-Boot transplantation (8) u-boot process

Publisher:吾道明亮Latest update time:2023-08-30 Source: elecfansKeywords:U-Boot Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

u-boot startup process:

  From the file level, the main processes are in two files: cpu/arm920t/start.s, lib_arm/board.c, 

  1)start.s 

   The boot code executed in flash, which is stage1 in bootloader, is responsible for initializing the hardware environment, loading u-boot from flash into RAM, and then jumping to start_armboot in lib_arm/board.c for execution.

1.1.6u-boot start.s process:

Hardware environment initialization:

     Enter svc mode; turn off watch dog; shield all IRQ masks; set clock frequencies FCLK, HCLK, PCLK; clear I/D cache; disable MMU and CACHE; configure memory control;

reset:

     If the current code is not at the address specified by the connection (0x3f000000 for smdk2410), u-boot needs to be copied from the current location to the RAM specified location;

            Establish a stack. The stack must be initialized before entering the C function.

Clear the .bss area.

Jump to the start_armboot function for execution. (lib_arm/board.c)

2)lib_arm/board.c:

   start_armboot is the first C language function executed by U-Boot. It completes the system initialization work, enters the main loop, and processes the commands entered by the user. Here is only a brief list of the main executed function flows:

   void start_armboot (void)

   {

       //The global data variable pointer gd occupies r8.

          DECLARE_GLOBAL_DATA_PTR;

         

          /* Arrange space for the global data variable gd*/

          gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));

          memset ((void*)gd, 0, sizeof (gd_t));

         

          /* Arrange space for the board data variable gd->bd*/

          gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));

          memset (gd->bd, 0, sizeof (bd_t));

          monitor_flash_len = _bss_start - _armboot_start;//Get the length of u-boot.

         

          /* Execute the initialization functions in the init_sequence array sequentially*/

          for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {

                 if ((*init_fnc_ptr)() != 0) {

                         hang();

                 }

          }

         

          /*Configure available Flash */

          size = flash_init ();

        …

          /*Initialize heap space*/

          mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);

          /* Relocate environment variables, */

         env_relocate ();

          /* Get the IP address from the environment variable */

          gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

          /* Ethernet interface MAC address */

          …

          devices_init (); /* device initialization*/

          jumptable_init (); //Jump table initialization

          console_init_r (); /* Completely initialize the console device*/

          enable_interrupts (); /* Enable interrupt processing*/

          /* Initialize through environment variables */

          if ((s = getenv ("loadaddr")) != NULL) {

                  load_addr = simple_strtoul (s, NULL, 16);

          }

          /* main_loop() loop is executed continuously*/

          for (;;) {

                  main_loop (); /* The main loop function processes and executes user commands-- common/main.c */

          }

   }

Initialization function sequence init_sequence[]

  The init_sequence[] array stores basic initialization function pointers. The names of these functions and the program files that implement them are in the comments below.

  

  init_fnc_t *init_sequence[] = {

         cpu_init, /* Basic processor related configuration--cpu/arm920t/cpu.c */

         board_init, /* Basic board-level configuration-- board/smdk2410/smdk2410.c */

         interrupt_init, /* Initialization exception handling--cpu/arm920t/s3c24x0/interrupt.c */

         env_init, /* Initialize environment variables--common/env_flash.c */

         init_baudrate, /* Initialize baud rate setting-- lib_arm/board.c */

         serial_init, /* Serial communication settings--cpu/arm920t/s3c24x0/serial.c */

         console_init_f, /* Console initialization phase 1 -- common/console.c */

         display_banner, /* print u-boot information-- lib_arm/board.c */

         dram_init, /* Configure available RAM -- board/smdk2410/smdk2410.c */

         display_dram_config, /* Display RAM configuration size-- lib_arm/board.c */

         NULL,

  };

The execution of the entire u-boot enters an infinite loop of waiting for the user to enter a command, parsing and executing the command.


Keywords:U-Boot Reference address:U-Boot transplantation (8) u-boot process

Previous article:U-Boot transplantation (9) u-boot main data structure
Next article:U-Boot transplantation (7) summarizes the overall structure of the U-Boot project

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号