#keywords 설치,구축,배포판,서버,OpenWRT,build,devops #title OpenWRT 빌드환경 [wiki:Home 대문] / [wiki:CategoryInstall 설치 및 구축], [wiki:CategoryProgramming 프로그래밍] / [wiki:OpenWrt OpenWrt 빌드환경] ---- == [wiki:OpenWrt OpenWrt 빌드환경] == * 작성자 조재혁([mailto:minzkn@minzkn.com]) * 고친과정 * 2021년 4월 7일 : 처음씀 * 2021년 7월 5일 : 참조 내용 추가 * 주요 내용 출처 : https://openwrt.org/ [[TableOfContents]] === 개요 === [^https://openwrt.org/ https://openwrt.org/_media/logo.png] OpenWrt(오픈더블유알티 : Open Wireless Router, LEDE)는 처음에는 Linksys사의 무선랜 라우터를 위한 비실시간(Non-Real-Time) 리눅스 기반의 오픈 소스 운영 체제로써 개발이 시작되었으나 현재는 보다 많은 플랫폼을 지원하면서 빌드시스템을 통합 관리하는 차원에서 개발자들에게 매우 광범위한 환경을 제공하는 프로젝트가 되었습니다. OpenWrt 는 GPLv2 (GNU General Public License Version 2) 기반 라이선스로 배포되고 있습니다. 본 문서는 이러한 OpenWrt (version 19.07.7 기준) 를 활용하는데 필요한 내용을 지극히 개인적인 시각으로써 정리하는 목적으로 작성되었으며 보다 상세한 사항은 [^https://openwrt.org/ OpenWrt 공식 웹사이트]을 방문하여 보실 것을 권합니다. === 개발환경 구축 === 참고 : https://openwrt.org/docs/guide-developer/build-system/install-buildsystem 개발환경을 구축하기 위해서 기본적으로 [^https://en.wikipedia.org/wiki/Linux GNU/Linux] 환경이 필요합니다. 다른 환경 ([^https://openwrt.org/docs/guide-developer/build-system/buildroot.exigence.macosx macOS], [^https://en.wikipedia.org/wiki/BSD BSD], [^https://openwrt.org/docs/guide-developer/build-system/wsl WSL], ...) 을 이용하시려면 [^https://openwrt.org/docs/guide-developer/build-system/start 여기] 를 참고하세요. 다음과 같은 또는 호환되는 패키지가 설치되어 있어야 합니다. (이 중에서 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 === 디렉토리 구조 === * config * include * LICENSES * 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_ which is a temporary directory used for building the toolchain for a specific architecture, and staging_dir_ 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-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc. 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. tools – automake, autoconf, sed, cmake 1. toolchain/binutils – as, ld, … 1. toolchain/gcc – gcc, g++, cpp, … 1. target/linux – kernel modules 1. package – core and feed packages 1. make package/example/download - download the soures of example 1. make package/example/prepare - extract the sources, apply patches and download if necessary 1. make package/example/compile - compile example, prepare and download if necessary 1. make package/example/clean - clean the sourcecode 1. make package/index - build a repository index to make the output directory usable as local opkg source 1. target/linux – kernel image 1. 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 로 사용했던 옵션) * 예) {{{#!plain $ make V=sc ... $ make V=sw ... }}} * parallel build 지원 (그러나 경우에 따라서 빌드 실패할 경우 존재) * "make -j $(($(nproc) + 1))" 와 같이 통상적으로는 Core 수에 1을 더한 수만큼을 job으로 잡으면 무난. * 빌드 전 "make download"를 통하여 download 시 발생될 수 있는 실패확률을 미리 다운로드 받아두게 하여 실패 발생률을 낮추는것을 권장 * 하나의 명령을 2개 이상의 패키지에서 중복되어 지원되는 경우가 있는데 이 경우 충돌이 빌드과정에서 일어날 수 있습니다. 중복된 기능/파일을 갖는 패키지는 하나만 선택하도록 설정을 검토하는게 바람직하며 그렇지 않을 경우도 빌드 순서에 따라서 실패 또는 성공이 명확하지 않을 때가 있으므로 설정에 주의가 필요합니다. === feeds 구조 === => https://openwrt.org/docs/guide-developer/feeds OpenWrt는 자체적으로 제공하는 준비된 패키지를 이용할 수 있을 뿐만 아니라 사용자가 추가/변경한 사항들을 별도의 분리된 구조인 feeds 라는 형태로 분리하여 다룰 수 있도록 되어 있습니다. 직접적으로 OpenWrt 를 수정해도 되지만 이렇게 되면 지속적 발전하고 있는 최신 OpenWrt 의 변경사항들을 반영하기 어려워지는 문제가 있기 때문에 feeds 를 사용하여 사용자가 추가/변경한 사항들만 분리하여 관리하도록 고려해두면 항상 OpenWrt 최신 사항을 반영해갈 수 있는 연속성을 유지하는 장점을 가질 수 있습니다. * feeds.conf 예시 {{{#!plain 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 * feeds 의 갱신과 반영 * feeds.conf 가 수정되거나 feeds.conf 가 가르키고 있는 feeds 내용이 변경되는 경우 다음과 같이 'scripts/feeds' 스크립트 명령을 통해서 이를 반영해야 합니다. {{{#!plain $ ./scripts/feeds update -a $ ./scripts/feeds install -a -f }}} * feeds.conf 가 재 반영되면 이에 따른 설정을 다시 할 수 있는데 다음과 같이 실행하여 설정을 검토하고 수정하여 저장해야 합니다. {{{#!plain $ make menuconfig }}} === 패키지 생성 === => 중요 https://openwrt.org/docs/guide-developer/packages * 하나의 패키지는 다음과 같은 파일 및 경로를 일반적으로 가짐. * 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) === 참고자료 === * [^https://openwrt.org/ OpenWrt 공식 웹사이트] * [^https://openwrt.org/docs/start Documentation] * [^https://openwrt.org/docs/guide-quick-start/start Quick start guide] {{{#!plain Requirements binutils bzip2 diff find flex gawk gcc-6+ getopt grep install libc-dev libz-dev make4.1+ perl python3.6+ rsync subversion unzip which Quickstart 1. Run ./scripts/feeds update -a to obtain all the latest package definitions defined in feeds.conf / feeds.conf.default 2. Run ./scripts/feeds install -a to install symlinks for all obtained packages into package/feeds/ 3. Run make menuconfig to select your preferred configuration for the toolchain, target system & firmware packages. 4. Run make to build your firmware. This will download all sources, build the cross-compile toolchain and then cross-compile the GNU/Linux kernel & all chosen applications for your target system. License OpenWrt is licensed under GPL-2.0 }}} * [^https://openwrt.org/docs/guide-user/start User guide] * [^https://openwrt.org/docs/guide-developer/start Developer guide] * [^https://openwrt.org/docs/guide-developer/build-system/start The build system] * [^https://openwrt.org/docs/guide-developer/build-system/install-buildsystem Build system setup] * [^https://openwrt.org/docs/guide-developer/build-system/use-buildsystem Build system usage] * [^https://openwrt.org/docs/guide-developer/feeds OpenWrt Feeds] * [^https://openwrt.org/docs/guide-developer/packages Creating packages] * [^https://openwrt.org/docs/guide-developer/packages.flags Overriding Build Options] * [^https://openwrt.org/docs/guide-developer/procd-init-scripts procd init script parameters] * [^https://openwrt.org/docs/guide-developer/procd-init-script-example Create a sample procd init script] * [^https://openwrt.org/docs/guide-developer/dependencies Using Dependencies] * [^https://openwrt.org/docs/techref/start Technical Reference] * [^https://openwrt.org/docs/techref/buildroot OpenWrt Buildroot – Technical Reference] * [^https://openwrt.org/supported_devices OpenWrt Hardware Database] * [^https://forum.openwrt.org/ Forum] * [^https://bugs.openwrt.org/ Bug Reports] * [^https://lists.openwrt.org/mailman/listinfo/openwrt-devel Dev Mailing List] * [^https://webchat.freenode.net/#openwrt Support Chat], [^https://webchat.freenode.net/#openwrt-devel Dev Chat] * [^https://git.openwrt.org/ The master OpenWrt/LEDE source code repositories reside on the OpenWrt/LEDE Project git server] * [^https://github.com/openwrt The OpenWrt/LEDE Project keeps a mirror of the master repository on GitHub] * [^https://sources.openwrt.org/ OpenWrt source archive] * Any OpenWrt development happens in the main openwrt.git repository which is accessible via both HTTP and HTTPS: {{{#!plain git clone https://git.openwrt.org/openwrt/openwrt.git }}} * You can find a mirror of the repository on Github: {{{#!plain git clone https://github.com/openwrt/openwrt.git }}} * [wiki:Buildroot Buildroot 빌드환경] * [wiki:Make Make 기초사용법] * [^http://korea.gnu.org/manual/] : Make 에 대하여 깊히 알고 싶다면 꼭! 이 문서를 읽어보시길 강력히 추천합니다. * GNU Automake manual 번역본: [^http://korea.gnu.org/manual/release/automake/] * GNU make manual 번역본 * 1부: [^http://korea.gnu.org/manual/release/make/make-sjp/] * 2부: [^http://korea.gnu.org/manual/release/make/make-cwryu/] * [^https://en.wikipedia.org/wiki/OpenWrt 위키페디아 - OpenWrt] * [^https://namu.wiki/w/OpenWRT 나무위키 - OpenWRT]