title: [Writing an OS Kernel from Scratch] 336 – U-Boot Porting: Getting Your Dev Board Running from Zero
category: os
tag: [u-boot, embedded, arm, porting]
source: https://github.com/golang12306/os-kernel-from-scratch

[Writing an OS Kernel from Scratch] 336 – U-Boot Porting: Getting Your Dev Board Running from Zero

1. The Essence of U-Boot Porting

U-Boot porting is essentially making the bootloader recognize your hardware. The chip vendor provides reference board code, and we modify GPIO, clocks, DDR, and storage drivers on that basis so that U-Boot can run stably on a new board.

Analogy to Windows: Think of U-Boot as a BIOS configuration tool under a Windows PE environment — you need to tell the system how to initialize memory, how to access storage, and how to load the kernel.

Bash
┌─────────────────────────────────────────────────────────────┐
│                U-Boot Porting Layered Architecture          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐          │
│  │  cmd_xxx    │  │  net_xxx    │  │  drivers/   │          │
│  │  (Command)  │  │  (Network)  │  │  (Driver)   │          │
│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘          │
│         └────────────────┼────────────────┘                │
│                          │                                  │
│                   ┌──────┴──────┐                           │
│                   │   common/   │  (Generic code)           │
│                   └──────┬──────┘                           │
│                          │                                  │
│         ┌────────────────┼────────────────┐                │
│         │                │                │                │
│   ┌─────┴─────┐    ┌─────┴─────┐    ┌─────┴─────┐           │
│   │  board/  │    │   arch/   │    │ configs/  │           │
│   │  Board    │    │  Arch     │    │  defconfig │           │
│   │  Config   │    │  ARM/RISC │    │  Build cfg │           │
│   └───────────┘    └───────────┘    └───────────┘           │
└─────────────────────────────────────────────────────────────┘

2. Hardware Information Preparation Before Porting

The following information must be obtained before porting (usually requested from the chip manufacturer):

Information Description Source
SoC datasheet Register definitions, clock tree Vendor
Hardware Manual Hardware design reference Vendor
DDR Datasheet Timing parameters, training algorithm Vendor
Board schematic GPIO routing, DDR layout Board designer
Reference BSP U-Boot/linux source code Vendor/VPS

3. Porting Workflow

Bash
U-Boot porting workflow:

1. Select a reference board (most similar to yours)
2. Create a new board directory:
   cp -r board/vendor/ref_board board/vendor/my_board

3. Modify key files:
   - board/my_board/my_board.c: Board-specific initialization
   - include/configs/my_board.h: Board configuration macros
   - arch/arm/dts/my_board.dts: Device tree

4. Configure DDR parameters (the hardest part):
   - Matching DDR chip timing parameters
   - Correcting DDR training algorithm

5. Configure clock tree:
   - CPU frequency, bus frequency, DDR frequency
   - Peripheral clocks (UART, SPI, I2C)

6. Configure boot media:
   - eMMC, NAND Flash, SD card, SPI NOR Flash

7. Compile and test:
   make my_board_defconfig
   make -j8
   # Burn to boot media and test
Last modified: 2024年1月13日

Author

Comments

Write a Reply or Comment

Your email address will not be published.