Reproduced OpenWrt Add Package method

Source: Internet
Author: User
Tags autoload

Http://blog.chinaunix.net/uid-10429687-id-3374873.html

OpenWrt is a relatively perfect embedded Linux development platform, with more than 100 software packages in wireless router applications. People can add software packages based on them to expand their scope of application. OpenWrt is extremely convenient to add software, according to the OPENWRT convention can be very simple to complete.

The added packages can be open source software or self-developed software that can be downloaded online. To add a package, you need to create a directory under the package to contain the various information about the packages and the files that are associated with OpenWrt. Then create a makefile to connect with OpenWrt, makefile need to follow the openwrt conventions. In addition, you can create a patchs to save patch files, the source code to download the appropriate amount of changes. The following is a general introduction to the basic makefile.
1. Introduction of documents
OpenWrt uses three makefile sub-files, respectively:
Include $ (topdir)/rules.mk
Include $ (include_dir)/kernel.mk
Include $ (include_dir)/package.mk
The way and method by which these makefile sub-files make sure that the software package is added to the openwrt. $ (Topdir)/rules.mk generally in makefile, $ (include_dir)/kernel.mk file is essential for the internal kernel of the software package, $ (include_dir)/ Package.mk is usually introduced after the basic information of the software package is complete.
2, write the basic information of the package, the information of these packages starts with pkg_, its meaning and function are as follows:
Pkg_name represents the package name, which will be seen in Menuconfig and ipkg.
Pkg_version represents the software version number.
Pkg_release represents the version number of the Makefile
Pkg_source represents the file name of the source code.
Pkg_source_url represents the source code for the download site location. @SF indicated on the SourceForge website, @GNU indicated on the GNU website, there are @gnome, @KERNEL. Access can be as follows: Git, svn, CVS, HG, BZR, etc. The download method can be found in $ (include_dir)/download.mk and $ (script_dir)/download.pl.
Pkg_md5sum represents the validation code for the source code file. Used to check if the package is downloaded correctly.
Pkg_cat represents the decompression method of the source code file. Including Zcat, Bzcat, unzip and so on.
Pkg_build_dir represents the package compilation directory. Its parent directory is $ (build_dir). If not specified, the default is $ (build_dir)/$ (pkg_name) $ (pkg_version).
There are some definitions of source codes.
Pkg_source_subdir
Pkg_source_proto
Pkg_source_mirror
Pkg_mirror_md5sum
Pkg_source_version

3. Compilation Package Definition
User programs and kernel modules are defined differently. Using the package with the User Software pack, the KernelPackage is used inside the core module.
3.1 User Program compilation package definition
The user program's compilation package begins with package/, then the software name, and the software name in the package definition can be different from the name of the bundle and can be defined more than once. The following uses $ (pkg_name) just to do an indication, not really using $ (pkg_name).

package/$ (Pkg_name)
Section represents the type of package, reserved.
Category is categorized and can be found under the Menuconfig menu.
Title for a short description of the software package
Description is used for a detailed description of the package and has been discarded. If you use DESCRIPTION, you'll be prompted with "error description:= is obsolete, using package/pkg_name/description".
The URL represents the download location for the package.
Maintainer represents the maintainer, option.
Depends represents a dependency on other software. This is required if you need additional software to compile or install. If there are multiple dependencies, each depends on a space. The use of the + sign before reliance indicates the implied indication that the image is not displayed at the time of the election, and that the use of @ is not shown, that is, when a dependency is chosen.
There are no autoload parameters for the internal core module in the user's software package. If the software needs to be self-running at boot time, it will need to add the corresponding foot file to the/ETC/INIT.D. The foot file requires a start argument, stating the priority at boot, and if it is closed after the boot process has been initiated, a step is required to set the stop parameters. If the stop parameters are present, the value must be greater than start. The foot file requires start () and stop () two functions, start () is the Execute program, stop () is the shutdown program. Shutting down a program generally requires a killall command. As/etc/rc.d/s10boot knows, the priority of the internal core module is 10, and the program that needs to use its own design of the inner module must be greater than 10. As is known by/etc/rc.d/s40network, a program that uses network communications must have a value of start greater than 40.

package/$ (Pkg_name)/conffiles
This package is an installed configuration file, one line at a. If the end of the file is used/, it is indicated as a record. It is used in the configuration file to illustrate that it will be used when the Sysupgrade command is executed.

package/$ (Pkg_name)/description
A detailed description of the package, replacing the description described earlier.

Build/prepare
The compilation preparation method, for the online download of the package does not need to be described. For non-web-downloaded or self-developed packages, the compilation preparation method must be described. The general preparation method is:
Define Build/prepare
Mkdir-p $ (Pkg_build_dir)
$ (CP)./src/* $ (pkg_build_dir)/
Endef
According to the habit of openwrt, generally put their own design procedures in the SRC directory.
Build/configure
It is necessary to do the./configure in Automake, so this configuration method is mainly designed for software packages that need to be configured, and the software packages that are normally developed by themselves are not described here. If you need to use this definition, refer to dropbear.

Build/compile
The compilation method, which is not specifically described, can be undefined. If you do not define the default compilation method will be used Build/compile/default
Self-developed packages can be considered using the following definitions.
Define Build/compile
$ (make)-C $ (pkg_build_dir) \
$ (target_configure_opts) cflags= "$ (target_cflags)-i$ (linux_dir)/include"
Endef

package/$ (Pkg_name)/install
The installation method of the package, including a series of copies of the compiled files to the specified location. The adjustment is a reference to a mirror file system embedded in the system, so $ (1) represents the mirrored directory of the embedded systems. You can generally use the following methods:
Define package/$ (Pkg_name)/install
$ (Install_dir) $ (1)/usr/bin
$ (Install_bin) $ (pkg_build_dir)/$ (Pkg_name) $ (1)/usr/bin/
Endef
Install_dir, Install_bin in the $ (topdir)/rules.mk file definition, so this makefile must introduce a $ (topdir)/rules.mk file.
Install_dir: =install-d-m0755 The meaning of the creation of the user can read and execute, other user can read the records can be done.
install_bin:=install-m0755 meaning good documents to mirror documents.
If the user's software is to be self-running at boot, you need to add an auto-run foot file installation and configuration file installation method to the installation method.
For example:
Define Package/mountd/install
$ (Install_dir) $ (1)/sbin/$ (1)/etc/config/$ (1)/etc/init.d/
$ (Install_bin) $ (pkg_build_dir)/mountd $ (1)/sbin/

$ (install_data)./files/mountd.config $ (1)/etc/config/mountd$ (install_bin)./files/mountd.init $ (1)/etc/init.d/mountdEndefThe installation files are placed in the files subdirectory and are not blended with source code document SRC to improve the accessibility. use clear file extensions to make it easier to install knowledge files. package/$ (pkg_name)/preinstPackage Pre-installation processing method, using scripting language, so the first line defined requires the following format#!/bin/shthe parameters of the embedded system are used to adjust the image. package/$ (pkg_name)/postinstPackage Installation post-processing method, using scripting language. package/$ (pkg_name)/prermPackage Delete pre-processing method, using scripting languagepackage/$ (pkg_name)/POSTRMPackage Removal post-processing method, using scripting language 3.2 kernel module package definition Linux is divided into kernel states and user states. The kernel part developed by the developer can be added directly to the Linux Kernel program, or a kernel module can be generated so that it needs to fashion into the kernel. OpenWrt generally want developers to generate kernel modules that are loaded automatically after Linux boot or manually using the insmod command. Kernel modules start with kernelpackage , and others are basically the same as general packages. added in kernel module definition submenu represents a submenu location, in which the /kernel.mk defines a CATEGORY of kernel modulesfor the kernel module. So the main menu of the kernel module in menuconfig is kernel modules, and then there is the next Level submenu $ (submenu). You can see the kmod-$ (pkg_name) item under the submenu. DEFAULT means directly into the kernel or generate kernel modules,y means directly into the kernel,m for generating kernel modules. the AUTOLOAD indicates that the kernel is automatically loaded and is typically represented by:

autoload:=$ (call AUTOLOAD, $ (priority), $ (autoload_mods))

the first parameter of AutoLoad is priority, which is the highest priority and the final load. For automatic loading can be seen under the /etc/modules.d directory, the second parameter $ (autoload_mods) module name, each module name is separated by a space character. Multiple kernel modules can be loaded simultaneously. in the development process, it is best not to use automatic loading, after strict testing and then use, you can reduce the workload of the experiment. 4. Definition of Useafter you have completed the previous definition, you must use the eval function to implement the various definitions. The format is:for generic packages$ (eval $ (call package,$ (Pkg_name )))or for kernel modules$ (eval $ (call kernelpackage,$ (Pkg_name )))If a software package has multiple programs, for example: An application has its own internal core module, the pkg_name used above need to be transformed. The eval function may be more than one. It can also be handled as multiple software packages.

Reproduced OpenWrt Add Package method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.