SlideShare a Scribd company logo
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_bre
aker
4
Setup OpenWRT environment
Using 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 Feeds
It 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 variables
PKG_NAME:=broadcom-wl
PKG_VERSION:=5.10.56.27.3
PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(ARCH).tar.bz2
PKG_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.
Makefile
patches # patches from diff
src # 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>/config
Makefile:
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 configuration
Makefile:
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 toolchain
Target 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/start
2. http://wiki.openwrt.org/about/toolchain
3. http://wiki.openwrt.org/doc/devel/packages
20

More Related Content

What's hot

Boosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uringBoosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uring
ShapeBlue
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
Kernel TLV
 

What's hot (20)

Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
BKK16-205 RDK-B IoT
BKK16-205 RDK-B IoTBKK16-205 RDK-B IoT
BKK16-205 RDK-B IoT
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory model
 
Openwrt wireless
Openwrt wirelessOpenwrt wireless
Openwrt wireless
 
Yoctoで綺麗なkernel configを作る
Yoctoで綺麗なkernel configを作るYoctoで綺麗なkernel configを作る
Yoctoで綺麗なkernel configを作る
 
Ceph Tech Talk -- Ceph Benchmarking Tool
Ceph Tech Talk -- Ceph Benchmarking ToolCeph Tech Talk -- Ceph Benchmarking Tool
Ceph Tech Talk -- Ceph Benchmarking Tool
 
Boosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uringBoosting I/O Performance with KVM io_uring
Boosting I/O Performance with KVM io_uring
 
eBPF Workshop
eBPF WorkshopeBPF Workshop
eBPF Workshop
 
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMIKernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
Kernel Recipes 2019 - No NMI? No Problem! – Implementing Arm64 Pseudo-NMI
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
AS45679 on FreeBSD
AS45679 on FreeBSDAS45679 on FreeBSD
AS45679 on FreeBSD
 
Ceph Performance and Sizing Guide
Ceph Performance and Sizing GuideCeph Performance and Sizing Guide
Ceph Performance and Sizing Guide
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
BusyBox for Embedded Linux
BusyBox for Embedded LinuxBusyBox for Embedded Linux
BusyBox for Embedded Linux
 
Container Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis Brendan Gregg, NetflixContainer Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis Brendan Gregg, Netflix
 
UEFI時代のブートローダ
UEFI時代のブートローダUEFI時代のブートローダ
UEFI時代のブートローダ
 
Linux Networking Explained
Linux Networking ExplainedLinux Networking Explained
Linux Networking Explained
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
GNU ld的linker script簡介
GNU ld的linker script簡介GNU ld的linker script簡介
GNU ld的linker script簡介
 
SpectreとMeltdown:最近のCPUの深い話
SpectreとMeltdown:最近のCPUの深い話SpectreとMeltdown:最近のCPUの深い話
SpectreとMeltdown:最近のCPUの深い話
 

Similar to OpenWRT guide and memo

Gnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-semGnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-sem
Sagun Baijal
 
ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packages
Quintagroup
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
Ben Lin
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
Thninh2
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 

Similar to OpenWRT guide and memo (20)

[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Gnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-semGnubs-pres-foss-cdac-sem
Gnubs-pres-foss-cdac-sem
 
Gnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-semGnubs pres-foss-cdac-sem
Gnubs pres-foss-cdac-sem
 
How to make debian package from scratch (linux)
How to make debian package from scratch (linux)How to make debian package from scratch (linux)
How to make debian package from scratch (linux)
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ubl
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packages
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
 
C make cache
C make cacheC make cache
C make cache
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
PHP selber bauen
PHP selber bauenPHP selber bauen
PHP selber bauen
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
 
Autotools
AutotoolsAutotools
Autotools
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 

Recently uploaded

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
Kamal Acharya
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
AbrahamGadissa
 

Recently uploaded (20)

Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
School management system project report.pdf
School management system project report.pdfSchool management system project report.pdf
School management system project report.pdf
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 

OpenWRT guide and memo

  • 1. OpenWRT Basic tutorial guide, memo. by Antony.Wu 1
  • 2. 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. 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_bre aker
  • 4. 4 Setup OpenWRT environment Using 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. 5 Understand OpenWRT Feeds It 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>
  • 6. 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
  • 7. 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
  • 8. Create OpenWRT package • Special Makefile template. • Please refer to BuildPackage variables PKG_NAME:=broadcom-wl PKG_VERSION:=5.10.56.27.3 PKG_RELEASE:=5 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(ARCH).tar.bz2 PKG_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. Makefile patches # patches from diff src # source code 8
  • 9. 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
  • 10. 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
  • 11. Create OpenWRT package 4 • Adding configuration options • Add MENU:=1 • Add Config.in Package/<name>/config Makefile: 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 configuration Makefile: ifeq ($(CONFIG_MJPEG_STREAMER_INPUT_UVC),y) $(CP) $(PKG_BUILD_DIR)/input_uvc.so $(1)/usr/lib endif 11
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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 toolchain Target 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
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. 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