Set up OpenWrt development environment (including the compilation process)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

OpenWrt is a highly modular, embedded Linux highly automated distribution, the compilation and installation process than ordinary Linux distribution, simple too much. If you are a novice, you that the fear of heart can on the stomach, ha ha. For the novice, the most troublesome is installed to software development environment.

The most basic conditions:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A 1.PC performance, strength, good performance compiling faster. Linux is recommended to install the ubuntu  8.04 Chinese Version (or SUSE) and fedora 11 (for beginners, it is best arranged in a virtual machine such as VM, can save a lot of trouble. How to install Linux in VM, you can Google or Baidu) 

2 broadband a need for speed, good point, because there are many software packages are downloaded and installed network.  

3 patience and time.

The compiler environment for installation (Linux distributions and software package):

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1 install ubuntu8.04 Chinese version or Fedora 9 or 11, get a network connection.

In a non root user login, open the &ldquo application; — - Annex — - terminal ”. If you have Linux installed, then please omit this step.

2 if you select Ubuntu, then Ubuntu development environment to sudo apt-get install GCC software g++ binutils patch bzip2 flex bison make Autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev

Then

sudo apt-get update

If you choose to install fedora11 or fedora9

Fedora 11 or 9: 

# yum install autoconf binutils bison bzip2 flex gawk gcc gcc-c++ gettext make ncurses-devel patch unzip wget zlib-devel 

Because the Fedora installation package is very comprehensive, so need to install anything less. So under normal circumstances, recommend to install Fedora 11. For starters, the most convenient way is to install Linux on VM.

Because Ubuntu is based on SUSE, so if you want to SUSE for the development environment, then you can install Ubuntu.

If you can read English, so please refer to

,

OpenWrt English Forum 2006 article: Building OpenWrt Kamikaze from source 

https://forum.openwrt.org/viewtopic.php?id=9180

Here is a more detailed description of the authority.

4 to obtain the OpenWrt source code and patches, updates 

1. svn checkout svn://svn.openwrt.org/openwrt/trunk (The development version, unstable, not recommended to download)

PS: wgethttp://downloads.openwrt.org/backfire/10.03/backfire_10.03_source.tar.bz2(The current stable version, suggestions)

2. Check the configuration environment

You must use a non root user operation, add a normal user. (Note: if you use the root operation, will prompt check failed: Checking 'non-root'... failed.)

[root@localhost trunk]# adduser openwrt 

[root@localhost trunk]# su openwrt

In order to prevent the file read and write permissions problems, need to be the root directory of all operations copy source code to openwet.

[openwrt@localhost openwrt]$ cd ~

[openwrt@localhost ~]$ cp -r /usr/src/test/trunk ./

[openwrt@localhost ~]$ cd trunk/

[openwrt@localhost trunk]$ ls

BSDmakefile  LICENSE   README  feeds.conf.default  package   scripts  toolchain

Config.in

Makefile  docs

include

rules.mk  target   tools

3 download feeds

Feeds is the OpenWrt environment required software suite. The most important feeds:

‘packages’Some additional software based router

‘LuCI’The default OpenWrt GUI

‘Xwrt’Another optional GUI interface

Need to be able to connect to the Internet.

In the download before you can view ’ feeds.conf.default’ file, to check which files need to be included in the environment.

To start the download, use:

[openwrt@localhost trunk]$ ./scripts/feeds update -a

Install the feeds package, only after the installation, behind make menuconfig, before you can check the relevant configuration.

[openwrt@localhost trunk]$ ./scripts/feeds install -a

If you update the feeds configuration file, you need to add new software package for generating system. Just repeat the process:

[openwrt@localhost trunk]$ ./scripts/feeds update -a

[openwrt@localhost trunk]$ ./scripts/feeds install -a

 The 4 configuration

Cross compiling process, cross compiler generated SDK and image files, depending on the type of application development environment, hardware, as well as the source code version. So to understand their environment, correctly configured to. I am in the configuration process, encountered this problem, my hardware is brcm47xx, when the first compilation, the choice is Target System (Broadcom BCM947xx/953xx), the last generation package cannot be installed on router, version mismatch. Second times during the installation, select Target System (Broadcom BCM947xx/953xx[2.4]), the installation is successful, the board may only support linux2.4 kernel. (Device models are Linksys Wrt54gs V3.0) (2011.05.01 added: in fact, Linksys Wrt54gs V3.0 is supported version of Linux 2.6, Target System Broadcom BCM947xx/953xx, after the compiler can be used, this weekend because of the project need to change a piece of software, each time to modify code, have to re compile firmware, after a dozen times back and forth compiler, can use. In addition. After the kernel version upgrade, wireless drive into the mac802.11, rather than the previous WL, think wl.o this special library only uses in linux2.4. )

[openwrt@localhost trunk]$ make defconfig

[openwrt@localhost trunk]$ make prereq

[openwrt@localhost trunk]$ make menuconfig

Through the text dialog box options configuration, configuration of the main a:

Target system(Target system)

Package selection(Package selection)

Build system settings  (The compiler system settings)

Kernel modules  (The kernel module)

[*]Said: this package selected compilation, and installed in the firmware,

[M]Said: this package selected compiler, but not installed in the firmware.

In the exit of Menuconfig, will be prompted to save configuration.

I only on target system were selected; check the Advanced configuration option and Build the OpenWrt SDK option.

5. Compile

(1)In general, the use of a simple command:

[openwrt@localhost trunk]$ make

(2)In order to improve the speed in the multi processor system, can be used (for example, 3 core processor):

[openwrt@localhost trunk]$ make –j 3

(3)Compile in the background, the use of idle I/O resources and CPU performance, can be used (such as the use of dual core processor)

[openwrt@localhost trunk]$ onice -c 3 nice -n 20 make -j 2

(4)Compile a separate package (for example in the cups software package):

[openwrt@localhost trunk]$ make package/cups/compile V=99

(5)If special reasons for the analysis of compiler error message:

[openwrt@localhost trunk]$ make V=99 2>&1 |tee build.log |grep -i error

Description: the compilation of all the output information is stored in build.log, the error information is printed on the screen.

(6)Application of a complex instruction

[openwrt@localhost trunk]$ 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)'

Description: the compilation of all the output information is stored in build.log, the error and warning information in the screen print. The compilation process using dual core CPU, occupation background resources.

The 6 generation image (Image) position

The new generation of image will default on a bin directory under the new. For example:/bin/brcm-2.4/packages

[openwrt@localhost trunk]$ ls bin/*

Make a backup will mirror the compiled, such as backup / directory:

[openwrt@localhost trunk]$ cp bin /

7 clean-up

Recommendations now clean compiler generated files, so as to avoid the next compile time conflict (file, if it exists, will not be replaced), make clean

Note: in the execution of the clean command, ensure that has compiled image for backup. The cleanup will clear the bin directory.

[openwrt@localhost trunk]$ make clean 

In addition to remove the directory, also want to clear the cross compiler tool chain (as well as the Tools Directory)

[openwrt@localhost trunk]$ make dirclean

Remove all things, including the download software, configuration files, feed content: (not recommended)

[openwrt@localhost trunk]$ make distclean

To update feeds error:

ERROR:please fix package/feeds/packages/mc/Makefile and other similar problems, need to perform this statement system cleaning


More detailed information that you reference


Should the latest and most authoritative document


Through the official website to download a lot of related software compilation process, so must guarantee to smoothly even on internet. The download speed limit, the compilation process takes about several hours. After the compilation, all products will be placed in the compiled the root directory of the bin/yourtarget/. product such as: I have compiled into./bin/brcm47xx/ files, which mainly has several kinds:

(1). bin/.trx files: These are under our selected target-system categories, according to the different router model, the router firmware version of the compiler. These different types and versions of openwrt router is arranged in advance, we do not need to change. As for the difference between.Bin and.Trx, a kind of view is, the first brush router, need to use the.Bin file, if need to upgrade, you can no longer use the. Bin file, and the need to use the.Trx file. The reason is,.Bin is the router configuration information and.Trx package together and generate packet, that is containing the router TRX version information. At the first brush firmware, we need to provide such information, and in the subsequent upgrades, it is no longer necessary, using.Trx files.

(2)Packages folder: it contains all the compiled package we set in the configuration file. By default, there will be the default selection software package.

(3) OpenWrt-SDK.**.tar.bz2: this is our custom compiled OpenWRT SDK environment. We will use this to the development of OpenWrt software package. For example, I have compiled SDK environment package: /bin/brcm47xx/OpenWrt-SDK- brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2

As can be seen from the name, target system brcm47xx, host system Linux-x86_64, use the compiler tools and libraries is 4.3.3+cs_uClibc-0.9.30.1.

(4)The md5sums file: this file records all we compiled file MD5 value, to ensure the integrity of the file. Because the file is not complete, it is easy to router into “ brick”.

The need is, compiled after the completion, it must be compiled bin directory backup (if that's important to you), because in the next before compiling, executing make clean will all files under the bin directory to remove!!

2, To change the original packages

In compiling the root directory will have a DL directory, the directory is “ download” or, in compiling stage, need data downloaded from a network packet will be placed in this directory, a feature of the software is installed automatically in the compiler, firmware, that is when we make menuconfig for some software, firmware configuration. If we need to change the source package, only need to change the source package packed into the same name in the directory, and then began to compile. Compile time, will unzip the package to the build_dir directory.

Of course, you can also create your own their own software package in DL, and then change the associated configuration file, so openwrt can identify this package.

Because of my project changes is the underlying, need to install with firmware. So, I use the method is to directly change the directory of DL software package, and then re firmware is compiled. Feel similar to the Linux kernel compile. Repeatedly made about a dozen times, without any problems.

The first compilation due to download a number of software packages, slowly wait, slow fast half an hour, 2, 3 hours. If the download is too slow, suggest you interrupt the compilation process, then use fast thunder to download, placed in the./dl directory. A speed tips: the small make up will have some commonly used software package for dl.tar, on tar, after downloading xvf dl.tar (in windows using WinRAR can be opened, and you use the FTP or Samba like to Linux  PC), will be unpacked out stuff directly into the./dl directory, which will greatly speed up the initial installation, compilation speed. Also can download the linux-2.36.30.10.tar.bz2, of course, you can also use fast thunder to down tools such as.

8 compiled file in the current directory under the bin folder.  

If it is brcm-2.4 

ls bin/brcm-2.4/ 

You can see plenty of familiar file.

9,  Install OpenWrt

Find the corresponding firmware, firmware upgrades. Online many methods, here no longer.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Below we write our own package:

Create your own packages

For their new package, and the package and do not need to install, together with the firmware in other words, is to be as an optional package. We can use our SDK environment to separate compilation, the compiler will generate a ipk file. And then use opkg install xxx.ipk to install the software.

The specific said, how to build a helloword software package.

(1)First of all, write HelloWorld program

Preparation of helloworld.c

/****************

* Helloworld.c

* The most simplistic C program ever written.

* An epileptic monkey on crack could write this code.

*****************/

#include <stdio.h>

#include <unistd.h>

int main(void)

{

printf("Hell! O' world, why won't my code compile?\n\n");

return 0;

}

Write Makefile file

# build helloworld executable when user executes "make"

helloworld: helloworld.o

$(CC) $(LDFLAGS) helloworld.o -o helloworld

helloworld.o: helloworld.c

$(CC) $(CFLAGS) -c helloworld.c

# remove object files and executable when user executes "make clean"

clean:

rm *.o helloworld

In these two files directory, make should generate a HelloWorld executable file. After the HelloWorld, can print out the “ Hell! O'world, why won't my code &rdquo compile?;. In this step, the main guarantee our source is normally compiled. Below we will migrate to OpenWRT.

(2)Unzip the OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2

tar –xvf OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2

(3)Enter the SDK

cd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1

You can see the directory structure inside with the directory structure before source we are basically the same, the need to compile the software package, need to be placed in the package directory

(4)Create a HelloWorld directory in the package directory

cd package

mkdir helloworld

cd helloworld

(5)Create a SRC directory, copy the HelloWorld file

mkdir src

cp /home/wrt/test/helloworld.c src

cp /home/wrt/test/Makefile src

(6)Create the Makefile file in the HelloWorld directory

This Makefile file is read to OpenWRT, and the Makefile file before writing to HelloWorld to compile the reading. The two Makefile is not on the same level directory.

touch Makefile

vim Makefile

Makefile file template contents are as follows:

##############################################

# OpenWrt Makefile for helloworld program

#

#

# Most of the variables used here are defined in

# the include directives below. We just need to

# specify a basic description of the package,

# where to build our program, where to find

# the source files, and where to install the

# compiled program on the router.

#

# Be very careful of spacing in this file.

# Indents should be tabs, not spaces, and

# there should be no trailing whitespace in

# lines that are not commented.

#

##############################################

include $(TOPDIR)/rules.mk

# Name and release number of this package

PKG_NAME:=helloworld

PKG_RELEASE:=1

# This specifies the directory where we're going to build the program.

# The root build directory, $(BUILD_DIR), is by default the build_mipsel

# directory in your OpenWrt SDK directory

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

# Specify package information for this program.

# The variables defined here should be self explanatory.

# If you are running Kamikaze, delete the DESCRIPTION

# variable below and uncomment the Kamikaze define

# directive for the description below

define Package/helloworld

SECTION:=utils

CATEGORY:=Utilities

TITLE:=Helloworld -- prints a snarky message

endef

# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above

define Package/helloworld/description

If you can't figure out what this program does, you're probably

brain-dead and need immediate medical attention.

endef

# Specify what needs to be done to prepare for building the package.

# In our case, we need to copy the source files to the build directory.

# This is NOT the default. The default uses the PKG_SOURCE_URL and the

# PKG_SOURCE which is not defined here to download the source from the web.

# In order to just build a simple program that we have just written, it is

# much easier to do it this way.

define Build/Prepare

mkdir -p $(PKG_BUILD_DIR)

$(CP) ./src/* $(PKG_BUILD_DIR)/

endef

# We do not need to define Build/Configure or Build/Compile directives

# The defaults are appropriate for compiling a simple program such as this one

# Specify where and how to install the program. Since we only have one file,

# the helloworld executable, install it by copying it to the /bin directory on

# the router. The $(1) variable represents the root directory on the router running

# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install

# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the

# command to copy the binary file from its current location (in our case the build

# directory) to the install directory.

define Package/helloworld/install

$(INSTALL_DIR) $(1)/bin

$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/

endef

# This line executes the necessary commands to compile our program.

# The above define directives specify all the information needed, but this

# line calls BuildPackage which in turn actually uses this information to

# build a package.

$(eval $(call BuildPackage,helloworld))

(7)Return to the root directory SDK

Implementation of make compiler

The build process will be completed in the build_dir directory

Compile the results will put helloworld_1_bcm47xx.ipk in the bin/[yourtarget]/package directory

(8)Upload helloworld_1_bcm47xx.ipk

Use the SFTP software to upload helloworld_1_bcm47xx.ipk router

Implementation of opkg install helloworld_1_bcm47xx.ipk

Type hello and then press the Tab key, we found that openwrt has a HelloWorld command.

Implementation of HelloWorld program viewing effect.

Hell! O' world, why won't my code compile?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Fanny at November 08, 2013 - 2:56 AM