본문 바로가기

임베디드 | 리눅스

Kernel image loading 과정-uboot

uboot 용 헤더가 들어있는 이미지는 uImage, 커널컴파일을한 후의 바이너리는 zImage 입니다.
두 이미지에 따른 커널 loading이 다음과 같이 다릅니다.

1. uImage를 이용한 커널 이미지 올리기

* uImage = u-boot용 kernel header + kernel image

* mkImage uImage 참고
 mkimage -A arm -O linux -T kernel -C none -a 0x8000 -e 0x8000 -n
"MontaVista Linux 2.6.10" -d arch/arm/boot/zImage uzImage.bin

-l = => list image header information
mkimage -A arch -O os -T type -C comp -a addr -e ep -n name
-d data_file[:data_file...] image
-A = => set architecture to 'arch'
-O = => set operating system to 'os'
-T = => set image type to 'type'
-C = => set compression type 'comp'
-a = => set load address to 'addr' (hex)
-e = => set entry point to 'ep' (hex)
-n = => set image name to 'name'
-d = => use image data from 'datafile'
-x = => set XIP (execute in place)

ex1)

mkimage -A arm -O linux -T firmware -C none -n "HAMR3_firmware" -d stm32_lamr_2014_1.bin h_stm32_lamr_2014_1.bin

ex2)

mkimage -A arm -O linux -C none -T kernel -a 20008000 -e 20008000 -n linux-2.6 -d zImage uImage


1-1. u-boot용 커널 헤더 구조
typedef struct image_header {
 uint32_t ih_magic;         /* Image Header Magic Number  uboot-1.3.4 0x27051956*/
 uint32_t ih_hcrc;           /* Image Header CRC Checksum */
 uint32_t ih_time;            /* Image Creation Timestamp */
 uint32_t ih_size;           /* Image Data Size  */
 uint32_t ih_load;           /* Data Load  Address  */
 uint32_t ih_ep;              /* Entry Point Address  */
 uint32_t ih_dcrc;           /* Image Data CRC Checksum */
 uint8_t  ih_os;              /* Operating System  */
 uint8_t  ih_arch;           /* CPU architecture  */
 uint8_t  ih_type;            /* Image Type   */
 uint8_t  ih_comp;          /* Compression Type  */
 uint8_t  ih_name[IH_NMLEN]; /* Image Name  IH_NMLEN = 32*/
} image_header_t;


1-2. 커널 loading 과정
->main_loop
...
->run_command
...기
->do_bootm
* 헤더정보(ih_comp)를 이용하여 커널 압축해제
* 헤더정보(ih_load)를 이용하여 압축해제후 RAM으로 올린다.
* 헤더정보(ih_os)를 이용하여 OS 별 함수로 분기한다. ->do_bootm_linux
->do_bootm_linux
* 헤더정보(ih_ep)를 이용하여 램에 올라간 커널 entrypoint로 제어 옮김


2-1. 커널 loading 과정 (tftp 이용)
# cp arch/arm/boot/zImage /tftpboot
->do_tftpb
# tftp 30008000 zImage (TARGET)


2-1. 램에 올라간 이미지의 entrypoint로 제어 옮김 (head.s)
->do_go
# go 30008000 (TARGET)

출처 : http://www.iamroot.org/xe/Kernel_8_ARM/57303 (유경환)