HelloDwr bundle

0

源起

想要測試一下 DWR 的功能,為了方便,這個例子是用 DWR2 來測的。

http://getahead.ltd.uk/dwr/getstarted http://getahead.ltd.uk/dwr/server/annotations

建議與 HelloJsp Bundle 交互參考。

src/haha/Component.java

這個物件將使用 LogService 與 HttpService 做一些設定,把原本 WEB-INF/web.xml 的設定改成直接註冊到 HttpService 的做法。

另外一個需要的設定檔的 WEB-INF/dwr.xml 採用 annotation 可以放到 src/haha/HeheBean.java 原始碼中間去,省掉 dwr.xml 檔案載入問題。

....
DwrServlet dwrServlet = new DwrServlet();
Hashtable initparams = new Hashtable();
initparams.put("debug", "true");
initparams.put("classes", HeheBean.class.getCanonicalName());
httpService.registerServlet("/dwr", dwrServlet, initparams,commonContext);
....

src/haha/HeheBean.java

要遠端存取的物件。

package haha;

import org.directwebremoting.annotations.Create;
import org.directwebremoting.annotations.RemoteMethod;

@Create
public class HeheBean {

    private String name;

    @RemoteMethod
    public int getFoo(){
        return 43;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

osgi console

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20061023
1    ACTIVE      HelloDwr_1.0.0
2    ACTIVE      javax.servlet_2.4.0.200609281713
3    ACTIVE      org.apache.commons.logging_1.0.4
4    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
5    ACTIVE      org.eclipse.equinox.http.jetty_1.0.0.v20061012
6    ACTIVE      org.eclipse.equinox.http.servlet_1.0.0.v20061023
7    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
8    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
9    ACTIVE      org.mortbay.jetty_5.1.11.200609281713

開瀏覽器到 http://localhost/index.html 測看看,也可以改點東西玩看看,只要改完在 console 輸入 update 1 就會生效。

Download

為了方便測試,將所有需要的 bundle 包一起,同時還有 HelloDwr 的原始碼,有需要的人可以用 eclipse 3.2 玩看看。

HelloDwr and osgi target platform

觀察

  1. 目前只有 hello 一下,看一下 debug 輸出,沒有測到太多部份。
  2. 試圖將 dwr 獨立成可重複使用的 bundle,沒有成功,因為 dwr 運作時需要載入 HeheBean.class 來讀取 annotation,如何將 HeheBean 變成服務反注入 dwr 還有待練習。

hellojsp bundle

0

源起

試著完成一個簡易的 JSP bundle,然後跑在 OSGi 的平台上。

要測前先看看之前的環境設定,先確定可以跑起來。

Hello OSGi JSP examples

Hello OSGi Servlet

hellojsp project

到 eclipse 建立一個純 OSGi 的 Plugin project,最後 export 成為 jar 即可。

  1. META-INF/MANIFEST.MF
  2. OSGI-INF/component.xml
  3. src/hello/Component.java
  4. build.properties
  5. web/index.html
  6. web/hello.jsp

MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloJsp Plug-in
Bundle-SymbolicName: HelloJsp
Bundle-Version: 1.0.0
Bundle-Localization: plugin
Import-Package: javax.servlet;version="2.4.0",
 org.eclipse.equinox.jsp.jasper,
 org.osgi.framework;version="1.4.0",
 org.osgi.service.component;version="1.0.0",
 org.osgi.service.http;version="1.2.0",
 org.osgi.service.log;version="1.3.0" 
Service-Component: OSGI-INF/component.xml

component.xml

<?xml version="1.0" encoding="UTF-8"?>
<component name="hello.component">
  <implementation class="hello.Component"/>
  <reference name="LOG" 
    interface="org.osgi.service.log.LogService" 
    cardinality="1..1" 
    bind="setLog" unbind="unsetLog" 
    policy="static"/>
  <reference name="HTTP" 
    interface="org.osgi.service.http.HttpService" 
    cardinality="1..1" 
    policy="dynamic" 
    bind="setHttp" 
    unbind="unsetHttp"/>
</component>

src/hello/Component.java

package hello;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.eclipse.equinox.jsp.jasper.ContextPathServletAdaptor;
import org.eclipse.equinox.jsp.jasper.JspServlet;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.osgi.service.log.LogService;

public class Component {

    LogService log;
    HttpService httpService;
    static final String ROOT = "/web";

    protected void activate(ComponentContext context) {

        log.log(LogService.LOG_INFO, "active hello.Component");
        HttpContext commonContext = this.httpService.createDefaultHttpContext();

        JspServlet jspServlet = new JspServlet(context.getBundleContext()
                .getBundle(), ROOT);

        Servlet adaptedJspServlet = new ContextPathServletAdaptor(jspServlet,
                "/", ROOT);
        try {
            httpService.registerResources("/", ROOT, commonContext);
            httpService.registerServlet("/*.jsp", 
                            adaptedJspServlet, null, commonContext);            
        } catch (NamespaceException ne) {
            log.log(LogService.LOG_ERROR, ne.getMessage());
        } catch (ServletException se) {
            log.log(LogService.LOG_ERROR, se.getMessage());
        }
    }

    protected void deactivate(ComponentContext context) {
        log.log(LogService.LOG_INFO, "deactive hello.Component");

    }

    protected void setLog(LogService logService) {
        this.log = logService;

    }

    protected void unsetLog(LogService logService) {
        this.log = null;
    }

    protected void setHttp(HttpService httpService) {
        this.httpService = httpService;
    }

    protected void unsetHttp(HttpService httpService) {
        this.httpService.unregister("/");
        this.httpService.unregister("/*.jsp");
        this.httpService = null;
    }

}

build.properties

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               OSGI-INF/,\
               web/

OSGi console

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20061023
27    ACTIVE      javax.servlet.jsp_2.0.0.200610251427
28    ACTIVE      org.apache.commons.el_1.0.0
29    ACTIVE      org.apache.jasper_5.5.17.200610251427
37    ACTIVE      org.eclipse.equinox.jsp.jasper_1.0.0.200610251427
38    ACTIVE      org.eclipse.equinox.jsp.jstl_1.0.0
40    ACTIVE      javax.servlet_2.4.0.200609281713
41    ACTIVE      org.apache.commons.logging_1.0.4
42    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
43    ACTIVE      org.eclipse.equinox.http.jetty_1.0.0.v20061012
44    ACTIVE      org.eclipse.equinox.http.servlet_1.0.0.v20061023
47    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
48    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
49    ACTIVE      org.mortbay.jetty_5.1.11.200609281713
51    ACTIVE      HelloJsp_1.0.0

測試

因為資源映射到 web 目錄下,所以直接用下面連結可以測試。

http://localhost/index.html

http://localhost/hello.jsp

觀察

  1. log service 改用 setXX/unsetXX 方式比較直覺,不需要再去找,OSGi 可以確保 active 到 deactive 之間這些服務運作正常。

hello osgi jsp example

0

源起

OSGi 的 HttpService 只提供 servlet 與靜態 resource 註冊,並不提供 JSP,同時 OSGi 定義只到 Servlet API 2.1 版本,如果需要支援 JSP 等標準,就必須另外掛一些 bundle 上去。

一開始需要下載 OSGi 的環境來用。

http://www.eclipse.org/equinox/

HTTP Service (Servlet 2.4 API)

目前還未正式釋出,可以用 eclipse 3.2 team project 匯入來使用,真正要用時再直接匯出成 jar 即可。根據 maillist 的說法,可能會在 3.3M3 釋出,到時就可以直接拿來用。

Embedding an HTTP server in Equinox

http://www.eclipse.org/equinox/server/http_in_equinox.php

http://www.eclipse.org/equinox/server/downloads/jettyhttp-anon.psf

HTTP Service 的實做變成 org.eclipse.equinox.http.jetty,設計方式為轉接 HTTP Service 介面到 jetty 的介面,就可以讓 OSGi 環境使用。

因為 jetty 緣故,所以可以提供 Servlet 2.4 支援,不過需要支援的相依 jar 會比較多。

osgi> 2006/10/26 上午 11:32:58 org.mortbay.http.HttpServer doStart
資訊: Version Jetty/5.1.x
2006/10/26 上午 11:32:58 org.mortbay.util.Container start
資訊: Started org.mortbay.jetty.servlet.ServletHandler@12558d6
2006/10/26 上午 11:32:58 org.mortbay.util.Container start
資訊: Started HttpContext[/,/]
2006/10/26 上午 11:32:58 org.mortbay.http.SocketListener start
資訊: Started SocketListener on 0.0.0.0:80
2006/10/26 上午 11:32:58 org.mortbay.util.Container start
資訊: Started org.mortbay.http.HttpServer@1e859c0

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
4    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
7    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
8    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
14    ACTIVE      javax.servlet_2.4.0.200610251415
15    ACTIVE      org.apache.commons.logging_1.0.4.200610251415
16    ACTIVE      org.eclipse.equinox.http.jetty_1.0.0.200610251415
17    ACTIVE      org.eclipse.equinox.http.servlet_1.0.0.200610251415
18    ACTIVE      org.mortbay.jetty_5.1.11.200610251415

JSP

一樣用 team projext 匯入。根據 maillist 的說法,可能會在 3.3M4 釋出,到時就可以直接拿來用。

OSGi based JSP Support

http://www.eclipse.org/equinox/server/jsp_support.php

http://www.eclipse.org/equinox/server/downloads/jspsupport-anon.psf

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
4    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
7    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
8    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
14    ACTIVE      javax.servlet_2.4.0.200610251415
15    ACTIVE      org.apache.commons.logging_1.0.4.200610251415
16    ACTIVE      org.eclipse.equinox.http.jetty_1.0.0.200610251415
17    ACTIVE      org.eclipse.equinox.http.servlet_1.0.0.200610251415
18    ACTIVE      org.mortbay.jetty_5.1.11.200610251415
27    ACTIVE      javax.servlet.jsp_2.0.0.200610251427
28    ACTIVE      org.apache.commons.el_1.0.0
29    ACTIVE      org.apache.jasper_5.5.17.200610251427
30    ACTIVE      org.eclipse.equinox.jsp.examples_1.0.0
31    ACTIVE      org.eclipse.equinox.jsp.jasper_1.0.0.qualifier
32    ACTIVE      org.eclipse.equinox.jsp.jstl_1.0.0
33    ACTIVE      org.eclipse.equinox.jsp.jstl.examples_1.0.0

The jsp/jstl examples can be found at :

http://localhost/jsp-examples/index.html

http://localhost/jstl-examples/index.html

心得

  1. OSGi 的應用慢慢移到 server-side 和 eclipse 的這些年應用推廣很有關係,目前來看,開發一個 Bundle 最方便的方式還是開 eclipse 來用,雖然它的 PDE 環境還不是完整地支援 OSGi 開發,但是應會慢慢變的更完整。就馬上要用的需求來說,eclipse 的 PDE 環境算是十分方便,這點還沒在其開發環境看到。
  2. 類似 OSGi 的環境猜想應早就有人做過,只是沒到臨界點無法流行,目前 OSGi 有 eclipse IDE 這類比較大的用戶基礎來支撐,可以不斷演進與除錯,這點對於微型應用開發者來說,還蠻重要的。

hello osgi servlet

0

源起

在 OSGi 原始的 R1 時代,Framework/Http/Log/Device Access 的部份就已經上場,這裡將試做 Http/Log 的部份,並使用 R4 的 Declarative Services 規格 org.osgi.service.component 來試驗。

規格書的 R4 Compendium V4.0.1 Specification 中 102 Http Service Specification 指的就是 org.osgi.service.http 這個部份,該部分實做可以參考 org.eclipse.equinox.http.HttpService。

如何用 Http Service

這裡建議使用 eclipse 來做,先建立一個空白標準 OSGi 專案,然後需要動到三個檔案,因為 eclipse PDE 尚未支援 Service-Component 的標籤,所以要自行到 MANIFEST 去填寫。

  1. META-INF/MANIFEST.MF (修改檔案 Service-Component point to component.xml)
  2. OSGI-INF/component.xml (新增檔案 implementation point to Component.java)
  3. Component.java (新增檔案 activate and deactivate methods)

META-INF/MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloHttp Plug-in
Bundle-SymbolicName: HelloHttp
Bundle-Version: 1.0.0
Bundle-Localization: plugin
Import-Package: javax.servlet;version="2.3.0",
 javax.servlet.http;version="2.3.0",
 org.osgi.framework;version="1.3.0",
 org.osgi.service.component;version="1.0.0",
 org.osgi.service.http;version="1.2.0",
 org.osgi.service.log;version="1.3.0" 
Service-Component: OSGI-INF/component.xml

OSGI-INF/component.xml

<?xml version="1.0" encoding="UTF-8"?>
<component name="hello.component">
  <implementation class="hello.Component"/>
  <reference name="LOG" 
    interface="org.osgi.service.log.LogService" 
    cardinality="1..1" 
    policy="static"/>
  <reference name="HTTP" 
    interface="org.osgi.service.http.HttpService" 
    cardinality="0..1" 
    policy="dynamic" 
    bind="setHttp" 
    unbind="unsetHttp"/>
</component>

hello/Component.java

package hello;

import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.osgi.service.log.LogService;

public class Component {
    LogService log;
    HttpService http;
    protected void activate(ComponentContext context) {
        log = (LogService) context.locateService("LOG");
        log.log(LogService.LOG_INFO, "#### Hello World");
    }
    protected void deactivate(ComponentContext context) {
        log.log(LogService.LOG_INFO, "#### Goodbye World");
    }
    protected void setHttp(HttpService h) {
        this.http = h;
        this.registerServlet();
    }
    protected void unsetHttp(HttpService h) {
        this.http.unregister("/haha");
        this.http = null;
    }
    private void registerServlet() {

        Hashtable initparams = new Hashtable();
        initparams.put("name", "value");

        Servlet myServlet = new HttpServlet() {

            String name = "foo";

            public void init(ServletConfig config) {
                this.name = (String) config.getInitParameter("name");
            }

            public void doGet(HttpServletRequest req, HttpServletResponse rsp)
                    throws IOException {
                String foo = req.getParameter("foo");
                rsp.setContentType("text/html;charset=UTF-8");
                StringBuilder sb = new StringBuilder();
                sb.append("The init parameter : " + this.name);
                sb.append("<BR/>");
                sb.append("The foo parameter : " + foo);
                sb.append("<BR/>");
                sb.append("日期 : " + new Date());
                sb.append("<BR/>");

                // servlet 2.3 only
                //Locale reqLocal = req.getLocale();
                //sb.append("The country is :" + reqLocal.getCountry()).append("<BR/>");
                //sb.append("The language is :" + reqLocal.getLanguage());    
                rsp.getWriter().println(sb.toString());

            }
        };

        try {

            http.registerServlet("/haha", myServlet, initparams,null);

        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamespaceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

測試

先看看 bundle 以及 log 服務是否運作。 然後開 http://127.0.0.1/haha?foo=abc 看看,之後再關掉 http service。

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
2    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
4    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
6    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
12    ACTIVE      HelloHttp_1.0.0
13    ACTIVE      org.eclipse.equinox.http_1.0.100.v20060821
14    ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060717

osgi> log
>Info [4] Log created; Log Size=100; Log Threshold=4 initial@reference:file:org.eclipse.equinox.log_1.0.100.v20060717.jar/
>Info [4] ServiceEvent REGISTERED {service.id=21}
>Info [4] ServiceEvent REGISTERED {service.id=22}
>Info [4] ServiceEvent REGISTERED {service.id=23}
>Info [4] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.log_1.0.100.v20060717.jar/
>Info [6] BundleEvent STARTED initial@reference:file:org.eclipse.osgi.services_3.1.100.v20060918.jar/
>Info [12] #### Hello World initial@reference:file:../HelloLog/
>Info [12] BundleEvent STARTED initial@reference:file:../HelloLog/
>Info [13] ServiceEvent REGISTERED {service.id=24}
>Info [13] ServiceEvent REGISTERED {service.id=25}
>Info [13] ServiceEvent REGISTERED {service.id=26}
>Info [13] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.http_1.0.100.v20060821.jar/
>Info [14] BundleEvent STARTED initial@reference:file:org.eclipse.equinox.servlet.api_1.0.0.v20060717.jar/
>Info [0] FrameworkEvent STARTLEVEL CHANGED System Bundle

osgi> stop 13

osgi> log

>Info [13] ServiceEvent UNREGISTERING {service.id=25}
>Info [13] ServiceEvent UNREGISTERING {service.id=26}
>Info [13] ServiceEvent UNREGISTERING {service.id=24}
>Info [13] BundleEvent STOPPED initial@reference:file:org.eclipse.equinox.http_1.0.100.v20060821.jar/

網路上找個新的 Http Service 來換。

osgi> install http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
Bundle id is 15

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
2    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
4    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
6    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
12    ACTIVE      HelloHttp_1.0.0
13    RESOLVED    org.eclipse.equinox.http_1.0.100.v20060821
14    ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060717
15    INSTALLED   org.knopflerfish.bundle.http_2.0.0

osgi> start 15

osgi> ss

Framework is launched.

id    State       Bundle
0    ACTIVE      system.bundle_3.3.0.v20060919
2    ACTIVE      org.eclipse.equinox.ds_1.0.0.v20060828
4    ACTIVE      org.eclipse.equinox.log_1.0.100.v20060717
6    ACTIVE      org.eclipse.osgi.services_3.1.100.v20060918
12    ACTIVE      HelloHttp_1.0.0
13    RESOLVED    org.eclipse.equinox.http_1.0.100.v20060821
14    ACTIVE      org.eclipse.equinox.servlet.api_1.0.0.v20060717
15    ACTIVE   org.knopflerfish.bundle.http_2.0.0

osgi> log
>Info [15] BundleEvent INSTALLED http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] BundleEvent RESOLVED http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] ServiceEvent REGISTERED {service.id=27}
>Info [15] No CM present, using default configuration http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] Updated pid=org.knopflerfish.bundle.http.factory.HttpServer.default http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] create pid=org.knopflerfish.bundle.http.factory.HttpServer.default http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] Creating socket http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] HTTP server started on port 8080 http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Info [15] ServiceEvent REGISTERED {service.id=28}
>Info [15] BundleEvent STARTED http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar
>Debug [15] Alias "/haha" was registered by bundle 12 http://www.knopflerfish.org/repo/jars/http/http_all-2.0.0.jar

再測一次看看。

Home Gateway Asus WL 500gp

6

源起

客廳需要一個小功率的電腦做一些居家環境控制的事,有些條件希望可以滿足。

  1. 不超過五千
  2. 比省電燈泡的 13w 還省
  3. 有很多人使用的經驗
  4. 豐富與即時的更改版韌體可供使用
  5. 支援 USB
  6. 支援網路下載功能

最後買了 Asus WL-500g Premium 小白來用,下面是一些使用紀錄。這台小白機器的外觀與內在都被拍下來,可以參考 這裡 ,看過才知道這類產品美國 FCC 都會有資料上網公開。

第一次測試

一開始總要先插電測看看是否正常,這台機器底部有寫預設 IP 為 192.168.1.1 與密碼防止忘記,一開始的動作就市找台電腦,調到同一個網段 192.168.1.xx 來操作,連上去後先 確認 firmware 與功能正常。

因為這機器是暫時內部用來測試,所以先不管 WLAN 的那個部份。網頁秀出的韌體版本是 1.9.6.7 ,目前 asus 新版本是 1.9.7.0,不過馬上要換成客製版韌體,所以也不用更新。

另外這機器的 MAC 地址後面是 3b:a5,雖然拔掉天線,Thinkpad T41 內建網卡隔個房間可抓到約 30 % 強度,既然暫時不會動 WLAN,也沒有進一步測試。

改韌體 firmware image

要在 Linux 環境上加些應用軟體,需要改用其他韌體來支援,才能提供 telnet/ssh 等擴充功能,當然也可以自己來,只是為了快速使用,直接採用別人測過的韌體比較簡便。

改機韌體有幾個選擇,這裡採用 Olegs 版本,這個版本加了 telnet/ssh/smaba/Qos/ipkg 等強化小白的必備工具,關於這個韌體更多資料可以參考 General information about Olegs Firmware

Olegs 的網頁 ASUS WL-500g/WL-500gx/WL-300g/WL-500b/WL-500bv2/WL-HDD custom firmware page

注意下面有提到的死機問題,到時可能會需要拆開才可以回復原廠設定,請先有準備。

WL-500g Premium Howto Part One

WL500g Premium pre7 firmware

開始換韌體。

  1. 上傳 WL500gp-1.9.2.7-7f-pre7.trx 到小白
  2. 網頁變成英文,可以下 command ,試看看 ifconfig。
  3. telnet 192.168.1.1 看看 OK。
  4. 檢查無線強度,在 status 關掉 wireless 看看。
  5. 重新開機檢視,在 status 關掉是臨時的,可以進 wireless 關掉,以後再開。
  6. LAN IP 為目前使用的內部網段,所以運作模式要改為 access point mode,這樣才方便設定 default gw 到原先的 router。
  7. 改掉預設的密碼

下面可以看出沒有增加記憶體到 32M,只有 16M。

[admin@whitebox /]$ df
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/root                 2944      2944         0 100% /
[admin@whitebox /]$ free
              total         used         free       shared      buffers
  Mem:        13932        10560         3372            0         1308
 Swap:            0            0            0
Total:        13932        10560         3372

進一步看看。

[admin@whitebox root]$ dmesg | more
CPU revision is: 00029006
Primary instruction cache 16kb, linesize 16 bytes (2 ways)
Primary data cache 16kb, linesize 16 bytes (2 ways)
Linux version 2.4.20 (root@omnibook) 
(gcc version 3.2.3 with Broadcom modifications) #60 Sun Sep 3 22:38:39 MSD 2006
Setting the PFC value as 0x15
Determined physical RAM map:
 memory: 01000000 @ 00000000 (usable)
On node 0 totalpages: 4096
zone(0): 4096 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/mtdblock2 noinitrd init=/linuxrc console=ttyS0,115200
CPU: BCM4704 rev 9 at 264 MHz
Calibrating delay loop... 262.96 BogoMIPS
Memory: 13860k/16384k available 
(1776k kernel code, 2524k reserved, 248k data, 72k init, 0k highmem)
Dentry cache hash table entries: 2048 (order: 2, 16384 bytes)
Inode cache hash table entries: 1024 (order: 1, 8192 bytes)
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 4096 (order: 2, 16384 bytes)

雖然有 telnet 預設,sshd 卻不是,需要加些設定。

ssh server

  1. mkdir -p /usr/local/etc/dropbear
  2. dropbearkey -t dss -f /usr/local/etc/dropbear/dropbear_dss_host_key
  3. dropbearkey -t rsa -f /usr/local/etc/dropbear/dropbear_rsa_host_key
  4. mkdir -p /usr/local/sbin/
  5. echo ”#!/bin/sh” >> /usr/local/sbin/post-boot
  6. chmod +x /usr/local/sbin/post-boot
  7. echo “dropbear” >> /usr/local/sbin/post-boot
  8. dropbear and netstat -at
  9. flashfs save && flashfs commit && flashfs enable && reboot

寫入 flash 後,每次開機 dropbear (ssh server) 都會被啟動,至於那隻 post-boot 會被自動叫起,那是這個韌體提供的便利之一。

目前資料開機後都會消失,所以需要藉由 USB 硬碟來提供可存放空間。

接上隨身碟

延續之前的設定,這次要加上可以放東西的空間,這裡是利用一隻舊隨身碟 128M。

ipkg package system Tutorial

  1. fdisk /dev/discs/disc0/disc
  2. d n p 1 enter +96M
  3. n p 2 enter enter t 2 82 w
  4. fdisk -l
  5. mke2fs -j /dev/discs/disc0/part1
  6. mkswap /dev/discs/disc0/part2
  7. mount /dev/discs/disc0/part1 /opt
  8. swapon /dev/discs/disc0/part2
  9. df
  10. free

測試可以後,裝些東西試看看。

  1. mkdir /opt/tmp
  2. mkdir /opt/tmp/ipkg
  3. ipkg.sh update
  4. ipkg.sh install ipkg
  5. /opt/bin/ipkg update
  6. /opt/bin/ipkg install nano
  7. /opt/bin/nano /usr/local/sbin/post-boot
  8. flashfs save && flashfs commit && flashfs enable && reboot

在之前的 dropbear 下面繼續加東西。

#!/bin/sh
dropbear
# wait for /opt to mount
mount /dev/discs/disc0/part1 /opt
i=0
while [ $i -le 30 ]
do
if [ -d /opt/etc ]
then
break
fi
sleep 1
i = `expr $i + 1`
done

# Activate swap
swapon /dev/discs/disc0/part2

開機後檢視一下 df/free 看是否正常,如有問題 dmesg 看一下。

java

java 環境已經有人幫忙做好,只要一點小改。

Unslung/WL500g packages available for Oleg’s firmware

改 /opt/etc/ipkg.conf 設定,讓 ipkg 裝別的地方。

src unslung http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable 
dest root /
  1. nano /opt/etc/ipkg.conf
  2. ipkg update
  3. mkdir -p /opt/usr/lib
  4. ipkg install uclibc
  5. ipkg install sablevm
  6. ipkg install jikes
  7. ipkg install zlib
  8. ipkg install popt
  9. ipkg list_installed

最後安裝結果。

ipkg - 0.99.149-2 -
jikes - 1.22-1 - IBM java compiler
libstdc++ - 0.2.0-4 - =Standard C++ library, wrapped for uClibc++
libtool - 1.5.10-2 - Library tools.
libuclibc++ - 0.2.1-5 - C++ standard library d....
nano - 1.2.5-3 - A pico like editor
ncurses - 5.5-1 - NCurses libraries
popt - 1.7-2 - A C library for parsing command line parameters.
sablevm - 1.13-2 - A robust... JVM.
uclibc - 0.9.28-1 - micro C library for embedded Linux systems
zlib - 1.2.3-1 - zlib is a .....

如果沒裝 popt/zlib 執行的時候會提醒你。

$ sablevm --version
SableVM version 1.13
- compile date and time: 2006-08-12 14:14:23 UTC
- gcc version: 3.4.6
- 'real life brokenness' features enabled
- copying garbage collection
- bidirectional object layout
- direct-threaded interpreter

測一下 HelloWorld。

  1. cd /opt/tmp
  2. nano HelloWorld.java
  3. jikes -classpath /opt/lib/sablevm/lib/libclasspath.jar HelloWorld.java
  4. sablevm HelloWorld

Samba

  1. mkdir /opt/etc/samba
  2. nano /opt/etc/samba/smb.conf
  3. nano /opt/etc/init.d/S97Samba
  4. chmod 755 /opt/etc/init.d/S97Samba

smb.conf

[global]
workgroup = WORKGROUP
guest account = nobody
security = share
browseable = yes
guest ok = yes
guest only = no
log level = 1
max log size = 100
encrypt passwords = no
dns proxy = no

[smbshare]
path=/opt/share
writeable = yes
browseable = yes
force user = admin

S97Samba

#!/bin/sh
/usr/sbin/smbd -D -l /opt/var/log/smbd.log -s /opt/etc/samba/smb.conf
/usr/sbin/nmbd -D -n myasus -o -l /tmp -s /opt/etc/samba/smb.conf 

最後要改起動檔 post-boot 加入一行 /opt/etc/init.d/rc.unslung ,代表啟動 S 開頭的服務。

  1. nano /usr/local/sbin/post-boot
  2. flashfs save && flashfs commit && flashfs enable && reboot
  3. netstat -at

\\192.168.1.1\smbshare 看看。

加大記憶體

預設只有 16MB RAM,但是板子上有 32MB,所以改一下 NVRAM 參數來用到 32MB RAM。 注意這是 gp 做法,其他板子不確定。

  1. nvram set sdram_init=0×0009
  2. nvram set sdram_ncdl=0
  3. nvram commit
  4. reboot
  5. free

一些觀察

  1. 安裝 Oleg 之後,網頁介面 USB Application – FTP Server 雖說 enable,但是檢驗 netstat/ps 看不到,想要 ftp 也是不行,這個設定跟掛載 USB 硬碟有關係,既然是用 post-boot 手動掛上, 如果需要 ftp 也要手動掛上。
  1. dropbear 沒有支援 sftp,只有 scp,要用 winscp 也需要一點會出現錯誤訊息,找到進階 選項的 SCP 部分,將 Lookup user groups 關掉就可以。參考 UseDropBearForRemoteAccess 獲得更多資訊。

links

關於核心效能參數的調整與強化參考 AP 進階改造,下載破表

很多的 Oleg 教學參考 Tutorials – Oleg

編譯官方核心的教學參考 HOW-TO: Compile a firmware for the WL-700g from the GPL 1.0.4.2

差別在 gp 部份,目前新版本為 24-Aug-2006 的 GPL_ToolChain.zip。

http://files.wl500g.info/asus/wl500gp/gpl/ ftp://dlsvr01.asus.com/pub/ASUS/wireless/WL-500gP/GPL_ToolChain.zip

一些 USB轉UART 使用 pl2303 的線應該可用,參考 Use an USB-serial port converter

外接基本 LCD 模組的做法參考 Connecting a LCD to the WL500g

Older posts: 1 ... 5 6 7 8 9 ... 18