Taixing Longyi Terminals Co.,Ltd. , https://www.txlyterminals.com
U-boot passes RAM and Linux kernel reads RAM parameters
U-boot passes various parameters to the Linux kernel, such as serial port settings, RAM information, video framebuffer details, and more. These parameters are stored in a structure called "tag," which is used to pass data between U-boot and the kernel. U-boot initializes this tag structure with relevant information and passes the physical address of the structure to the Linux kernel when it starts. The kernel then uses this address to parse the tags using the `parse_tags` function.
In this article, we will focus on how U-boot passes RAM-related parameters to the Linux kernel and how the kernel reads and processes them.
1. **How U-boot Passes RAM Parameters to the Kernel**
The `do_bootm_linux` function in `./lib_arm/bootm.c` handles the boot process for Linux images. This function calls several helper functions to set up the tag structure. One of these functions is `setup_memory_tags`, which initializes memory-related tags based on the board's DRAM configuration.
The `setup_memory_tags` function iterates through all the DRAM banks defined in the board data (`bd_t`) and sets up each memory region as an ATAG_MEM entry in the tag list.
2. **How the Linux Kernel Reads the RAM Parameters**
Once the kernel boots, it starts from `arch/arm/kernel/head.S`, which eventually leads to the `start_kernel()` function. Inside `start_kernel()`, the `setup_arch()` function is called, which parses the tag list passed by U-boot.
The `setup_arch()` function checks the `__atags_pointer` or the platform-specific `boot_params` to locate the start of the tag list. It then uses `parse_tags()` to process each tag, including the `ATAG_MEM` tag, which contains the RAM information.
The `parse_tag_mem32()` function is responsible for processing the `ATAG_MEM` tag. It calls `arm_add_memory()` to add the memory region to the kernel's internal memory information structure (`meminfo`), which is used during memory management.
3. **Understanding `bd` and `gd` in U-boot**
U-boot maintains two key global structures: `bd_t` (board information) and `gd_t` (global data). The `gd_t` structure holds many important variables, including the `bd` pointer, which contains board-specific data like memory layout and peripheral configurations.
The `gd_t` structure is accessed via a register (typically R8) using the macro `DECLARE_GLOBAL_DATA_PTR`. This allows U-boot to efficiently access global data across different parts of the code.
4. **Summary**
In summary, U-boot prepares a tag list containing essential system information, including RAM details, and passes this structure to the Linux kernel. The kernel then processes this information to initialize its memory management and other subsystems. Understanding how this communication works is crucial for developers working on embedded systems and custom bootloaders.
This article covers U-boot 1.3.4 and Linux kernel 2.6.28 on an ARM platform.