# BYOS SDK使用说明
## 一、BYOS简介
BYOS是基于OpenWRT深度定制的嵌入式操作系统,专为我公司DHG系列物联网关设计,具有灵活的扩展性,并提供完整的SDK开发包和交叉编译工具链,用户可以方便地在BYOS上进行二次开发,基本上与开发标准Linux应用方式无异。
## 二、使用BYOS SDK编译软件包
1. 解压BYOS SDK压缩包至任一目录,假设为/opt,命令如下:
```
$ tar xjf byos-sdk-ramips-*.tar.bz2 -C /opt
$ cd /opt/byos-sdk-ramips
$ ls
build_dir Config-build.in Config.in dl docs feeds.conf include LICENSE Makefile package prepare.mk README.SDK rules.mk scripts staging_dir target tmp
$
```
2. 编译开源软件包
```
$ scripts/feeds update (加载软件列表)
$ scripts/feeds install package_name (安装需要的软件包)
$ make menuconfig (选择要编译的软件包)
$ make
$ ls bin/ramips/packages (编译好的软件包为.ipk文件,可下载到网关上进行安装)
```
3. 创建自己的软件包
若要编译自己的软件包,需要在``packages``下建立一个目录,并创建相应的Makefile,之后就可以跟开源软件包一样操作了,有关Makefile的具体格式可参考``packages``下面的两个示例:``umodem``和``uci2dat``。
~~~
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/package.mk
PKG_NAME:=devman
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/devman-$(PKG_VERSION)
define Package/devman
SUBMENU:=devman
SECTION:=devman program
CATEGORY:=Devman
TITLE:=devman programming
MAINTAINER:=wangquan
DEPENDS:=+libuci +libghttp
endef
define Package/devman/Default/description
devman is main software in netkeeper.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/devman/install
$(INSTALL_DIR) $(1)/usr/sbin $(1)/usr/lib/drivers $(1)/etc/ $(1)/usr/share/ $(1)/etc/init.d/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/devman $(1)/usr/sbin/
$(CP) $(PKG_BUILD_DIR)/drivers/*.so $(1)/usr/lib/drivers/
$(CP) $(PKG_BUILD_DIR)/conf/*lst $(1)/etc/
$(CP) $(PKG_BUILD_DIR)/conf/*dat $(1)/usr/share/
$(CP) $(PKG_BUILD_DIR)/conf/devman $(1)/etc/init.d/
$(CP) $(PKG_BUILD_DIR)/conf/messages.gbk $(1)/etc/
endef
$(eval $(call BuildPackage,devman))
~~~
注意:makefile照着以上格式修改即可,把依赖得库添加到DEPENDS后面,加上依赖后,会自动先编译所选依赖,然后注意最后install那里,是将程序具体安装得路径。
## 三、使用交叉编译工具链
若用户程序比较简单,源文件不多,也没有太多外部依赖的话,也可以直接用交叉编译工具链来编译。
1. 解压工具链(toolchain)
```
$ tar xjf byos-toolchain-ramips-*.tar.bz2 -C /opt
$ cd /opt/byos-toolchain-ramips
$ ls
hello.c LICENSE README.TOOLCHAIN toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2 version.mk
$
```
2. 交叉编译
```
$ export STAGING_DIR=/opt/byos-toolchain-ramips
$ export X=$STAGING_DIR/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux
$ $X-gcc -o hello hello.c
$ file hello
hello: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped
$
```
## 四、BYOS日常操作说明
1. 登录系统
```
$ ssh -p60022 root@192.168.1.1
The authenticity of host '[192.168.1.1]:60022 ([192.168.1.1]:60022)' can't be established.
RSA key fingerprint is 30:9d:b9:88:dc:65:84:85:53:8f:0d:e3:04:8f:b7:cf.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.1.1]:60022' (RSA) to the list of known hosts.
root@192.168.1.1's password: (默认密码:321toor)
BusyBox v1.23.2 (2017-02-07 16:21:26 CST) built-in shell (ash)
______ ____ ____ ___ ______
|_ _ \ |_ _||_ _| .' `. .' ____ \
| |_) | \ \ / / / .-. \ | (___ \_|
| __'. \ \/ / | | | | _.____`.
_| |__) | _| |_ \ `-' / | \____) |
|_______/ |______| `.___.' \______.'
------------------------------------------------
v1.0.0 for DHG-100, Rev: 94b42-170906154034
------------------------------------------------
root@BYOS:~#
```
2. 修改IP地址
```
$ uci set network.lan.ipaddr='192.168.1.1' (set LAN ip address)
$ uci set network.lan.netmask='255.255.255.0' (set LAN netmask)
$ uci set network.wan.ipaddr='192.168.8.10' (set WAN ip address)
$ uci set network.wan.netmask='255.255.255.0' (set WAN netmask)
$ uci set network.wan.gateway='192.168.8.1' (set WAN gateway)
$ /etc/init.d/network restart
```
3. 从开发机下载文件
```
$ wget ftp://192.168.1.8/pub/xx-xx.ipk
$ scp user@192.168.1.8:/tmp/xx-xx.ipk /tmp
```
4. 安装软件包
```
$ opkg install ./xx-xx.ipk
$ opkg install http://x.x.x.x/packages/xx-xx.ipk
```
5. 系统升级
```
$ wget ftp://192.168.1.8/some/path/firmware.bin
$ sysupgrade -n firmware.bin
```
```
```