Presentation is loading. Please wait.

Presentation is loading. Please wait.

U-boot(Universal Bootloader)

Similar presentations


Presentation on theme: "U-boot(Universal Bootloader)"— Presentation transcript:

1 U-boot(Universal Bootloader)
U-boot의 구조와 새로운 CPU로의 포팅방법

2 임베디드시스템 임베디드 시스템 "특정 목적을 위한 특정 시스템"으로 말할 수 있음. 통신 장비나, PDA등의 단말등의 시스템. PC와는 틀리게 필요한 디바이스만 붙이게 되어 있음. 실시간을 요구할 수도 있음. OS가 올라가도 되고 안올라가도 됨.

3 임베디드 리눅스 대부분의 임베디드 시스템은 대부분 RTOS(real time os)사용. 저사양의 cpu를 이용한 가볍고 응답시간이 빠른것이 요구됨 리눅스: UNIX like한 운영체제로 초기에 x86을 타겟으로 만든 OS 임베디드 리눅스: x86용의 리눅스를 임베디드 장비에 포팅. 1> OpenSource => 능력만 있으면 마음대로 수정가능 2> 전세계 여러사람들이 개발하니 내가 안해도 남들이 한것을 이용할수있다(최대장점) 3> 시스템 사양이 높아졌고, 저장장치가 점점 싸지는 추세. 4> x86에서 작성한 app를 거의 그대로 사용할 수 있다. 즉, 시뮬레이션이 쉽다

4 UNIX계열의 부팅 리눅스나 유닉스 계열 부팅의 3박자(^^) ※ NFS root FileSystem? - 부트로더 - 커널
커널이 다 부팅이 되면 init란 맨 상위 프로세스를 돌리게 된다. 즉, root filesystem이란 넘은 OS가 동작하는데 필요한 기본적인 파일들을 말하는 것.(ex> ramdisk, nfs, mtd+jffs2등등…) ※ NFS root FileSystem? 임베디드의 장비의 경우 저장장소가 상대적으로 크지않음. 그래서 압축을 하거나 네트워크 디바이스가 있을경우 네트워크 공유개념을 활용. 압축하는 방법: 압축해서 쓰는 ramdisk나 mtd+jffs2등 공유방법: Network File System(전통적인 UNIX 체계의 공유방법)이용. 다른장비에 보드에서 사용할 root fs를 넣어놓고 그냥 원격으로 로딩해서 쓰는것임 장점: nfs root fs를 자기 개발 host에 넣어 놓으면 app개발시 꼭 장비로 다운로드 안받고 nfs root fs 디렉토리로 복사하면 장비에서 바로 사용할 수가 있어서 개발에 편리.

5 U-Boot란? & 특징 부트로더 간단하게 특정 cpu에 OS 혹은 어떤 프로그램을 돌릴 수 있도록 cpu가 동작하는데 필요한 아주 기초적인 부분이나 ROM(or flash), RAM, UART등의 기본적인 디바이스들을 동작할 수 있게 만드는 프로그램. Universal Bootloader 의 약자로 간단하게 PowerPC와 ARM에 기반을 둔 임베디드 보드를 위한 부트로더. Ppcboot와 ARMboot를 썼던 사람들에게 익숙하다.. 발전을 해가면서 다양한 platform에 포팅(ppc, arm, mips, x86...) 코드가 깔끔하고 구조가 좋음. 굉장히 강력하고 그나마 쉬운(?) 환경 설정: 많이 쓰이는 cpu를 사용한 상용 evaluation board에 대한 기본 sample코드 존재(수정하여 사용가능) -> ex> S3C2410 evboard = smdk2410 다른cpu에 대해 같은 명령어 체계를 사용하므로, 다른 platform에 적용을 하더라도 큰 어려움 없이 쉽게 접근가능

6 U-boot download & compile
site: Compile Target: cpu - 삼성 S3C2410, evboard – smdk2410 Compile 순서 Makefile 에서 crosscompiler prefix지정 Ex> CROSS_COMPILE = arm_920TDI- make clobber make smdk2410_config make U-boot 1.0.0을 기준으로 설명

7 Custom Board용 u-boot설정
1) copy: board/smdk2410 => board/new2410 2) copy: include/configs/smdk2410.h => include/configs/new2410.h로 복사 3) vi Makefile smdk2410_config : unconfig @./mkconfig arm arm920t smdk2410 => 밑에 두줄 추가 new2410_config : unconfig @./mkconfig arm arm920t new2410 4) vi board/new2410/Makefile change: smdk2410 => new2410 5) compile make clobber make new2410_config make

8 Source tree 구조 /board ---/smdk2410 : cpu 디렉토리에 있는 cpu들로 만들어진 보드에 대한코드
보드에 밀접한 코드들로 보드 초기화 코드, memory bank 설정코드 flash코드, 부트로더가 dram에 위치해야하는 relocation address를 기록한 config.mk, 전체코드의 배치를 지정하는 u-boot.lds라는 링커 스크립트 파일 /common : 각종 명령어, user interface main routine /cpu ---/cpu/arm920t : cpu에 대한 startup코드(cpu초기화)와 serial, clock, timer등의 cpu specific한 코드 /doc : 각종 readme file /drivers : 각종 network과 같은 driver /examples : 부트로더상에서 실행시키는 standalone app example /fs ---/jffs : OS(특히 linux)지원 file system /include ---/include/asm-arm : 해당 platform에 대한 코드는 include/asm-arm같은식으로 존재. 중요한 파일로 u-boot.h에 board description structure가 존재함. (ppc에서 매우 중요함, arm에서는 덜 중요) ... /include/configs : 각 보드에 대한 설정파일들이 있습니다, [보드이름].h의 형태. /lib_arm : u-boot의 arm쪽 C 메인코드들이 있습니다. /net : tftp등의 네트워크 코드 /rtc : Real Time Clock driver /tools : mkimage등의 툴

9 Source Flow startup(cpu/arm920t/start.S) c쪽의 start코드(lib_arm/board.c)
cpu초기화, dram초기화, 그 후에 부트로더의 ram으로의 relocation, C코드에서의 main인 start_armboot()를 호출함. c쪽의 start코드(lib_arm/board.c) dram초기화 이후의 flash, uart등등의 주변 디바이스 초기화 메인루프(command line shell: common/main.c) 유닉스 shell과 같은 명령어 처리 루틴. autoboot delay동안 enter키 입력을 기다리는데 그동안 키 입력이 안되면 바로 boot command(설정파일을 보면 나옴)를 실행시킴. app의 실행 혹은 리눅스등의 OS로 부팅(lib_arm/armlinux.c) 헤더가 붙은 커널의 헤더를 읽어서 압축을 풀고(이부분이 일반 부트로더-blob혹은 ezboot등-랑 틀린부분이죠.) 리눅스로 제어권을 넘겨주는 코드

10 smdk2410 보드 구성 메모리와 주변 회로 구성 (회로도 참조)
CS0: Amd29LV800BB, 1MB, 16 bit모드 - boot flash CS1: Intel strata flash E28F128J3A x 2, 32비트 모드 - data저장용 flash CS3: cs8900 ethernet driver CS6: 삼성 K4S561632C-TC75 32MB x 2, 32비트 - SDRAM cs0 와 cs1의 설정: 점퍼로 조정, boot flash 선택가능 nandboot: OM[1:0]핀 설정 u-boot설정 및 코드: 부트플래쉬 -> amd 16 bit flash LCD, 등등....

11 S3C2410X Memory Map

12 SMDK2410 board configuration & Startup Code(1)
참고자료 ARM Assembly Guide GNU ld manual S3C2410 manual DRAM manual

13 Startup Code(2) 관련 파일 Start.S의 흐름 board/smdk2410/u-boot.lds
board/smdk2410/config.mk board/smdk2410/memsetup.S cpu/arm920t/start.S Start.S의 흐름 cpu초기화(interrupt mask, Clock setting) dram초기화 flash에 있는 코드를 작업공간인(relocation area) dram으로 relocate stack setup malloc area setup BSS clear C쪽 코드의 메인인 board/lib_arm/board.c의 start_armboot()로 점프

14 config.mk # SMDK2410 has 1 bank of 64 MB DRAM # 3000'0000 to 3400'0000
# Linux-Kernel is expected to be at 3000'8000, entry 3000'8000 # optionally with a ramdisk at 3080'0000 # we load ourself to 33F8'0000 # download area is 3300'0000 TEXT_BASE = 0x33F80000

15 Start.S설명(1) 자세한 코드는 kelp강좌란 파일참조 간단한 설명(u-boot 1.1.1 버전)
_start: b reset // exception의 처음인 0x 번지이다. reset 함수로 분기 ... _TEXT_BASE: // TEXT_BASE = 0x33F80000(board/smdk2410/config.mk) .word TEXT_BASE /* * the actual reset code */ reset: * mask all IRQs by setting all bits in the INTMR - default mov r1, #0xffffffff ldr r0, =INTMSK // INTMSK가 있는 녀석의 번지로딩 str r1, [r0]

16 Start.S설명(2) /* * FCLK:HCLK:PCLK = 1:2:4
bit 1: 0이면 hclk는 fclk랑 같고, 아님 hclk = fclk/2 bit 0: 0이면 pclk는 hclk랑 같고, 아님 pclk = hclk/2 여기서 집어넣는 값이 0x 이니 당근 1:2:4가 되겠지? */ ldr r0, =CLKDIVN mov r1, #3 str r1, [r0] #ifdef CONFIG_INIT_CRITICAL // smdk2410.h에 정의되어 있음 bl cpu_init_crit // 요 밑에 있는 녀석으로 jump, sdram세팅(dram초기화) #endif relocate: /* relocate U-Boot to RAM */ adr r0, _start /* r0 <- current position of code */ ldr r1, _TEXT_BASE /* test if we run from flash or RAM */ cmp r0, r /* don't reloc during debug */ beq stack_setup // no relocation code(for nandboot) ...

17 Start.S설명(3) … copy_loop:
ldmia r0!, {r3-r10} /* copy from source address [r0] */ stmia r1!, {r3-r10} /* copy to target address [r1] */ cmp r0, r2 /* until source end addreee [r2] */ ble copy_loop ... /* Set up the stack */ stack_setup: ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */ sub r0, r0, #CFG_MALLOC_LEN /* malloc area */ sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */ clear_bss: ldr r0, _bss_start /* find start of bss segment */ ldr pc, _start_armboot // ==> lib_arm/board.c의 start_armboot()로 jump _start_armboot: .word start_armboot

18 lib_arm/board.c의 start_armboot()
중요한 변수: global data 스트럭쳐중 bd_info(include/asm-arm/u-boot.h) bi_arch_number bi_boot_params start_armboot()함수 시작 - cpu_init( => cpu/arm920t/cpu.c ): stack setup. u-boot 1.1.1에서는 변경 - board_init(=> board/smdk2410/smdk2410.c) clock과 gpio등의 설정을 합니다. cpu가 같지만 board설계에 따라 틀려지는 부분설정 gd->bd->bi_arch_number = 193; gd->bd->bi_boot_params = 0x ; arch number(인식번호): arch number of SMDK2410-Board(kernel/arch/arm/tools/mach-types) kernel/arch/arm/mach-s3c2410/smdk.c(mizi kernel) MACHINE_START(SMDK2410, "Samsung-SMDK2410") BOOT_MEM(0x , 0x , 0xe ) BOOT_PARAMS(0x ) FIXUP(fixup_smdk) MAPIO(smdk_map_io) INITIRQ(s3c2410_init_irq) MACHINE_END

19 Start_armboot() - 계속 - interrupt_init(=> cpu/arm920t/interrupts.c ): 타이머 설정. udelay함수관련 설정으로 아주 중요함. - env_init(=> common/env_*.c이나 flash의 경우는 common/env_flash.c) ipaddr, serverip, etheraddr, bootarg ...등등 - init_baudrate(board.c): baudrate설정(global structure로) - serial_init(==> cpu/arm920t/serial.c ): serial설정 - console_init_f(==> common/console.c): 특별히 하는 일 없음 - display_banner(board.c): 설정정보 화면에 표시 - dram_init(==> board/smdk2410/smdk2410.c ): dram configuration setting(size, start addr) - display_dram_config: 디램 세팅 화면에 표시 - flash_init(==>board/smdk2410/flash.c): user coding부분 샘플은 u-boot/board/*

20 Start_armboot() - 계속 - display_flash_config(): flash정보 display
- mem_malloc_init (_armboot_real_end): malloc영역설정. u-boot 1.1.1에서는 변경됨 - env_relocate(common/env_common.c): env_init에서 설정된 default_environment[]를 env영역의 데이터가 들어가는데로 복사. - devices_init(common/devices.c): device driver 리스트초기화 - console_init_r(common/console.c): stdout, stdin, stderr를 out,in device로 세팅 devices_init()에서는 초기화 여기서는 세팅. - enable_interrupts(cpu/arm920t/interrupts.c ): 그냥 return됨. - main_loop() autoboot -1초가 아닐경우 딜레이만큼 기다리고 부트코맨드를 실행하고 -1이면 무조건 프롬프트 띄우고 그냥 스톱

21 U-boot 명령 tftpboot(혹은 tftp) bootm [옵션들....] printenv setenv
tftp uImage bootm [옵션들....] bootm , bootm printenv setenv setenv ipaddr Nor Flash관련명령 protect off 1:0-2, erase 1:0-2 cp.b $(filesize), protect on 1:0-2 erase bank 1 Nand Flash관련 명령 nand erase tftp nandboot.bin nand write $(filesize) nand read

22 U-boot용 image making .... boot: vmlinux
@$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C arch/$(ARCH)/boot uImage: vmlinux $(OBJCOPY) -S -O binary vmlinux vmlinux.bin gzip -vf9 vmlinux.bin mkimage -A arm -O linux -T kernel -C gzip -a 0x \ -e 0x n 'ARM Linux-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)' \ -d ./vmlinux.bin.gz cp /tftpboot nImage: vmlinux mkimage -A arm -O linux -T kernel -C none -a 0x \ -d ./vmlinux.bin

23 bootm 명령의 흐름 및 새명령어작성 bootm 명령의 흐름 새로운 명령의 작성 별첨 2: common/cmd_bootm.c
별첨 3: lib_arm/armlinux.c 새로운 명령의 작성 별첨 4: common/cmd_blw.c

24 NAND Flash Code 작성 doc/README.nand 를 참조.
README.nand에서 지정하듯이 common/cmd_nand.c 에서 사용되는 macro등을 작성(#define을 이용) 주의할 점은 각 보드의 hw구성에 따라 nand flash 접근 방식이 틀리기 때문에 이 점을 고려하여 작성을 한다. 주로 macro는 include/configs의 보드설정파일에 넣는다 Common/cmd_nand.c를 수정 이 부분도 macro와 hw의 구성에 알맞게 코드를 수정해야한다. 기본구조는 되어 있으나 함수의 재작성등의 수정이 필요. 가장 중요한 것으로 nand flash의 spec에 알맞은 delay등을 조정해줘야 한다.(이것이 안될경우 제 동작 안하는 수가 많이 생김)

25 새로운 CPU로의 U-boot porting(1)
포팅하고자하는 cpu와 가장 유사한 platform선정 Configuration 파일 설정 Startup code를 target에 알맞게 수정 Clock, ram setup Board initialize routine설정 Device관련 레지스터, pin등의 in/out setup UART clock source등의 설정, GPIO설정 등등 UART setup 처음엔 clock을 계산하여 baudrate등을 수동으로 설정 어느정도의 코드 완성후엔 함수등을 이용한 설정

26 새로운 CPU로의 U-boot porting(2)
Timer routine 작성(ex> cpu/arm920t/interrupts.c) Timer루틴이 실제 포팅에서 가장 중요하다고 느꼈음(^^) Down/up counter timer에 따라 루틴의 변경이 필요 주변디바이스에 대한 코드작성 Nor Flash code LAN driver NAND Flash code 커널과의 매칭에 유의하여 각종 pin설정 Gpio등의 설정등을 커널에서 할것이냐 부트로더에서 할것이냐등의 결정

27 끝….^^


Download ppt "U-boot(Universal Bootloader)"

Similar presentations


Ads by Google