openwrt

development 2015. 2. 24. 10:51

openwrt


소스 다운로드

  Trunk

    git clone git://git.openwrt.org/openwrt.git openwrt


  14.07 branch (Barrier Breaker)

    git clone git://git.openwrt.org/14.07/openwrt.git


필요 유틸들

  gcc

  binutils

  bzip2

  flex

  python

  perl

  make

  find

  grep

  diff

  unzip

  gawk 

  getopt

  subversion

  libz-dev

  libc-headers


Configure

$ > make menuconfig

$ > make kernel_menuconfig

=> initramdisk 를 사용할 수 있도록 커널 설정을 변경한다. 


build

 $ > make


결과물

$ > ls bin/at91

md5sums

openwrt-at91-AT91SAM9G25EK-rootfs.tar.gz

openwrt-at91-root.jffs2-128k

openwrt-at91-root.squashfs

openwrt-at91-vmlinux-initramfs.elf

packages/

uImage

openwrt-at91-9g25ek-uImage  openwrt-at91-root.ext4

openwrt-at91-root.jffs2-64k

openwrt-at91-rootfs.cpio.gz

u-boot.2010.06.bin

                

결과물에서 사용할 것은,


  uImge => kernel image

  openwrt-at91rootfs.cpio.gz => rootfs image

  at91sam9x25ek.dtb => fdt file(이건 하위 디렉토리 검색해서 찾아보면 됨)


인데, 아래와 같이 적당히 가공을 해 주어야 한다. 


cp uImge openwrt.kernel

cp at91sam9x25ek.dtb 3.10.dtb

mkimage -n "Ramdisk Image" -A arm -O linux -T ramdisk -C gzip -d openwrt-at91-rootfs.cpio.gz openwrt.rootfs


부팅

U-boot > tftp 0x21000000 poplinux/3.10.dtb

U-boot > tftp 0x22000000 poplinux/openwrt.kernel

U-boot > tftp 0x23000000 poplinux/openwrt.rootfs

U-boot > bootm 0x22000000 0x23000000 0x21000000

## Booting kernel from Legacy Image at 22000000 ...

   Image Name:   linux-2.6

   Image Type:   ARM Linux Kernel Image (uncompressed)

   Data Size:    7163428 Bytes = 6.8 MiB

   Load Address: 20008000

   Entry Point:  20008000

   Entry Point:  20008000

   Verifying Checksum ... OK

## Loading init Ramdisk from Legacy Image at 23000000 ...

   Image Name:   Ramdisk Image

   Image Type:   ARM Linux RAMDisk Image (gzip compressed)

   Data Size:    1542835 Bytes = 1.5 MiB

   Load Address: 00000000

   Entry Point:  00000000

   Verifying Checksum ... OK

## Flattened Device Tree blob at 21000000

   Booting using the fdt blob at 0x21000000

   Loading Kernel Image ... OK

   Loading Ramdisk to 27c6b000, end 27de3ab3 ... OK

   Loading Device Tree to 27c63000, end 27c6aa3a ... OK


Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0

[    0.000000] Linux version 3.10.49 (poplinux@raw) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 r4445

[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177



BusyBox v1.22.1 (2015-02-24 12:13:29 KST) built-in shell (ash)

Enter 'help' for a list of built-in commands.



  _______                     ________        __

 |       |.-----.-----.-----.|  |  |  |.----.|  |_

 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|

 |_______||   __|_____|__|__||________||__|  |____|

          |__| W I R E L E S S   F R E E D O M

 -----------------------------------------------------

 BARRIER BREAKER (Barrier Breaker, r44441)

 -----------------------------------------------------

  * 1/2 oz Galliano         Pour all ingredients into

  * 4 oz cold Coffee        an irish coffee mug filled

  * 1 1/2 oz Dark Rum       with crushed ice. Stir.

  * 2 tsp. Creme de Cacao

 -----------------------------------------------------

root@OpenWrt:/#



Buildroot

외부 컴파일러 사용

외부 컴파일러를 사용하는 목적은 크게 두가지입니다. 


  1. 여러 개발자들이 개발환경을 동일하게 사용하기 위해서.

  2. 컴파일러를 빌드하는 시간을 아끼기 위해서.


우선, openWRT 를 full-build 합시다. full-build 를 하게 되면 staging_dir 디렉토리 밑에 tool-chain 이 생성됩니다. 

생성된 tool-chain 을 아래와 같이 원하는 디렉토리로 복사합니다. 


$ openWRT > cp -arf staging_dir/toolchain-arm_arm926ej-s_gcc-4.8-linaro_uClibc-0.9.33.2_eabi /usr/local/sdk/atmel/sdk/


tool-chain 복사가 끝났다면, 아래와 같이 설정을 잡아 줍니다. 


$ openWRT > make menuconfig

  [*] Advanced configuration options (for developers)  --->

      [*]   Use external toolchain  --->

        [ ]   Use host's toolchain

          (arm-openwrt-linux-uclibcgnueabi) Target name

          (arm-openwrt-linux-uclibcgnueabi-) Toolchain prefix

          (/usr/local/sdk/atmel/sdk/toolchain-arm_arm926ej-s_gcc-4.8-linaro_uClibc-0.9.33.2_eabi) Toolchain root

          (uclibc) Toolchain libc

          (./usr/bin ./bin) Toolchain program path

          (./usr/include ./include) Toolchain include path

          (./usr/lib ./lib) Toolchain library path



새로운 팩키지 추가 방법

참조 사이트 : http://wiki.openwrt.org/doc/devel/packages


디렉토리 생성


$ openWRT > mkdir package/hello

  

Makefile

# rules.mk 를 최상단에 무조건 삽입해야 한다. include $(TOPDIR)/rules.mk # 패키지에 대한 기본 정보를 설정한다. PKG_NAME:=hello PKG_VERSION:=1.0 PKG_RELEASE:=1 # 팩키지를 어느 디렉토리에서 빌드할 것인지 지정한다. PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) # 팩키지의 소스가 어디인지를 지정한다. PKG_SRC_DIR:=$(TOPDIR)/package/hello/src # tmp/.config-package.in 을 자동 생성하는데 사용된다. # help 항목으로 저장됨. PKG_MAINTAINER:=kay.kim # package.mk 를 반드시 삽입해야 한다. include $(INCLUDE_DIR)/package.mk ################################################################################################### ################################################################################################### ################################################################################################### # For create "tmp/.config-package.in" # 아래 정보는, tmp/.config-package.in 을 자동 생성하는데 사용된다. # SECTION : 별 의미 없는 것으로 보임. # CATEGORY : "test" 라는 상위 메뉴에 소속됨을 알림. => menu "test" 로 변환됨 # TITLE : "................................... hello example" 로 변환됨 # URL : help 항목으로 저장됨. define Package/hello/Default SECTION:=test CATEGORY:=test TITLE:=hello example URL:=test.net endef # tmp/.config-package.in 을 자동 생성하는데 사용된다. # help 항목으로 저장됨. define Package/hello/Default/description This is just sample for "How to add new project to buildroot" endef # tmp/.config-package.in 생성과정에서 필요한 정보를 정의한 "Package/hello/Default" 를 호출해준다. define Package/hello $(call Package/hello/Default) endef # tmp/.config-package.in 생성과정에서 필요한 정보를 정의한 "Package/hello/Default" 를 호출해준다. define Package/hello/description $(call Package/hello/Default/description) endef ################################################################################################### ################################################################################################### ################################################################################################### # 실제 빌드에 관련된 동작을 관장하는 부분입니다. # 소스 설치등의 컴파일 이전에 필요한 내용을 준비합니다. define Build/Prepare @echo "[S]==========================================" @echo "[package/hello] : Build/Prepare" $(TOPDIR)/scripts/src_link.sh $(TOPDIR) $(BUILD_DIR) $(PKG_SRC_DIR) $(PKG_NAME) package @echo "[E] Build/Prepare====================" endef # ./configure 를 지원하는 소스일 경우엔, 아래 부분에서 진행하게 됩니다. # 이 예제에서는 사용하지 않습니다. define Build/Configure @echo "[S]==========================================" @echo "[package/hello] : Build/Configure" endef # 빌드시 사용할 추가 설정등을 지정합니다. TARGET_CFLAGS += \ -I$(STAGING_DIR)/usr/include MAKE_FLAGS += \ CFLAGS="$(TARGET_CFLAGS)" \ LDFLAGS="$(TARGET_LDFLAGS)" \ -j4 # 아래 섹션을 사용할 경우엔, 컴파일 방법을 원하는 대로 설정할 수 있습니다. #define Build/Compile # @echo "[S]==========================================" # @echo "[package/hello] : Build/Compile" # @echo "[E] Build/Compile============================" #endef # 컴파일이 끝난후, rootfs 나 staging dir 에 설치하는 방법을 지정하는 곳입니다. define Package/hello/install @echo "[S]==========================================" @echo "[package/hello] : Package/hello/install" $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/hello $(1)/usr/bin/hello @echo "[E] Package/hello/install====================" endef # 위에서 설정한 모든 내용은, 아래의 BuildPackage 함수를 호출해야 동작되며, # ARG 로 프로젝트의 이름(디렉토리 이름) 을 전달해 주어야 합니다. # 여기서 전달된 이름은 tmp/.config-package.in 에서 "config PACKAGE_hello" 로 변환됩니다. $(eval $(call BuildPackage,hello))


새로운 팩키지 적용

  make menuconfig 실행시, 출력되는 메뉴는 tmp/.config-package.in 파일을 참조해서 만들어 지게 되는데, 

  .config-package.in 파일은 최초 make menuconfig 실행시에 자동으로 생성된다.

  만약 중간에 새로운 팩키지를 추가했다면, 아래와 같이 tmp/.config-package.in 파일을 새로 생성해 주어야 한다. 


$ openWRT > make prepare-tmpinfo

$ openWRT > make menuconfig








'development' 카테고리의 다른 글

[gcc] -march, -mtune 옵션  (0) 2016.01.08
[gcc] __attribute__((......)) 키워드  (0) 2016.01.06
[network] nat 설정법  (0) 2015.01.15
[linux] debug fs 사용법  (0) 2015.01.07
[driver] ipTime N150UA-4dBi  (8) 2014.09.16
블로그 이미지

김유석0

,