2017年10月26日 星期四

linux 使用 wake on lan

來源 http://yumax1012.blogspot.tw/2008/01/linux-wake-on-lan.html

可以試建立
/etc/init.d/halt.local

~~~內容如下
# script with local commands to be executed from init on system shutdown
#
# Here you should add things, that should happen directly before shuting
# down.
#
# enable WOL for magic packet (g) and broadcast (b)
#wol pumbagsd...
# Set Wake-on-LAN options. Not all devices support this. The
# argument to this option is a string of characters specifying
# which options to enable.
# p Wake on phy activity
# u Wake on unicast messages
# m Wake on multicast messages
# b Wake on broadcast messages
# a Wake on ARP
# g Wake on MagicPacket(tm)
# s Enable SecureOn(tm) password for MagicPacket(tm)
# d Disable (wake on nothing). This option clears all previous
# options.
/sbin/ifup eth0
/usr/sbin/ethtool -s eth0 wol g
#/usr/sbin/ethtool eth0

沒有ethtool 要先安裝 ethtool 套件:
apt-get install ethtool
執行 ethtool:
$ ethtool eth0
Settings for eth0:
Supports Wake-on: g
Wake-on: d
Link detected: yes

主要要看 Wake-on 這一項,要設成 g:

$ ethtool -s eth0 wol g

在執行一次 ethtool 確認有設定好:

$ ethtool eth0
Settings for eth0:
Supports Wake-on: g
Wake-on: g
Link detected: yes

由於這是在電腦開機前動作,
被喚醒的電腦只需要有 BIOS 及硬體有支援即可!
這樣就 ok 了。

2 則留言:

Jason Tseng 提到...
不好意思增加一些建議:
修改 : /etc/network/interfaces
iface eth0 inet dhcp
post-up /usr/sbin/ethtool -s $IFACE wol g
post-down /usr/sbin/ethtool -s $IFACE wol g

可每次開機自動設定好
http://wiki.debian.org/WakeOnLan
小麥 提到...
謝謝您的建議!!

移植 WG7833 最新 driver 至 kernel 3.14.49

原文 http://onlybernie.blogspot.tw/2015/10/



http://processors.wiki.ti.com/index.php/WL18xx_System_Build_Scripts

上面是 wl18xx 的 build code script,TI 說最簡單的方法就是使用它們....,但是因為我的

 filesystem 以及 toolchain 不是用官方的....,所以不能一次 build 完所有 wifi 所需要的 tool 和

 library。對我來說還滿麻煩的,因為我 libnl 、iw、openssl、wpa_supplicant 必須額外抓

 source code 來移植到板子上。

  iw - 3.15
  iw 使用的 libnl-3.2.24
  wpa_supplicant - 2.0
  wpa_supplicant 使用的 openssl-1.0.1h
  wpa_supplicant 使用的? (網路上好像沒說需要 libnl) libnl-1.1.4

  =====================================================================

1  用 TI build script 來 build 出 wifi modules: compat.ko、cfg80211.ko、mac80211、
    wlcore.ko、wl18xx.ko 以及 wlcore_sdio.ko。

    mkdir wl18xx
    cd wl18xx
    git clone git://git.ti.com/wilink8-wlan/build-utilites.git
    cp setup-env.sample setup-env
    vim setup-env

             export TOOLCHAIN_PATH=/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi
             export ROOTFS=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi
             export KERNEL_PATH=/home/bernie/kernel-source
             export KERNEL_VARIANT=DEFAULT
             export CROSS_COMPILE=arm-poky-linux-gnueabi-
             export ARCH=arm

     先確認 verify_kernel_config.sh 內的 CONFIG 在你的 kernel 內有沒有選取,沒有的話要記得 enable,並且 kernel 要先 build 過。

     ./sudo_build_wl18xx.sh modules

     在 build code 中,會出現一些 error,原因是 toolchain 版本問題,我的是 4.9.2,會無法識別__TIMESTAMP__問題,只要用常數取代即可。另外,得到的 wlcore_sdio.ko要載入時,會出現 time_sync error,因為它程式內寫死用 gpio66,我們並沒有gpio66,所以到 compat_wireless/drivers/net/wireless/ti/wlcore/main.c 將 time_sync 內相關的 code 註解掉即可。

am335x uart 移植

原文 http://onlybernie.blogspot.tw/2015/10/

在 dts file已經增加 uart1 和 uart2 的 pinmux 了,在系統內卻無法使用。看了 dmesg ,發現奇怪的訊息。

   WARNING: Your 'console=ttyO0' has been replaced by 'ttyS0'
[    0.000398] This ensures that you still see kernel messages. Please
[    0.000404] update your kernel commandline.


google之後發現,這是 8250 driver 在搞鬼,只要將 kernel 中的 SERIAL_8250 dirver 移除,以及選上  OMAP serial port support 的 driver,就可以使用 ttyOx了。

系統會出現

    Kernel command line: console=ttyO0,115200n8 root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait

    [    0.511510] 44e09000.serial: ttyO0 at MMIO 0x44e09000 (irq = 88, base_baud = 3000000) is a OMAP UART0
[    1.180674] 48022000.serial: ttyO1 at MMIO 0x48022000 (irq = 89, base_baud = 3000000) is a OMAP UART1
[    1.197232] 48024000.serial: ttyO2 at MMIO 0x48024000 (irq = 90, base_baud = 3000000) is a OMAP UART2

的訊息了。

移植 iptable 命令至 am335x

原文 http://onlybernie.blogspot.tw/2015/10/

下載 iptables-1.4.18.tar.gz

1先 source poky sdk 的 env setup script
2解壓後,進入資料夾內輸入

    ./configure --host=arm-poky-linux-gnueabi --prefix=/home/bernie/app/iptables --enable-static --disable-shared


最後進入 /home/bernie/app/iptables/sbin,將裡面的所有資料 tar 起來,丟至目標板,解壓放至 /usr/sbin 內。

因為我們一開始採用靜態編譯,所以執行 iptables 命令時不會去 /lib 尋找 library。

移植 iw 命令至 am335x

原文 http://onlybernie.blogspot.tw/2015/10/

TI Wlink 8 最新的 driver R8.6,不支援 Wireless Extentsion。所謂的 Wireless Extentsion,就是一組通用 API,要使用的話,也必須 wifi driver 有支援。所以我們另外使用 iw 來取代,TI 的 driver 有支援此命令。


iw-3.15
libnl-3.2.24

iw 需要 netlink library,所以我們先移植 libnl。進入 libnl 資料夾,打上

   source poky sdk env setup script
  ./configure --host=arm-poky-linux-gnueabi --prefix=/home/bernie/app/libnl-3.2.24

   make
   make install

   編譯 libnl 安裝完成
====================================================================

  接著不要 source poky sdk 環境,進入 iw 資料夾。打上

   export PKG_CONFIG_PATH=/home/bernie/app/libnl-3.2.24/lib/pkgconfig
   修改 Makefile 中的 CC 值

    CC=/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi

   make
======================================================================
   error:  發現少了 libnl 的 gen.h 檔案

   solution: 修改 Makefile 的 CFLAGS,讓他增加指向
                  -I/home/bernie/app/libnl-3.2.24/include/libnl3

   make
=======================================================================
   error:
 /opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: error: iw uses VFP register arguments, version.o does not
/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/ld: failed to merge target specific data of file version.o
collect2: error: ld returned 1 exit status

  solution: 在 Makefile 中的  CC 變數加上 poky sdk 裡的 envsetup script 中的 CC 值即可。

編譯成功後,將 iw命令丟到目標板 /usr/sbin。

 

移植 wpa_supplicant 命令至 am335x

原文 http://onlybernie.blogspot.tw/2015/10/

要有 wpa_supplicant 指令,要先有 openssl  的 library 以及 libnl 的 library,前一章已經移植過了 libnl-3.2.24 了。

選擇 openssl-1.0.1h。進入openssl-1.0.1h,打上

  source poky sdk env setup script
 ./Configure linux-generic32 --prefix=/home/bernie/app/openssl

  修改 Makefile 中的 CC 為 CC= $(CROSS_COMPILE)gcc ... 後面為 sdk 的參數設定。
   make
   make install

   編譯 openssl 安裝完成
 ========================================================================

 進入 wpa_supplicant-2.2,打上
  不用 source poky  sdk env setup script,但是要 export PATH=sdk 的 bin
  cp defconfig .config
  在 .config 內加上
 
      CC=arm-poky-linux-gnueabi-gcc  -march=armv7-a -marm  -mthumb-interwork -mfloat-
abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi

    CFLAGS += -I /home/bernie/app/libnl-3.2.24/include/libnl3
    CFLAGS += -I /home/bernie/app/openssl/include
    LIBS += -L /home/bernie/app/openssl/lib
    LIBS += -L /home/bernie/app/libnl-3.2.24/lib
    CONFIG_LIBNL32=y-->這個要加,不然會出現 ld找不到 -lnl 的訊息

    make

    編譯完成後,將 wpa_supplicant 和 wpa_cli 丟至開發板 /usr/sbin

=======================================================================

wpa_supplicant 用法

mkdir /var/run/wpa_supplicant

 vi  /etc/wpa_supplicant.conf

   ctrl_interface=/var/run/wpa_supplicant
   update_config=1

   network={
        psk="12345678"
        ssid="bernie"
   }

##update_config=1 /* 讓 wpa_cli 程式可以更新 wpa_supplicant */
## ctrl_interface=/var/run/wpa_supplicant /* 讓 supplicant 可以建立行程 pid */
 
 最後下指令:
wpa_supplicant -d -Dnl80211(也有可能是 wext) -c/etc/wpa_supplicant.conf -iwlan0 -B

     root@am335x-evm:/# [  684.159242] wlan0: authenticate with 18:00:2d:75:f7:80[  684.170487] wlan0: send auth to 18:00:2d:75:f7:80 (try 1/3)
[  684.199773] wlan0: authenticated
[  684.205871] wlan0: associate with 18:00:2d:75:f7:80 (try 1/3)
[  684.314794] wlan0: RX AssocResp from 18:00:2d:75:f7:80 (capab=0x431 status=0 aid=2)
[  684.335695] wlan0: associated
[  684.410374] wlcore: Association completed.

 成功會有上述字樣


 udhcpc -i wlan0

 即可拿到 IP

Poky vs Yocto vs OpenEmbedded

Package list: apps_proc/oe-core/build/tmp-glibc/deploy/images/<target>/<image>.rootfs.manifest


1. Why not just call this project Poky? What has changed between Poky and the Yocto Project?

The Yocto Project is an umbrella project. Accordingly, it includes a number of projects and resources specifically intended for facilitating development with Linux on embedded devices, and it is an appropriate place for larger organizations to collaborate on the development of build infrastructure for embedded Linux. Poky is one of the the largest components of the Yocto Project, and Poky continues as an independent, open source project developing the build system used by the Yocto Project, as well as by other open source projects.

Poky is a reference system for the Yocto Project, showing how the tools work together. It includes BitBake, openembedded-core, and several other components that anyone can use to start developing with embedded Linux. Poky as a build system is tested by the Yocto Project teams before each release. When you download and use the Yocto Project build system, you are actually downloading Poky and using it to create a distribution that by default is also named Poky. (You can, of course, name your distribution anything you like.)


2. What is the difference between OpenEmbedded and the Yocto Project?

The Yocto Project and OpenEmbedded share a core collection of metadata called openembedded-core. However, the two organizations remain separate, each with its own focus. OpenEmbedded provides a comprehensive set of metadata for a wide variety of architectures, features, and applications. The Yocto Project focuses on providing powerful, easy-to-use, interoperable, well-tested tools, metadata, and board support packages (BSPs) for a core set of architectures and specific boards.