커널 분석의 시작 점은 크게 두가지 차이가 있다.
1. 커널를 압축해제 하는 부분
2. 순수 커널의 시작 부분 

또한 임베디드 시스템을 구성 할 경우 시스템의 저장 공간(일반적으로 ROM)에  퓨징 하는 커널도 두 가지로 구분 할 수 있다.
1. 압축된 커널을 퓨징해서 사용하는 경우
2. 압축되지 않은 커널을 퓨징해서 사용하는 경우

부트로더 입장에서는 압축 해제는 커널에서 하기 때문에 두가지의 차이가 없다.
저장 공간의 용량이 변수가 된다면, 1번 항을 선택 할 것이며, 좀 더 빠른 부팅을 원한다면, 2번 항을 선택하게 된다.

커널 분석을 시작하는 지점이 꼭 정해져 있는 것은 아니라고 본다. 
시간을 단축하고자 할때는 압축 해제 코드는 그냥 무시 해도 된다는 것이다.
스터디를 시작하는 단계에서 이러한 부분이 가끔 논쟁이 되기도 한다. 

이전 글의 make 로그 과정에서 이미지 생성 과정을 다시 살펴보면, 아래의 그림과 같이 요약 할 수 있다.



순수 커널 부분이 1) vmlinux 이며, 압축 해제 코드와 압축된 커널은 2) vmlinux 가 된다.

그럼 각각 시작 부분을 살펴 보자. 두번째 2) vmlinux 의 시작 부분을 링커스크립터를 통해서 살펴 보자.
이때 빌드 시 사용하는  링커스크립터는 arch/arm/boot/compressed/vmlinux.lds 이다.

$ head -n 20 arch/arm/boot/compressed/vmlinux.lds
/*
 *  linux/arch/arm/boot/compressed/vmlinux.lds.in
 *
 *  Copyright (C) 2000 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
OUTPUT_ARCH(arm)
ENTRY(_start) /* 시작 심볼 지정 */
SECTIONS
{
  /DISCARD/ : {
    *(.ARM.exidx*)
    *(.ARM.extab*)
    /*
     * Discard any r/w data - this produces a link error if we have any,
     * which is required for PIC decompression.  Local data generates
     * GOTOFF relocations, which prevents it being relocated independently
     * of the text/got segments.
     */
    *(.data)
  }

  . = 0;
  _text = .;

  .text : {
    _start = .;        /* [BLEE] _start 심볼을 정의함 , ENTRY(_start) 지정이 이곳이라고 본다. */
    *(.start)
    *(.text)
:


ENTRY 가 _start 로 지정되어 있다. 
다음으로 objdump 한 어셈블리 코드를 살펴 보자.
 

$ head -n 20 arch/arm/boot/compressed/vmlinux.objdump

vmlinux:     file format elf32-littlearm

Disassembly of section .text:

00000000 <start>:
       0:       e1a00000        nop                     (mov r0,r0)
       4:       e1a00000        nop                     (mov r0,r0)
       8:       e1a00000        nop                     (mov r0,r0)
       c:       e1a00000        nop                     (mov r0,r0)
      10:       e1a00000        nop                     (mov r0,r0)
      14:       e1a00000        nop                     (mov r0,r0)
      18:       e1a00000        nop                     (mov r0,r0)
      1c:       e1a00000        nop                     (mov r0,r0)
      20:       ea000002        b       30 <_text+0x30>
      24:       016f2818        .word   0x016f2818
      28:       00000000        .word   0x00000000
      2c:       001307a8        .word   0x001307a8
      30:       e1a07001        mov     r7, r1
      34:       e1a08002        mov     r8, r2

 
0 번지가 start 로 지정되어 있다. 여기서 한 가지 의문이 드는데, 링커스크립터에서는 _start 라고 되어 있는데, 실제로 objdump 한 파일에서는 start 라고 되어 있다. 링커스크리터에서 ENTRY()는 심볼를 지정하게 되었는데, 링커스크립터 내에서 _start 심볼을 .start 섹션의 처음 부분으로 지정하고 있다. 

이 부분의 시작 코드는 arch/arm/boot/compressed/head.S 의 start 심볼이다.

첫번째 1) vmlinux의 시작 부분을 링커스크립터를 통해서 살펴 보자.

$ vi arch/arm/kernel/vmlinux.lds

OUTPUT_ARCH(arm)
ENTRY(stext)
jiffies = jiffies_64;
SECTIONS
{


 ENTRY 가 stext 로 지정되어 있다. 
 다음으로 objdump 한 파일로 첫 시작 부분을 살펴 보자.
 

$ head -n 20 vmlinux.objdump

vmlinux:     file format elf32-littlearm

Disassembly of section .head.text:

c0008000 <stext>:
c0008000:       e321f0d3        msr     CPSR_c, #211    ; 0xd3
c0008004:       ee109f10        mrc     15, 0, r9, cr0, cr0, {0}
c0008008:       eb061b5a        bl      c018ed78 <__lookup_processor_type>
c000800c:       e1b0a005        movs    sl, r5
c0008010:       0a061b69        beq     c018edbc <__error_p>
c0008014:       e28f302c        add     r3, pc, #44     ; 0x2c
c0008018:       e8930110        ldm     r3, {r4, r8}
c000801c:       e0434004        sub     r4, r3, r4
c0008020:       e0888004        add     r8, r8, r4
c0008024:       eb00004b        bl      c0008158 <__vet_atags>
c0008028:       eb0873f4        bl      c0225000 <__init_begin>
c000802c:       eb000007        bl      c0008050 <__create_page_tables>
c0008030:       e59fd00c        ldr     sp, [pc, #12]   ; c0008044 <stext+0x44>
c0008034:       e28fe004        add     lr, pc, #4      ; 0x4

 

이 부분의 시작 코드는 arch/arm/kernel/head.S 의 stext 심볼이다.
Posted by blee
,