[高通] IPQ 系列 FAQ2 - 新增客製化軟件

1. 簡介


近幾年網通相關產品都以 Openwrt 為基底並整合開源碼的相關套件, 高通的 QSDK 就是一個例子. 我今天將簡單介紹以 QSDK 為基礎, 如何新增一個客製化應用程式套件, 並在該平台上執行.

2. 新增 helloworld 套件


首先我們先建立一個 helloworld 並新增 Makefile, 來測試 helloworld 應用程式是否正常

mkdir -p ait/helloworld
touch ait/helloworld/src/Makefile
touch ait/helloworld/src/helloworld.c

2.1 編輯 ait/helloworld/src/helloworld.c


簡單寫一個 Hello World 應用程式
$ vim ait/helloworld/src/helloworld.c

#include  
int main(int argc, char *argv) 
{
printf("Hello World!\r\n");
return 0; 
}

2.2 編輯 ait/helloworld/src/Makefile


透過 Makefile , 來幫助我們可以編譯 helloworld 應用程式

TARGET = helloworld

OBJS = helloworld.o

all: $(TARGET)


$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)

%.o: %.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<

install: all
install -m 755 $(TARGET) $(ROOT_FS)/bin

clean:
rm -f $(TARGET) *.o

2.3 編譯 helloworld


測試 helloworld 是否可以正常編譯

$ cd ait/ait/helloworld/src
$ make
cc -c -o helloworld.o helloworld.c
cc -o helloworld helloworld.o

$ tree

.
|-- Makefile
|-- helloworld
|-- helloworld.c
`-- helloworld.o

2.4 清除 helloworld


測試 helloworld 是否可以正常清除


$ make clean
rm -f helloworld *.o

$ tree
.
|-- Makefile
`-- helloworld.c


3. 編輯 ait/helloworld/Makefile


在可以正常編譯 helloworld 應用程式後, 接下來我們就將 helloworld 套件整合進 QSDK 裡.

3.1 新增 Makefile

我們需要在 helloworld 這個目錄下, 新增一個 Makefile 檔案, Openwrt 會根據這個 Makefile 去編譯應用程式

$ touch ait/helloworld/Makefile

3.2 編輯 Makefile


因為我們需要將 helloworld 套件整合進 Openwrt 架構, 根據 Openwrt 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
CATEGORY:=AIT Proprietary Software
TITLE:= Hello World
endef


define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Configure
endef

define Package/helloworld/description
hello world
endef

define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
AR="$(TARGET_CROSS)ar" \
LD="$(TARGET_CROSS)ld"
endef

define Package/helloworld/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/sbin
endef

$(eval $(call BuildPackage,helloworld))

4. 編輯 feeds.conf


Openwrt 會根據 feeds.conf 內容去整合相關套件, 在此, 我們需要編輯 feeds.conf. 又因為我們套件是撰寫在 ait目錄裡, 所以我們需要將 ait 做連結.

$ vim feeds.conf

...
src-link ait ../ait
...

5. 更新 feeds


在我們已經編輯完 feeds.conf 且已經針對 helloworld 套件新增 Makefile, 我們需要透過 Openwrt 來更新 feeds.

$ cd qsdk
$ ./scripts/feeds update -a
$ ./scripts/feeds install -a -f

6. menuconfig


透過 menuconfig, 將 helloworld 套件選用, 預設 feeds 更新完, 該套件是不會被啟用的.


7. 編譯 helloworld 套件


在啟用 helloworld 套件後, 我們可以簡單的透過 Openwrt 來編譯 helloworld 套件

$make package/helloworld/{clean,compile} V=s -j1

8. 測試 helloworld


在剛剛編譯完後, 我們會看見 helloworld 會被編譯在 build_dir 裡面

qsdk$ find build_dir/ -name helloworld
build_dir/target-arm_cortex-a7_musl-1.1.16_eabi/helloworld
build_dir/target-arm_cortex-a7_musl-1.1.16_eabi/helloworld/ipkg-ipq/helloworld
build_dir/target-arm_cortex-a7_musl-1.1.16_eabi/helloworld/ipkg-ipq/helloworld/usr/sbin/helloworld
build_dir/target-arm_cortex-a7_musl-1.1.16_eabi/helloworld/helloworld


我們將 helloworld 應用程式, 透過 tftp 方式, 將該應用程式放到 DUT 上執行

root@OpenWrt:/tmp# tftp -r helloworld 192.168.0.230 -g
root@OpenWrt:/tmp# chmod +x helloworld
root@OpenWrt:/tmp# ./helloworld
Hello World!

9. 結論


根據以上的方式, 我們已經可以快速的新增客製化套件到 QSDK 裡面. 希望這篇文章能夠幫助您.

10. 參考


1. 新增軟件

★博文內容均由個人提供,與平台無關,如有違法或侵權,請與網站管理員聯繫。

★文明上網,請理性發言。內容一周內被舉報5次,發文人進小黑屋喔~

評論