--作者:燕十三(flyingcys)
-- blog:http://blog.csdn.net/flyingcys
--QQ:294102238
一、概述
Alios-Things是一款由阿里巴巴開發的面向IoT領域的輕量級物聯網嵌入式操作系統,致力於搭建雲端一體化IoT基礎設備。具備極致性能,極簡開發、雲端一體、豐富組件、安全防護等關鍵能力,並支持中斷設備連接到阿里Link,可廣泛應用在智能家居、智慧城市、新出行等領域。Alios-Things源碼目前託管在github上,地址爲:https://github.com/alibaba/AliOS-Things,當前最新正式版爲1.3.1,處於快速更新迭代中。
架構描述:
Alios-Things的架構可以適用於分層架構和組件化架構。從底部到頂部,Alios-Things包括:
- 板級支持包(BSP):主要由Soc供應商開發和維護
- 硬件抽象層(HAL):比如WiFi和Uart
- 內核:包括Rhino實時操作系統內核、Yloop、VFS、KV存儲
- 協議棧:包括TCP/IP協議棧(LwIP),uMesh網絡協議棧
- 安全:安全傳輸層協議(TLS)、可信服務框架(TFS)、可信運行環境(TEE)
- AOS API:提供可供應用軟件和中間件使用的API
- 中間件:包括常見的物聯網組件和阿里巴巴增值服務中間件
- 示例應用:阿里自主開發的示例代碼,以及通過了完備測試的應用程序(比如Alinkapp)
- 所有的模組都已經被組織成組件,且每個組件都有自己的.mk文件,用於描述它和其他組件間的依賴關係,方便應用開發者按需選用。
結構框圖:
文件夾結構:
文件夾名稱 | 內容描述 |
board | 評估板(如STM32L496G-Discovery) |
build | 編譯框架 |
device | 連接MCU/SoC的外設,比如支持使用AT命令的WiFi系列模組 |
example | 代碼示例,通過了完備測試的應用程序(比如Alink) |
framework | IoT 通用組件 |
include | 系統頭文件 |
kernel | 包括Rhino和協議棧 |
platform | 芯片架構支持的相關文件 |
security | 包括TLS,TFS, TEE在內的安全組件 |
tools | 命令行界面(CLI)和用於建立遠程設備中心的testbed工具 |
utility | IoT通用軟件庫,比如 cJSON |
test | UT測試用例 |
二、編譯與運行:
編譯環境搭建
Alios-Things提供了基於Visual Studio Code插件的AliOS Studio集成開發環境(IDE),可提供編輯、編譯、調試等功能,不過我是在Linux下(Ubuntu16.04 64bit)開發。在Ubuntu上開發需要先搭建開發環境。1.依賴軟件包安裝,在命令行下輸入:
sudo apt-get install -y python gcc-multilib libssl-dev libssl-dev:i386 libncurses5-dev libncurses5-dev:i386 libreadline-dev libreadline-dev:i386 python-pip minicom
2.安裝aos-cube,用python包管理器pip安裝aos-cube和相關依賴包pip install setuptools wheel aos-cube
請確認pip環境是基於python 2.7的,如果遇到權限問題,可能需要sudo來執行3.下載源碼
git clone https://github.com/alibaba/AliOS-Things.git
Alios Things倉庫比較大,下載需要一些時間。編譯
下載完成後,在命令行下,進入Alios-Things根目錄,執行編譯命令aos make。編譯採用的是example@board的模式,如example爲example目錄下對應的應用helloworld,board則爲對應的運行平臺linuxhost。aos與aos make命令詳細指令如下:- aos
usage: aos [-h] [--version] ...
Code management tool for aos - https://code.aliyun.com/aos/aos
version 0.2.42
Use 'aos <command> -h|--help' for detailed help.
Online manual and guide available at https://code.aliyun.com/aos/aos-cube
optional arguments:
-h, --help show this help message and exit
--version print version number and exit
Commands:
new Create new aos program or component
ls List cube info, default components info
import Import program from URL
add Add component from AOS_SDK_PATH or URL
rm Remove component
deploy Find and add missing components and source codes
codes Import the optional component from the remote repository
publish Publish program or component
update Update to branch, tag, revision or latest
sync Synchronize aos component references
status Show version control status
make Make aos program/component
scons Make aos program/component by scons
makelib Compile static library
config Tool configuration
upload Upload aos image
monitor Serial port monitor
upgrade Upgrade aos-cube to latest
help This help screen
- aos make
Usage: make <target> [download] [run | debug] [JTAG=xxx] [total] [VERBOSE=1] [BINS=app/framework/kernel]
make run
<target>
One each of the following mandatory [and optional] components separated by '@'
* Application (apps in example)
* Board (cy8ckit-149 mk1101 gd32f4xx mk3080 mk3060 mk3239 stm32f429zi-nucleo xr871evb r5f565ne frdmkl27z stm32f769i-discovery lpcxpresso54102 rda8955 linuxhost uno-91h r5f100lea stm32l496g-discovery starterkit mk3165 atsame54-xpro eml3047 developerkit stm32l432kc-nucleo pca10056 esp32devkitc bk7231devkitc mk3166 esp8266 stm32l073rz-nucleo b_l475e rk1108 cb2201 amebaz_dev pca10040 bk7231udevkitc stm32l476rg-nucleo stm32l433rc-nucleo dh5021a_evb cy8ckit-062)
* [debug | release] Building for debug or release configurations
[download]
Download firmware image to target platform
[run]
Reset and run an application on the target hardware
[total]
Build all targets related to this application and board
[JTAG=xxx]
JTAG interface configuration file from the tools/OpenOCD dirctory
Default option is jlink_swd
[VERBOSE=1]
Shows the commands as they are being executed
[BINS=app/framework/kernel]
Build bins: app or framework or kernel
Notes
* Component names are case sensitive
* 'rhino' and 'debug' are reserved component names
* Component names MUST NOT include space or '@' characters
* Building for debug is assumed unless '@release' is appended to the target
Example Usage
Build for Debug
make helloworld@mk3060
Build, Download and Run using the default USB-JTAG programming interface
make helloworld@mk3060 download run
Build for Release
make helloworld@mk3060@release
Reset and run an application on the target hardware
make run
Clean output directory
make clean. Stop.
執行aos make helloworld@linuxhost,目標文件在根目錄out目錄下對應目錄下out/helloworld@linuxhost/binary。
運行
在命令行下執行./out/helloworld@linuxhost/binary/[email protected]運行demo,可看到demo運行情況。三、rtl8710bn
netmgrapp編譯
rtl8710bn是realtek最新推出的Cortex-M4F內核SOC WiFi,主頻125MHz,512KB ROM,RAM:256KB,支持128MBFlash,RSIP/RDP固件保護。2xUart/SPI Master/SPI Slave,2xI2C,I2S,RTC,6PWM,12bit ADC等衆多外設。rtl8710bn在Alios-Things對應board名爲amebaz_dev,example這次我們選擇的是netmgrapp,該example支持WiFi連接操作。
在命令行輸入netmgrapp@amebaz_dev開始編譯,aos將檢測交叉編譯器,如linux環境變量未發現對應的交叉編譯器,aos將自動下載對應的交叉編譯器。將rtl8710bn交叉編譯器gcc-arm-none-eabi下載至build/compiler/gcc-arm-none-eabi/Linux64目錄。交叉編譯器下載完成後,開始編譯:
vcall init auto_component
kernel_version:AOS-R-1.3.1
app_version:app-1.0.0-20180615.0148
app_version:app-1.0.0-20180615.0148
kernel_version:AOS-R-1.3.1
Build AOS Now
TOOLCHAIN_PATH=/home/share/samba/application/AliOS-Things/build/compiler/gcc-arm-none-eabi/Linux64/bin/
Compiling alicrypto
Compiling board_amebaz_dev
Compiling auto_component
Compiling cli
Compiling digest_algorithm
Compiling framework
Compiling hal
Compiling kernel_init
Compiling vfs_device
Compiling newlib_stub
Compiling log
Compiling kv
Compiling netmgr
Compiling netmgrapp
Compiling armv7m
Compiling rtl8710bn
Compiling rtl8710bn_Peripheral_Drivers
Compiling rtl8710bn_SDK
Compiling net
Compiling rhino
Compiling vcall
Compiling vfs
Compiling yloop
Making out/netmgrapp@amebaz_dev/libraries/alicrypto.a
Making out/netmgrapp@amebaz_dev/libraries/board_amebaz_dev.a
Making out/netmgrapp@amebaz_dev/libraries/auto_component.a
Making out/netmgrapp@amebaz_dev/libraries/cli.a
Making out/netmgrapp@amebaz_dev/libraries/digest_algorithm.a
Making out/netmgrapp@amebaz_dev/libraries/framework.a
Making out/netmgrapp@amebaz_dev/libraries/hal.a
Making out/netmgrapp@amebaz_dev/libraries/kernel_init.a
Making out/netmgrapp@amebaz_dev/libraries/vfs_device.a
Making out/netmgrapp@amebaz_dev/libraries/newlib_stub.a
Making out/netmgrapp@amebaz_dev/libraries/log.a
Making out/netmgrapp@amebaz_dev/libraries/kv.a
Making out/netmgrapp@amebaz_dev/libraries/netmgr.a
Making out/netmgrapp@amebaz_dev/libraries/netmgrapp.a
Making out/netmgrapp@amebaz_dev/libraries/armv7m.a
Making out/netmgrapp@amebaz_dev/libraries/rtl8710bn.a
Making out/netmgrapp@amebaz_dev/libraries/rtl8710bn_Peripheral_Drivers.a
Making out/netmgrapp@amebaz_dev/libraries/rtl8710bn_SDK.a
Making out/netmgrapp@amebaz_dev/libraries/net.a
Making out/netmgrapp@amebaz_dev/libraries/rhino.a
Making out/netmgrapp@amebaz_dev/libraries/vfs.a
Making out/netmgrapp@amebaz_dev/libraries/yloop.a
Making out/netmgrapp@amebaz_dev/libraries/vcall.a
Making netmgrapp@amebaz_dev.elf
Making netmgrapp@amebaz_dev.xip2.elf
Making netmgrapp@amebaz_dev.hex
Making netmgrapp@amebaz_dev.bin
Can't parse memory configure, memory info get fail!
Making netmgrapp@amebaz_dev.xip2.bin
Linux64 /home/share/samba/application/AliOS-Things netmgrapp amebaz_dev /home/share/samba/application/AliOS-Things/build/compiler/gcc-arm-none-eabi/Linux64/bin/
Generate Standard Flash Images: out/netmgrapp@amebaz_dev/binary/netmgrapp@amebaz_dev.all.bin
Build complete
Making .gdbinit
由上可見,默認編譯顯示編譯信息較精簡,可通過執行aos make VERBOSE=1 netmgrapp@amebaz_dev 來查看詳細的編譯過程。編譯完成後,我們可以在out/netmgrapp@amebaz_dev/binary/
其中:
boot_all.bin是amebaz的Boot
image2_all_ota1.bin是amebaz的OTA1區固件;image2_all_ota2.bin是amebaz的OTA2區固件
netmgrapp@amebaz_dev.all.bin是以上3個固件的合併固件。
其中boot只需要下載1次,不需要每次都下載。調試代碼時可只下ota1,可節省下載時間。
運行
重新上電後,可通過串口看到正常啓動log。
#爲Alios-Things命令行cli提示符,在命令行下輸入:help查詢當前支持的cli命令
rtl8710bn網絡連接
netmgr爲Alios-Things下的WiFi網絡管理組件,支持start/clear/connect等功能。使用netmgr connect 360usbwifi 1234567890,連接路由器,ssid爲360usbwifi,密碼爲1234567890。可看到連接成功log。四、Alios-Things運行流程
- aos:aos初始化及啓動
- arch:芯片相關.h及lwip配置文件
- bin:boot_all.bin文件
- hal:hal適配文件
- lib:庫文件
- peripherals:外設驅動庫
- script:編譯鏈接腳本
- sdk:芯片SDK
- tools:bin文件合成工具
入口
rtl8710bn應用入口在platform->mcu->rtl8710bn->aos目錄下,其中main()位於aos.c中。void main(void)
{
aos_init();
krhino_task_dyn_create(&g_aos_init, "aos-init", 0, AOS_DEFAULT_APP_PRI , 0, AOS_START_STACK, (task_entry_t)sys_init_func, 1);
SysTick_Config(SystemCoreClock/RHINO_CONFIG_TICKS_PER_SECOND);
aos_start();
return;
}
運行流程
- 調用aos_init()->krhino_init()完成krhion初始化。
- 在sys_init_func任務內完成hal初始化及啓動、wlan初始化及啓動、aos_kernel_init()完成各種組件初始化,並調用application()函數,完成netmgrapp初始化及啓動。
- 初始化systick定時器
- 4.調用aos_start(),啓動Alios-Things