OpenWRT guide and memo

Preview:

Citation preview

OpenWRT

Basic tutorial guide, memo.by Antony.Wu

1

OpenWRT builtroot• It is a set of Makefiles and patches that allows users to generate

a cross-toolchain and a root filesystem for embeded system.• It generates cross-compiler toolchain and use the toolchain to

build an image for your target board, such as AR-5387un router.• It can also download packages (feeds), patches (using quilt) it

for you.• # make toolchain/gdb/prepare QUILT=1• <modify files in build_dir/>• # make toolchain/gdb/updatevim

• It has modified make targets: component/name/action.• # make toolchain/gdb/compile V=s

• V=s means “Verboase = stdout/stderror”• # make toolchain/gdb/clean V=s

2

V=?

s standard output/error

w shows only warning

3

Get OpenWRT buildroot

Main repositories and feeds # git clone git://git.openwrt.org/openwrt.git # git clone git://git.openwrt.org/packages.git

Barrier Breaker # git clone git://git.openwrt.org/14.07/openwrt.git # git clone git://git.openwrt.org/14.07/packages.git # svn co -r 42990

svn://svn.openwrt.org/openwrt/branches/barrier_breaker

4

Setup OpenWRT environmentUsing Fedora distribution, you need the following

package ready. # yum install -y subversion binutils bzip2 gcc gcc-c++ gawk

gettext flex ncurses-devel zlib-devel make patch unzip perl-ExtUtils-MakeMaker glibc glibc-devel glibc-static quilt ncurses-lib sed sdcc intltool sharutils bison wget

Check environment variables # echo $SED # must be empty, or issue '# unset SED' # echo $GREP_OPTIONS # don't contain '--initial-tab'

Set the PATH: PATH=$PATH:<buildroot dir>/staging_dir/host/bin PATH=$PATH:<buildroot dir>/staging_dir/toolchain-

<platform>-<gcc_ver>-<libc_ver>/bin

5

Understand OpenWRT FeedsIt is a set of packages, like a ‘yum repo’, or ‘apt-get repo’ on

desktop linux. The script downloads the packages info into ‘feeds/’ . The script installs packages into ‘package/feeds/’ Packages in feeds selectable by CONFIG_PACKAGE_xxxx in .config

file.

The repo is configured in the feeds.conf or feeds.conf.default (such as yum repo configured in /etc/yum.repos.d)

A script is used to control those packages # ./scripts/feeds update -a

Package index (information) will be stored into feeds/ # ./scripts/feeds install <package_name>

Src will be checkouted into package/feeds/<package_name>

OpenWRT Make

• Clean• # make clean # rm -rf bin build_dir

• # make dirclean # rm -rf bin build_dir staging_dir toolchain logs

• # make distclean # all above, rm all downloaded packages and .config

• Ignore errors• #IGNORE_ERRORS=1 make <make options>

• component/name/action.• Clean Linux objects

• # make target/linux/clean V=s

• Clean package luci.• # make package/luci/clean

6

OpenWRT Make sequence

1. # make tools/install

2. # make toolchain/install

3. # make target/compile

4. # make package/cleanup

5. # make package/compile

6. # make package/install

7. # make package/preconfig

8. # make target/install

9. # make package/index

You can issue them, one by one, in order, so that you can check and debug each step.

7

Create OpenWRT package• Special Makefile template.

• Please refer to BuildPackage variablesPKG_NAME:=broadcom-wlPKG_VERSION:=5.10.56.27.3PKG_RELEASE:=5

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(ARCH).tar.bz2PKG_SOURCE_URL:=http://downloads.openwrt.org/sources ……$(eval $(call KernelPackage,brcm-wl))$(eval $(call KernelPackage,brcm-wl-mini))$(eval $(call BuildPackage,wlc))$(eval $(call BuildPackage,wl))$(eval $(call BuildPackage,nas))

• BuildPackage only takes one argument directly – the name of the package to be built, in this case “wlc".

# ls -l package/broadcom-wl/files # default config.Makefilepatches # patches from diffsrc # source code

8

Create OpenWRT package 2• BuildPackage define ‘Package/’

• The following describe the ‘define’ you may need:define Package/broadcom-wl/Default

<action>endef

• Package/description : description

• Package/conffiles : config-files installed by this pkg.

• Build/Prepare (optional): How to unpack/patch src.

• Build/Configure (optional) : How to configure src.

• Build/Compile (optional) : How to compile src.

• Build/InstallDev (optoinal) : Lib. needed

• Please refer to BuildPackage defines

Note: ‘define’ in makefile is like ‘=‘ operator.

Define the action when calling ‘Package/broadcom/wl/Default ‘

9

Create OpenWRT package 3• Override Build option

• Autoconf• Eg. CONFIGURE_VARS += ac_cv_header_regex_h=no• Eg. CONFIGURE_ARGS += --disable-native-affinity

• Compiler flags• Eg. TARGET_CFLAGS+= -Wall

• Make• Eg. MAKE_VARS = CFLAGS="$(TARGET_CFLAGS) $(EXTRA_CFLAGS)

$(TARGET_CPPFLAGS) $(EXTRA_CPPFLAGS)" \ …• Eg. MAKE_FLAGS = $(TARGET_CONFIGURE_OPTS) \ CROSS="$

(TARGET_CROSS)" ARCH="$(ARCH)“• CMake and Scons

• CMAKE_OPTIONS, CMAKE_HOST_OPTIONS• SCONS_VARS

10

Create OpenWRT package 4• Adding configuration options

• Add MENU:=1• Add Config.in Package/<name>/configMakefile:

define Package/mjpg-streamer/config source "$(SOURCE)/Config.in“ endef

Config.in:menu "Configuration" depends on PACKAGE_mjpg-streamer config MJPEG_STREAMER_AUTOSTART bool "Autostart enabled" default n

• How to check your configurationMakefile:

ifeq ($(CONFIG_MJPEG_STREAMER_INPUT_UVC),y) $(CP) $(PKG_BUILD_DIR)/input_uvc.so $(1)/usr/lib endif

11

Create OpenWRT package 5• Working on local application source

• Using feeds to tracking your state-of-the-art work.# ln -s /path/to/local/awesome_app_tree/.git feeds/my_cool_feed/awesome_app/git-src # make package/awesome_app/{clean,compile} V=s

• Using USE_SOURCE_DIR# make package/awesome_app/clean V=s # make package/awesome_app/prepare USE_SOURCE_DIR=~/src/awesome_src V=s # make package/awesome_app/clean V=s

• make prepare needs to be run every time• make package/awesome_app/{clean,compile}

USE_SOURCE_DIR=~blah doesn't work

12

OpenWRT kernel package Adding configuration options

Add .mk file#vim package/kernel/modules/block.mk

define KernelPackage/loop SUBMENU:=$(BLOCK_MENU) TITLE:=Loopback device support KCONFIG:= CONFIG_BLK_DEV_LOOP CONFIG_BLK_DEV_CRYPTOLOOP=n

FLES:=$(LINUX_DIR)/drivers/block/loop.ko AUTOLOAD:=$(call AutoLoad,30,loop)endef$(eval $(call KernelPackage,loop))

Announce to build system.# touch package/kernel/linux/Makefile

Add a kernel module that is not part of kernel distribution Please refer to ‘package/madwifi/Makefile’

13

What’s in the following slides?

1. # make tools/install

2. # make toolchain/install

3. # make target/compile

4. # make package/cleanup

5. # make package/compile

6. # make package/install

7. # make package/preconfig

8. # make target/install

9. # make package/index

You can issue them, one by one, in order, so that you can check and debug each step.

14

External Toolchain Compile everything with the target board,

you will have a dir named toolchain, called build1

Copy the .config-file from the build1 and make menuconfig.

[*] Advanced configuration options (for developers)[*] Use external toolchainTarget name: arm-openwrt-linux-uclibcgnueabi (in my case, yours may vary)Toolchain prefix: arm-openwrt-linux-uclibcgnueabi- (mind the dash at the end)Toolchain root: /path/to/toolchain/staging_dir/toolchain-arm_v5te_gcc-linaro_uClibc-0.9.32_eabi

15

Alter download procedure $DL_DIR is the location for download

Through "include/download.mk“ Init in “rules.mk”

To share downloaded packages Put them in a shared location /opt/… Check them in download procedure “define Download”

in file “download.mk” MEMO: we can use shell to do this.

Eg . test -e /opt/dl/$(FILE) && ln -s /opt/dl/$(FILE) $(DL_DIR)/$(FILE) || ( $(if $(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/$(call dl_method,$(URL),$(PROTO))),$(DownloadMethod/unknown)) )

16

What has been added?dl/ # for downloaded src.build_dir/ # source code location

├── host ├── target-mips_mips32_uClibc-0.9.33.2 └── toolchain-mips_mips32_gcc-4.8.3_uClibc-0.9.33.2

logs/ # for compile logs ├── target ├── toolchain └── tools

staging_dir/ # built out binary files. ├── host ├── target-mips_mips32_uClibc-0.9.33.2 └── toolchain-mips_mips32_gcc-4.8.3_uClibc-0.9.33.2

tmp/

17

What’s in the following slides?

1. # make tools/install

2. # make toolchain/install

3. # make target/compile

4. # make package/cleanup

5. # make package/compile

6. # make package/install

7. # make package/preconfig

8. # make target/install

9. # make package/index

You can issue them, one by one, in order, so that you can check and debug each step.

18

Add our own BSP in target The makefile in target will go into each

subdir. Create a dir <BSP> of yours in the target dir. Create a Makefile contains the following target.

all, download, prepare,

compile, install, clean

This also apply to the general ruls Eg # make target/<BSP>/prepare

19

Reference

1. http://wiki.openwrt.org/doc/start2. http://wiki.openwrt.org/about/toolchain3. http://wiki.openwrt.org/doc/devel/packages

20

Recommended