Openwrt:如何将bin文件打包到ipk包中?

时间:2018-12-07 02:47:23

标签: openwrt

我已经编译了openwrt源代码并在我的设备(HC5661)上运行它。然后我使用Eclipse IDE编写了一个helloword.cpp(示例,任何其他名称),helloword.bin是通过编译成功生成并在上面调试的目标设备使用sftp和gdb。现在,我想将helloword编译为ipk包。如何将bin文件打包为ipk包?

2 个答案:

答案 0 :(得分:1)

您必须使用SDK。您可以按照以下步骤操作:

1)下载OpenWrt-SDK

2)在OpenWrt-SDK文件夹中运行./scripts/feeds/update -a && ./scripts/feeds/install -a

3)在路径helloworld

中创建一个名为OpenWrt-SDK/feeds/packages/utils/的文件夹。

4)在此文件夹中,创建一个名为Makefile的文件和一个名为src的新文件夹。

5)在src文件夹中放入helloworld.cppMakefile,以便进行编译。

6)您在文件夹Makefile中的OpenWrt-SDK/scripts/feeds/packages/utils/如下所示:

include $(TOPDIR)/rules.mk

# Name and release number of this package
PKG_NAME:=helloworld
PKG_VERSION:=1.0
PKG_RELEASE:=0

# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/uclibc++.mk
include $(INCLUDE_DIR)/package.mk


# Specify package information for this program.
# The variables defined here should be self explanatory.

define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=helloworld exampke
endef

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


TARGET_CFLAGS += \
    -I$(STAGING_DIR)/usr/include \
    -D_GNU_SOURCE \
    -ggdb3

MAKE_FLAGS += \
    CFLAGS="$(TARGET_CFLAGS)" \
    LDFLAGS="$(TARGET_LDFLAGS)"

define Build/Compile
    $(call Build/Compile/Default, \
        CCOPTS="$(TARGET_CFLAGS)" \
        INCLUDE="$(EXTRA_CFLAGS)" \
        LDFLAGS="$(EXTRA_LDFLAGS)" \
    )
endef


define Package/helloworld/install
    $(INSTALL_DIR) $(1)/bin
    $(CP) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/bin/
endef


# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))

7)在OpenWrt-SDK文件夹中运行./scripts/feeds update -i && ./scripts/feeds install helloworld

8)在同一文件夹中运行make package/helloworld/compile

9)您可以在.ipk中找到您的OpenWrt-SDK/bin/ar71xx/packages/packages/

PS:您可能需要通过键入(Ubuntu)ccache来安装sudo apt-get install ccache。您不能使用空格键入makefile,而必须使用制表符。

答案 1 :(得分:0)

如果您已经拥有hello.bin,则可以将其放入hello / src和:

makefile(hello /):

include $(TOPDIR)/rules.mk

PKG_NAME:=hello
PKG_VERSION:=1.0

include $(INCLUDE_DIR)/package.mk

define Package/hello
  CATEGORY:=Examples
  TITLE:=hello
  DEPENDS:=+libstdcpp
endef

define Package/hello/description
  hello world
endef

define Package/hello/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) ./src/hello $(1)/usr/bin

endef

$(eval $(call BuildPackage,hello))

makefile(hello / src):

all:hello

如果没有,则应将hello.cpp放入hello / src中,然后:

makefile(hello /):

include $(TOPDIR)/rules.mk

PKG_NAME:=hello
PKG_VERSION:=1.0

include $(INCLUDE_DIR)/package.mk

define Package/hello
  CATEGORY:=Examples
  TITLE:=hello
  DEPENDS:=+libstdcpp
endef

define Package/hello/description
  hello world
endef

define Package/hello/install
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/hello $(1)/usr/bin

endef

$(eval $(call BuildPackage,hello))

makefile(hello / src):

target=hello
all:$(target)

objects=hello.o
hello:$(objects)
    $(CXX) -o $(target) $(objects)

clean:
    @rm -rf $(objects)