RBMTX-Lite OpenWrt SDK Exmaple: Różnice pomiędzy wersjami

Z Elproma Wiki Knowledge Base
Skocz do: nawigacja, szukaj
 
(Nie pokazano 32 wersji utworzonych przez 4 użytkowników)
Linia 6: Linia 6:


<ul>
<ul>
     <li>A PC, laptop or virtual machine running Linux OS (preferably Ubuntu distro)</li>
     <li>A PC, laptop or virtual machine running Linux OS (preferably Debian/Ubuntu distro)</li>
     <li>An SDK intended for your router, which can be downloaded here: <b>[[Software Development Kit]]</b></li>
     <li>An SDK intended for your router, which can be downloaded here: <b>[[Software Development Kit]]</b></li>
</ul>
</ul>


==Preparation==
==Preparation==
#Create directory, where the SDK will be extrated e.g RBMTX_SDK.
#Create a directory where the SDK will be extracted, e.g. RBMTX_SDK.
#Open terminal in created folder and unpack SDK.
#Open a terminal in the folder you created and unzip the SDK.
  tar -xf ~/Downloads/rbmtx3-owrt-sdk-....Linux-x86_64.tar.xz
  tar -xf ~/Downloads/rbmtx3-owrt-sdk-....Linux-x86_64.tar.xz
#<li value="3"> Go to the SDK directory.
#<li value="3"> Go to the SDK directory.
  cd rbmtx3-owrt-sdk-22.10.14-rbmtx3_gcc-8.4.0_musl_eabi.Linux-x86_64/
  cd rbmtx3-owrt-sdk-.....Linux-x86_64/
#<li value="4"> Update the feeds.
#<li value="4"> Update the feeds.
  ./scripts/feeds update -a
  ./scripts/feeds update -a


==Compiling a custom package==
==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.
In this example, we are going to show you how to generate OpenWrt package based on the simple Modbus client and server application.
<ol>
<ol>
<li> To create custom package, when you are in the SDK directory go to the package directory.
 
<li> Install dependency library (in this example, it is '''libmodbus'''). To install library run:
<pre>./scripts/feeds install libmodbus</pre></li>
 
<li> To create your custom package, when you are in the SDK directory go to the package directory.
<pre>cd package</pre></li>
<pre>cd package</pre></li>
<li>Make new directory where the package Makefile should be placed.
 
<li>Make a new directory where the package Makefile should be placed.
  <pre> mkdir modbus_server
  <pre> mkdir modbus_server
  cd modbus_server</pre></li>
  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
<li>
define Package/helloworld/description
Create the Makefile file to build your custom package. Example Makefile is shown below.
  A simple "Hello, world!" -application.
* It is important to change all '''modbus_server''' strings with your package name.
endef
* In the '''SOURCE_DIR''' section add path to your package sources.
* If you are using external library, it is important to complete the dependency sections e.g.:
<pre>TARGET_LDFLAGS=-lmodbus
DEPENDS:= +libmodbus
PKG_BUILD_DEPENDS+= libs/libmodbus</pre>
[[Plik:MakefileNew.png|800px|border|class=tlt-border]]
</li>


# Package preparation instructions; create the build directory and copy the source code.
<li>Now we are ready to select the packages and libraries which we want to compile. Return to the SDK root directory and execute the command: <pre> make menuconfig</pre>
# 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
You should see a view like the one below.
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
[[Plik:RBMTX-Lite Menuconfig.png|800px|border|class=tlt-border]]
define Package/helloworld/install
</li>
$(INSTALL_DIR) $(1)/usr/bin
<li>Then turn off the ''' Cryptographically sign package lists''' option in  the '''Global build settings'''
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin
<br>
endef
[[Plik:Turn_off_cryptograpy.png |800px|border|class=tlt-border]]
<br>
</li>
<li> Then go to the '''Libraries''' section and make sure the libraries you want to use are checked.
<br>
[[Plik:RBMTX-Lite Libraries.png|800px|border|class=tlt-border]]
<br>
</li>
<li>Next, go to the section where you placed the package to compilation. The name of section depends on the name that was placed in the '''CATEGORY:''' option in the package's Makefile. In our case it is '''Example''' section. Make sure your custom package is checked.
<br>
[[Plik:RBMTX-Lite Cutom Package.png|800px|border|class=tlt-border]]
<br>
</li>
<li>At the end, save all settings - leave the default name of the configuration. </li>
<li>Exit the menuconfig.</li>
<li>Now, we are ready to compile our custom package. Type command '''make''' in the terminal and wait for compilation to finish.
You should see the output like the one below:
<br>
[[Plik:RBMTX-Lite Compilation Output.png|800px|border|class=tlt-border]]
<br>
</li>
<li>Once the compilation process is complete, the package can be found in the '''bin/packages/arm_cortex-a7_neon/base''' directory.
<pre>cd bin/packages/arm_cortex-a7_neon/base</pre>
<br>
[[Plik:RBMTX-Lite Packages.png|600px|border|class=tlt-border]]
<br>
</li>
</ol>


# This command is always the last, it uses the definitions and variables we give above in order to get the job done
[[Category:RBMTX-Lite]]
$(eval $(call BuildPackage,helloworld))</pre>

Aktualna wersja na dzień 15:09, 27 kwi 2023

Prerequisites

You will need:

  • A PC, laptop or virtual machine running Linux OS (preferably Debian/Ubuntu distro)
  • An SDK intended for your router, which can be downloaded here: Software Development Kit

Preparation

  1. Create a directory where the SDK will be extracted, e.g. RBMTX_SDK.
  2. Open a terminal in the folder you created and unzip the SDK.
tar -xf ~/Downloads/rbmtx3-owrt-sdk-....Linux-x86_64.tar.xz
  1. Go to the SDK directory.
cd rbmtx3-owrt-sdk-.....Linux-x86_64/
  1. 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 based on the simple Modbus client and server application.

  1. Install dependency library (in this example, it is libmodbus). To install library run:
    ./scripts/feeds install libmodbus
  2. To create your custom package, when you are in the SDK directory go to the package directory.
    cd package
  3. Make a new directory where the package Makefile should be placed.
     mkdir modbus_server
     cd modbus_server
  4. Create the Makefile file to build your custom package. Example Makefile is shown below.
    • It is important to change all modbus_server strings with your package name.
    • In the SOURCE_DIR section add path to your package sources.
    • If you are using external library, it is important to complete the dependency sections e.g.:
    TARGET_LDFLAGS=-lmodbus
    DEPENDS:= +libmodbus
    PKG_BUILD_DEPENDS+= libs/libmodbus

    MakefileNew.png

  5. Now we are ready to select the packages and libraries which we want to compile. Return to the SDK root directory and execute the command:
     make menuconfig

    You should see a view like the one below.

    RBMTX-Lite Menuconfig.png

  6. Then turn off the Cryptographically sign package lists option in the Global build settings
    Turn off cryptograpy.png
  7. Then go to the Libraries section and make sure the libraries you want to use are checked.
    RBMTX-Lite Libraries.png
  8. Next, go to the section where you placed the package to compilation. The name of section depends on the name that was placed in the CATEGORY: option in the package's Makefile. In our case it is Example section. Make sure your custom package is checked.
    RBMTX-Lite Cutom Package.png
  9. At the end, save all settings - leave the default name of the configuration.
  10. Exit the menuconfig.
  11. Now, we are ready to compile our custom package. Type command make in the terminal and wait for compilation to finish. You should see the output like the one below:
    RBMTX-Lite Compilation Output.png
  12. Once the compilation process is complete, the package can be found in the bin/packages/arm_cortex-a7_neon/base directory.
    cd bin/packages/arm_cortex-a7_neon/base


    RBMTX-Lite Packages.png