Learn Deep Openwrt
Learn Deep Openwrt
Learn Deep Openwrt
development framework
Contents
1 Design
1.3 Toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4
2.1.1
2.1.2
2.3.1
Using quilt
. . . . . . . . . . . . . . . . . . . . . . . .
2.3.2
3 Deploying OpenWrt
OpenWrt
Design
1.1
Directory structure
1.2
OpenWrt
1.3 Toolchain
1.3
Toolchain
OpenWrt
1.4
Software architecture
OpenWrt uses the common embedded Linux tools such as uClibc, busybox,
shell interpreter and provides a hardware abstraction layer and package manager. Here is the software stack that OpenWrt uses:
Every architecture uses a different Linux kernel allowing the user-space environnment to be shared and consistent acrross devices. Therefore you only
need to recompile the uClibc and packages to match your target architecture
to get the same programs running on a totally different embedded device.
1.5
<type> ["<name>"]
<name> "<value>"
# Section
# Option
3
OpenWrt
Later on, the system scripts and the UCI library allows you to parse this
configuration context from either an init script or directly an user-space program.
Developing with OpenWrt is easy and allows you to be really flexible with
kernel, C library and user-space programs development.
2.1
Creating packages
One of the cool things with OpenWrt is that it supports different fetching
methods, allowing you to retrieve the source of a package from various fetching methods such as:
4
OpenWrt
GIT
Subversion
CVS
HTTP
local source
For instance, if you wish to checkout a particular revision of a package using Subversion, just define the following download method in your package
Makefile:
PKG_VER:=963
PKG_BRANCH:=batman-adv-userspace
PKG_VERSION:=r\$(PKG\_REV)
PKG_SOURCE_PROTO:=svn
PKG_SOURCE_URL:=http://downloads.open-mesh.net/svn/batman/trunk/
It then becomes very easy to test development snapshots and branches of
your application.
2.1.2
OpenWrt assumes you use IPKG as the default package manager, but extending the build system to generate RPMs, DEBs or other package system could
be easily achieved by tweaking the package templates in include/package*.mk.
2.2
The OpenWrt distribution makes the distinction between two kind of kernel
modules, those coming along with the mainline kernel, and the others available as a separate project. We will see later that a common template is used
for both of them.
For kernel modules that are part of the mainline kernel source, the makefiles are located in package/kernel/modules/*.mk and they appear under the
section Kernel modules
5
OpenWrt
For external kernel modules, you can add them to the build system just like
if they were software packages by defining a KernelPackage section in the
package makefile.
After you have created your package/kernel/modules/<name>.mk, the new
kernel modules package will automatically show in the menu under Kernel
modules next time you run make menuconfig and if selected will be built
automatically the next time make is run.
Provided that you gave the right KCONFIG variables, your kernel configuration will be updated accordingly and the kernel module will be built only if
the corresponding module is selected. It is also possible to make the packaged
modules be loaded at boot time simply by defining it the Makefile.
2.3
OpenWrt is very convenient when it comes to adding support for a new target
and requires few steps to be quickly operationnal. You will have to create
a new directory under target/linux/<my target> which will contain a
Makefile defining its build system features and the kernel version to use.
Adding custom patches against a particular kernel version can be done by
putting the patches into the target/linux/<my target>/ /patches directory wich an index number to let them be applied into the right order.
One of the interesting feature is that you can also put files that will be copied
to the Linux kernel build directory. For instance, if you are developing a new
file which should be into arch/mips/<my target>/ in the Linux kernel directory, just place this file in target/linux/<my target>/ /files/arch/mips/<my
target>/ file.c and it will be copied to the Linux kernel.
This feature is really interesting when you are developing because you prefer
editing C files instead of patches directly that will be creating C files.
2.3.1
Using quilt
OpenWrt natively supports quilt so that you can easily create and rebase your
existing patches without the need to develop scsript to patch the sources up
to a certain patch number, and then let you in with an editor.
Using quilt is very easy and allows you to edit the source files and generate
the differences to produce a new patch with the right patch level. This patch
is then automatically placed into the right location under the OpenWrt build
6
OpenWrt
tree, such that you only need to issue the make component/subcomponent/compile
command to get it recompiled with your previously edited patch.
2.3.2
OpenWrt recently added support for building an external kernel build tree
wich allows you to use the cross-compiler created by the OpenWrt framework
with, for instance a GIT snapshot of a kernel tree. The only thing that you
need to configure is the path poinntig to your kernel directory.
This option is partcularly interesting for embedded developers who wish to
focus on testing their modifications against a git snapshot, will it be for later
submission into the mainline kernel or for internal use. Of course, quilt can
be used inside the external kernel tree along with the source content manager
tools.
3
3.1
Deploying OpenWrt
Supported root filesystems
Testing OpenWrt is really easy since you can flash your embedded device
using JFFS2, SquashFS, ext2/3, cpio images, and even run ramdisk enabled
kernel just by selecting an option in the configuration menu.
If the expected root filesystem does not exist, you can easily add it by tweaking the image generation process of your particular target.
3.2
OpenWrt
3.3
The SDK
The Software Development kits also contains a binary toolchain, that allows you to compile packages without the need to build your toolchain from
scratch.
This tool is particularly useful to test new package versions that are not yet
packaged by OpenWrt or any other external repository and upload them to
your embedded device for testing.
OpenWrt
Getting further
You can reach the OpenWrt team using the following communication means.
IRC
You can chat with us on IRC using the Freenode Network and joining the
#openwrt or #openwrt-devel channels.
Mailing-lists
You can get access to the list of mailing-lists at https://lists.openwrt.org/. To
ask questions about the OpenWrt development please use the openwrt-devel
mailing list.
Web site
The OpenWrt website is at http://openwrt.org/ and has a news engine and
a forum to get in touch with other OpenWrts users and developers.
There is a trac interface on https://dev.openwrt.org/ which can be used to
monitor svn commits and browse the source repository.