RBMTX-Lite OpenWrt SDK Exmaple: Różnice pomiędzy wersjami
Z Elproma Wiki Knowledge Base
| Linia 23: | Linia 23: | ||
In this example we are going to show you how to generate OpenWrt package base on the simple Modbus client and server application. | In this example we are going to show you how to generate OpenWrt package base on the simple Modbus client and server application. | ||
<ol> | |||
<li> To create custom package, when you are in the SDK directory go to the package directory. | |||
<pre>cd package</pre></li> | |||
<li>Make new directory where the package Makefile should be placed. | |||
<pre> mkdir modbus_server | |||
cd modbus_server</pre></li> | |||
<li>Create the Makfile file to build your custom package. Exmaple Makefile shown below.</li> | |||
<pre>include $(TOPDIR)/rules.mk | |||
# Name, version and release number | |||
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR) | |||
PKG_NAME:=helloworld | |||
PKG_VERSION:=1.0 | |||
PKG_RELEASE:=1 | |||
# Source settings (i.e. where to find the source codes) | |||
# This is a custom variable, used below | |||
SOURCE_DIR:=/home/build/helloworld | |||
include $(INCLUDE_DIR)/package.mk | |||
# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig') | |||
define Package/helloworld | |||
SECTION:=examples | |||
CATEGORY:=Examples | |||
TITLE:=Hello, World! | |||
endef | |||
# Package description; a more verbose description on what our package does | |||
define Package/helloworld/description | |||
A simple "Hello, world!" -application. | |||
endef | |||
# Package preparation instructions; create the build directory and copy the source code. | |||
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system. | |||
define Build/Prepare | |||
mkdir -p $(PKG_BUILD_DIR) | |||
cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR) | |||
$(Build/Patch) | |||
endef | |||
# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable | |||
define Build/Compile | |||
$(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c | |||
$(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o | |||
endef | |||
# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder | |||
define Package/helloworld/install | |||
$(INSTALL_DIR) $(1)/usr/bin | |||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin | |||
endef | |||
# This command is always the last, it uses the definitions and variables we give above in order to get the job done | |||
$(eval $(call BuildPackage,helloworld))</pre> | |||
Wersja z 13:18, 19 kwi 2023
Prerequisites
You will need:
- A PC, laptop or virtual machine running Linux OS (preferably Ubuntu distro)
- An SDK intended for your router, which can be downloaded here: Software Development Kit
Preparation
- Create directory, where the SDK will be extrated e.g RBMTX_SDK.
- Open terminal in created folder and unpack SDK.
tar -xf ~/Downloads/rbmtx3-owrt-sdk-....Linux-x86_64.tar.xz
- Go to the SDK directory.
cd rbmtx3-owrt-sdk-22.10.14-rbmtx3_gcc-8.4.0_musl_eabi.Linux-x86_64/
- Update the feeds.
./scripts/feeds update -a
Compiling a custom package
In this example we are going to show you how to generate OpenWrt package base on the simple Modbus client and server application.
- To create custom package, when you are in the SDK directory go to the package directory.
cd package
- Make new directory where the package Makefile should be placed.
mkdir modbus_server cd modbus_server
- Create the Makfile file to build your custom package. Exmaple Makefile shown below.
include $(TOPDIR)/rules.mk
# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=1
# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
SOURCE_DIR:=/home/build/helloworld
include $(INCLUDE_DIR)/package.mk
# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/helloworld
SECTION:=examples
CATEGORY:=Examples
TITLE:=Hello, World!
endef
# Package description; a more verbose description on what our package does
define Package/helloworld/description
A simple "Hello, world!" -application.
endef
# Package preparation instructions; create the build directory and copy the source code.
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
$(Build/Patch)
endef
# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
$(TARGET_CC) $(TARGET_CFLAGS) -o $(PKG_BUILD_DIR)/helloworld.o -c $(PKG_BUILD_DIR)/helloworld.c
$(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$1 $(PKG_BUILD_DIR)/helloworld.o
endef
# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
endef
# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,helloworld))