2015年4月30日 星期四
[php] 列出 1~100 質數並加總
1.原理: 100 = 10*10,所以只要驗證10以內的質因數即可
2.利用常數限定數值範圍
3.計算質數總和
<?php
$number = 0;
$sum = 0;
define("MAX","100");
define("MIN", "1");
echo "This is homework for php done by Anne on April 29.<br/>";
do{
if ( $number > MIN ){
switch ($number){
case 2:
case 3:
case 5:
case 7:
echo $number." is prime <br/>";
$sum += $number;
break;
default:
if( $number % 2 !=0 ){
if ($number % 3 !=0){
if ($number % 5 !=0){
if ($number % 7 !=0){
echo $number." is prime<br/>";
$sum += $number;
}
}
}
}
break;
}
}
$number ++;
}while( $number < MAX);
echo "Sum of the primes =".$sum;
?>
2013年7月1日 星期一
[Linux] Qemu Settings : Networking
[Reference]
http://blog.chinaunix.net/uid-26061689-id-2981914.html
http://www.mediaonfire.com/en/tech_tips/QEMUNetworking.html
https://people.gnome.org/~markmc/qemu-networking.html
http://opencsl.openfoundry.org/Lab03_root_filesystem.rst.html
http://www.osslab.com.tw/Hardware/Open_Embedded_System/ARM/ARM_Simulator_on_x86_with_Qemu/%E5%9C%A8x86_%E6%A8%A1%E6%93%AC%E7%92%B0%E5%A2%83%E4%B8%8B%E6%B8%AC%E8%A9%A6ARM_Ubuntu
http://blog.roodo.com/use_the_force/archives/2717044.html
http://user.frdm.info/ckhung/b/sa/qemu.php
http://idobest.pixnet.net/blog/post/22040220-%5B%E8%BD%89%E8%B2%BC%5D-qemu-%E7%B6%B2%E8%B7%AF%E8%A8%AD%E5%AE%9A
http://mikelev.in/2010/07/qemu-network-qemu-networking/
The following steps showing about how to enable internet function for qemu:
00. Host PC environment
Linux yen-desktop 3.2.0-48-generic #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
01. Install packages
sudo apt-get install uml-utilities
sudo apt-get install bridge-utils
[Trying records]
sudo apt-get install uml-utilities
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
uml-utilities 已經是最新版本了。
以下套件為自動安裝,並且已經無用:
libtxc-dxtn-s2tc0 libllvm3.1
使用 'apt-get autoremove' 來將其移除。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
02.Host PC Setting Commands
ifconfig eth0 down
brctl addbr br0
brctl addif br0 eth0
brctl stp br0 off
brctl setfd br0 1
brctl sethello br0 1
ifconfig br0 0.0.0.0 promisc up
ifconfig eth0 0.0.0.0 promisc up
dhclient br0
brctl show br0
brctl showstp br0
tunctl -t tap0 -u root
brctl addif br0 tap0
ifconfig tap0 0.0.0.0 promisc up
brctl showstp br0
http://blog.chinaunix.net/uid-26061689-id-2981914.html
http://www.mediaonfire.com/en/tech_tips/QEMUNetworking.html
https://people.gnome.org/~markmc/qemu-networking.html
http://opencsl.openfoundry.org/Lab03_root_filesystem.rst.html
http://www.osslab.com.tw/Hardware/Open_Embedded_System/ARM/ARM_Simulator_on_x86_with_Qemu/%E5%9C%A8x86_%E6%A8%A1%E6%93%AC%E7%92%B0%E5%A2%83%E4%B8%8B%E6%B8%AC%E8%A9%A6ARM_Ubuntu
http://blog.roodo.com/use_the_force/archives/2717044.html
http://user.frdm.info/ckhung/b/sa/qemu.php
http://idobest.pixnet.net/blog/post/22040220-%5B%E8%BD%89%E8%B2%BC%5D-qemu-%E7%B6%B2%E8%B7%AF%E8%A8%AD%E5%AE%9A
http://mikelev.in/2010/07/qemu-network-qemu-networking/
The following steps showing about how to enable internet function for qemu:
00. Host PC environment
Linux yen-desktop 3.2.0-48-generic #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
sudo apt-get install uml-utilities
sudo apt-get install bridge-utils
[Trying records]
sudo apt-get install uml-utilities
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
uml-utilities 已經是最新版本了。
以下套件為自動安裝,並且已經無用:
libtxc-dxtn-s2tc0 libllvm3.1
使用 'apt-get autoremove' 來將其移除。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
sudo apt-get install bridge-utils
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
bridge-utils 已經是最新版本了。
以下套件為自動安裝,並且已經無用:
libtxc-dxtn-s2tc0 libllvm3.1
使用 'apt-get autoremove' 來將其移除。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
02.Host PC Setting Commands
ifconfig eth0 down
brctl addbr br0
brctl addif br0 eth0
brctl stp br0 off
brctl setfd br0 1
brctl sethello br0 1
ifconfig br0 0.0.0.0 promisc up
ifconfig eth0 0.0.0.0 promisc up
dhclient br0
brctl show br0
brctl showstp br0
tunctl -t tap0 -u root
brctl addif br0 tap0
ifconfig tap0 0.0.0.0 promisc up
brctl showstp br0
[Trying records]
yen0430@yen-desktop:/$ brctl
Usage: brctl [commands]
commands:
addbr <bridge> add bridge
delbr <bridge> delete bridge
addif <bridge> <device> add interface to bridge
delif <bridge> <device> delete interface from bridge
hairpin <bridge> <port> {on|off} turn hairpin on/off
setageing <bridge> <time> set ageing time
setbridgeprio <bridge> <prio> set bridge priority
setfd <bridge> <time> set bridge forward delay
sethello <bridge> <time> set hello time
setmaxage <bridge> <time> set max message age
setpathcost <bridge> <port> <cost> set path cost
setportprio <bridge> <port> <prio> set port priority
show [ <bridge> ] show a list of bridges
showmacs <bridge> show a list of mac addrs
showstp <bridge> show bridge stp info
stp <bridge> {on|off} turn stp on/off
yen0430@yen-desktop:/$ sudo brctl addbr br0
[sudo] password for yen0430:
yen0430@yen-desktop:/$ sudo brctl addif br0 eth0
yen0430@yen-desktop:/$ sudo brctl stp br0 off
yen0430@yen-desktop:/$ sudo brctl setfd br0 1
yen0430@yen-desktop:/$ sudo brctl sethello br0 1
yen0430@yen-desktop:/$ sudo ifconfig br0 0.0.0.0 promisc up
yen0430@yen-desktop:/$ sudo ifconfig eth0 0.0.0.0 promisc up
yen0430@yen-desktop:/$ sudo dhclient br0
yen0430@yen-desktop:/$ sudo brctl show br0
bridge name bridge id STP enabled interfaces
br0 8000.eca86b8de3e0 no eth0
yen0430@yen-desktop:/$ sudo brctl showstp br0
br0
bridge id 8000.eeeeeeeeeeeeeee
designated root 8000.eeeeeeeeeeeee
root port 0 path cost 0
max age 20.00 bridge max age 20.00
hello time 1.00 bridge hello time 1.00
forward delay 1.00 bridge forward delay 1.00
ageing time 300.01
hello timer 0.06 tcn timer 0.00
topology change timer 0.00 gc timer 271.03
flags
eth0 (1)
port id 8001 state forwarding
designated root 8000.eeeeeeeeeeee path cost 4
designated bridge 8000.eeeeeeeeeeee message age timer 0.00
designated port 8001 forward delay timer 0.00
designated cost 0 hold timer 0.06
flags
yen0430@yen-desktop:/$ ifconfig
br0 Link encap:Ethernet HWaddr eeeeeeeeeeeeeeeeee
inet addr:xxx.xx.4.92 Bcast:xxx.xx.255.255 Mask:255.255.0.0
inet6 addr: fe80::eeeeeeeeeeeeeee/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:2196 errors:0 dropped:0 overruns:0 frame:0
TX packets:258 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:375516 (375.5 KB) TX bytes:36069 (36.0 KB)
eth0 Link encap:Ethernet HWaddr eeeeeeeeeeeeee
inet6 addr: fe80::eeeeeeeeeeeeeeeeeee/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:33131 errors:0 dropped:0 overruns:0 frame:0
TX packets:13408 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14094542 (14.0 MB) TX bytes:2130457 (2.1 MB)
Interrupt:20 Memory:f7c00000-f7c20000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2646 errors:0 dropped:0 overruns:0 frame:0
TX packets:2646 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:276862 (276.8 KB) TX bytes:276862 (276.8 KB)
yen0430@yen-desktop:~$ sudo tunctl -t tap0 -u root
inet addr:xxx.xx.4.92 Bcast:xxx.xx.255.255 Mask:255.255.0.0
inet6 addr: fe80::eeeeeeeeeeeeeee/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:2196 errors:0 dropped:0 overruns:0 frame:0
TX packets:258 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:375516 (375.5 KB) TX bytes:36069 (36.0 KB)
eth0 Link encap:Ethernet HWaddr eeeeeeeeeeeeee
inet6 addr: fe80::eeeeeeeeeeeeeeeeeee/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:33131 errors:0 dropped:0 overruns:0 frame:0
TX packets:13408 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14094542 (14.0 MB) TX bytes:2130457 (2.1 MB)
Interrupt:20 Memory:f7c00000-f7c20000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2646 errors:0 dropped:0 overruns:0 frame:0
TX packets:2646 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:276862 (276.8 KB) TX bytes:276862 (276.8 KB)
yen0430@yen-desktop:~$ sudo tunctl -t tap0 -u root
Set 'tap0' persistent and owned by uid 0
yen0430@yen-desktop:~$ sudo brctl addif br0 tap0
yen0430@yen-desktop:~$ sudo ifconfig tap0 0.0.0.0 promisc up
yen0430@yen-desktop:~$ sudo brctl showstp br0
br0
bridge id 8000.eeeeeeeeeeeeeeeeee
designated root 8000.eeeeeeeeeeeeeeee
root port 0 path cost 0
max age 20.00 bridge max age 20.00
hello time 1.00 bridge hello time 1.00
forward delay 1.00 bridge forward delay 1.00
ageing time 300.01
hello timer 0.08 tcn timer 0.00
topology change timer 0.00 gc timer 50.04
flags
eth0 (1)
port id 8001 state forwarding
designated root 8000.eeeeeeeeeeeeee path cost 4
designated bridge 8000.eeeeeeeeeeeee message age timer 0.00
designated port 8001 forward delay timer 0.00
designated cost 0 hold timer 0.11
flags
tap0 (2)
port id 8002 state disabled
designated root 8000.eeeeeeeeeeeee path cost 100
designated bridge 8000.eeeeeeeeeeeee message age timer 0.00
designated port 8002 forward delay timer 0.00
designated cost 0 hold timer 0.00
flags
yen0430@yen-desktop:~$ sudo brctl addif br0 tap0
yen0430@yen-desktop:~$ sudo ifconfig tap0 0.0.0.0 promisc up
yen0430@yen-desktop:~$ sudo brctl showstp br0
br0
bridge id 8000.eeeeeeeeeeeeeeeeee
designated root 8000.eeeeeeeeeeeeeeee
root port 0 path cost 0
max age 20.00 bridge max age 20.00
hello time 1.00 bridge hello time 1.00
forward delay 1.00 bridge forward delay 1.00
ageing time 300.01
hello timer 0.08 tcn timer 0.00
topology change timer 0.00 gc timer 50.04
flags
eth0 (1)
port id 8001 state forwarding
designated root 8000.eeeeeeeeeeeeee path cost 4
designated bridge 8000.eeeeeeeeeeeee message age timer 0.00
designated port 8001 forward delay timer 0.00
designated cost 0 hold timer 0.11
flags
tap0 (2)
port id 8002 state disabled
designated root 8000.eeeeeeeeeeeee path cost 100
designated bridge 8000.eeeeeeeeeeeee message age timer 0.00
designated port 8002 forward delay timer 0.00
designated cost 0 hold timer 0.00
flags
03. Add br0 and tap0 to /etc/network/interfaces
yen0430@yen-desktop:~$ sudo vim /etc/network/interfaces
yen0430@yen-desktop:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
# The bridge network interface(s)
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
# The tap0 network interface(s)
auto tap0
iface tap0 inet manual
pre-up tunctl -t tap0 -u root
pre-up ifconfig tap0 0.0.0.0 promisc up
post-up brctl addif br0 tap0
yen0430@yen-desktop:~$ sudo vim /etc/network/interfaces
yen0430@yen-desktop:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
# The bridge network interface(s)
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
# The tap0 network interface(s)
auto tap0
iface tap0 inet manual
pre-up tunctl -t tap0 -u root
pre-up ifconfig tap0 0.0.0.0 promisc up
post-up brctl addif br0 tap0
04. Add eth0 to target machine/board root file system
yen0430@yen-desktop:~$ vim ${TARGET_BOARD_ROOTFS}/etc/network/interfaces
# Configure Loopback
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
[NOTES]
For buildroot, add these to " buildroot/system/skeleton/etc/network/interfaces " as default.
05. Run qemu
yen0430@yen-desktop:~$ sudo qemu-system-i386 -kernel output/images/bzImage -m 1024 -net nic,model=ne2k_pci -net tap
Could not open option rom 'pxe-ne2k_pci.rom': No such file or directory
[NOTES]
[qemu command]
qemu-system-i386
qemu-system-x86_64
[use 'bzImage' as kernel image]
-kernel output/images/bzImage
Other items:
Linux/Multiboot boot specific:
-kernel bzImage use 'bzImage' as kernel image
-append cmdline use 'cmdline' as kernel command line
-initrd file use 'file' as initial ram disk
[set virtual RAM size to megs MB [default=384]]
-m 1024
[create a new Network Interface Card and connect it to VLAN 'n']
-net nic,model=ne2k_pci
[connect the host TAP network interface to VLAN 'n' and use the network scripts 'file' (default=/etc/qemu-ifup) ]
-net tap
2012年10月5日 星期五
Build up Android Development Environment
Build up Android Development Environment
---------------------------------------------------------------------------------------------------------
Overall
1.Install Packages(sun-java6-jdk, etc...)
2.Install SDK
3.Install Eclipse
4.Install ADT Plugin for Eclipse
5.Install Android Packages
5.Install Android Packages
----------------------------------------------------------------------------------------------------------
[Step1. 安裝相關套件]
root@yen0924-android:/etc/apt# vim sources.list
root@yen0924-android:/etc/apt# tail -2 sources.list
#Java Developement Kit 20121004 added
deb http://ppa.launchpad.net/ferramroberto/java/ubuntu lucid main
root@yen0924-android:~# apt-get update && apt-get upgrade
W: GPG error: http://ppa.launchpad.net lucid Release: 由於無法取得它們的公鑰,以下簽章無法進行驗證: NO_PUBKEY B725097B3ACC3965
W: 無法取得 http://ppa.launchpad.net/sun-java-commuity-team/sun-java6/ubuntu/dists/lucid/main/binary-amd64/Packages.gz,404 Not Found
[使用此方法安裝sun-java6-jdk不成功,改用其他方法替代,詳見後述之補充說明]
root@yen0924-android:~# apt-get upgrade
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
下列套件將會被升級:
apt apt-transport-https apt-utils devscripts libc-bin libc-dev-bin libc6
libc6-dev libc6-dev-i386 libc6-i386 libxml2 libxml2-utils python-libxml2
python-software-properties software-properties-gtk
升級 15 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
需要下載 17.6MB 的套件檔。
此操作完成之後,會空出 303kB 的磁碟空間。
是否繼續進行 [Y/n]?y
0% [等待標頭]
[若Ubuntu為64-bit,則需要安裝下列套件]
root@yen0924-android:~# apt-get install ia32-libs
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
ia32-libs 已經是最新版本了。
以下套件是被自動安裝進來的,且已不再會被用到了:
linux-headers-2.6.32-38 linux-headers-2.6.32-38-generic
使用 'apt-get autoremove' 來將其移除。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
root@yen0924-android:~#
[安裝sun-java-6-jdk]
root@yen0924-android:~# apt-get install sun-java6-jdk
正在讀取套件清單... 完成
正在重建相依關係
正在讀取狀態資料... 完成
sun-java6-jdk 已經是最新版本了。
以下套件是被自動安裝進來的,且已不再會被用到了:
linux-headers-2.6.32-38 linux-headers-2.6.32-38-generic
使用 'apt-get autoremove' 來將其移除。
升級 0 個,新安裝 0 個,移除 0 個,有 0 個未被升級。
root@yen0924-android:~#
[補充說明:安裝sun-java6-jdk]
Ubuntu:10.04 64bits
Kernel:2.6.31-43
Ubuntu當中,若要安裝java6,自動的安裝指令為#apt-get inatall openjdk-6-jdk
若要安裝Oracle(Sun)Java6 則需要手動安裝。
參考網站如下:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
https://help.ubuntu.com/community/Java
http://blog.cheyingwu.tw/index.php/2010/05/02/ubuntu-10-04-switch-to-sun-jdk/
http://way3sec.blogspot.tw/2010/05/ubuntu-1004java.html
步驟如下:(以root執行下列指令)
#add-apt-repository “deb http://archive.canonical.com/ lucid partner”
#apt-get update apt-get install sun-java6-jdk sun-java6-plugin
#update-java-alternatives -s java-6-sun
安裝之後,最重要的是要手動選擇需要的java6版本
#update-alternatives --config java
執行過程如下:
root@yen0924-android:~/ex_ADE# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path 優先級 Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.
root@yen0924-android:~/ex_ADE#
---------------------------------------------------------------------------------
[Step2. 下載 SDK 並逐步安裝]
root@yen0924-android:~# tar zfx android-sdk_r20.0.3-linux.tgz
root@yen0924-android:~# ls
Android_Build_System gingerBread_0925ver01
android-sdk-linux notes_0925_initEnv.txt
android-sdk_r20.0.3-linux.tgz notes_0926.buildAndroid.txt
ex_ADE_01 oab-java6.sh
ex_shell oab-java.sh
gB_0925_ver02 oab-java.sh.log
root@yen0924-android:~/android-sdk-linux# file *
add-ons: directory
platforms: directory
SDK Readme.txt: ASCII English text
tools: director
[閱讀Readme,擷取相關內容如下]
root@yen0924-android:~/android-sdk-linux# cat SDK\ Readme.txt
To start the SDK Manager, please execute the program "android".
From the command-line you can also directly trigger an update by
executing:
tools/android update sdk --no-ui
Tip: use --help to see the various command-line options.
For more information, please consult the Android web site at
http://developer.android.com/sdk/
[根據Readme的內容,執行安裝指令,下列為安裝過程訊息,結束後即完成SDK的安裝]
root@yen0924-android:~/android-sdk-linux# ./tools/android update sdk --no-ui
---------------------------------------------------------------------------------
[Step3. 下載Eclipse,解壓縮後執行]
http://www.eclipse.org/downloads/
選擇 Eclipse Juno(4.2) SR1 Package for Linux -> Eclipse IDE for Java EE Developers (Linux 64 Bit)
root@yen0924-android:~/android-sdk-linux# tar zfx eclipse-jee-juno-SR1-linux-gtk-x86_64.tar.gz
root@yen0924-android:~/android-sdk-linux# cd eclipse
root@yen0924-android:~/android-sdk-linux# pwd
/root/eclipse
root@yen0924-android:~/android-sdk-linux# ./eclipse
設定workspace為 /root/workspace
---------------------------------------------------------------------------------
[Step4. 安裝Eclipse Plugin (ADT)]
http://developer.android.com/sdk/installing/installing-adt.html
root@yen0924-android:~/android-sdk-linux# ./eclipse
點選上方工具列 Help -> Install New Software
-> [click] Add
-> [填寫] Name:"ADT Plugin", URL:"http://dl-ssl.google.com/android/eclipse/"
-> [click] OK
-> [click] Next...-> [click] Finish
-> 重新開啟Eclipse
若要更新ADT
點選上方工具列 Help-> Check for Update
---------------------------------------------------------------------------------
[Step5. 安裝需要的Android版本]
http://developer.android.com/sdk/installing/adding-packages.html
點選上方工具列Window -> Android SDK Manager
-> 找出需要的Packages並勾選
-> [click] Install packages
SDK Tools, SDK Platform-tools, SDK Platform 必選
---------------------------------------------------------------------------------
訂閱:
文章 (Atom)