MINZKN.COM |  |  | Services | About

OpenWrt 빌드환경

1.1. 개요

OpenWrt(오픈더블유알티 : Open Wireless Router, LEDE)는 처음에는 Linksys사의 무선랜 라우터를 위한 비실시간(Non-Real-Time) 리눅스 기반의 오픈 소스 운영 체제로써 개발이 시작되었으나 현재는 보다 많은 플랫폼을 지원하면서 빌드시스템을 통합 관리하는 차원에서 개발자들에게 매우 광범위한 환경을 제공하는 프로젝트가 되었습니다.

OpenWrt 는 GPLv2 (GNU General Public License Version 2) 기반 라이선스로 배포되고 있습니다.

본 문서는 이러한 OpenWrt (version 19.07.7 기준) 를 활용하는데 필요한 내용을 지극히 개인적인 시각으로써 정리하는 목적으로 작성되었으며 보다 상세한 사항은 [https]OpenWrt 공식 웹사이트[]을 방문하여 보실 것을 권합니다.

1.2. 개발환경 구축

참고 : https://openwrt.org/docs/guide-developer/build-system/install-buildsystem

개발환경을 구축하기 위해서 기본적으로 [https]GNU/Linux[] 환경이 필요합니다. 다른 환경 ([https]macOS[], [https]BSD[], [https]WSL[], ...) 을 이용하시려면 [https]여기[] 를 참고하세요.

다음과 같은 또는 호환되는 패키지가 설치되어 있어야 합니다. (이 중에서 OpenWrt 이용계획에 따라서 일부 패키지는 선택사항일 수 있으며 여기에 명시되지 않은 추가적인 패키지들이 필요할 수 있습니다.)
  • Version control system (git, subversion, Mercurial)
  • GNU Autotools (GNU Autoconf, GNU Automake, GNU Libtool)
  • asciidoc
  • GNU Bash
  • GNU Binutils
  • bzip2, gzip, unzip, zlib, tar
  • flex
  • GNU C/C++ Compiler (gcc/g++)
  • GNU Time
  • getopt
  • GNU awk
  • help2man
  • inittool-update
  • libelf-dev
  • make
  • ncurses
  • openssl
  • patch
  • perl-ExtUtils-MakeMaker
  • perl-Thread-Queue
  • python2-dev OR python3-dev
  • GNU Wget
  • xgettext
  • xsltproc
  • ccache
  • rsync
  • swig
  • diffutils
  • grep
  • which
  • findutils
  • perl
  • coreutils

1.3. 디렉토리 구조

  • config
  • include
  • package
  • scripts
  • target
  • tools - needs to be written about.
  • toolchain - refers to the compiler, the c library, and common tools which will be used to build the firmware image. The result of this is two new directories, toolchain_build_<arch> which is a temporary directory used for building the toolchain for a specific architecture, and staging_dir_<arch> where the resulting toolchain is installed. You won't need to do anything with the toolchain directory unless you intend to add a new version of one of the components above.
  • target - refers to the embedded platform, this contains items which are specific to a specific embedded platform. Of particular interest here is the target/linux directory which is broken down by platform and contains the kernel config and patches to the kernel for a particular platform. There's also the target/image directory which describes how to package a firmware for a specific platform.
  • package - is for exactly that - packages. In an OpenWrt firmware, almost everything is an ipk, a software package which can be added to the firmware to provide new features or removed to save space.

  • "build_dir" : 모든 소스들이 여기에서 압축이 해제되어 컴파일이 수행됩니다.
    • "build_dir/host" , for compiling all the tools that run on the host computer (OpenWRT builds its own version of sed and many other tools from source). This area will be use for compiling programs that run only on your host.
    • "build_dir/toolchain..." for compiling the cross-C compiler and C standard library components that will be used to build the packages. This area will be use for compiling programs that run only on your host (the cross C compiler, for example) and also, libraries designed to run on the target that are linked to - e.g. uClibc, libm, pthreads, etc.
    • "build_dir/target..." for compiling the actual packages, and the Linux kernel, for the target system
  • "staging_dir" : The directory staging_dir is used to "install" all the compiled programs into, ready either for use in building further packages, or for preparing the firmware image.
    • "staging_dir/host" is a mini Linux root with its own bin/, lib/, etc. that the host tools are installed into; the rest of the build system then prefixes its PATH with directories in this area
    • "staging_dir/toolchain..." is a mini Linux root with its own bin/, lib/, etc that contains the cross C compiler used to build the rest of the firmware. You can actually use that to compile simple C programs outside of OpenWRT that can be loaded onto the firmware. The C compiler might be something like: staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc- You can see the version of the CPU, the C library and gcc encoded into it; this allows multiple targets to be built in the same area concurrently.
    • "staging_dir/target.../root-..." contains “installed” versions of each target package again arranged with bin/, lib/, this will become the actual root directory that with some tweaking will get zipped up into the firmware image, something like root-ar71xx. There are some other files in staging_dir/target… primarily used for generating the packages and development packages, etc.
  • dl
  • feeds
  • tmp

1.4. 빌드 순서

  • 전체 빌드 흐름
    1. tools – automake, autoconf, sed, cmake
    2. toolchain/binutils – as, ld, …
    3. toolchain/gcc – gcc, g++, cpp, …
    4. target/linux – kernel modules
    5. package – core and feed packages
      1. make package/example/download - download the soures of example
      2. make package/example/prepare - extract the sources, apply patches and download if necessary
      3. make package/example/compile - compile example, prepare and download if necessary
      4. make package/example/clean - clean the sourcecode
      5. make package/index - build a repository index to make the output directory usable as local opkg source
    6. target/linux – kernel image
    7. target/linux/image – firmware image file generation
  • "make world" 명령에서의 빌드 순서
    • make target/compile
    • make package/cleanup
    • make package/compile
    • make package/install
    • make package/preconfig
    • make target/install
    • make package/index
  • 빌드시 경고 및 에러등의 추적
    • make 명령행 실행시 V 인자변수 또는 OPENWRT_VERBOSE 환경변수에 다음의 값을 하나이상의 조합하여 사용 가능.
      • s : stdout + stderr (예전에는 V=99 로 사용했던 옵션)
      • c : 명령들 (명령
      • w : 경고 또는 에러만 (예전에는 V=1 로 사용했던 옵션)
    • 예)
      $ make V=sc
      $ make V=sw
  • parallel build 지원 (그러나 경우에 따라서 빌드 실패할 경우 존재)
    • "make -j $(($(nproc) + 1))" 와 같이 통상적으로는 Core 수에 1을 더한 수만큼을 job으로 잡으면 무난.
    • 빌드 전 "make download"를 통하여 download 시 발생될 수 있는 실패확률을 미리 다운로드 받아두게 하여 실패 발생률을 낮추는것을 권장

1.5. feeds 구조

  • feeds.conf 예시
    src-git packages https://git.openwrt.org/feed/packages.git
    src-git luci https://git.openwrt.org/project/luci.git
    src-git routing https://git.openwrt.org/feed/routing.git
    src-git telephony https://git.openwrt.org/feed/telephony.git
    #src-git video https://github.com/openwrt/video.git
    #src-git targets https://github.com/openwrt/targets.git
    #src-git management https://github.com/openwrt-management/packages.git
    #src-git oldpackages http://git.openwrt.org/packages.git
    #src-link custom /usr/src/openwrt/custom-feed
    #src-git local_feed_name https://example.com/repo_name/something.git;branch_name
    #src-git local_feed_name https://example.com/repo_name/something.git^commit_hash
  • feeds.conf 의 method 종류
    • src-bzr : Data is downloaded from the source path/URL using bzr
    • src-cpy : Data is copied from the source path. The path can be specified as either relative to OpenWrt repository root or absolute.
    • src-darcs : Data is downloaded from the source path/URL using darcs
    • src-git : Data is downloaded from the source path/URL using git as a shallow (depth of 1) clone
    • src-git-full : Data is downloaded from the source path/URL using git as a full clone
    • src-gitsvn : Bidirectional operation between a Subversion repository and git
    • src-hg : Data is downloaded from the source path/URL using hg
    • src-link : A symlink to the source path is created. The path must be absolute.
    • src-svn : Data is downloaded from the source path/URL using svn

1.6. 패키지 생성

  • 하나의 패키지는 다음과 같은 파일 및 경로를 일반적으로 가짐.
    • package/Makefile : 다운로드와 컴파일에 필요한 사항들을 명시
    • package/patches
    • package/files
  • 주요 변수
    • PKG_NAME - The name of the package, as seen via menuconfig and ipkg. Avoid using underscores in the package name, to avoid build failures–for example, the underscore separates name from version information, and may confuse the build system in hard-to-spot places.
    • PKG_VERSION - The upstream version number that we're downloading
    • PKG_RELEASE - The version of this package Makefile
    • PKG_LICENSE - The license(s) the package is available under, SPDX form.
    • PKG_LICENSE_FILES- file containing the license text
    • PKG_BUILD_DIR - Where to compile the package
    • PKG_SOURCE - The filename of the original sources
    • PKG_SOURCE_URL - Where to download the sources from (directory)
    • PKG_HASH - A checksum to validate the download. It can be either a MD5 or SHA256 checksum, but SHA256 should be used, see scripts/download.pl
    • PKG_CAT - How to decompress the sources (zcat, bzcat, unzip)
    • PKG_BUILD_DEPENDS - Packages that need to be built before this package. Use this option if you need to make sure that your package has access to includes and/or libraries of another package at build time. Specify the directory name (i.e. openssl) rather than the binary package name (i.e. libopenssl). This build variable only establishes the build time dependency. Use DEPENDS to establish the runtime dependencies. This variable uses the same syntax as DEPENDS below.
    • PKG_CONFIG_DEPENDS - specifies which config options influence the build configuration and should trigger a rerun of Build/Configure on change
    • PKG_INSTALL - Setting it to “1” will call the package's original “make install” with prefix set to PKG_INSTALL_DIR
    • PKG_INSTALL_DIR - Where “make install” copies the compiled files
    • PKG_FIXUP - See below
      • PKG_FIXUP:=autoreconf
      • PKG_FIXUP:=patch-libtool
      • PKG_FIXUP:=gettext-version
  • 선택적 변수
    • PKG_SOURCE_PROTO - the protocol to use for fetching the sources (git, svn, etc).
      • PKG_SOURCE_PROTO:=bzr
      • PKG_SOURCE_PROTO:=cvs
      • PKG_SOURCE_PROTO:=darcs
      • PKG_SOURCE_PROTO:=git
      • PKG_SOURCE_PROTO:=hg
      • PKG_SOURCE_PROTO:=svn
    • PKG_SOURCE_URL - source repository to fetch from. The URL scheme must be consistent with PKG_SOURCE_PROTO (e.g. git://), but most VCS accept http:// or https:// URLs nowadays.
    • PKG_SOURCE_VERSION - must be specified, the commit hash or SVN revision to check out.
    • PKG_SOURCE_DATE - a date like 2017-12-25, will be used in the name of generated tarballs.
    • PKG_MIRROR_HASH - SHA256 checksum of the tarball generated from the source repository checkout (previously named PKG_MIRROR_MD5SUM). See below for details.
    • PKG_SOURCE_SUBDIR - where the temporary source checkout should be stored, defaults to $(PKG_NAME)-$(PKG_VERSION)

1.7. 참고자료

Copyright ⓒ MINZKN.COM
All Rights Reserved.