OpenWrt Compile Add Module package__openwrt

Source: Internet
Author: User
Tags prepare

3. Add Modules

In general we need to build our own module (package), when compiling the firmware can choose whether to compile their own modules into the firmware. 3.1. Establishment of package

The final Helloword file directory structure is:

helloword/
├──makefile
└──src
   ├──helloworld.c
   └──makefile


Create a new Helloword folder under the./openwrt/trunk/package/utils/directory.

Then under the Helloword folder, create a new src folder. 3.2. Write the HelloWorld program under the SRC directory

In the SRC directory, write HELLOWORLD.C

#include <stdio.h>
int main (void)
{
<span style= "White-space:pre" >	</span> printf ("helloworld\n");
<span style= "White-space:pre" >	</span>return 0;
}



Write makefile file in src directory, note makefile file format, especially tab tab indent

HELLOWORLD:HELLOWORLD.O
<span style= "White-space:pre" >	</span>$ (CC) $ (ldflags) Helloworld.o-o HelloWorld
helloworld.o:helloworld.c
<span style= "White-space:pre" >	</span>$ (CC) $ ( Cflags)-C helloworld.c Clean
:
<span style= "White-space:pre" >	</span>rm *.o HelloWorld


3.3. Create makefile files in the HelloWorld directory

This makefile file is read to OpenWrt, and the makefile file that was previously written is read to the HelloWorld for compilation. Two makefile are not in the same level directory. Note the makefile file format, especially the Tab tab indent

############################################## #OpenWrt Makefile for HelloWorld, mostof variables used he Re are defined in # Theinclude directives below.  We just need to #specify a basic description of the package, and #where to builds our program, where to find # thesource files,
And where to install the #compiled program on the router.
# # Bevery Careful of spacing in this file.
#Indents should is tabs, not spaces, and #there should is no trailing whitespace in #lines that are not commented. # ############################################## include$ (topdir)/RULES.MK # Nameand Release number of this package PKG_
Name:=helloworld pkg_release:=1 # thisspecifies The directory where we ' re going to build the program. # Theroot Build directory, $ (build_dir), are by default the Build_mipsel #directory in your openwrt SDK directory Pkg_build
_dir:= $ (Build_dir)/$ (pkg_name) include$ (include_dir)/package.mk #Specify Package information for this program. # Thevariables defined here shOuld be self explanatory. # Ifyou are running kamikaze, delete the DESCRIPTION #variable below and uncomment the kamikaze define #directive for the Description below Definepackage/helloworld section:=utils category:=utilities title:=helloworld--a prints Message endef #Uncomment portion below for kamikaze and delete DESCRIPTION variable above
ption If youcan ' t figure out what this program does, for you ' re probably brain-deadand, need, immediate, medical.
Endef #Specify What needs to being done to prepare for building the package.
# Inour case, we are need to copy the source files to the ' build directory. # Thisis not the default.
The default uses the Pkg_source_url and the #PKG_SOURCE which is not defined this SOURCE from the Web.
# inorder to just builds a simple program that we have just written, it's # Mucheasier to does it this way. Definebuild/prepare <span style= "White-space:pre" > </span>mkdir-p $ (pkg_build_dir) &LT;SPAn style= "White-space:pre" > </span>$ (CP)./src/* $ (pkg_build_dir)/Endef # Wedo No need to define Build/configu Re or build/compile directives # Thedefaults are appropriate for compiling a simple program such as this one #Specify whe Re and how to install the program. Since we only have one file, # Thehelloworld executable, install it through copying it to The/bin directory on # therouter. The $ (1) variable represents the root directory on the router running #OpenWrt. The $ (INSTALL_DIR) variable contains a command to prepare the INSTALL #directory if it does not already. Likewise $ (install_bin) contains the #command to copy of the binary file from their current location
Rectory) to the install directory. Definepackage/helloworld/install <span style= "White-space:pre" > </span>$ (INSTALL_DIR) $ (1)/bin <span style= "White-space:pre" > </span>$ (Install_bin) $ (pkg_build_dir)/helloworld $ (1)/bin/endef $ (eval$ (call Buildpackage,helloworld)) 



3.4 HelloWorld Module

In the trunk directory, knock make Menuconfig

Select Utilities


Select the utilities to see HelloWorld, and select the module to compile the Helloword module into the firmware.


After make recompile firmware in the trunk directory

The results of the compilation are placed in the Bin/[yourtarget]/package directory HELLOWORLD_1_XX.IPK,

may also be recorded in the Bin/[yourtarget]/package. Can be done by find. –name hello* command to find the compiled module HelloWorld.

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.