OpenWRT: Build Firmware

From OnnoWiki
Jump to navigation Jump to search

Sumber:


Prosedur

  • Lakukan sebagai non-root user
  • Lakukan semua perintah di <buildroot dir> misalnya ~/openwrt/trunk/
  • Update OpenWrt source
  • Update & install package feeds.
  • Configure build.
  • Start build. Ini akan secara automatis compile Ttoolchain, cross-compile sources, package packages, dan generate image siap untuk di flashed.
  • Proceed to Installing OpenWrt

Persiapan

Lakukan

sudo su
apt-get update
apt-get install subversion gawk flex sharutils bison libz-dev patch fakeroot lzma

Menggunakan SVN

Sebagai user biasa lakukan

svn co svn://svn.openwrt.org/openwrt/branches/backfire ~/openwrt/trunk/
cd ~/openwrt/trunk/
./scripts/feeds update
./scripts/feeds install <pkg_name_1> <pkg_name_2> ... <pkg_name_N>
make defconfig
make menuconfig
make world

Update SVN

cd ~/openwrt/trunk/
svn update
./scripts/feeds update

Menggunakan GIT

git clone git://nbd.name/openwrt.git ~/openwrt/trunk/
cd ~/openwrt/trunk/
./scripts/feeds update # You have to change feeds.conf to use the git packages repo. See the patch below.
./scripts/feeds install <pkg_name_1> <pkg_name_2> ... <pkg_name_N> # After installing the package (creates the symlink for you, you can select it in menuconfig)
make menuconfig # Choose your Target System/Subtarget/Target Profile and select packages/features
make world

Update GIT

cd ~/openwrt/trunk/
git pull
./scripts/feeds update

Tips

You should specify which chipset you are using. But on your target/linux/chipname/, there should be a makefile that tells you which build you are supposed to build.

For my case it was in kamikaze/target/linux/atheros/Makefile.

LINUX_VERSION:=2.6.23.17 <-- just change this to whatever is your rev is you probably need to know the subversion.


Building on multi-core CPU

The build process can be accelerated by running multiple concurrent job processes using the -j-option:

make -j 3
   Use the standard formula <your number of CPUs + 1>
   If this produces random build errors try compiling again without the -j-option

Building in the background

If you intend to use your system while building, you can have the build process use only idle I/O and CPU capacity like this (dualcore CPU):

ionice -c 3 nice -n 20 make -j 2

Building single Packages

When developing or packaging software for OpenWrt, it is convenient to be able to build only the package in question (e.g. with package cups):

make package/cups/compile V=99

For the package mc (midnight commander), which is contained the feed packages it looks like this:

make package/feeds/packages/mc/compile v=99

Spotting build errors

If for some reason the build fails, the easiest way to spot the error is to do:

make V=99 2>&1 | tee build.log | grep -i error

The above saves a full verbose copy of the build output (with stdout piped to stderr) in /openwrt/trunk/build.log and only shows errors on the screen.

Another example:

ionice -c 3 nice -n 20 make -j 2 V=99 CONFIG_DEBUG_SECTION_MISMATCH=y 2>&1 | tee build.log | egrep -i '(warn|error)'

The above saves a full verbose copy of the build output (with stdout piped to stderr) in build.log and outputs only warnings and errors while building using only background resources on a dual core CPU. Getting beep notification

Depending on your CPU, the process will take a while, or while longer. If you want an acoustic notification, you could use echo -e '\a':

make V=99 ; echo -e '\a'

Locating Images

After a successful build, the freshly built image(s) can be found in the newly created <buildroot dir>/bin directory. The compiled files are additionally classfied by the target platform, so e.g. a firmware built for an ar71xx device will be located in <buildroot dir>/bin/ar71xx directory.

E.g. if your <buildroot dir> is /openwrt/trunk, the binaries are in /openwrt/trunk/bin/ar71xx.

Cleaning Up

You might need to clean your build environment every now and then. The following make-targets are useful for that job:

Clean

make clean

deletes contents of bin and build_dir directories.

Dirclean

make dirclean

deletes contents of /bin and /build_dir directories and additionally /staging_dir and /toolchain (=the cross-compile tools). 'Dirclean' is your basic "Full clean" operation.

Distclean

make distclean

nukes everything you have compiled or configured and also deletes all downloaded feeds contents and package sources.

CAUTION: In addition to all else, this will erase your build configuration (.config), your toolchain and all other sources. Use with care!

There are numerous other functionalities in the OpenWrt build system, but the above should have covered some of the fundamentals.

Referensi

Pranala Menarik