U-boot memory distribution and global data structure

Source: Internet
Author: User

U-boot, unless it is debugged in RAM, typically executes a piece of code from Flash, then moves the code and data stored in Flash into RAM and jumps to ram for execution. Of course, this should also be the general bootloader of the implementation of the way,everyone is similar, but the memory planning (stacks, heaps, and so on) of each bootloader is not the same, and U-boot also plans some space for storing environment variables and some data structures in memory space, so if you don't know it, you can directlyIf you look at the code, you'll be a little confused. It is necessary to introduce first. about the memory distribution of u-boot, or memory mapping, someone on the web drew a picture, the comparison is clear, as follows: the above figure actually missed a part, that is, in Flash, the general situation immediately after the u-boot image, there is a storage environment variable area (although this area seems to be optional), usually in flash to take a sector to store environment variables.
  • U-boot Image: U-boot burned into the flash image, in uboot terms, this part of the size is called Monitor_ Size. So in uboot, this binary file is called Monitor. The u-boot image is shipped to RAM, and you can see a piece of RAM in the U-boot image as well.
  • Environment variable Area: Environment variable is stored in Flash and RAM, in Flash is generally stored in the next sector immediately after Monitor is the u-boot mirror, storing some information, such as IP address, when the program is copied into RAM, Environment variables are also copied to ram.
  • Cfg_malloc_len: This area is used to store heap data and environment variables, and this area is immediately followed by the u-boot image in RAM, and it can be seen that this area has been opened down the U-boot base site. Environment variables are saved in Flash, in the system initialization, the flash environment variables are also copied to RAM, when the system is running, you can modify the value of RAM to change the system's environment variables, but after the power-down restart, still use the set value in Flash, Of course, you can also write flash to change the default environment variables.
  • Gbl_data_size: This area is immediately followed by the Cfg_malloc_len data section, as can be seen from the diagram, this section is used to store a gd_t data structure, the data is a uboot used in the database, to store some information about the system, This data structure is listed below
  • In addition, at the beginning of the Sdram_base address, generally hold a two-level jump interrupt vector, these interrupt vectors are generally used for uclinux and other operating systems.
  • Other distributions such as stacks are shown.
The definition of the GT_D data structure used in Uboot is listed below (ARM):the meaning of the value is also more intuitive
1typedefstructGlobal_data {2bd_t *BD;3UnsignedLongflags;4UnsignedLongbaudrate;5UnsignedLongHave_console;/*Serial_init () was called*/6UnsignedLongReloc_off;/*Relocation Offset*/7UnsignedLongENV_ADDR;/*Address of Environment struct*/8UnsignedLongEnv_valid;/*Checksum of environment valid?*/9UnsignedLongFb_base;/*base Address of frame buffer*/Ten #ifdef config_vfd OneUnsignedCharVfd_type;/*Display Type*/ A     #endif -     #if0 -UnsignedLongCPU_CLK;/*CPU Clock in hz! */ theUnsignedLongBUS_CLK; -UnsignedLongRam_size;/*RAM Size*/ -UnsignedLongReset_status;/*Reset Status register at boot*/ -     #endif +     void**JT;/*Jump Table*/ -} gd_t;
the following options are available for flags:
1 /* 2 * Global Data Flags 3 */ 4 #define Gd_flg_reloc    0x00001/         * Code is relocated to RAM            */5#define gd_flg_devinit  0x00002/         * Devices have been initialized        */6#define gd_flg_silent   0x00004 /         * Silent mode                          */
where the BD_T data structure is defined as follows:
1typedefstructBd_info {2     intBi_baudrate;/*Serial console BaudRate*/3UnsignedLongBI_IP_ADDR;/*IP Address*/4UnsignedCharbi_enetaddr[6];/*Ethernet adress*/5     structenvironment_s *bi_env;6     ULONGBi_arch_number;/*Unique ID for this board*/7     ULONGBi_boot_params;/*where this board expects params*/8     struct                              /*RAM Configuration*/9 {Ten       ULONGstart; One       ULONGsize; A } Bi_dram[config_nr_dram_banks]; - #ifdef config_has_eth1 -       /*second onboard Ethernet port*/ theUnsignedCharbi_enet1addr[6]; -     #endif -} bd_t;

U-boot memory distribution and global data structure

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.