Openwrt Compiling Add Module package

Source: Internet
Author: User

3. Add a Module

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. Building the 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 create a new src folder under the Helloword folder.

3.2. Write the HelloWorld program in the SRC directory

In the SRC directory, write the 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 the makefile file in the SRC directory, note the makefile file format, especially tab tab indent

Helloworld:helloworld.o<span style= "White-space:pre" ></span>$ (CC) $ (ldflags) Helloworld.o-o Helloworldhelloworld.o:helloworld.c<span style= "White-space:pre" ></span>$ (CC) $ (CFLAGS)-C Helloworld.cclean:<span style= "White-space:pre" ></span>rm *.o HelloWorld


3.3. Create the makefile file in the HelloWorld directory

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

############################################## #OpenWrt Makefile for HelloWorld program### mostof the variables used Here is defined in# theinclude directives below. We just need to#specify a basic description of the package, #where to build our program, where to find# thesource files, an D Where to install the#compiled program on the router.## bevery careful of spacing in this file. #Indents should be tabs, n OT spaces, And#there should is no trailing whitespace in#lines that is not commented.#################################### ########## #include $ (topdir)/rules.mk# Nameand release number of this packagepkg_name:=helloworldpkg_release:=1# Thisspecifies the directory where we ' re going to build the program.# theroot build directory, $ (Build_dir), was by default The build_mipsel#directory in your OpenWrt SDK directorypkg_build_dir:= $ (build_dir)/$ (pkg_name) include$ (Include_dir) /package.mk#specify Package Information-program.# thevariables defined here should being self explanatory.# IfyOU is running kamikaze, delete the description#variable below and uncomment the kamikaze define#directive for the Descrip tion belowdefinepackage/helloworldsection:=utilscategory:=utilitiestitle:=helloworld--Prints a snarky messageendef #Uncomment portion below for kamikaze and delete DESCRIPTION variable abovedefinepackage/helloworld/descriptionif Youcan ' t figure out what the This program does, you ' re probablybrain-deadand need immediate medical attention.endef#specify WH At needs-to-be-done-prepare for building the package.# Inour case, we need-copy the source files to the build direct ory.# Thisis not the default. The default uses the Pkg_source_url and The#pkg_source which is not defined here to download the SOURCE from the web.# Ino Rder to just build a simple program that we had just written, it is# Mucheasier to does it this way.definebuild/prepare< Span style= "White-space:pre" ></span>mkdir-p $ (pkg_build_dir) <span style= "White-space:pre" ></ span>$ (CP)./src/* $ (Pkg_build_dir)/endef# Wedo not need to define build/configure or Build/compile directives# thedefaults is appropriate For compiling a, such as this one#specify where and what to install the program. Since we only has one file,# thehelloworld executable, install it by 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 exist. Likewise $ (install_bin) contains the#command to copy the binary file from their current location (the Build#dire Ctory) 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, tap make Menuconfig

Select Utilities


You can see the HelloWorld in the utilities and select the module to compile the Helloword module into the firmware.


After make recompile the firmware in the trunk directory

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

It may also be recorded in Bin/[yourtarget]/package's subdirectory. Can be obtained through find. –name hello* command to find the compiled module HelloWorld.


Openwrt Compiling Add Module package

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.