OpenWrt 的世界︰樹莓派 3B 【路由器】移星轉斗《五》編譯 一

為求盡快確認『樹莓派 3B+』當作 OpenWrt 開發系統之『可行性』 ?憑藉過往回憶,選擇了 16G 的 SD 卡【※約有 9-10 G 空間】!

然後依據

Quick Image Building Guide

文件打造

The build systemAbout

The build system is a set of Makefiles and patches that allows users to easily generate both a cross-compilation toolchain and a root filesystem for embedded systems. The cross-compilation toolchain uses musl, a tiny C standard library.

A compilation toolchain is the set of tools used to compile code for your system. It consists of:

  • a compiler (in our case, gcc )
  • binary utils like assembler and linker (in our case, binutils )
  • a C standard library (for example GNU Libc, musl-libc, uClibc or dietlibc).

A compilation toolchain generates code for the same processor’s instruction set architecture (ISA) it runs on (in the case of most PCs and servers, for an x86 processor).
On most Linux systems, the compilation toolchain uses the GNU libc as C standard library. This is called the “host compilation toolchain”, and the machine it is running on is called the “host system”. The host compilation toolchain is provided by the Linux distribution running on the host system, and has nothing to do with the actual build system.

Embedded systems use a different processor and require a cross-compilation toolchain – a compilation toolchain that runs on a host system but that generates code for a target system (and target processor’s instruction set architecture (ISA)). For example, if your host system uses x86 and your target system uses MIPS32, the cross-compilation toolchain runs on x86 but generates code for MIPS32.

While it is possible to manually configure and compile your own software, this is complex and does not guarantee reproducible builds. LEDE’s build system automates this process and provides a 100% reproducible build.

While the build system was designed for developers, inexperienced users can also use it to easily build their own custom firmware!

The build system’s Makefiles have their own syntax, different from the conventional Makefiles of Linux make tool.
The Makefiles define the meta information of the package, where to download the package, how to compile, where to install the compiled binaries, etc.

………

 

接著查詢『目標』︰

Raspberry Pi

The Raspberry Pi is a single-board computer without an Ethernet Network Switch. There are many more Single-board computers without one.

OpenWrt for Raspberry Pi 2 is compiled with the ARM hard-float kernel ABI (armhf). This means that non-integer math is done in hardware instead of in software. Raspberry Pi 1 (and Zero) support only soft-float (armel) which is slower than hard float.

Supported Versions

The Raspberry Pi is supported in the brcm2708 target.
Subtargets are bcm2708 for Raspberry Pi 1, bcm2709 for the Raspberry Pi 2, bcm2710 for the Raspberry Pi 3.

Model Version Current Release Unsupported Functions OEM Info Forum Topic Technical Data
Raspberry Pi A 18.06.1       View/Edit data
Raspberry Pi B 18.06.1       View/Edit data
Raspberry Pi B+ 18.06.1       View/Edit data
Raspberry Pi 2 B 18.06.1     forum.openwrt.org View/Edit data
Raspberry Pi 3 B 18.06.1 Country Code setting pi-3-model-b   View/Edit data
Raspberry Pi 3 B+ 18.06.1 Country Code setting, WiFi 2.4GHz, WiFi 5GHz, WIP pi-3-model-b-plus forum.openwrt.org View/Edit data
Raspberry Pi Zero W   18.06.1   pi-zero-wireless   View/Edit data

 

決定了︰

make menuconfig

“Target System” ⇒ “Broadcom BCM27xx”
“Subtarget” ⇒ “BCM2710 64 bit based boards”
“Target Profile” ⇒ “Raspberry Pi 3B/3B+”

 

心想樹莓派 3B+ 既有四顆 arm CPU 內核,何不用

make -j 4 呢☺

pi@raspberrypi:~/openwrt make -j 4 time: target/linux/prereq#0.32#0.11#0.42  make[1] world  make[2] tools/compile  make[2] package/cleanup  make[3] -C tools/flock compile  make[3] -C tools/sed compile  make[3] -C tools/patch compile  make[3] -C tools/xz compile  make[3] -C tools/tar compile  make[3] -C tools/m4 compile  make[3] -C tools/pkg-config compile  make[3] -C tools/expat compile  make[3] -C tools/sstrip compile  make[3] -C tools/patch-image compile  make[3] -C tools/scons compile  make[3] -C tools/mtools compile  make[3] -C tools/lzma compile  make[3] -C tools/autoconf compile  make[3] -C tools/missing-macros compile  make[3] -C tools/automake compile  make[3] -C tools/libressl compile  make[3] -C tools/dosfstools compile  make[3] -C tools/libtool compile  make[3] -C tools/cmake compile  make[3] -C tools/mkimage compile  make[3] -C tools/gmp compile  make[3] -C tools/libelf compile  make[3] -C tools/flex compile  make[3] -C tools/mklibs compile  make[3] -C tools/e2fsprogs compile  make[3] -C tools/mm-macros compile  make[3] -C tools/gengetopt compile  make[3] -C tools/patchelf compile  make[3] -C tools/mpfr compile  make[3] -C tools/bison compile  make[3] -C tools/findutils compile  make[3] -C tools/bc compile  make[3] -C tools/mpc compile ...</pre>    <img class="alignnone size-full wp-image-93081" src="http://www.freesandal.org/wp-content/uploads/pi@raspberrypi-top_1.png" alt="" width="737" height="518" />     <span style="color: #666699;">還可邀讀者想想</span> <div class="os-article__top"> <div class="os-article__top-inner"> <div class="panel-pane pane-node-title"> <h1><span style="color: #666699;"><a style="color: #666699;" href="https://opensource.com/article/18/6/embedded-linux-build-tools">4 tools for building embedded Linux systems</a></span></h1> </div> <div class="panel-pane pane-entity-field pane-node-field-article-subhead"> <div class="field field-name-field-article-subhead field-type-text-long field-label-hidden"> <div class="field-items"> <h2><span style="color: #ff9900;">Explore Yocto, Buildroot, OpenWRT, and adapted desktop distros to determine the right option for your project.</span></h2> </div> </div> </div> <div class="panel-pane pane-os-content-article-byline"> <div class="byline">  <span style="color: #808080;"><span class="byline__date">15 Jun 2018</span> <span class="byline__author-name"><a class="username" style="color: #808080;" title="View user profile." xml:lang="" href="https://opensource.com/users/drewmoseley">Drew Moseley</a> <span class="byline__feed"><a style="color: #808080;" href="https://opensource.com/user/233466/feed">Feed</a></span> </span></span> <div id="rate-node-45541-1-1" class="rate-widget-1 rate-widget clear-block rate-average rate-widget-thumbs_up rate-5b071800954428c09e83b5c45b481502 rate-node-45541-1-1 rate-processed"> <div class="rate-info"><span style="color: #808080;">51</span></div> <span style="color: #808080;"><a id="rate-button-1" class="rate-button rate-thumbs-up-btn-up" style="color: #808080;" title="up" href="https://opensource.com/article/18/6/embedded-linux-build-tools?rate=85BtO_Dp0DXA1MtBCFsLWxWAEd1Z0RO76uCg4psUojc" rel="nofollow">up</a></span>  </div> <span class="byline__comment-count" style="color: #808080;"><a style="color: #808080;" href="https://opensource.com/article/18/6/embedded-linux-build-tools#comments">1 comment</a></span>  </div> </div> </div> </div> <div class="os-article__image"> <div class="panel-pane pane-entity-field pane-node-field-lead-image"> <div class="field field-name-field-lead-image field-type-image field-label-hidden"> <div class="field-items"> <div class="field-item even"><img class="image-full-size" title="4 tools for building embedded Linux systems" src="https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/desk_clock_job_work.jpg?itok=Nj4fuhl6" alt="4 tools for building embedded Linux systems" width="520" height="292" /></div> </div> </div> </div> </div> <div class="field-label"><span style="color: #999999;">Image by :  opensource.com</span></div> <div class="os-article__top"></div> <span style="color: #008080;">Linux is being deployed into a much wider array of devices than Linus Torvalds anticipated when he was working on it in his dorm room. The variety of supported chip architectures is astounding and has led to Linux in devices large and small; from <a style="color: #008080;" href="https://en.wikipedia.org/wiki/Linux_on_z_Systems" target="_blank" rel="noopener noreferrer">huge IBM mainframes</a> to <a style="color: #008080;" href="http://www.picotux.com/" target="_blank" rel="noopener noreferrer">tiny devices</a> no bigger than their connection ports and everything in between. It is used in large enterprise data centers, internet infrastructure devices, and personal development systems. It also powers consumer electronics, mobile phones, and many Internet of Things devices.</span>  <span style="color: #008080;">When building Linux software for desktop and enterprise-class devices, developers typically use a desktop distribution such as <a style="color: #008080;" href="https://www.ubuntu.com/" target="_blank" rel="noopener noreferrer">Ubuntu</a> on their build machines to have an environment as close as possible to the one where the software will be deployed. Tools such as <a style="color: #008080;" href="https://www.virtualbox.org/" target="_blank" rel="noopener noreferrer">VirtualBox</a> and <a style="color: #008080;" href="https://www.docker.com/" target="_blank" rel="noopener noreferrer">Docker</a> allow even better alignment between development, testing, and productions environments.</span>  <span style="color: #808080;">………</span>     <span style="color: #666699;">優缺點比較!讀讀總覽︰</span> <h2 id="quick_overview_of_openwrt_s_internals" class="sectionedit2"><span style="color: #ff9900;">Quick overview of OpenWrt's internals</span></h2> <h2 id="overview" class="sectionedit1"><span style="color: #ff9900;"><a style="color: #ff9900;" href="https://openwrt.org/docs/guide-developer/overview">Overview</a></span></h2> <div class="level2">  <span style="color: #339966;">If you are already familiar with Linux systems, you will find your way pretty easily, if you are not, then we will need to start from basic concepts first.</span>  <span style="color: #339966;">You might have read that OpenWrt is a Linux distribution (or ``distro'') aimed at embedded devices.</span> <span style="color: #339966;"> A Linux ``<strong>distribution</strong>'' is a project that creates and maintains packages used to create a linux operating system tailored to the user's needs.</span> <span style="color: #339966;"> A ``<strong>package</strong>'' is a compressed archive containing a program or some scripts, its accompanying configuration files and also the information used to integrate it in the operating system. These packages are handled by a <strong>package manager</strong>, (opkg in OpenWrt) a program that downloads/opens/installs/uninstalls the packages.</span> <span style="color: #339966;"> So, a OpenWrt firmware is made by assembling packages around a Linux kernel.</span>  <span style="color: #339966;">Each package is compiled separately and then when it's all done the needed packages are ``installed'' in a temporary folder that will then be compressed to become the compressed-read-only partition (squashfs) in the device firmware.</span>  <span style="color: #339966;">Also the kernel is handled like a package, but is added to the firmware image in the special way each device's bootloader expects it, so you can replace the stock firmware without touching the bootloader itself (that is dangerous and not always possible).</span>  <span style="color: #339966;">The last step in the building process is actually creating a firmware file, (the files you use to install OpenWrt or to upgrade it).</span> <span style="color: #339966;"> This file is usually a disk image ready to be written raw in the internal flash storage of the device, so you will find many developers that just call it ``image'' on <abbr title="Internet Relay Chat">IRC</abbr> or in the mailing list.</span>  </div> <h3 id="how_a_package_is_compiled" class="sectionedit2"><span style="color: #339966;">How a package is compiled</span></h3> <div class="level3">  <span style="color: #339966;">If you look at a package Makefile (the file defining settings for building a specific package), <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/Makefile" href="https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/Makefile" rel="nofollow">https://github.com/openwrt/openwrt/blob/master/package/utils/busybox/Makefile</a> you will notice that it states the official download link for the sources that will be compiled, a SHA256 hash to check the integrity of such download, and two version numbers (one for upstream and one for OpenWrt). On some other packages it will state git commit/timestamp or other way to identify the same source to pull down and build. They generally favor archives with sources from official releases, but some upstream projects don't always have that.</span>  <span style="color: #339966;">In /patches folder of each package's folder you will find any patches that will be applied to the source after downloading it, before compiling it: <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/openwrt/tree/master/package/utils/busybox/patches" href="https://github.com/openwrt/openwrt/tree/master/package/utils/busybox/patches" rel="nofollow">https://github.com/openwrt/openwrt/tree/master/package/utils/busybox/patches</a> There are also other folders for configuration files or for uci integration (not always present).</span>  <span style="color: #339966;">The kernel's makefile is a bit more complex because of reasons, but you can see that it still uses the same structure, pulling down the same kernel version (depending from device) every time.<a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/openwrt/blob/master/package/kernel/linux/Makefile" href="https://github.com/openwrt/openwrt/blob/master/package/kernel/linux/Makefile" rel="nofollow">https://github.com/openwrt/openwrt/blob/master/package/kernel/linux/Makefile</a></span>  <span style="color: #339966;">All packages are compiled by OpenWrt's own toolchain, which is again handled like packages (see /toolchain and /tools in the source) so you will always have the same compiler/tools as everyone else as they get downloaded from the same sources at the same version.</span>  <span style="color: #339966;">When you run a <strong>make</strong> the OpenWrt build system will use your system's existing building infrastructure to compile the OpenWrt's toolchain first, and then use that to compile the packages. This also has the major benefit of not requiring the user to set up a cross-compiling toolchain that is rather annoying and relatively complex.</span>  </div> <h3 id="package_feeds" class="sectionedit3"><span style="color: #339966;">Package feeds</span></h3> <div class="level3">  <span style="color: #339966;">Not all packages you can install in OpenWrt are from OpenWrt project proper, in fact most packages are not.</span>  <span style="color: #339966;">The packages from OpenWrt's main repository are maintained directly by core developers (and they are the more important or even essential components of OpenWrt firmware, or parts of the build system), and ``<strong>package feeds</strong>'' that are source repositories that contain additional packages, maintained by the community (each package has its own maintainer). This is OpenWrt's main repo (on github) <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/openwrt" href="https://github.com/openwrt/openwrt" rel="nofollow">https://github.com/openwrt/openwrt</a></span>  <span style="color: #339966;">These are official package feeds: <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/luci" href="https://github.com/openwrt/luci" rel="nofollow">https://github.com/openwrt/luci</a> <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/telephony" href="https://github.com/openwrt/telephony" rel="nofollow">https://github.com/openwrt/telephony</a> <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt-routing/packages" href="https://github.com/openwrt-routing/packages" rel="nofollow">https://github.com/openwrt-routing/packages</a> <a class="urlextern" style="color: #339966;" title="https://github.com/openwrt/packages" href="https://github.com/openwrt/packages" rel="nofollow">https://github.com/openwrt/packages</a></span>  <span style="color: #339966;">Being ``official feeds'', the packages therein will be compiled and offered by the official download server, but they are not technically OpenWrt proper, they are community-maintained. The ``package feed'' system is designed to allow easy addition of your own custom feeds too in your custom firmware images, but you will have to compile them and host them on your own servers, of course.</span>  <span style="color: #339966;">If you look at the built packages here on the download server (this is the same server opkg uses to download packages in a live OpenWrt system), <a class="urlextern" style="color: #339966;" title="https://downloads.openwrt.org/releases/18.06.1/packages/x86_64/" href="https://downloads.openwrt.org/releases/18.06.1/packages/x86_64/" rel="nofollow">https://downloads.openwrt.org/releases/18.06.1/packages/x86_64/</a></span>  <span style="color: #339966;">They are divided by feed name, packages in ``base'' come from main repository, and also from main repository you get packages that are found in target-specific folders, like for example here<a class="urlextern" style="color: #339966;" title="https://downloads.openwrt.org/releases/18.06.1/packages/x86_64/packages/" href="https://downloads.openwrt.org/releases/18.06.1/packages/x86_64/packages/" rel="nofollow">https://downloads.openwrt.org/releases/18.06.1/packages/x86_64/packages/</a> that you see has mostly kmod-* and other drivers.</span>  </div> <h3 id="package_versions" class="sectionedit4"><span style="color: #339966;">Package Versions</span></h3> <div class="level3">  <span style="color: #339966;">As said above, package makefiles have PKG_VERSION that shows the upstream version (major version) and PKG_RELEASE that is used to show changes on the OpenWrt side (the minor version). If you see a package that lists version as 123-1, its major version is 123 and its minor version is 1.</span>  <span style="color: #339966;">Packages with a timestamp use that instead of major version, and they still have a minor version, for example 2016-09-21-42ad5367-1 where the last ``1'' is the minor version.</span>  <span style="color: #339966;">You can see all versions used in the first page of the table of packages in the wiki <a class="urlextern" style="color: #339966;" title="https://openwrt.org/packages/start" href="https://openwrt.org/packages/start" rel="nofollow">https://openwrt.org/packages/start</a></span>  <span style="color: #339966;">Or by browsing a Package.manifest in the package download folders <a class="urlextern" style="color: #339966;" title="https://downloads.openwrt.org/releases/18.06.1/packages/mips_24kc/base/Packages.manifest" href="https://downloads.openwrt.org/releases/18.06.1/packages/mips_24kc/base/Packages.manifest" rel="nofollow">https://downloads.openwrt.org/releases/18.06.1/packages/mips_24kc/base/Packages.manifest</a></span>  </div> <h3 id="repeatable_builds" class="sectionedit5"><span style="color: #339966;">Repeatable builds</span></h3> <div class="level3">  <span style="color: #339966;">Most of the above system allows repeatable builds, the hashes and time stamps of source archives or commits are written in the package's makefile in the git repository (either main repo or community package feeds), you can see full history of changes to that file with git.</span>  <span style="color: #339966;">There is a cache server that stores source archives because it's more convenient than having the build bots spamming upstream download servers and it is a fallback if the upstream download disappears, it should keep the source packages for a long while (as long as the release is supported for sure, as it is used by build bots).</span>  <span style="color: #339966;">It is here <a class="urlextern" style="color: #339966;" title="https://sources.openwrt.org/" href="https://sources.openwrt.org/" rel="nofollow">https://sources.openwrt.org/</a></span>  <span style="color: #339966;">Source cache server is <a class="urlextern" style="color: #339966;" title="https://downloads.openwrt.org/sources/" href="https://downloads.openwrt.org/sources/" rel="nofollow">https://downloads.openwrt.org/sources/</a></span>  </div> <span style="color: #808080;">………</span>     <span style="color: #666699;">,怎知卻遭遇莫名事件☻</span> <pre class="lang:default decode:true "> make[3] -C toolchain/gcc/initial compile make -r world: build failed. Please re-run make with -j1 V=s or V=sc for a higher verbosity level to see what's going on /home/pi/openwrt/include/toplevel.mk:216: recipe for target 'world' failed make: *** [world] Error 1 pi@raspberrypi:~/openwrt make
 make[1] world
 make[2] toolchain/compile
 make[3] -C toolchain/gdb compile
 make[3] -C toolchain/binutils compile
 make[3] -C toolchain/gcc/initial compile

【demsg】

[ 7002.114849] Workqueue: events_freezable mmc_rescan
[ 7002.114867] [<8079ef70>] (__schedule) from [<8079f5d8>] (schedule+0x50/0xa8)
[ 7002.114875] [<8079f5d8>] (schedule) from [<8061a2d0>] (__mmc_claim_host+0xb8/0x1cc)
[ 7002.114884] [<8061a2d0>] (__mmc_claim_host) from [<8061a414>] (mmc_get_card+0x30/0x34)
[ 7002.114891] [<8061a414>] (mmc_get_card) from [<80623010>] (mmc_sd_detect+0x20/0x74)
[ 7002.114898] [<80623010>] (mmc_sd_detect) from [<8061ccdc>] (mmc_rescan+0x1c8/0x394)
[ 7002.114907] [<8061ccdc>] (mmc_rescan) from [<801379b4>] (process_one_work+0x158/0x454)
[ 7002.114914] [<801379b4>] (process_one_work) from [<80137d14>] (worker_thread+0x64/0x5b8)
[ 7002.114921] [<80137d14>] (worker_thread) from [<8013dd98>] (kthread+0x13c/0x16c)
[ 7002.114930] [<8013dd98>] (kthread) from [<801080ac>] (ret_from_fork+0x14/0x28)

 

也只好鼻子摸著明天看結果吧★

pi@raspberrypi:~/openwrt $ make
 make[1] world
 make[2] toolchain/compile
 make[3] -C toolchain/gdb compile
 make[3] -C toolchain/binutils compile
 make[3] -C toolchain/gcc/initial compile
 make[3] -C toolchain/kernel-headers compile
 make[3] -C toolchain/musl compile
 make[3] -C toolchain/gcc/final compile
...