부트로더-2

Download Report

Transcript 부트로더-2

FUSING
목차
1
2
3
4
5
6
overview
Bootloader
kernel image
rootfile-system image
fusing
부트로더 분석
2
1 Overview
1 Overview
Target System
HOST System
2. Download
Serial Interface
or
Ethernet
Linux Kernel
Root File System
User File system
Interface
SDRAM
JTAG Interface
3.Fusing
Boot Loader
1.Fusing
Boot Loader
FLASH Memory
JTAG
4
1 Overview

필수 구성 요소
 Target System을 구동하기 위해서는 적어도 다음의 3가지 구
성요소가 필요하다.
 Boot Loader
 하드웨어를 초기화하고 kernel image를 sdram에 올려주어 수행
을 넘겨주는 역할을 하는 프로그램
 OS Kernel
 OS 의 핵심 프로그램
 Root File System
 Kernel 에서 사용할 File System
5
1 Overview

What is Boot Loader?
 시스템이 부팅될 때 가장 먼저 실행되는 프로그램
 Main Function
 Hardware Initialization



CPU clock, Memory timing, interrupt, UART, ETC.
PC의 BIOS
Kernel Load

운영 체제를 RAM에 올려주고 실행.
 Additional Function
 Target board에 개발한 program을 전송하기 위한 기능들.
 Download Image to SDRAM



Serial – xmodem, uuencode
Ethernet – tftp, bootp
Fusing Flash Rom

Write, Read, Erase, Lock/Unlock
6
1 Overview

Kernel
 OS의 핵심기능을 수행하는 프로그램
 Process management
 Memory management
 Device management
 Network management
 File System Management
 API (Application Programming Interface)
 ETC.

Kernel Image
 Kernel 을 압축한 것으로 boot loader에 의해 압축이 해제되어
sdram으로 load 된다.
 시스템의 저장 공간을 최소한으로 사용하기 위한 목적으로 압축 상
태로 존재
7
1 Overview

Root File System
 “/” 디렉토리로 마운트 되는 파일 시스템으로 리눅스가 동작하
기 위해 기본적으로 필요한 프로그램 및 설정 파일을 가지고
있다.
 Kernel 에서 기본적인 초기화 작업 후 Root File System을 마
운트 한다.
 Embedded System 은 대부분 크기가 작아야 하므로 hard
disk를 가지고 있을 수 없기 때문에 주로 Ramdisk를 사용하여
Root File System을 구축한다.
8
1 Overview

Target Operating 순서 [1]

Boot Loader
SDRAM
1. Power On
2.Execute 0x00000000
Boot Loader
Linux Kernel
RAMDISK
JFFS2
3.Load Kernel
4. Load Root File System
(RAMDISK)
FLASH Memory
9
1 Overview

Target Operating 순서 [2]

Kernel
Kernel 이미지 적재
Root File System 마운트
•시스템 초기화
 네트워크 설정
호스트 이름 설정
Device 구동
‘init’(/sbin/init) process 실행
다른 file system 마운트
ETC
파일 시스템 점검
Login 처리
가상 콘솔 접속 관리
ETC.
10
2 Bootloader
부트로더를 컴파일하고 jtag으로 flash에 fusing 한다.
2 Boot Loader 설치
1.
2.
Bootloader를 컴파일 하기 위해서는 타겟보드용 Toolchain이 설치
되어 있어야 한다. Toolchain 설치를 다시 한 번 해 보자.
Source 압축을 해제한다.
tar zxvf iwmmxt-1.0.0.tar.gz
12
2 Boot Loader 설치
13
2 Boot Loader 설치
3.
Boot Loader compile
14
2 Boot Loader 설치
4.
Compile이 완료되면, boot가 생성이 된다.
5.
생성되어진 boot가 bootloader image이다.
15
2 Boot Loader 설치
< JTAG program 설치 >

What is JTAG?

Joint European Test Access Group



JTAG은 PCB와 IC를 테스트 하기 위한 목적으로 1985년 조직
된
JTAG(Joint Test Action Group)에 의해 제정된 표준이다.
Boundary Scan Test
칩 내부에 Boundary Cell이란 것을 두어 외부의 핀과 일대
일로 연결시켜 프로세서가 할 수 있는 동작을 중간에 Cell을
통해 모든 동작을 인위적으로 수행할 수 있어 여러 가지 하
드웨어 테스트나 연결 상태 등을 체크할 수 있다.
16
2 Boot Loader 설치
< JTAG program 설치 >

JTAG 기능
 프로세서(CPU)의 상태와는 상관없이 디바이스의 모든 외부
핀을 구동시키거나 값을 읽어 들일 수 있는 기능을 제공
 회로의 배선과 소자의 전기적 연결상태 test
 디바이스간의 연결상태 test
 Flash memory fusing
17
2 Boot Loader 설치
< JTAG program 설치 >

PC를 통한 JTAG 호환 장치의 제어
18
2 Boot Loader 설치
 JTAG 설치
19
2 Boot Loader 퓨징

JTAG Build


JTAG 소스가 있는 디렉토리로 이동한다.
Makefile 이 작성되어 있으므로 make 명령을 사용하면 JTAG 소스가
컴파일 된다. 컴파일이 성공하면 Jflashmm 이란 바이너리 파일이 생
성된다.
20
2 Boot Loader 설치

타겟보드에 Bootloader 올리기
앞에서 컴파일한 부트로더를 위에서 컴파일한 jflashmm를 이용하여 플
레시 메모리에 Fusing 한다.
jflashmm 프로그램은 보드의 JTAG 커넥터와 연결된 호스트 PC의 프린터
포트를 제어하여 타겟보드용 부트로더를 Fusing 할 수 있다.
roothost]# ./jflashmm pxa27x32.dat boot
부트로더 이미지(boot)를 cpu와 flash 메모리에 대한 정
보를 인자값(pxa27x32.dat)으로 해서 퓨징시키고 있다.
21
2 Boot Loader 퓨징

Bootloader Fusing

JTAG을 통해 flash 0번지에 부트로더 fusing
22
3 Kernel Image
3 Kernel Compile
Target System
HOST System
2. Download
Serial Interface
or
Ethernet
Linux Kernel
Root File System
User File system
Interface
SDRAM
JTAG Interface
3.Fusing
Boot Loader
1.Fusing
Boot Loader
FLASH Memory
JTAG
24
3 Kernel Compile


필요한 파일 (CD 에 있는 내용)
<보드용 리눅스 커널>
- X-Hyper270-TKU Kernel : linux-2.6.11-h270-tku_v1.1
커널을 압축시킨 파일
X-Hyper270-TKU Kernel : linux-2.6.11-h270-tku_v1.1.tar.gz
25
3 Kernel Compile
 X-Hyper270-TKU Kenel인 linux-2.6.11-h270-tku_v1.1.tar.gz를 compile 하여
zImage를 생성
 Kernel source가 있는 디렉토리로 이동한다. 먼저 아래 그림처럼 X-Hyper270-TKU
설정을 한 후 menuconfig 화면으로 이동한다.
/Kernel]# cd linux-2.6.11-h270-tku_v1.1
/linux-2.6.11-h270-tku_v1.1]# make xhyper270tku_defconfig
/linux-2.6.11-h270-tku_v1.1]# make menuconfig
/linux-2.6.11-h270-tku_v1.1]# make zImage
설정을 그대로 저장하고 빠져나온다.
 “make xhyper270tku_deconfig”는 kernel 컴파일 옵션을 TKU보드에 맞추어 주는
일을 한다. makemenu config의 저장 파일인 kconfig 파일이 변경된다.
 make zimage로 컴파일을 하면 이 환경설정 파일을 참조해서 컴파일한다.
26
3 Kernel Compile

컴파일된 kernel 이미지를 /tftpboot 로 복사
# cp ./arch/arm/boot/zImage /tftpboot/

bootloader로 부팅
 minicom을 실행 한다.
 bootloader command mode로 target system booting
27
4 rootfile-system image
4 jffs2 file system
Target System
HOST System
2. Download
Serial Interface
or
Ethernet
Linux Kernel
Root File System
User File system
Interface
SDRAM
JTAG Interface
3.Fusing
Boot Loader
1.Fusing
Boot Loader
FLASH Memory
JTAG
29
4 jffs2 file system

mkfs.jffs2 설치
 jffs2 file system을 만들기 위해서는 mkfs.jffs2 프로그램이
필요하다.
 Host에 설치 되어있나 확인하고 되어있지 않으면 설치한다.
30
4 jffs2 file system


flash용 파일시스템인 Jffs2 image는 mkfs.jffs2 라는
유틸리티를 통해 image로 만든다.
아래와 같은 명령어로 루트 파일 시스템을 만든다.
31
4 jffs2 file system
 mkjffs2 사용법

스크립트의 내용은 다음과 같다.
 생성된 rootfs.img 이미지를 bootloader를 이용해 다운로드 한 후 에는 필히
flash에 write해 주어야 한다.
32
5 FUSING
5 FUSING

Fusing
 사용법 : “tftp “전송할 파일명” “해당 영역”
hybus>tftp zImage kernel
hybus>flash kernel
hybus>tftp rootfs.img root
hybus>flash root
34
5 FUSING

Booting linux kernel

정상적으로 이미지가 퓨징되었다면 타깃시스템이 잘 동작할 것이다.
다음의 boot명령어로 booting하거나 reset 버튼을 눌러 타깃시스템
을 재 동작시킨다.
hybus> boot
타깃시스템의 잘 동작하는지 확인한다.
이로써 타깃시스템에 대한 fusing을 마쳤다.
35
6 Bootloader 소스분석
X-HYPER270-TKU의 부트로더 흐름도

X-HYPER270-TKU의 부트로더 흐름도

부트로더 소스




어셈블리 코드 파일: 3개
C 프로그램: 21개
기타: 스크립트 파일, Makefile, 헤더 파일
main.c
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
count = 2000;
autoboot = true;
do {
if (getc() != -1) { autoboot=false; break; }
if (!(--count % 1000)) putc('.');
mdelay(1);
} while (count);
putc('\n');
if (autoboot) {
printf(" autoboot started.\n");
autoboot_mode();
}
printf(" autoboot aborted\n");
printf(" type \"help\" to get a list of commands\n");
command_mode();

command.c
46 static struct command_t *cmdlist[] = {
// 부트 명령어 선언 부분
47
&cmd_load,
48
&cmd_ping,
49
&cmd_bootp,
/* command.h */
50
&cmd_tftp,
#ifndef _COMMAND_H
51
&cmd_flash,
52
&cmd_erase,
#define _COMMAND_H
53
&cmd_config,
54
&cmd_boot,
55
&cmd_memcpy,
struct command_t {
56
&cmd_memcmp,
const char *name;
57
&cmd_memset,
58
&cmd_hexdump,
bool (*run)(int argc, char
59
&cmd_write,
void (*usage)(void);
60
&cmd_read,
};
61
&cmd_reboot,
62
0
…
63 };
…….
112 extern bool do_command(int argc, char **argv) { // 부트 명령어 실행 부분
113
bool res = true;
114
struct command_t **cp;
115
116
if (!strcmp(argv[0], "ls")) {
……
124
} else if (!strcmp(argv[0], "help")) {
125
for (cp=cmdlist; *cp; cp++)
126
(*cp)->usage();
127
} else {
128
for (cp=cmdlist; *cp; cp++) {
129
if (!strcmp(argv[0], (*cp)->name)) {
130
res = (*cp)->run(argc, argv);
131
return res;
132
}
133
}
134
if (!*cp) { printf(" %s : unknown command\n", argv[0]); res = false; }
135
}
**argv);

command.c
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
static void reboot_usage(void){
usage_format("reboot", "software reboot");
return;
}
static bool do_reboot(int argc, char **argv){
void (*restart)(void) = 0;
printf(" restarting...\n");
restart();
return true;
}
struct command_t cmd_reboot = {
.name = "reboot",
.run = do_reboot,
.usage = reboot_usage
};