[RPI U-Boot](- https://elinux.org/RPi_U-Boot)
[Environment Variables](- https://docs.u-boot.org/en/latest/usage/environment.html)
- 부트로더의 역할
booting: 전원 인가 후 하드웨어 초기화(CPU,메모리, 클럭 설정 등)
loading: 운영체제인 커널을 로딩함.
역할 완료 후 제어권을 OS에 넘기면서 더 이상 메모리에 상주하지 않음.
U-Boot 빌드 및 부팅 흐름 요약
U-Boot(Universal Bootloader)
오픈소스 2차 부트로더. 다양한 아키텍처(PowerPC,ARM,MIPS등)를 지원함
boot ROM→SPL1차 부트로더→2차부트로더 로드. (boot ROM에서 로드된다)
하드웨어를 초기화하거나, 테스트를 한다.
또한 애플리케이션을 다운로드,실행을 할 수 있다.
리눅스 이미지 로드.
같은 쉘에서 다른 보드의 명령어를 실행할 수 있도록하고 새로운 커맨드를 추가할 수 있는 확장성과 confiurable한 특징이 있다.
readme 설명
This directory contains the source code for U-Boot, a boot loader for Embedded boards based on PowerPC, ARM, MIPS and several other processors, which can be installed in a boot ROM and used to initialize and test the hardware or to download and run application code. The development of U-Boot is closely related to Linux: some parts of the source code originate in the Linux source tree, we have some header files in common, and special provision has been made to support booting of Linux images. Some attention has been paid to make this software easily configurable and extendable. For instance, all monitor commands are implemented with the same call interface, so that it's very easy to add new commands. Also, instead of permanently adding rarely used code (for instance hardware test utilities) to the monitor, you can load and run it dynamically.
U-Boot 빌드 과정 (Make→ Link 까지)
1. Make
- 어떤 C/ASM 소스가 빌드 대상이 될지 결정된다.
- Makefile + Kconfig 시스템으로 보드/아키텍처 설정 반영
- make
→ .config 생성 - .config → include/autoconf.mk, include/autoconf.h 생성
- 여기서 어떤 소스가 컴파일되고, 어떤 드라이버와 아키텍처 설정이 필요한지 결정
- make
2. 링크 스크립트 생성
- u-boot.lds.S 파일을 전처리(cpp_하여 u-boot.lds 생성
예)
cpp -E -P -include autoconf.h -include config.h -D__ASSEMBLY__ [u-boot.lds](http://u-boot.lds).S > u-boot.lds → GNU ld에 전달 cpp -E -P \
-include autoconf.h -include config.h \
-D__ASSEMBLY__ \
u-boot.lds.S > u-boot.lds
이 스크립트는 u-boot 이미지의 메모리 배치를 결정!u-boot.lds 주요 내용
ENTRY(_start) → 실행 시작 심볼 지정
.text → 코드 영역 (start.o가 맨 앞에 배치)
.rodata, .data, .bss → 데이터 섹션
.u_boot_list →U-boot의 드라이버 / 명령어 등록용 리스트 섹션.
→ 이 단계 에서 실행 이미지의 “지도”가 만들어진다고 보면 된다!
3. 최종 링크
- ld -T u-boot.lds -o u-boot
리셋 이후 실행 흐름
➤ Reset Vector→ _start (arch/xxx/cpu/start.S)
- SoC 리셋 후 PC는 리셋 벡터 주소 가리킴(0x00000000 또는 0xFFFF0000)
- U-Boot의 start.s 안 ENTRY(_start)가 이 위치에 배치!
- 주요 역할
- CPU 레지스터 초기화, 스택 포인터 설정, 캐시,MMU 설정 등 진행
- 이후 reset : 레이블로 분기
➤ reset 함수(start.S)
- 하드웨어 초기화를 위한 아주 초반 단계
- ROM/부트로더에서 넘긴 부트 파라미터 저장 (save_boot_params)
- PIE(Position Independent Execution) 지원을 위한 코드/데이터 재배치 작업 수행 (.rela.dyn 처리)
- 준비 끝나면 crt0.S 내의 _main 함수 호출! 진입!
➤ _main (arch/xxx/lib/crt0.S)
- 진짜 C 런타임으로 넘어가기 전의 준비 코드
- 주요 동작
- 초기 스택 재설정 (SRAM 및 캐시 영역)
- board_init_f(0) 함수 호출
➤ board_init_f (arch/xxx/lib/board_f.c)
초기 하드웨어 초기화
여기선 아직 DRAM을 쓰지 않아, 필수 장치만 켜준다.
UART(디버깅 출력), 클럭,PLL , DRAM 컨트롤러 초기화 수행
DRAM 주소 및 리로케이션 대상 주소 설정
초기화 완료 후 _main 함수로 복귀
➤ _main 복귀 이후 (crt0.s)
- 이제 DRAM 사용 가능!
- DRAM에 새로운 스택 포인터(SP)와 GD(Global Data) 구조체 설정
- relocate_code 호출:
- U-Boot 이미지를 ROM/Flash에서 DRAM으로 복사
- PC를 DRAM 내 새 U-Boot 위치로 점프
- relocate_vectors, c_runtime_cpu_setup호출 → 예외 벡터 설정, BSS 영역 초기화 진행
➤ board_init_r(gd, gd->relocaddr) 호출(arch/xxx/lib/board_r.c)
- 본격적인 런타임 단계.U-Boot 실행 시작
- 모든 드라이버와 하위 시스템 초기화 (콘솔출력,eMMC/SD/NAND,네트워크, 환경변수로드)
- U-Boot 메인 루프 진입. → autoboot(커널 로드,실행), CLI (명령어 해석기)진입!
'Linux' 카테고리의 다른 글
| [리눅스 커널과 디바이스 드라이버]애플리케이션->syscall->vfs->디바이스파일open 까지 (2) | 2025.08.17 |
|---|---|
| 리눅스 디바이스 드라이버 - module_init() 모듈 등록부터 사용자 호출까지 (1) | 2025.08.17 |
| syscall번호를 테이블에 넣어 커널에 빌트인하여 사용 (2) | 2025.08.17 |
| U-Boot 부팅 흐름 과정 요약 2 -Linux kernel 로드 (3) | 2025.08.16 |
| UART3 활성화하여 PC와 시리얼 통신[dtoverlay 사용해보기] (1) | 2025.08.16 |