Openwrt SDK
SDK) Software Development Kit) This term is believed to be familiar to everyone. So what is the use of Openwrt SDK? Why use SDK? Generally, we use the SDK to develop application layer programs. The SDK builds a complete compilation environment for us. As long as we use the SDK corresponding to the platform, we do n’t need to know what his hardware is. Generate .ipk file after compilation and install it on Openwrt. Just like the programmer who developed the Android APP, he uses Google's integrated development environment, android studio, without having to worry about what type of mobile phone and hardware you use.
The following is a brief introduction to the acquisition and use of Openwrt SDK, etc.
1. Obtaining Openwrt SDK
There are two ways to obtain the SDK:
1. Go to the official website to download the SDK for the corresponding platform
For example, miwifi uses the mt7620 master control of mips, then we can download the SDK at https://downloads.openwrt.org/chaos_calmer/15.05/ramips/mt7620/OpenWrt-SDK-15.05-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
.
If you need other SDKs, you can also download them at https://downloads.openwrt.org/ .
2. Generate the corresponding SDK through Openwrt source project compilation
If we have cloned the openwrt15.05 project, then when we make configuration in make menuconfig, select the Build the OpenWrt SDK
options as follows:
After recompiling with make V = 99, we can find an OpenWrt-SDK-15.05-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
additional SDK in the bin / ramips directory , which is actually the same as what we downloaded above.
3. Comparison of Openwrt source project and Openwrt SDK
We make a simple comparison between the source project of Openwrt and the produced SDK. After we decompress the generated SDK, we can compile directly through make V = 99, and it only takes a few seconds to compile. Why is it so fast?
We check that its framework is basically consistent with the source code, as follows:
But we found that there is no feeds expansion package in the SDK, and there are no software packages under dl and package. Entering the build_dir or target folder, there is nothing to see next. It turns out that the SDK will cancel all programs that are not related to the platform, leaving only the tools and platform-related code required for compilation. Use du -sh to check the size. It only occupies a few hundred M, but the source project has several G. This is undoubtedly a lot more convenient for non-embedded engineers who only open applications.
2. Use Openwrt SDK to add applications
Now that we have the SDK, we will try to start adding software packages to the SDK.
Here is the simplest Helloworld as an example
First create the folder helloworld under the package, then add the source code and Makefile, the overall tree is as follows:
/openwrt/package/helloworld$ tree
.
├── Makefile
└── src
├── helloworld.c
└── Makefile
The code for each file is listed below
1.Main Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=helloworld
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Helloworld -- prints a snarky message
endef
define Package/helloworld/description
It's my first package demo.
endef
define Build/Prepare
echo "Here is Package/Prepare"
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/helloworld/install
echo "Here is Package/install"
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef
$(eval $(call BuildPackage,helloworld))
2.helloworld.c
#include <stdio.h>
int main()
{
printf("This is my hello word!\n");
return 0;
}
3.Makefile
helloworld : helloworld.o
$(CC) $(LDFLAGS) helloworld.o -o helloworld
helloworld.o : helloworld.c
$(CC) $(CFLAGS) -c helloworld.c
clean :
rm *.o helloworld
After writing the code, find the location of helloworld through make menuconfig. The location of helloworld is defined in the main Makefile CATEGORY:=Utilities
, as follows:
make V=99
Just compile, the main Makefile defines the location $(INSTALL_DIR) $(1)/bin
where the helloworld executable file is installed after compilation in the bin folder.
:~/openwrt/openwrt-15.05/OpenWrt-SDK/bin/ramips/packages/base$ ls
helloworld_1_ramips_24kec.ipk Packages Packages.gz
Transfer the ipk to Openwrt via tftp, and then opkg install helloworld_1_ramips_24kec.ipk
install it on consloe. After installation, there will be an additional helloworld executable file in the / bin / folder.