SW TARGET HOST Debug Agent Simulation Environment Target
임베디드 시스템 개발 구조 일반적인 임베디드 S/W 개발 환경 구성 TARGET HOST Debug Agent Simulation Environment Target Server GUI Development Tools - 12 - Embeded Application Library Sub-system Core OS Kernel www. hanback. co. kr
EMPOS-II HW/SW 구성 - 13 - www. hanback. co. kr
EMPOS-II HW/SW 구성 하드웨어 자원 • • • • • Memory : 128 Mbyte SDRAM, 32 -Mbyte Flash memory. 1 Mbyte SRAM PCMCIA slot 1개, Compact slot 1개 PS 2 Keyboard, Mouse controller Ethernet : 10/100 M LAN 91 C 111 Primary/Secondary Ethernet controller Touch-screen panel controllers : Burr Brown ADS 7846 Audio CODEC : Cirrus CS 4202 TFT LCD panel USB Client port 1 Port Ir. DA (infrared) transceiver 1 Port Full-Function UART 1 Port Bluetooth UART l Port SD(Secure Digital memory Card ) or Multi. Media. Card Slot 1개 I 2 C to 24 C 16 EEPROM Epson RTC 4513 Real Time Clock Module Intel SA-1111 companion 칩 확장용 Expansion 1 Port 7세그먼트 LED 4 Digit LED * 8 EA Keyboard 스위치 * 8 EA 20 x 2 TEXT LCD * 1 EA - 14 - www. hanback. co. kr
EMPOS-II HW/SW 구성 하드웨어 블럭도 - 15 - www. hanback. co. kr
EMPOS-II HW/SW 구성 소프트웨어 구성 • • • 부트로더 : EMPOS-BOOT v 0. 1 리눅스 커널 : linux-2. 4. 19 -rmk 4 -pxa 2 -empx 1 파일 시스템 : ramdisk-16 m(ext 2) GUI : QT/E-2. 3. 2, Qtopia-1. 4. 0 (jffs) 개발 툴 : GNU Toolkit, Visual Esto 디바이스 모듈 구성 • • 커널 삽입 디바이스 - TFT LCD, PCMIA/CF, PS 2 Keyboard, Touch Screen - AC 97 Audio, Ir. DA, FFUART, MMC 등 모듈 형태 디바이스 - SMC 91111 Primary/Secondary Ethernet Driver(커널 소스에 포함) - Prism 2 Wireless Driver - ide Disk Dirver - Text LCD Driver - LED, Button Driver - 7 Segment LED Driver - GPIO Input , Output Driver - 16 - www. hanback. co. kr
부트로더 분석(EMPOS-BOOT) - 17 - www. hanback. co. kr
부트로더 분석 일반 리눅스 EMPOS Boot. Loader LILO(LInux LOader) EMPOS_boot 하드 디스크의 MBR에서 동작 Flash 0 block에서 동작 여러 O/S를 선택적으로 부팅 Linux Booting Command line • Kernel/root filesystem을 Downloading • Ram에서 Flash로 writing - 18 - www. hanback. co. kr
부트로더 분석 부트로더의 역할 • • • hardware 초기화 - Memory setting - CPU Clock setting - GPIO setting - Serial setting - MAC address 획득 및 Ethernet port setting Flash 에서 RAM으로 memory copy - kernel image copy - ramdisk image copy - 부트로더 자신 copy Kernel booting Command mode 제공 포팅의 편의를 위한 Debug 모드 제공 여러 부트로더들 • blob, Redboot, ppcboot, armboot, bootldr 등 - 19 - www. hanback. co. kr
리눅스 매모리 관리 커널이 프로세스에게 0 x 20000000 ~0 x 2003 ffff 까지 선형 주소 공간을 할당을 할 경우 0 x 2003 ffff(0010000000111111) 0 x 80, 0 x 63 - 33 - www. hanback. co. kr
리눅스 프로세스 관리 state nead_reched counter priority tty_struct next_task prev_task next_run prev_run 프로세스완 연관된 tty fs_struct p_optr ……. . 현재 디랙토리 files_struct 파일 디스크립터 포인터 tty mm_struct tss 메모리 영역 디스크립터 포인터 signal_struct fs files 수신한 시그널 mm signal_lock sig ……. . - 38 - www. hanback. co. kr
리눅스 프로세스 관리 프로세스 상태 전의 Suspended signal ptrace exit TASK_RUNNING (running) TASK_STOPPED TASK_ZOMBIE Resume signal ptrace scheduling sleep on Interruptible_sleep_on preempt wait TASK_INTERRUPTIBLE TASK_UNINTERRUPTIBLE (asleep) TASK_RUNNING (ready) wake_up_interruptable - 40 - NULL www. hanback. co. kr
리눅스 프로세스 관리 pid = fork() PC Wait((int*)0) PC fork 전 execl(“bin/ls”. . ) PC fork 후 exec 후 ls Wait((int *)0) PC PC - 41 - www. hanback. co. kr
리눅스 프로세스 관리 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. #include <unistd. h> int docommand(char * command) { pid_t pid if((pid =fork()) <0) return (-1); if(pid ==0) /* 자식 */ { execl(“/bin/sh”, “-c”, command, (char *)0); peror(“execl”); exit(1); } /* 부모의 코드 */ wait((int *)0); return (0); } - 42 - www. hanback. co. kr
리눅스 프로세스 관리 프로세스 리스트 prev_task init_task next_task_struck prev_task next_task …… Running_queue_head …… RUNNING task next_task_struck RUNNING prev_task RUNNING …… RUNNING current - 43 - www. hanback. co. kr
리눅스 커널 - 46 - www. hanback. co. kr
리눅스 커널 - 48 - www. hanback. co. kr
리눅스 파일 시스템 램디스크 • • 램디스크 생성 - dd if=/dev/zero of=. /empos. ramdisk. fs count=4096 bs=1024 - mkfs -t ext 2 empos. ramdisk. fs 램디스크 수정 - gunzip ramdisk-16 m. gz - mount –oloop ramdisk-16 m dir_name JFFS • mkfs. jffs 2 -o usr. jffs -e 0 x 40000 -r tmpdir - 57 - www. hanback. co. kr
개발 환경 설치 - 58 - www. hanback. co. kr
개발 환경 설치 bootp 환경 설정 • /etc/bootptab. default: ₩ : hd=/tftpboot: bf=null: ₩ : sm=255. 0 empos : ht=1: ha=0 x 000 B 8 A 000001: tc=. default • /etc/hosts 192. 169. 123. 200 empos. hanback. co. kr empos - 61 - www. hanback. co. kr
개발 환경 설치 bootp 환경 설정 • /etc/xinetd. d/bootp service bootps { disable flags socket_type protocol=udp wait user server_args } =no =REUSE NAMEINARGS =dgram =yes =root =/usr/sbin/bootpd =-s - 62 - www. hanback. co. kr
개발 환경 설치 tftp 환경 설정 • /etc/xinetd. d/tftp service tftp { disable socket_type protocol=udp wait user server_args } =no =dgram =yes =root =/usr/sbin/in. tftpd =-s /tftpboot - 63 - www. hanback. co. kr
개발 환경 설치 nfs 환경 설정 • /etc/exports /nfs_resource 192. 168. 123. 200 (rw, no_root_squash) - 64 - www. hanback. co. kr
응용프로그램 - 65 - www. hanback. co. kr
응용 프로그램 hello. c 컴파일 방법 – – gcc –o hello. c (i 386에서) arm-linux-gcc –o hello. c (arm에서) 파일 타입 – 실행 파일을 파일 타입을 살펴 봄으로서 어뗜 CPU에서 동작되는지를 알수있다. file. /hello: ELF 32 -bit LSB executable, ARM, version 1 (ARM), for GNU/LINUX 2. 4. 19, Dynamically linked (used shared libs), not stripped - 67 - www. hanback. co. kr
디바이스 드라이버 문자형 디바이스의 골격 #include <linux/kernel. h> #include <linux/module. h> #include <linux/init. h> Header Files int device_open( … ) { … } int device_release( … ) { … } ssize_t device_write( … ) { … } ssize_t device_read( … ) { … } Function Prototypes static struct file_operations device_fops = { … ssize_t (*read) (…); ssize_t (*write) (…); … int (*open) (…); int (*release) (…); … }; File Operation int init_module(void) { … } 모듈 설치시 초기화 수행 void cleanup_module(void) { … } 모듈 제거시반환 작업수행 - 76 - www. hanback. co. kr
디바이스 드라이버 struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char *, size_t, loff_t *); ssize_t (*write) (struct file *, const char *, size_t, loff_t *); int (*readdir) (struct file *, void *, filldir_t); unsigned int (*poll) (struct file *, struct poll_table_struct *); int (*ioctl)(struct inode *, struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, struct dentry *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*readv)(struct file *, const struct iovec *, unsigned long, loff_t *); ssize_t (*writev)(struct file*, const struct iovec *, unsigned long, loff_t *); ssize_t (*sendpage)(struct file *, struct page *, int, size_t, loff_t *, int); unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long); }; - 77 - www. hanback. co. kr
디바이스 드라이버 포인터를 사용 – 포인터는 곧 번지이다. – 포인터을 이용하여 값을 쓰는 방법 unsigned char *addr; addr = (unsigned char *)(0 xf 1600000); *addr = 0 xaa; 포인터을 이용하여 값을 읽는 방법 unsigned char *addr; char ch; addr = (unsigned char *)(0 xf 1600000); ch = *addr; - 79 - www. hanback. co. kr
디바이스 드라이버 C에서 제공되는 함수를 사용 – 메모리로부터 값을 읽는 함수 • _u 8 inb(unsigned int port); • _u 16 inw(unsigned int port); • _u 32 inl(unsigned int port); – 메모리에 • void 값을 쓰는 함수 outb(_u 8 data, unsigned int port); outw(_u 16 data, unsigned int port); outl(_u 32 data, unsigned int port); - 80 - www. hanback. co. kr
디바이스 드라이버 모듈에서 사용하는 테이터 전송함수 – get_user(void *x, const void *addr) *addr의 값을 커널 영역인 x로 sizeof(addr)만큼 복사한다. – put_user(void *x, const void *addr) *x의 값을 user영역인 addr로 sizeof(addr)만큼 복사한다. – copy_to_user(void *to, void *from, unsigned long size) – copy_from_user(void *to, void *from, unsigned long size) - 81 - www. hanback. co. kr
디바이스 드라이버 Hello 디바이스 드라이버 – Init_module(), cleanup_module() • printk문을 이용하여 콘솔에 어떤 함수가 실행되는지 알려준다. hello. c #include <linux/module> #include <linux/kernel. h> #include <linux/init. h> int init_module(void) { printk(“Hello, Kernel!₩n”); } void cleanup_module(void) { printk(“Good-bye, Kernel!₩n”); } - 85 - www. hanback. co. kr
디바이스 드라이버 Makefile CC = arm-linux-gcc KERNELDIR = /working/kernel/linux-2. 4. 19 -rmk 4 -pax 2 -empx 1 INCLUDEDIR = -I$(KERNELDIR)/include –I. / CFLAGS = -D__KERNEL__ -DMODULE –Wall –O 2 – I$(INCLUDEDIR) MODULE_OBJS = hello. o MODULE_SRCS = hello. c $(MODULE_OBJS) : $(CC) $(CFLAGS) –c $(MODULE_SRCS) clean: rm –f *. o - 86 - www. hanback. co. kr
디바이스 드라이버 컴파일 $make 드라이버 수행 $insmod hello. o Using hello. o Hello, Kernel! $lsmod Module size Used by hello 216 0 (unsed) $rmmod hello Good-bye, Kernel! - 87 - www. hanback. co. kr
디바이스 드라이버 EMPOSII에 커널에(linux-2. 4. 19 -rmk 4 -pax 2 empx 1/arch/arm/mach-pax/empos_x 255. x)설정된 디바이스의 가상 메모리 맵 static struct map_desc empos_x 255_io_desc[] __initdata = { /* virtual physical length domain r w c b */ {0 xf 0000000, 0 x 00080000, 0 x 00040000, DOMAIN_IO, 0, 1, 0, 0}, /* empos status flash block*/ {0 xf 1000000, 0 x 10000000, 0 x 00010000, DOMAIN_IO, 0, 1, 0, 0 }, /* pcmcia status */ {0 xf 1100000, 0 x 10100000, 0 x 00010000, DOMAIN_IO, 0, 1, 0, 0 }, /*nport */ {0 xf 1300000, 0 x 10300000, 0 x 00010000, DOMAIN_IO, 1, 1, 0, 0}, /*7 Segment */ {0 xf 1400000, 0 x 10400000, 0 x 00010000, DOMAIN_IO, 1, 1, 0, 0}, /*7 Segment */ {0 xf 1500000, 0 x 10500000, 0 x 00010000, DOMAIN_IO, 0, 1, 0, 0}, /*Push button */ {0 xf 1600000, 0 x 10600000, 0 x 00010000, DOMAIN_IO, 1, 1, 0, 0}, /* LED */ {0 xf 1700000, 0 x 10700000, 0 x 00010000, DOMAIN_IO, 1, 1, 0, 0}, /*Text LCD */ {0 xf 4000000, 0 x 00100000, DOMAIN_IO, 0, 1, 0, 0}, /* Primary ETHERNET */ { 0 xf 5000000, 0 x 08000000, 0 x 00100000, DOMAIN_IO, 0, 1, 0, 0 }, /* Secondary ETHERNET */ LAST_DESC }; - 88 - www. hanback. co. kr
디바이스 드라이버 - GPIO 레지스터 정리 Register type GPIO[31: 0] GPIO[63: 32] GPIO[84: 64] GPLR 0 GPLR 1 GPLR 2 GPSR 0 GPSR 1 GPSR 2 GPCR 0 GPCR 1 GPCR 2 GPDR 0 GPDR 1 GPDR 2 GRER 0 GRER 1 GRER 2 GFER 0 GFER 1 GFER 2 GEDR 0 GEDR 1 GEDR 2 GAFR 0_U GAFR 0_L GAFR 1_U - 92 - GAFR 1_L GAFR 2_U GAFR 2_L www. hanback. co. kr
디바이스 드라이버에서 ioctl 사용방법 – 함수 선언 • int (*ioctl)(struct inode *inode, struct file *file, unsigned int cmd, unsigned long gdata); – cmd : 명령 번호 – gdata : 함수 호출시 넘겨 받는 인수 – 함수 구현 switch(cmd) { case: TEXTLCD_COMMAMD_SET: . . . break; case: TEXTLCD_FUNCTION_SET: . . . break; … } - 97 - www. hanback. co. kr
디바이스 드라이버 - 텍스트 LCD모듈의 제어 명령표 제어 신호 Executed Time 제어 명령 기능 RS R/W D 7 D 6 D 5 D 4 D 3 D 2 D 1 D 0 1. 64 m. S Clear Display 0 0 0 0 0 1 1. 64 m. S Return Home 0 0 0 0 1 0 40 u. S Entry Mode Set 0 0 0 0 1 I/D S 40 u. S Display on/off Control 0 0 0 1 D C S 40 u. S Cursor or Display Shift 0 0 0 1 S/ C R/ L 0 0 40 u. S Function Set 0 0 1 D/ L N F 0 0 40 u. S Set CG RAM Address 0 0 0 1 Set DD RAM Address 0 0 1 DD RAM Address 40 u. S Read Busy Flag and Address 0 1 BF Address Counter 40 u. S Data Write to CG RAM or DD RAM 1 0 Write Address 40 u. S Data Read to CG RAM or DD RAM 1 1 Read Address 40 u. S CG RAM Address - 99 - 40 u. S www. hanback. co. kr
디바이스 드라이버 - Text LCD의 Write 타이밍도 - 100 - www. hanback. co. kr
참고문헌 • • Intel PXA 255 Processor Develper’s Manual Hanback Electronics EMPOS II SW/HW Manual Understanding the Linux KERNEL ARM Architecture Reference Manual Unix 시스템 프로그래밍 Beginning Linux Programming Add-on Linux Kernel - 103 - www. hanback. co. kr
- Slides: 103