Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1742027
  • 博文数量: 782
  • 博客积分: 2455
  • 博客等级: 大尉
  • 技术积分: 4140
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-06 21:37
个人简介

Linux ,c/c++, web,前端,php,js

文章分类

全部博文(782)

文章存档

2015年(8)

2014年(28)

2013年(110)

2012年(307)

2011年(329)

分类:

2013-01-06 20:59:04

原文地址:openwrt结构分析 作者:Jiker4836

Download OpenWrt
$ svn checkout kamikaze
 
The directory structure
四个关键性的目录:
• tools
• toolchain
• package
• target
tools和toolchain通常是用作固化内核,编译和c库的工具,编译的结果会产生三个新的目录,build_dir/host ,这是一个临时用来建立target工具;
build/toolchain-*这是用来建立特殊结构的toolchain;
staging_dir/toolchain-*toolchain安装的目录;
如果你不需要增加新版本的原件就不需要对toolchain目录进行修改。
 
package is for exactly that – packages. In an OpenWrt firmware, almost everything
is an .ipk, a software package which can be added to the firmware
to provide new features or removed to save space. Note that packages are also
maintained outside of the main trunk and can be obtained from subversion using
the package feeds system:
 
$ ./scripts/feeds update -a
$ ./scripts/feeds install -a
target refers to the embedded platform, this contains items which are specific to
a specific embedded platform. Of particular interest here is the ”target/linux”
directory which is broken down by platform and contains the patches to
the kernel, profile config, for a particular platform. There’s also the ”target/image”
directory which describes how to package a firmware for a specific platform.
Both the target and package steps will use the directory ”build_dir/
as a temporary directory for compiling. Additionally, anything downloaded by
the toolchain, target or package steps will be placed in the ”dl” directory.
 

$make defconfig

$make prereq

$make menuconfig

Running the command ”make menuconfig” will bring up OpenWrt’s configuration
menu screen, through this menu you can select which platform you’re
targeting, which versions of the toolchain you want to use to build and what
packages you want to install into the firmware image. Note that it will also
check to make sure you have the basic dependencies for it to run correctly. If
that fails, you will need to install some more tools in your local environment
before you can begin.
 
If you want, you can also modify the kernel config for the selected target system.
simply run ”make kernel_menuconfig” and the build system will unpack
the kernel sources (if necessary), run menuconfig inside of the kernel tree, and
then copy the kernel config to target/linux/ /config so that it is
preserved over ”make clean” calls.
 
$make
To begin compiling the firmware, type ”make”. By default OpenWrt will only
display a high level overview of the compile process and not each individual
command.To see the full output, run the command ”make V=99”.
 
During the build process, buildroot will download all sources to the ”dl” directory
and will start patching and compiling them in the ”build_dir/
directory. When finished, the resulting firmware will be in the ”bin” directory
and packages will be in the ”bin/packages” directory.
 
Creating packages
打开一个典型的openwrt中package目录下都能发现两个相同点:
• package/ /Makefile
• package/ /patches
• package/ /files
 
The patches directory is optional and typically contains bug fixes or optimizations
to reduce the size of the executable. The package makefile is the important
item, provides the steps actually needed to download and compile the package.
The files directory is also optional and typicall contains package specific startup
scripts or default configuration files that can be used out of the box with Open-
Wrt.
 
  1. # $Id: Makefile 5624 2006-11-23 00:29:07Z nbd $
  2. 2
  3. 3 include $(TOPDIR)/rules.mk
  4. 4
  5. 5 PKG_NAME:=bridge
  6. 6 PKG_VERSION:=1.0.6
  7. 7 PKG_RELEASE:=1
  8. 8
  9. 9 PKG_SOURCE:=bridge-utils-$(PKG_VERSION).tar.gz
  10. 10 PKG_SOURCE_URL:=@SF/bridge
  11. 11 PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd
  12. 12 PKG_CAT:=zcat
  13. 13
  14. 14 PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION)
  15. 15
  16. 16 include $(INCLUDE_DIR)/package.mk
  17. 17
  18. 18 define Package/bridge
  19. 19 SECTION:=net
  20. 20 CATEGORY:=Base system
  21. 21 TITLE:=Ethernet bridging configuration utility
  22. 22 URL:=
  23. 23 endef
  24. 24
  25. 25 define Package/bridge/description
  26. 26 Manage ethernet bridging:
  27. 27 a way to connect networks together to form a larger network.
  28. 28 endef
  29. 29
  30. 30 define Build/Configure
  31. 31 $(call Build/Configure/Default, \
  32. 32 --with-linux-headers="$(LINUX_DIR)" \
  33. 33 )
  34. 34 endef
  35. 35
  36. 36 define Package/bridge/install
  37. $(INSTALL_DIR) $(1)/usr/sbin
  38. 38 $(INSTALL_BIN) $(PKG_BUILD_DIR)/brctl/brctl $(1)/usr/sbin/
  39. 39 endef
  40. 40
  41. 41 $(eval $(call BuildPackage,bridge))
• PKG_NAME
The name of the package, as seen via menuconfig and ipkg
• PKG_VERSION
The upstream version number that we are downloading
• PKG_RELEASE
The version of this package Makefile
• PKG_SOURCE
The filename of the original sources
• PKG_SOURCE_URL
Where to download the sources from (no trailing slash), you can add
multiple download sources by separating them with a
and a carriage return.
• PKG_MD5SUM
A checksum to validate the download
• PKG_CAT
How to decompress the sources (zcat, bzcat, unzip)
• PKG_BUILD_DIR
Where to compile the package
 
The PKG_* variables define where to download the package from; @SF is a special
keyword for downloading packages from sourceforge. There is also another keyword
of @GNU for grabbing GNU source releases. If any of the above mentionned
download source fails, the OpenWrt mirrors will be used as source.
 
MD5sum用来验证下载到包是否正确,PKG_BUILD_DIR用来定义下载资源后放在哪个目录,把未压缩的source放在$(BUILD_DIR)目录中。
BuildPackage uses the following defines:
Package/:
matches the argument passed to buildroot, this describes the package
the menuconfig and ipkg entries. Within Package/ you can define the
following variables:
• SECTION
The type of package (currently unused)
• CATEGORY
Which menu it appears in menuconfig: Network, Sound, Utilities, Multimedia
...
• TITLE
A short description of the package
• URL
Where to find the original software
• MAINTAINER (optional)
Who to contact concerning the package
• DEPENDS (optional)
Which packages must be built/installed before this package. To reference
a dependency defined in the same Makefile, use . If
defined as an external package, use +. For a kernel
version dependency use: @LINUX 2
 
Package//conffiles (optional):
A list of config files installed by this package, one file per line.
Build/Prepare (optional):
A set of commands to unpack and patch the sources. You may safely leave this
undefined.
Build/Configure (optional):
You can leave this undefined if the source doesn’t use configure or has a normal
config script, otherwise you can put your own commands here or use ”$(call
Build/Configure/Default, )”as
above to pass in additional arguments for a standard configure script. The first
list of arguments will be passed to the configure script like that: -arg 1 -arg
2. The second list contains arguments that should be defined before running
the configure script such as autoconf or compiler specific variables.
To make it easier to modify the configure command line, you can either extend
or completely override the following variables:
• CONFIGURE_ARGS
Contains all command line arguments (format: -arg 1 -arg 2)
• CONFIGURE_VARS
Contains all environment variables that are passed to ./configure (format:
NAME="value")
Build/Compile (optional):
How to compile the source; in most cases you should leave this undefined.
As with Build/Configure there are two variables that allow you to override
the make command line environment variables and flags:
• MAKE_FLAGS
Contains all command line arguments (typically variable overrides like
NAME="value"
• MAKE_VARS
Contains all environment variables that are passed to the make command
Build/InstallDev (optional):
If your package provides a library that needs to be made available to other packages,
you can use the Build/InstallDev template to copy it into the staging
directory which is used to collect all files that other packages might depend on
at build time. When it is called by the build system, two parameters are passed
to it. $(1) points to the regular staging dir, typically staging_dir/ARCH , while
$(2) points to staging_dir/host. The host staging dir is only used for binaries,
which are to be executed or linked against on the host and its bin/ subdirectory
is included in the PATH which is passed down to the build system processes.
Please use $(1) and $(2) here instead of the build system variables $(STAGING_
DIR) and $(STAGING_DIR_HOST), because the build system behavior when
staging libraries might change in the future to include automatic uninstallation.
Package//install:
A set of commands to copy files out of the compiled source and into the ipkg
which is represented by the $(1) directory. Note that there are currently 4
defined install macros:
• INSTALL_DIR
install -d -m0755
• INSTALL_BIN
install -m0755
• INSTALL_DATA
install -m0644
• INSTALL_CONF
install -m0600
The reason that some of the defines are prefixed by ”Package/ ” and
others are simply ”Build” is because of the possibility of generating multiple
packages from a single source. OpenWrt works under the assumption of one
source per package Makefile, but you can split that source into as many packages
as desired. Since you only need to compile the sources once, there’s one global
set of ”Build” defines, but you can add as many ”Package/” defines as
you want by adding extra calls to BuildPackage – see the dropbear package for
an example.
After you have created your package/ /Makefile, the new package will
automatically show in the menu the next time you run ”make menuconfig” and
if selected will be built automatically the next time ”make” is run.
 
 
阅读(781) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~