소스 검색

Merge remote-tracking branch 'upstream/master'

ZYH 6 년 전
부모
커밋
010f070295

+ 166 - 0
bsp/amebaz/README.md

@@ -0,0 +1,166 @@
+# amebaz on RT-Thread
+
+## 1. 简介
+
+amebaz 是由Realtek推出的Cortex-M4内核的WiFi SOC芯片rtl8710b系列
+包括如下硬件特性:
+
+| 硬件 | 描述 |
+| -- | -- |
+|芯片型号| amebaz |
+|CPU| Cortex-M4 |
+|主频| 125MHz |
+
+## 2. 编译说明
+
+
+| 环境         | 说明                                                         |
+| ------------ | ------------------------------------------------------------ |
+| PC操作系统   | Linux/MacOS/Windows                                          |
+| 编译器       | arm-none-eabi-gcc version 6.3.1 20170620 (release)/iar |
+| 构建工具     | scons/iar                                               |
+| 依赖软件环境 | Env工具/(IAR或arm-none-eabi-gcc)/git/调试器驱动         |
+
+1) 下载源码
+
+```bash
+    git clone https://github.com/RT-Thread/rt-thread.git
+```
+
+2) 配置工程并准备env
+
+(Linux/Mac)
+
+```bash
+    cd rt-thread/bsp/amebaz
+    scons --menuconfig
+    source ~/.env/env.sh
+    pkgs --upgrade
+```
+
+(Windows)
+
+>在[RT-Thread官网][1]下载ENV工具包
+
+3) 配置芯片型号
+
+(Linux/Mac)
+
+```bash
+    scons --menuconfig
+```
+
+(Windows(ENV环境中))
+
+```bash
+    menuconfig
+```
+
+在menuconfig页面配置并选择对应的芯片型号,若开发环境为IAR,则需要生成工程
+
+4) 下载package
+
+amebaz配套的驱动库以package形式提供,故需先下载对应的package(realtek-ameba),请使用env下载package
+
+```bash
+    pkgs --update
+```
+
+5) 生成工程(Mac/Linux下请跳过此步骤)
+
+(Windows IAR)
+
+```bash
+    SET RTT_CC=iar
+    scons --target=iar -s
+```
+
+*该板级支持包不支持生成mdk的工程
+
+
+6) 编译
+
+使用IAR请参见对应教程
+
+(Windows arm-none-eabi-gcc)
+使用以下指令设置gcc路径
+
+```bash
+    SET RTT_EXEC_PATH=[GCC路径]
+```
+
+(Linux/Mac arm-none-eabi-gcc)
+使用以下指令设置gcc路径
+
+```bash
+    export RTT_EXEC_PATH=[GCC路径]
+```
+
+编译(WindowsLinux/Mac arm-none-eabi-gcc)
+
+```bash
+    scons -j4
+```
+
+出现下列信息即为编译成功
+
+```bash
+LINK rtthread.axf
+arm-none-eabi-objcopy -j .ram_image2.entry -j .ram_image2.data -j .ram_image2.bss -j .ram_image2.skb.bss -j .ram_heap.data -Obinary rtthread.axf ram_2.r.bin
+arm-none-eabi-objcopy -j .xip_image2.text -Obinary rtthread.axf xip_image2.bin
+arm-none-eabi-objcopy -j .ram_rdp.text -Obinary rtthread.axf rdp.bin
+python gen_bin.py
+is_law = 1
+start = 10005000, end = 0, base = 10000000
+Input file size: 65852
+copy size 45372
+start = 10005000, end = 0, base = 10000000
+Input file size: 45372
+copy size 24892
+start = 0, end = 0, base = 0
+Input file size: 336816
+copy size 336816
+size = 361772
+checksum 209b36c
+'true' is not recognized as an internal or external command,
+operable program or batch file.
+Done...
+scons: done building targets.
+```
+
+如果编译正确无误,会产生image2_all_ota1.bin文件。
+
+## 3. 烧写及执行
+
+烧写可以使用仿真器 串口等多种方式 此处不再赘述
+
+### 3.1 运行结果
+
+如果编译 & 烧写无误,会在专用日志串口*上看到RT-Thread的启动logo信息:
+
+```bash
+ \ | /
+- RT -     Thread Operating System
+ / | \     3.0.4 build May 15 2018
+ 2006 - 2018 Copyright by rt-thread team
+msh />
+```
+
+*默认串口
+
+
+## 4. 驱动支持情况及计划
+
+| 驱动       | 支持情况 | 备注                         |
+| ---------- | :------: | :--------------------------: |
+| UART       | 支持     | UART0                   |
+
+
+## 5. 联系人信息
+
+维护人:
+[flyingcys][4] < [flyingcys@163.com][5] >
+
+  [1]: https://www.rt-thread.org/page/download.html
+  [4]: https://github.com/flyingcys
+  [5]: mailto:flyingcys@163.com

+ 7 - 4
bsp/amebaz/drivers/drv_wifi.c

@@ -33,6 +33,9 @@
 //#define ETH_TX_DUMP
 //#define MINI_DUMP
 
+struct sk_buff * rltk_wlan_get_recv_skb(int idx);
+struct sk_buff * rltk_wlan_alloc_skb(unsigned int total_len);
+
 #define     MAX_ADDR_LEN        6
 
 struct ameba_wifi
@@ -217,9 +220,9 @@ struct netif *rltk_wlan_get_netif(int idx)
     struct netif *netif;
     
     if(idx == 0)
-        netif = &wifi_sta.parent.parent.netif;
-    else if(idx = 1)
-        netif = &wifi_ap.parent.parent.netif;
+        netif = wifi_sta.parent.parent.netif;
+    else if(idx == 1)
+        netif = wifi_ap.parent.parent.netif;
 
     return netif;
 }
@@ -356,7 +359,7 @@ rt_err_t  rt_ameba_wifi_control(rt_device_t dev, int cmd, void *args)
     {
         int *channel = (int *)args;
 
-        channel = amebaz_wifi_get_channel();
+        *channel = amebaz_wifi_get_channel();
     }
         break;
         

+ 134 - 123
bsp/amebaz/project.ewp

@@ -313,50 +313,51 @@
           <name>CCIncludePath2</name>
           <state />
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\wlan_ram_map\rom</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\lwip</state>
           <state>$PROJ_DIR$\..\..\components\libc\compilers\dlib</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\ssl_ram_map\rom</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\wlan_ram_map\rom</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\platform</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi</state>
-          <state>$PROJ_DIR$\..\..\components\drivers\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\platform</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\realtek\8711b\include</state>
+          <state>$PROJ_DIR$\..\..\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\include</state>
           <state>$PROJ_DIR$\..\..\libcpu\arm\common</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\os_dep\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\polarssl-1.3.8\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\os_dep\include</state>
+          <state>$PROJ_DIR$\..\..\components\drivers\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\rtw_wpa_supplicant\src</state>
           <state>$PROJ_DIR$\drivers</state>
-          <state>$PROJ_DIR$\app_wifi</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc</state>
+          <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\netif</state>
+          <state>$PROJ_DIR$\..\..\libcpu\arm\cortex-m4</state>
           <state>$PROJ_DIR$\.</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\include</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include</state>
-          <state>$PROJ_DIR$\..\..\libcpu\arm\cortex-m4</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\libc\rom\string</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal_ext</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\api</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\RT-Thread</state>
-          <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\netif</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\realtek\8711b\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\rtw_wpa_supplicant\src</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis\device</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\libc\rom\string</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal_ext</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos</state>
           <state>$PROJ_DIR$\applications</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\polarssl-1.3.8\include</state>
+          <state>$PROJ_DIR$\drivers\wlan</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\portable\IAR\ARM_CM4F</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\ipv4</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\rtl_lib</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\portable\IAR\ARM_CM4F</state>
           <state>$PROJ_DIR$\..\..\components\finsh</state>
-          <state>$PROJ_DIR$\..\..\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\src\osdep</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\os</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis\device</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\rtl_lib</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\os</state>
+          <state>$PROJ_DIR$\..\..\components\drivers\wlan</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\src\osdep</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\ssl_ram_map\rom</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\include</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\arch\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\api</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b</state>
         </option>
         <option>
           <name>CCStdIncCheck</name>
@@ -682,8 +683,8 @@
       <name>BUILDACTION</name>
       <archiveVersion>1</archiveVersion>
       <data>
-        <prebuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\prebuild.vbs" "$PROJ_DIR$" "1" "0x08080000"</prebuild>
-        <postbuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\postbuild_img2.vbs" "$TARGET_DIR$" "$PROJ_DIR$"</postbuild>
+        <prebuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\prebuild.vbs" "$PROJ_DIR$" "1" "0x08080000"</prebuild>
+        <postbuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\postbuild_img2.vbs" "$TARGET_DIR$" "$PROJ_DIR$"</postbuild>
       </data>
     </settings>
     <settings>
@@ -719,7 +720,7 @@
         </option>
         <option>
           <name>IlinkRawBinaryFile</name>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\image\boot_all.bin</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\image\boot_all.bin</state>
         </option>
         <option>
           <name>IlinkRawBinarySymbol</name>
@@ -820,10 +821,10 @@
         <option>
           <name>IlinkAdditionalLibs</name>
           <state />
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_platform.a</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_rtlstd.a</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wlan.a</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wps.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_platform.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_rtlstd.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wlan.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wps.a</state>
         </option>
         <option>
           <name>IlinkOverrideProgramEntryLabel</name>
@@ -1320,50 +1321,51 @@
           <name>CCIncludePath2</name>
           <state />
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\wlan_ram_map\rom</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\lwip</state>
           <state>$PROJ_DIR$\..\..\components\libc\compilers\dlib</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\ssl_ram_map\rom</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\wlan_ram_map\rom</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\platform</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi</state>
-          <state>$PROJ_DIR$\..\..\components\drivers\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\platform</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\realtek\8711b\include</state>
+          <state>$PROJ_DIR$\..\..\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\include</state>
           <state>$PROJ_DIR$\..\..\libcpu\arm\common</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\os_dep\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\polarssl-1.3.8\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\os_dep\include</state>
+          <state>$PROJ_DIR$\..\..\components\drivers\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\rtw_wpa_supplicant\src</state>
           <state>$PROJ_DIR$\drivers</state>
-          <state>$PROJ_DIR$\app_wifi</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc</state>
+          <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\netif</state>
+          <state>$PROJ_DIR$\..\..\libcpu\arm\cortex-m4</state>
           <state>$PROJ_DIR$\.</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\include</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include</state>
-          <state>$PROJ_DIR$\..\..\libcpu\arm\cortex-m4</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\libc\rom\string</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal_ext</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\api</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\RT-Thread</state>
-          <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\netif</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\realtek\8711b\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\rtw_wpa_supplicant\src</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis\device</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\libc\rom\string</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\hal_ext</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos</state>
           <state>$PROJ_DIR$\applications</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\polarssl-1.3.8\include</state>
+          <state>$PROJ_DIR$\drivers\wlan</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\portable\IAR\ARM_CM4F</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\include\ipv4</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\rtl_lib</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\freertos\freertos_v8.1.2\Source\portable\IAR\ARM_CM4F</state>
           <state>$PROJ_DIR$\..\..\components\finsh</state>
-          <state>$PROJ_DIR$\..\..\include</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\src\osdep</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\os</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis\device</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\rtl_lib</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\os</state>
+          <state>$PROJ_DIR$\..\..\components\drivers\wlan</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\drivers\wlan\realtek\src\osdep</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\network\ssl\ssl_ram_map\rom</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\swlib\std_lib\include</state>
           <state>$PROJ_DIR$\..\..\components\net\lwip-1.4.1\src\arch\include</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\api</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b</state>
         </option>
         <option>
           <name>CCStdIncCheck</name>
@@ -1827,10 +1829,10 @@
         <option>
           <name>IlinkAdditionalLibs</name>
           <state />
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_platform.a</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_rtlstd.a</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wlan.a</state>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wps.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_platform.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_rtlstd.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wlan.a</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\lib\common\IAR\lib_wps.a</state>
         </option>
         <option>
           <name>IlinkOverrideProgramEntryLabel</name>
@@ -2020,12 +2022,6 @@
       <name>$PROJ_DIR$\applications\main.c</name>
     </file>
   </group>
-  <group>
-    <name>app_wifi</name>
-    <file>
-      <name>$PROJ_DIR$\app_wifi\wifi_test.c</name>
-    </file>
-  </group>
   <group>
     <name>Drivers</name>
     <file>
@@ -2039,129 +2035,135 @@
     </file>
   </group>
   <group>
-    <name>RT-Thread</name>
+    <name>amebaz_wlan</name>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\os\rtthread_service.c</name>
+      <name>$PROJ_DIR$\drivers\wlan\amebaz_wlan.c</name>
     </file>
+  </group>
+  <group>
+    <name>rtt_patch</name>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\realtek\8711b\rtl8710b_startup.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\os\rtthread_service.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\realtek\8711b\app_start.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\realtek\8711b\rtl8710b_startup.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\RT-Thread\realtek\common\wifi\wifi_conf.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\realtek\8711b\app_start.c</name>
+    </file>
+    <file>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\rtthread_patch\realtek\common\wifi\wifi_conf.c</name>
     </file>
   </group>
   <group>
     <name>ameba_wifi</name>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\wifi_ind.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\wifi_ind.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\wifi_util.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\wifi_util.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\wifi_promisc.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\wifi_promisc.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\rtw_wpa_supplicant\wpa_supplicant\wifi_eap_config.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\api\wifi\rtw_wpa_supplicant\wpa_supplicant\wifi_eap_config.c</name>
     </file>
   </group>
   <group>
     <name>mbed</name>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\analogin_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\analogin_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\dma_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\dma_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\efuse_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\efuse_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\flash_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\flash_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\gpio_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\gpio_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\gpio_irq_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\gpio_irq_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\i2c_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\i2c_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\i2s_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\i2s_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\nfc_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\nfc_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\pinmap.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\pinmap.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\pinmap_common.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\pinmap_common.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\port_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\port_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\pwmout_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\pwmout_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\rtc_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\rtc_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\serial_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\serial_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\sleep.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\sleep.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\spi_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\spi_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\sys_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\sys_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\timer_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\timer_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\us_ticker.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\us_ticker.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\us_ticker_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\us_ticker_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\wait_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\wait_api.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\wdt_api.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\common\mbed\targets\hal\rtl8711b\wdt_api.c</name>
     </file>
   </group>
   <group>
     <name>os_dep</name>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\os_dep\osdep_service.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\os\os_dep\osdep_service.c</name>
     </file>
   </group>
   <group>
     <name>soc_8711b</name>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis\device\system_8195a.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\cmsis\device\system_8195a.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\ram_lib\rtl8710b_pinmapcfg.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\ram_lib\rtl8710b_pinmapcfg.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\ram_lib\rtl8710b_intfcfg.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\fwlib\ram_lib\rtl8710b_intfcfg.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\ram\rtl_consol.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\ram\rtl_consol.c</name>
     </file>
     <file>
-      <name>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\ram\monitor.c</name>
+      <name>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\app\monitor\ram\monitor.c</name>
     </file>
   </group>
   <group>
@@ -2253,6 +2255,15 @@
     <file>
       <name>$PROJ_DIR$\..\..\components\drivers\src\workqueue.c</name>
     </file>
+    <file>
+      <name>$PROJ_DIR$\..\..\components\drivers\wlan\wlan_cmd.c</name>
+    </file>
+    <file>
+      <name>$PROJ_DIR$\..\..\components\drivers\wlan\wlan_dev.c</name>
+    </file>
+    <file>
+      <name>$PROJ_DIR$\..\..\components\drivers\wlan\wlan_mgnt.c</name>
+    </file>
   </group>
   <group>
     <name>finsh</name>

+ 3 - 3
bsp/amebaz/template.ewd

@@ -37,7 +37,7 @@
         </option>
         <option>
           <name>MacFile</name>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\preload.mac</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\preload.mac</state>
         </option>
         <option>
           <name>MemOverride</name>
@@ -45,7 +45,7 @@
         </option>
         <option>
           <name>MemFile</name>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\8710b.ddf</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\8710b.ddf</state>
         </option>
         <option>
           <name>RunToEnable</name>
@@ -603,7 +603,7 @@
         </option>
         <option>
           <name>IjetCpuClockEdit</name>
-          <state>72.0</state>
+          <state></state>
         </option>
         <option>
           <name>IjetSwoPrescalerList</name>

+ 3 - 3
bsp/amebaz/template.ewp

@@ -636,8 +636,8 @@
       <name>BUILDACTION</name>
       <archiveVersion>1</archiveVersion>
       <data>
-        <prebuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\prebuild.vbs" "$PROJ_DIR$" "1" "0x08080000"</prebuild>
-        <postbuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\postbuild_img2.vbs" "$TARGET_DIR$" "$PROJ_DIR$"</postbuild>
+        <prebuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\prebuild.vbs" "$PROJ_DIR$" "1" "0x08080000"</prebuild>
+        <postbuild>CSCRIPT  "$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\postbuild_img2.vbs" "$TARGET_DIR$" "$PROJ_DIR$"</postbuild>
       </data>
     </settings>
     <settings>
@@ -673,7 +673,7 @@
         </option>
         <option>
           <name>IlinkRawBinaryFile</name>
-          <state>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\image\boot_all.bin</state>
+          <state>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\bsp\image\boot_all.bin</state>
         </option>
         <option>
           <name>IlinkRawBinarySymbol</name>

+ 5 - 5
bsp/amebaz/tmp.board

@@ -3,19 +3,19 @@
 <flash_board> 
   <pass>    
     <range>CODE 0x8000000 0x8004fff</range>    
-    <loader>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\flashloader\FlashRTL8195aMP.flash</loader>    
+    <loader>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\flashloader\FlashRTL8195aMP.flash</loader>    
     <abs_offset>0x00000000</abs_offset>    
   </pass>    
   <pass> 
     <range>CODE 0x800b020 0x807ffff</range> 
-    <loader>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\flashloader\FlashRTL8195aMP.flash</loader>    
+    <loader>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\flashloader\FlashRTL8195aMP.flash</loader>    
     <abs_offset>0xb020</abs_offset>  
   </pass> 
   <pass>    
-    <range>CODE 0x10005000 0x10005A43</range>    
-    <loader>$PROJ_DIR$\packages\realtek_ameba\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\flashloader\FlashRTL8195aMP.flash</loader>      
+    <range>CODE 0x10005000 0x10005A6B</range>    
+    <loader>$PROJ_DIR$\packages\realtek_ameba-latest\sdk-ameba-v4.0b_without_NDA_GCC_V1.0.0\component\soc\realtek\8711b\misc\iar_utility\common\flashloader\FlashRTL8195aMP.flash</loader>      
     <abs_offset>0xb000</abs_offset>    
     <args>--concat</args>    
   </pass>    
-  <ignore>CODE 0x10005a44 0x1003dfff</ignore> 
+  <ignore>CODE 0x10005a6c 0x1003dfff</ignore> 
 </flash_board> 

+ 22 - 0
components/drivers/Kconfig

@@ -112,6 +112,28 @@ config RT_USING_SDIO
     bool "Using SD/MMC device drivers"
     default n
 
+    if RT_USING_SDIO
+        config RT_SDIO_STACK_SIZE
+            int "The stack size for sdio irq thread"
+            default 512
+
+        config RT_SDIO_THREAD_PRIORITY
+            int "The priority level value of sdio irq thread"
+            default 15
+
+        config RT_MMCSD_STACK_SIZE
+            int "The stack size for mmcsd thread"
+            default 1024
+
+        config RT_MMCSD_THREAD_PREORITY
+            int "The priority level value of mmcsd thread"
+            default 22
+
+        config RT_MMCSD_MAX_PARTITION
+            int "mmcsd max partition"
+            default 16
+    endif
+
 config RT_USING_SPI
     bool "Using SPI Bus/Device device drivers"
     default n

+ 0 - 1
components/drivers/include/drivers/mmcsd_core.h

@@ -213,7 +213,6 @@ rt_inline rt_uint32_t __rt_fls(rt_uint32_t val)
 	}
 	if (!(val & 0x80000000u)) 
 	{
-		val <<= 1;
 		bit -= 1;
 	}
 

+ 15 - 6
components/drivers/wlan/wlan_cmd.c

@@ -426,13 +426,22 @@ int wifi(int argc, char **argv)
             int index, num;
 
             num = scan_result->ap_num;
-            rt_kprintf("----Wi-Fi APInformation----\n");
+            rt_kprintf("             SSID                      MAC            rssi   chn    Mbps\n");
+            rt_kprintf("------------------------------- -----------------     ----   ---    ----\n");
             for (index = 0; index < num; index ++)
             {
-                rt_kprintf("SSID:%-.32s, ", scan_result->ap_table[index].ssid);
-                rt_kprintf("rssi:%d, ", scan_result->ap_table[index].rssi);
-                rt_kprintf("chn:%d, ", scan_result->ap_table[index].channel);
-                rt_kprintf("rate:%d\n", scan_result->ap_table[index].datarate);
+                rt_kprintf("%-32.32s", scan_result->ap_table[index].ssid);
+                rt_kprintf("%02x:%02x:%02x:%02x:%02x:%02x     ", 
+                    scan_result->ap_table[index].bssid[0],
+                    scan_result->ap_table[index].bssid[1],
+                    scan_result->ap_table[index].bssid[2],
+                    scan_result->ap_table[index].bssid[3],
+                    scan_result->ap_table[index].bssid[4],
+                    scan_result->ap_table[index].bssid[5]
+                );
+                rt_kprintf("%4d    ", scan_result->ap_table[index].rssi);
+                rt_kprintf("%2d    ", scan_result->ap_table[index].channel);
+                rt_kprintf("%d\n", scan_result->ap_table[index].datarate / 1000000);
             }
         }
         rt_wlan_release_scan_result(&scan_result);
@@ -502,7 +511,7 @@ int wifi(int argc, char **argv)
                        wlan->info->bssid[4],
                        wlan->info->bssid[5]);
             rt_kprintf(" Channel: %d\n", wlan->info->channel);
-            rt_kprintf("DataRate: %dMbps\n", wlan->info->datarate / 1000);
+            rt_kprintf("DataRate: %dMbps\n", wlan->info->datarate / 1000000);
             rt_kprintf("    RSSI: %d\n", rssi);
         }
         else

+ 161 - 139
tools/building.py

@@ -112,8 +112,33 @@ class Win32Spawn:
 
         return proc.wait()
 
+# generate cconfig.h file
+def GenCconfigFile(env, BuildOptions):
+    import rtconfig
+    
+    if rtconfig.PLATFORM == 'gcc':
+        contents = ''
+        if not os.path.isfile('cconfig.h'):
+            import gcc
+            gcc.GenerateGCCConfig(rtconfig)
+
+        # try again
+        if os.path.isfile('cconfig.h'):
+            f = file('cconfig.h', 'r')
+            if f:
+                contents = f.read()
+                f.close();
+
+                prep = PatchedPreProcessor()
+                prep.process_contents(contents)
+                options = prep.cpp_namespace
+
+                BuildOptions.update(options)
+
+                # add HAVE_CCONFIG_H definition
+                env.AppendUnique(CPPDEFINES = ['HAVE_CCONFIG_H'])
+
 def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
-    import SCons.cpp
     import rtconfig
 
     global BuildOptions
@@ -121,6 +146,64 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
     global Env
     global Rtt_Root
 
+    # ===== Add option to SCons =====
+    AddOption('--copy',
+                      dest = 'copy',
+                      action = 'store_true',
+                      default = False,
+                      help = 'copy rt-thread directory to local.')
+    AddOption('--copy-header',
+                      dest = 'copy-header',
+                      action = 'store_true',
+                      default = False,
+                      help = 'copy header of rt-thread directory to local.')
+    AddOption('--dist',
+                      dest = 'make-dist',
+                      action = 'store_true',
+                      default = False,
+                      help = 'make distribution')
+    AddOption('--cscope',
+                      dest = 'cscope',
+                      action = 'store_true',
+                      default = False,
+                      help = 'Build Cscope cross reference database. Requires cscope installed.')
+    AddOption('--clang-analyzer',
+                      dest = 'clang-analyzer',
+                      action = 'store_true',
+                      default = False,
+                      help = 'Perform static analyze with Clang-analyzer. ' + \
+                           'Requires Clang installed.\n' + \
+                           'It is recommended to use with scan-build like this:\n' + \
+                           '`scan-build scons --clang-analyzer`\n' + \
+                           'If things goes well, scan-build will instruct you to invoke scan-view.')
+    AddOption('--buildlib',
+                      dest = 'buildlib',
+                      type = 'string',
+                      help = 'building library of a component')
+    AddOption('--cleanlib',
+                      dest = 'cleanlib',
+                      action = 'store_true',
+                      default = False,
+                      help = 'clean up the library by --buildlib')
+    AddOption('--target',
+                      dest = 'target',
+                      type = 'string',
+                      help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk')
+    AddOption('--genconfig',
+                dest = 'genconfig',
+                action = 'store_true',
+                default = False,
+                help = 'Generate .config from rtconfig.h')
+    AddOption('--useconfig',
+                dest = 'useconfig',
+                type = 'string',
+                help = 'make rtconfig.h from config file.')
+    AddOption('--verbose',
+                dest = 'verbose',
+                action = 'store_true',
+                default = False,
+                help = 'print verbose information during build')
+
     Env = env
     Rtt_Root = os.path.abspath(root_directory)
     # set RTT_ROOT in ENV
@@ -130,19 +213,60 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
 
     sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
 
+    # {target_name:(CROSS_TOOL, PLATFORM)}
+    tgt_dict = {'mdk':('keil', 'armcc'),
+                'mdk4':('keil', 'armcc'),
+                'mdk5':('keil', 'armcc'),
+                'iar':('iar', 'iar'),
+                'vs':('msvc', 'cl'),
+                'vs2012':('msvc', 'cl'),
+                'vsc' : ('gcc', 'gcc'),
+                'cb':('keil', 'armcc'),
+                'ua':('gcc', 'gcc'),
+                'cdk':('gcc', 'gcc')}
+    tgt_name = GetOption('target')
+
+    if tgt_name:
+        # --target will change the toolchain settings which clang-analyzer is
+        # depend on
+        if GetOption('clang-analyzer'):
+            print '--clang-analyzer cannot be used with --target'
+            sys.exit(1)
+
+        SetOption('no_exec', 1)
+        try:
+            rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
+            # replace the 'RTT_CC' to 'CROSS_TOOL'
+            os.environ['RTT_CC'] = rtconfig.CROSS_TOOL
+            reload(rtconfig)
+        except KeyError:
+            print 'Unknow target: %s. Avaible targets: %s' % \
+                    (tgt_name, ', '.join(tgt_dict.keys()))
+            sys.exit(1)
+    elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
+        and rtconfig.PLATFORM == 'gcc':
+        AddDepend('RT_USING_MINILIBC')
+
+    # auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed
+    if not os.path.exists(rtconfig.EXEC_PATH):
+        if os.environ['RTT_EXEC_PATH']:
+            # del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py
+            del os.environ['RTT_EXEC_PATH']
+            reload(rtconfig)
+
     # add compability with Keil MDK 4.6 which changes the directory of armcc.exe
     if rtconfig.PLATFORM == 'armcc':
         if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
             if rtconfig.EXEC_PATH.find('bin40') > 0:
                 rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace('bin40', 'armcc/bin')
-                Env['LINKFLAGS']=Env['LINKFLAGS'].replace('RV31', 'armcc')
+                Env['LINKFLAGS'] = Env['LINKFLAGS'].replace('RV31', 'armcc')
 
         # reset AR command flags
         env['ARCOM'] = '$AR --create $TARGET $SOURCES'
-        env['LIBPREFIX']   = ''
-        env['LIBSUFFIX']   = '.lib'
+        env['LIBPREFIX'] = ''
+        env['LIBSUFFIX'] = '.lib'
         env['LIBLINKPREFIX'] = ''
-        env['LIBLINKSUFFIX']   = '.lib'
+        env['LIBLINKSUFFIX'] = '.lib'
         env['LIBDIRPREFIX'] = '--userlibpath '
 
     # patch for win32 spawn
@@ -174,62 +298,6 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
     PreProcessor.process_contents(contents)
     BuildOptions = PreProcessor.cpp_namespace
 
-    if rtconfig.PLATFORM == 'gcc':
-        contents = ''
-        if not os.path.isfile('cconfig.h'):
-            import gcc
-            gcc.GenerateGCCConfig(rtconfig)
-
-        # try again
-        if os.path.isfile('cconfig.h'):
-            f = file('cconfig.h', 'r')
-            if f:
-                contents = f.read()
-                f.close();
-
-                prep = PatchedPreProcessor()
-                prep.process_contents(contents)
-                options = prep.cpp_namespace
-
-                BuildOptions.update(options)
-
-                # add HAVE_CCONFIG_H definition
-                env.AppendUnique(CPPDEFINES = ['HAVE_CCONFIG_H'])
-
-        if str(env['LINKFLAGS']).find('nano.specs') != -1:
-            env.AppendUnique(CPPDEFINES = ['_REENT_SMALL'])
-
-    # add copy option
-    AddOption('--copy',
-                      dest='copy',
-                      action='store_true',
-                      default=False,
-                      help='copy rt-thread directory to local.')
-    AddOption('--copy-header',
-                      dest='copy-header',
-                      action='store_true',
-                      default=False,
-                      help='copy header of rt-thread directory to local.')
-    AddOption('--dist',
-                      dest = 'make-dist',
-                      action = 'store_true',
-                      default=False,
-                      help = 'make distribution')
-    AddOption('--cscope',
-                      dest='cscope',
-                      action='store_true',
-                      default=False,
-                      help='Build Cscope cross reference database. Requires cscope installed.')
-    AddOption('--clang-analyzer',
-                      dest='clang-analyzer',
-                      action='store_true',
-                      default=False,
-                      help='Perform static analyze with Clang-analyzer. '+\
-                           'Requires Clang installed.\n'+\
-                           'It is recommended to use with scan-build like this:\n'+\
-                           '`scan-build scons --clang-analyzer`\n'+\
-                           'If things goes well, scan-build will instruct you to invoke scan-view.')
-
     if GetOption('clang-analyzer'):
         # perform what scan-build does
         env.Replace(
@@ -249,59 +317,13 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
         # found or something like that).
         rtconfig.POST_ACTION = ''
 
-    # add build library option
-    AddOption('--buildlib',
-                      dest='buildlib',
-                      type='string',
-                      help='building library of a component')
-    AddOption('--cleanlib',
-                      dest='cleanlib',
-                      action='store_true',
-                      default=False,
-                      help='clean up the library by --buildlib')
-
-    # add target option
-    AddOption('--target',
-                      dest='target',
-                      type='string',
-                      help='set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk')
-
-    #{target_name:(CROSS_TOOL, PLATFORM)}
-    tgt_dict = {'mdk':('keil', 'armcc'),
-                'mdk4':('keil', 'armcc'),
-                'mdk5':('keil', 'armcc'),
-                'iar':('iar', 'iar'),
-                'vs':('msvc', 'cl'),
-                'vs2012':('msvc', 'cl'),
-                'vsc' : ('gcc', 'gcc'),
-                'cb':('keil', 'armcc'),
-                'ua':('gcc', 'gcc'),
-                'cdk':('gcc', 'gcc')}
-    tgt_name = GetOption('target')
+    # generate cconfig.h file
+    GenCconfigFile(env, BuildOptions)
 
-    if tgt_name:
-        # --target will change the toolchain settings which clang-analyzer is
-        # depend on
-        if GetOption('clang-analyzer'):
-            print '--clang-analyzer cannot be used with --target'
-            sys.exit(1)
+    # auto append '_REENT_SMALL' when using newlib 'nano.specs' option
+    if rtconfig.PLATFORM == 'gcc' and str(env['LINKFLAGS']).find('nano.specs') != -1:
+        env.AppendUnique(CPPDEFINES = ['_REENT_SMALL'])
 
-        SetOption('no_exec', 1)
-        try:
-            rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
-        except KeyError:
-            print 'Unknow target: %s. Avaible targets: %s' % \
-                    (tgt_name, ', '.join(tgt_dict.keys()))
-            sys.exit(1)
-    elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
-        and rtconfig.PLATFORM == 'gcc':
-        AddDepend('RT_USING_MINILIBC')
-
-    AddOption('--genconfig',
-                dest = 'genconfig',
-                action = 'store_true',
-                default = False,
-                help = 'Generate .config from rtconfig.h')
     if GetOption('genconfig'):
         from genconf import genconfig
         genconfig()
@@ -318,22 +340,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
             menuconfig(Rtt_Root)
             exit(0)
 
-    AddOption('--useconfig',
-                dest = 'useconfig',
-                type='string',
-                help = 'make rtconfig.h from config file.')
     configfn = GetOption('useconfig')
     if configfn:
         from menuconfig import mk_rtconfig
         mk_rtconfig(configfn)
         exit(0)
 
-    # add comstr option
-    AddOption('--verbose',
-                dest='verbose',
-                action='store_true',
-                default=False,
-                help='print verbose information during build')
 
     if not GetOption('verbose'):
         # override the default verbose command string
@@ -709,18 +721,8 @@ def DoBuilding(target, objects):
         program = Env.Program(target, objects)
 
     EndBuilding(target, program)
-
-def EndBuilding(target, program = None):
-    import rtconfig
-
-    Env['target']  = program
-    Env['project'] = Projects
-
-    Env.AddPostAction(target, rtconfig.POST_ACTION)
-    # Add addition clean files
-    Clean(target, 'cconfig.h')
-    Clean(target, 'rtua.py')
-    Clean(target, 'rtua.pyc')
+        
+def GenTargetProject(program = None):
 
     if GetOption('target') == 'mdk':
         from keil import MDKProject
@@ -777,27 +779,47 @@ def EndBuilding(target, program = None):
         from cdk import CDKProject
         CDKProject('project.cdkproj', Projects)
 
+def EndBuilding(target, program = None):
+    import rtconfig
+
+    need_exit = False
+
+    Env['target']  = program
+    Env['project'] = Projects
+
+    Env.AddPostAction(target, rtconfig.POST_ACTION)
+    # Add addition clean files
+    Clean(target, 'cconfig.h')
+    Clean(target, 'rtua.py')
+    Clean(target, 'rtua.pyc')
+
+    if GetOption('target'):
+        GenTargetProject(program)
+
     BSP_ROOT = Dir('#').abspath
     if GetOption('copy') and program != None:
         from mkdist import MakeCopy
         MakeCopy(program, BSP_ROOT, Rtt_Root, Env)
-        exit(0)
+        need_exit = True
     if GetOption('copy-header') and program != None:
         from mkdist import MakeCopyHeader
         MakeCopyHeader(program, BSP_ROOT, Rtt_Root, Env)
-        exit(0)
+        need_exit = True
     if GetOption('make-dist') and program != None:
         from mkdist import MkDist
         MkDist(program, BSP_ROOT, Rtt_Root, Env)
-        exit(0)
+        need_exit = True
     if GetOption('cscope'):
         from cscope import CscopeDatabase
         CscopeDatabase(Projects)
 
     if not GetOption('help') and not GetOption('target'):
         if not os.path.exists(rtconfig.EXEC_PATH):
-            print "Error: Toolchain path (%s) is not exist, please check 'EXEC_PATH' in path or rtconfig.py." % rtconfig.EXEC_PATH
-            sys.exit(1)
+            print "Error: the toolchain path (%s) is not exist, please check 'EXEC_PATH' in path or rtconfig.py." % rtconfig.EXEC_PATH
+            need_exit = True
+
+    if need_exit:
+        exit(0)
 
 def SrcRemove(src, remove):
     if not src:

+ 3 - 3
tools/iar.py

@@ -164,7 +164,7 @@ def IARVersion():
     def IARPath():
         import rtconfig
 
-        # set environ
+        # backup environ
         old_environ = os.environ
         os.environ['RTT_CC'] = 'iar'
         reload(rtconfig)
@@ -183,11 +183,11 @@ def IARVersion():
     if os.path.exists(path):
         cmd = os.path.join(path, 'iccarm.exe')
     else:
-        print('Get IAR version error. Please update IAR installation path in rtconfig.h!')
+        print('Error: get IAR version failed. Please update the IAR installation path in rtconfig.py!')
         return "0.0"
 
     child = subprocess.Popen([cmd, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
     stdout, stderr = child.communicate()
 
     # example stdout: IAR ANSI C/C++ Compiler V8.20.1.14183/W32 for ARM
-    return re.search('[\d\.]+', stdout).group(0)
+    return re.search('[\d\.]+', stdout).group(0)