2014年1月13日 星期一

編譯核心給 s3c2440 出現 error: ‘__LINUX_ARM_ARCH__’ undeclared (first use in this function)

編譯核心給 s3c2440 出現error: ‘__LINUX_ARM_ARCH__’ undeclared (first use in this function) 解法


把 System Type -> S3C2440 Machines 裡面的東西全選



mini2440 buildroot 
http://buildroot-busybox.2317881.n4.nabble.com/build-of-e2fsprogs-fails-2012-02-rc3-td1597.html

2014年1月12日 星期日

Ethernet And Wireless Bonding(在 linux 下合併兩張網卡,變成一張)


為什麼要把兩張網卡合併成一張呢?
理由:

  1. 當一張網卡壞掉時,還有另一張,因此不會引起斷線
  2. 網路速度提昇(因為可以走兩條路)
  3. load balance

下面的例子是如何合併筆電的有線網卡和無線網卡。

先安裝所軟體

sudo apt-get install ifenslave

首先先編輯 /etc/NetworkManager/NetworkManager.conf 這個檔案。改成像下面那樣。你可以簡單的把 managed 設成 false,或是在 unmanaged-devices 設定哪些裝置不要被 NetworkManager 管。基本上要被合併的網卡不能被 NetworkManager 控制。


[main]
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
[keyfile]
unmanaged-devices=mac:your_mac



在 /etc/network/interfaces 新增下面的設定,你需要修改無線網卡怎麼連線以及 bond0 怎麼連線,bond0 就是合併後的新界面

auto bond0
iface bond0 inet dhcp
  bond_mode 0
  bond_primary eth0
  bond_miimon 100
  bond_downdelay 200
  bond_updelay 200
  wpa-ssid ssid
  wpa-ap-scan 1
  wpa-psk password
  wpa-scan-ssid 1
  wpa-iface wlan0                                                                
  dns-nameserver 8.8.8.8                                                          
  slaves eth0 wlan0 



重新啟動網路

sudo /etc/init.d/networking restart


用下面指令檢查設定是否成功

cat /proc/net/bonding/bond0


如果你的電腦變成只能用 ip 連但是不能用網址連
如 ping 8.8.8.8 可以通,但是透過網址不行

則在編輯  /etc/resolv.conf 這個檔案
加上

nameserver 8.8.8.8
nameserver 8.8.4.4


mode 0 和6的選擇:
如果你希望能夠平衡網卡的流量,或是你的網卡無法取得速度
則用 mode 0
否則 mode 6 會是較好的選擇


注意參考連結2的 mode 0 的說明。
 "如果一个连接或者会话的数据包从不同的接口发出的话,中途再经过不同的链路,在客户端很有可能会出现数据包无序到达的问题,而无序到达的数据包需要重新要求被发送,这样网络的吞吐量就会下降"

參考資料:

  1. http://techpatterns.com/forums/about1327.html
  2. http://www.huawei.com/ecommunity/bbs/10155553.html



註:之前範例有些問題,因此今天有作更新。 

2014年1月9日 星期四

在 linux 下讓 sdk 可以正確偵測 g2


  1. 將手機連線方式改成"數據連線"
  2. 開啟 debug 模式
  3. 跑下面指令
  4. sudo ./adb kill-server
    sudo ./adb start-server
    sudo ./adb devices
    這樣 sdk 就可以正確偵測到 g2 手機了

參考連結

2014年1月6日 星期一

Arduino LCD KeyPad Shield 的測試程式碼

Arduino LCD KeyPad Shield 的測試程式碼

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
 
/*******************************************************
 
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
 
********************************************************/
 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor 
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 // For V1.1 us this threshold
 if (adc_key_in < 50)   return btnRIGHT;  
 if (adc_key_in < 250)  return btnUP; 
 if (adc_key_in < 450)  return btnDOWN; 
 if (adc_key_in < 650)  return btnLEFT; 
 if (adc_key_in < 850)  return btnSELECT;  
 
 // For V1.0 comment the other threshold and use the one below:
/*
 if (adc_key_in < 50)   return btnRIGHT;  
 if (adc_key_in < 195)  return btnUP; 
 if (adc_key_in < 380)  return btnDOWN; 
 if (adc_key_in < 555)  return btnLEFT; 
 if (adc_key_in < 790)  return btnSELECT;   
*/
 
 
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("Push the buttons"); // print a simple message
}
  
void loop()
{
 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up
 
 
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP:
     {
     lcd.print("UP    ");
     break;
     }
   case btnDOWN:
     {
     lcd.print("DOWN  ");
     break;
     }
   case btnSELECT:
     {
     lcd.print("SELECT");
     break;
     }
     case btnNONE:
     {
     lcd.print("NONE  ");
     break;
     }
 }
 
}


出處:
http://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)

2014年1月5日 星期日

cross compile python for arm

這裡是編譯 Python 3.3.3 的方法

1. 建立 config.site,檔案內容如下

ac_cv_file__dev_ptmx=no
ac_cv_file__dev_ptc=no 


2.  在 python 3.3.3 的目錄下依序輸入以下指令。cross compiler 的相關變數你改成你系統的。



CONFIG_SITE=config.site CC=arm-linux-gcc CXX=arm-linux-g++ AR=arm-linux-ar RANLIB=arm-linux-ranlib ./configure --host=arm-linux --build=x86_64-linux-gnu --prefix=/python LDFLAGS="-static -static-libgcc" CPPFLAGS="-static -march=armv4t" --disable-ipv6
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-linux-gcc -static" CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=x86_64-linux-gnu
 make install HOSTPYTHON=./hostpython BLDSHARED="arm-linux-gcc -static" CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes prefix=~/mypython

參考資料:

http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
http://bugs.python.org/msg136962

2014年1月4日 星期六

x86 qemu 使用方式

讓 qemu 指執行 kenel
sudo qemu-system-x86_64 -kernel /boot/vmlinuz-3.8.0-19-generic -m 256
這段指令執行到最後會發生 kernel panic 。因為找不到 root
sudo qemu-system-x86_64 -kernel /boot/vmlinuz-3.8.0-19-generic -initrd /boot/initrd.img-3.8.0-19-generic -append "root=/ram/" -m 256
上面這個指令複雜一些,kenel 會讀取 initrd (用來讀取其他檔案系統的玩意,細節) 。他會執行這個執行檔在 initrd 裡的 /init 這個執行檔,最後會失敗。進入 terminal 模式。你可以打 cat /init 看他做了什麼。


讓 cubie truck 從 sd 卡開機


這裡只是簡單的描述,細節請看 http://docs.cubieboard.org/zh/tutorials/ct1/installation/install_lubuntu_desktop_server_to_sd_card#make_bootable_sd_card

  1. 下載 u-boot,bootfs,rootfs
  2. 清除 sd 卡
    • sudo dd if=/dev/zero of=${card} bs=1024 seek=544 count=128
  3. 把 u-boot 寫進 sd 卡。
    • sudo dd if=u-boot-sunxi-with-spl-ct-20131102.bin of=$card bs=1024 seek=8
  4. 再做磁碟分割,bootfs(第一個磁區) 要 ext2,第二個磁區要 ext4,像這樣(sdd 會隨每個電腦環境不同而有所不同)
    1. Device Boot      Start         End      Blocks   Id  System
      /dev/sdd1            2048      133119       65536   83  Linux
      /dev/sdd2          133120    15278079     7572480   83  Linux
  5. 建立檔案系統並把 bootfs 和rootfs 寫進你剛剛新建的磁區
    1. $mkdir /tmp/sdd1 /tmp/sdd2
      $sudo mount -t ext2 ${card}1 /tmp/sdd1
      $sudo mount -t ext4 ${card}2 /tmp/sdd2
      $sudo tar -C /tmp/sdd1 -xvf bootfs-part1.tar.gz
      $sudo tar -C /tmp/sdd2 -xvf rootfs-part2.tar.gz
      $sync
      $sudo umount /tmp/sdd1
      $sudo umount /tmp/sdd2

2014年1月1日 星期三

在 qemu 底下模擬 Raspberry Pi


1. 安裝 qemu-system-arm

2. 下載 http://xecdesign.com/downloads/linux-qemu/kernel-qemu

3. 執行下面程式碼

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2013-09-25-wheezy-raspbian.img

重點就那個 kernel image 和 qemu 的參數,詳情請看參考連結。

參考連結:
http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/

2013年12月31日 星期二

編譯 busybox 並建立一個linux 系統


編譯 busybox 把 arm-none-linux-gnueabi- 換成你的編譯器。然後記得靜態編譯 busybox(在 menuconfig 裡選擇)
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
編譯完後的檔案會放在 _install。把他做成 img
$ cd _install
$ find . | cpio -o --format=newc > ../rootfs.img

你可以用下面指令測試一下
qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img -append "root=/dev/ram rdinit=/bin/sh"

建立系統必要的目錄
$ cd _install
$ mkdir proc sys dev etc etc/init.d
$ cd ..




新增一個檔案,_install/etc/init.d/rcS,加入下面的內容
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s


讓剛剛的檔案可以被執行

chmod +x _install/etc/init.d/rcS
最後的驗收

qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/sbin/init"
參考資料

arm cross compile 常用指令備忘



製作 initramfs image

find . | cpio -H newc -o | gzip -9 > /boot/initrd.img
或是
find . | cpio -H newc -o > rootfs
解壓縮 initramfs image

gunzip -c /boot/initrd.img-2.6.24-19-generic | cpio -i

修改 initrd image

mount -t ext2 -o loop initrd.img temp/

編譯 arm 核心,arm-linux-gnueabi-請換成你用 cross_compiler

make ARCH=arm versatile_defconfigmake ARCH=arm menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- all

編譯完後,核心路徑在 arch/arm/boot


qemu-system-arm -M versatilepb -m 128M -kernel zImage -no-reboot


第一支程式

#include <stdio.h>
int main() {  printf("Hello World!\n");  while(1);}


編譯第一支程式
arm-linux-gnueabi-gcc -static    test.c   -o test 
製作 rootfs
echo test | cpio -o --format=newc > rootfs
執行第一支程式
qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs -append "root=/dev/ram rdinit=/test" -no-reboot
啟動核心後,核心會執行你的程式。

其他:如果你要測試編譯出來的程式,也可以直接用下面指令。
qemu-arm -L /usr/arm-linux-gnueabi/ a.out

參考資料

http://backreference.org/2010/07/04/modifying-initrdinitramfs-files/
http://balau82.wordpress.com/2010/03/22/compiling-linux-kernel-for-qemu-arm-emulator/