This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
openwrt_coding [2009/06/11 03:29] eric |
openwrt_coding [2013/05/21 16:12] (current) eric |
||
---|---|---|---|
Line 3: | Line 3: | ||
//Written by Eric Bishop < | //Written by Eric Bishop < | ||
- | Part I: A Simple Program In C added 8/23/2007 | + | [[openwrt_coding# |
- | Part II: C++ and the Standard Template Library (STL) added 10/10/2007 | + | [[openwrt_coding# |
- | Part III: Building and Using the Kamikaze SDK added 12/9/2007 | + | [[openwrt_coding# |
=====Tutorial Moved To New Location -- 7/ | =====Tutorial Moved To New Location -- 7/ | ||
- | I haven' | + | I haven' |
- | This tutorial now makes use of external stylesheets to fit in with the Gargoyle website theme. I realize this may make it more difficult to download and easily reference on your local computer, so I will continue to make the old version of this tutorial available. This version can be found here. | + | This tutorial now makes use of external stylesheets to fit in with the Gargoyle website theme. I realize this may make it more difficult to download and easily reference on your local computer, so I will continue to make the old version of this tutorial available. This version can be found [[http:// |
Line 22: | Line 22: | ||
- | The code for the examples in this tutorial can be downloaded from here. The example from the first part of the tutorial is in the **openwrt-programming-examples/ | + | The code for the examples in this tutorial can be downloaded from [[http:// |
=====Part I: A Simple Program in C -- 8/ | =====Part I: A Simple Program in C -- 8/ | ||
Line 51: | Line 51: | ||
helloworld: helloworld.o | helloworld: helloworld.o | ||
- | $(CC) $(LDFLAGS) helloworld.o -o helloworld helloworld.o: | + | $(CC) $(LDFLAGS) helloworld.o -o helloworld |
- | helloworld.c $(CC) $(CFLAGS) -c helloworld.c | + | |
+ | helloworld.o: | ||
+ | $(CC) $(CFLAGS) -c helloworld.c | ||
# remove object files and executable when user executes "make clean" | # remove object files and executable when user executes "make clean" | ||
Line 286: | Line 288: | ||
</ | </ | ||
- | Now, ssh into the router. We just copied the package to root's home directory so we are finally ready to install our program. In root's home directory, (where we end up immediately after connecting to the router via ssh) type "ipkg install helloworld_1_mipsel.ipk" | + | Now, ssh into the router. We just copied the package to root's home directory so we are finally ready to install our program. In root's home directory, (where we end up immediately after connecting to the router via ssh) type "ipkg install helloworld_1_mipsel.ipk" |
< | < | ||
Line 534: | Line 536: | ||
**~/ | **~/ | ||
< | < | ||
+ | ############################################## | ||
+ | # OpenWrt Makefile for helloworld program | ||
+ | # | ||
+ | # | ||
+ | # Most of the variables used here are defined in | ||
+ | # the include directives below. We just need to | ||
+ | # specify a basic description of the package, | ||
+ | # where to build our program, where to find | ||
+ | # the source files, and where to install the | ||
+ | # compiled program on the router. | ||
+ | # | ||
+ | # Be very careful of spacing in this file. | ||
+ | # Indents should be tabs, not spaces, and | ||
+ | # there should be no trailing whitespace in | ||
+ | # lines that are not commented. | ||
+ | # | ||
+ | ############################################## | ||
+ | |||
+ | include $(TOPDIR)/ | ||
+ | |||
+ | # Name and release number of this package | ||
+ | PKG_NAME: | ||
+ | PKG_RELEASE: | ||
+ | |||
+ | |||
+ | # This specifies the directory where we're going to build the program. | ||
+ | # The root build directory, $(BUILD_DIR), | ||
+ | # directory in your OpenWrt SDK directory | ||
+ | PKG_BUILD_DIR := $(BUILD_DIR)/ | ||
+ | |||
+ | |||
+ | include $(INCLUDE_DIR)/ | ||
+ | |||
+ | # Specify package information for this program. | ||
+ | # The variables defined here should be self explanatory. | ||
+ | # If you are running Kamikaze, delete the DESCRIPTION | ||
+ | # variable below and uncomment the Kamikaze define | ||
+ | # directive for the description below | ||
+ | define Package/ | ||
+ | SECTION: | ||
+ | CATEGORY: | ||
+ | TITLE: | ||
+ | DESCRIPTION: | ||
+ | If you can't figure out what this program does, \\\ | ||
+ | you' | ||
+ | medical attention. | ||
+ | endef | ||
+ | |||
+ | |||
+ | # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above | ||
+ | #define Package/ | ||
+ | # If you can't figure out what this program does, you're probably | ||
+ | # | ||
+ | #endef | ||
+ | |||
+ | |||
+ | # Specify what needs to be done to prepare for building the package. | ||
+ | # In our case, we need to copy the source files to the build directory. | ||
+ | # This is NOT the default. | ||
+ | # PKG_SOURCE which is not defined here to download the source from the web. | ||
+ | # In order to just build a simple program that we have just written, it is | ||
+ | # much easier to do it this way. | ||
+ | define Build/ | ||
+ | mkdir -p $(PKG_BUILD_DIR) | ||
+ | $(CP) ./src/* $(PKG_BUILD_DIR)/ | ||
+ | endef | ||
+ | |||
+ | |||
######################################################################################### | ######################################################################################### | ||
# The Build/ | # The Build/ | ||
Line 558: | Line 628: | ||
$(1); | $(1); | ||
endef | endef | ||
- | </ | + | |
# Specify where and how to install the program. Since we only have one file, | # Specify where and how to install the program. Since we only have one file, | ||
Line 635: | Line 705: | ||
Once again, please do **not** contact me about any issues you might have with your own programs. | Once again, please do **not** contact me about any issues you might have with your own programs. | ||
+ | |||
+ | =====PART III: Building and Using the Kamikaze SDK -- 12/ | ||
+ | |||
+ | The OpenWrt SDK for Kamikaze is available only for 64 bit processors. If you're one of us mere mortals who posesses only one of those antique 32 bit processors, you have a problem. You can sometimes get away with using the //White Russian// SDK if you only need your program to run on the MIPS architecture, | ||
+ | |||
+ | First, download the source from [[http:// | ||
+ | |||
+ | < | ||
+ | ockingbird@linuxbox: | ||
+ | mockingbird@linuxbox: | ||
+ | mockingbird@linuxbox: | ||
+ | BSDmakefile | ||
+ | Config.in | ||
+ | mockingbird@linuxbox: | ||
+ | </ | ||
+ | |||
+ | In order to specify the architecture of the router and to specify that we want to build the SDK, we need to run "make menuconfig" | ||
+ | < | ||
+ | mockingbird@linuxbox: | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Checking ' | ||
+ | Collecting target info: done | ||
+ | Collecting package info: package/ | ||
+ | Collecting package info: done | ||
+ | </ | ||
+ | |||
+ | You will see the following screen. Select the architecture of your router on the top " | ||
+ | |||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | [ ] Select all packages by default (NEW) | ||
+ | [ ] Advanced configuration options (for developers) (NEW) ---& | ||
+ | [ ] Build the OpenWrt Image Builder (NEW) | ||
+ | [*] Build the OpenWrt SDK | ||
+ | [ ] Image configuration (NEW) ---> | ||
+ | Base system | ||
+ | | ||
+ | |||
+ | < Select > < Exit > < Help > | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now, make sure you have at least 1.5 GB of disk space and a good book (I recommend [[http:// | ||
+ | |||
+ | < | ||
+ | mockingbird@linuxbox: | ||
+ | make[2] -C / | ||
+ | make[3] -C tools install | ||
+ | make[4] -C tools/sed prepare | ||
+ | make[4] -C tools/sed compile | ||
+ | make[4] -C tools/sed install | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/lzma prepare | ||
+ | make[4] -C tools/lzma compile | ||
+ | make[4] -C tools/lzma install | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[4] -C tools/ | ||
+ | make[2] -C / | ||
+ | make[3] -C toolchain install | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[4] -C toolchain/ | ||
+ | make[2] -C / | ||
+ | make[3] -C target compile | ||
+ | make[4] -C target/ | ||
+ | make[5] -C target/ | ||
+ | make[4] -C target/ | ||
+ | make[2] -C / | ||
+ | make[3] -C package compile | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/mtd compile | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ | ||
+ | make[4] -C package/ppp compile | ||
+ | make[2] -C / | ||
+ | make[3] -C package install | ||
+ | make[4] -C package install-targets | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/mtd install | ||
+ | make[5] -C package/ | ||
+ | make[5] -C package/ppp install | ||
+ | make[5] -C package/ | ||
+ | make[4] -C package preconfig | ||
+ | make[2] -C / | ||
+ | make[3] -C target install | ||
+ | make[4] -C target/ | ||
+ | make[5] -C target/ | ||
+ | make[4] -C target/ | ||
+ | make[4] -C target/ | ||
+ | make[5] -C target/ | ||
+ | make[4] -C target/sdk install | ||
+ | make[2] -C / | ||
+ | make[3] -C package index | ||
+ | mockingbird@linuxbox: | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | That's all there is to compiling the SDK The SDK tar.bz2 file is now in the bin subdirectory. You can install it just as I describe above for the White Russian SDK that can be downloaded in its compiled form. | ||
+ | |||
+ | However, if you are working with Kamikaze 7.09 (the latest as of this writing) or before, you're likely to have trouble compiling packages with your newly compiled SDK. There' | ||
+ | |||
+ | **Excerpt from ~/ | ||
+ | < | ||
+ | world: FORCE | ||
+ | $(MAKE) package/ | ||
+ | -( \ | ||
+ | cd package; \ | ||
+ | find . -maxdepth 2 -name Config.in | \ | ||
+ | sed -e ' | ||
+ | xargs -n1 $(MAKE) compile -C; \ | ||
+ | ) | ||
+ | |||
+ | </ | ||
+ | |||
+ | With this, fixed, code: | ||
+ | |||
+ | **Excerpt from ~/ | ||
+ | < | ||
+ | world: FORCE | ||
+ | $(MAKE) package/ | ||
+ | -( \ | ||
+ | cd package; \ | ||
+ | for configfile in `find . -maxdepth 2 -name Config.in` ; do \ | ||
+ | $(MAKE) compile -C `dirname $$configfile` ; \ | ||
+ | done \ | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | You should now be able to compile your code just as you did with the //White Russian// SDK. | ||
+ | |||
+ | I toyed with the idea of not reiterating, | ||
+ | |||
+ | |||
+ | This tutorial is provided under the [[http:// |