2015年8月13日 星期四

Raspberry Pi: Pi 2 with Pi Mapper ---- 1/3

since: 2015/08/13
update: 2016/02/29
reference:
1. PiMapper

A. 安裝作業系統影像檔
    1.  下載 Raspbian 映像檔: https://www.raspberrypi.org/downloads/  (1.03 G)
         建議用 torrent 下載, 解壓縮成: 2015-05-05-raspbian-wheezy.img (3.28G)

    2. 把 microSD 卡(在此為 8GB 48MB/秒 讀取)放入 Mac 的讀卡機中, 利用
        SD Card Formatter,將其格式化為 FAT32. (可能需要轉接卡)

    3. Apple -> 關於這台 Mac -> 系統報告... -> 讀卡機:
         ->確認其 BSD 名稱: disk1

    備註: 利用 $ diskutil list 來確認其磁碟名稱, 而不是分割區的名稱

    4. 利用磁碟工具程式, 將剛剛新增的分割區 Unmount (不是退出),
         之後才可以將影像檔寫入.

    5. 寫入影像檔: 從終端機執行(約 21 分鐘)
         $ cd /Lanli/RD/software
         $ sudo dd bs=1m if=2015-05-05-raspbian-wheezy.img of=/dev/rdisk1

    6. 將裝好作業系統的 microSD, 放到 Pi 的 microSD卡槽裡, 幫 Pi 接上無線網卡,
         鍵盤, 螢幕等最後接上電源時便會啟動開機.

    7. 登入系統後, 先將預設帳號 pi 更改密碼: (預設密碼為:raspberry)
         $ sudo passwd pi

    8. 無線網卡設定(在此使用 LB-LINK 型號: BL-LW05-AR5)
        Pi 支援的無線網卡: RPi USB Wi-Fi Adapters - eLinux.org

        => 確認系統是否有抓到網卡:
             $ sudo lsusb

        => 啟動 X 視窗系統: $ startx
             , 接著便可在右上角設定無線網路了, 設好後, 請重新開機回到文字模式下.
                  $ sudo reboot
             或 $ sudo shutdown -h now

    9. 啟用遠端 SSH 登入功能:
        a. $ sudo raspi-config
        b. 選擇: 8 Advanced Options > Select

        c. 選擇: A4 SSH > Select > Enable > OK > Finish

   10. SSH 遠端登入
         a. 查詢 Pi 2 的 IP:
             $ ifconfig
wlan0     Link encap:Ethernet  HWaddr ac:a2:13:d5:a0:5d 
              inet addr:192.168.1.33  Bcast:192.168.1.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:1160 errors:0 dropped:200 overruns:0 frame:0
              TX packets:169 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:204769 (199.9 KiB)  TX bytes:24217 (23.6 KiB)


         b.  遠端登入:
              $ ssh pi@192.168.1.33

   11. 查詢剩餘空間與記憶體
         $ df -h
         $ free -h

2015年8月1日 星期六

Using the Jetson TK1 as a remote development environment for CUDA

since: 2015/08/01
update: 2015/08/01

reference:
1. How to use the Jetson TK1 as a remote development environment for CUDA
2. Remote application development using NVIDIA® Nsight™ Eclipse Edition
3. NVIDIA CUDA GETTING STARTED GUIDE FOR LINUX v6.5
4. CUDA 6.0 in Ubuntu 14.04.1 LTS - NVIDIA Developer Forums
5. CUDA Toolkit 6.5
6. CUDA Toolkit Documentation v7.0


A. 在 Local (Mac) 上安裝 CUDA toolkit
     1. 安裝 Xcode

     2. 安裝 Xcode Command Line Tools:
         $ xcode-select --install

     3. 到 CUDA Toolkit 6.5 下載 CUDA Toolkit 6.5 for Mac OSX
         版本: cuda_6.5.14_mac_64.pkg  (latest 64-bit CUDA 6.5 package)

     4. 點二下安裝, 其中 CUDA DriverLocal 處可以不需要安裝, 除非要執行 CUDA-Z.

-----------------------------------------------------------------------------------------------

B. 在 Remote (Jetson TK1) 上安裝 CUDA toolkit
     1. Verify You Have a CUDA-Capable GPU
         $ lspci | grep -i nvidia
         00:00.0 PCI bridge: NVIDIA Corporation Device 0e13 (rev a1)

     2. 到 CUDA Toolkit 6.5 下載 CUDA Toolkit 6.5 for Linux ARM
         版本: ONLY to be used for Jetson TK1
         cuda-repo-l4t-r21.2-6-5-prod_6.5-34_armhf.debf (L4T 21.2 DEB)
         (將檔案傳送到 remote 的 /home/ubuntu/RD/software 目錄下)

     3. 安裝:
          $ cd /home/ubuntu/RD/software
          $ sudo dpkg -i cuda-repo-l4t-r21.2-6-5-prod_6.5-34_armhf.deb
          $ sudo apt-get update
          $ sudo apt-get install cuda-toolkit-6-5

     4. Add the user to the video group
          $ sudo usermod -a -G video ubuntu

     5. Environment Setup ...
          To change the environment variables for 32-bit ARM operating systems:
          $ export PATH=/usr/local/cuda-6.5/bin:$PATH
          $ export LD_LIBRARY_PATH=/usr/local/cuda-6.5/lib:$LD_LIBRARY_PATH

     6. check the L4T version with the following command
         $ head -1 /etc/nv_tegra_release
            # R21 (release), REVISION: 4.0, GCID: 5650832, BOARD: ardbeg, EABI: hard, DATE: Thu Jun 25 22:38:59 UTC 2015

     7. install g++-4.6
         $ sudo apt-get install g++-4.6

     8. (Optional) Install Writable Samples
          $ cd /usr/local/cuda-6.5/bin
          $ cuda-install-samples-6.5.sh /home/ubuntu/RD/projects/
          $ cd NVIDIA_CUDA-6.5_Samples
          $ make

          The resulting binaries will be placed under:
          /home/ubuntu/RD/projects/NVIDIA_CUDA-6.5_Samples/bin


     9. After restart the system, Finally start one of the samples! 
         $ cd /home/ubuntu/RD/projects/NVIDIA_CUDA-6.5_Samples/bin
         $ cd armv7l/linux/release/gnueabihf
         $ ./deviceQuery


         $ ./bandwidthTest

-----------------------------------------------------------------------------------------------

C. Configure Git
       To synchronize CUDA projects between local(Mac) and target(Jetson TK1) systems,
       you need to configure git on both the local and the target systems using these
       commands:


       $ git config --global user.email "lanli0210@gmail.com"
       $ git config --global user.name "lanli"

-----------------------------------------------------------------------------------------------

D.Create nsight project on local(Mac)
     1. 開啟 nsight:
         YourMac > Developer/NVIDIA/CUDA-6.5/libnsight/nsight.app

     2. Select a workspace


     3. Create a new project
         File > New > CUDA C/C++ Project

     4. Project type: Empty Project

     5. Basic settings:

     6. Target system > Manage... > Remote Connections

     7. Configure CUDA Toolkit

     8. Target System(Project Path)

     9. remove the Local System

    結果:

     10. 完成:

-----------------------------------------------------------------------------------------------

E. Adding the source code for CUDA project
     1. File > New > Source File

     2. Source File Configure (just use a template)

     3. 完成:

     4. 按下 "編譯"
       p.s. Note that the build command is /usr/local/cuda-6.5/bin/nvcc,
              which is the compiler on the Jetson, not on the Macbook.

-----------------------------------------------------------------------------------------------

F. Debugging the code on CUDA project
     1. Debug Configurations

     2. Debugging ...
         p.s. By default the debugger will break in main() – this can be switched off
                in the debug configuration.

 

2015年7月25日 星期六

How to re-flash your Jetson TK1 Development Kit

since: 2015/07/25
update: 2015/10/19

reference:
1. Jetson TK1 - eLinux.org
2. Jetson TK1 User Guide - Flashing Jetson
3. How to Reinstall the Original File System on Jetson TK1
4. Linux For Tegra Archive
5. Debian -- Package Search Results -- firmware-iwlwifi

A. 說明:

    1. 需要重新再安裝 Jetson TK1 檔案系統的原因:
        a.  Jetson TK1 原本的檔案系統被弄亂了(甚至開機後, 無法進入系統 ---> 我啦)
        b. 想要提升 Jetson TK1 在 eMMC(Embedded MultiMediaCard:嵌入式多媒體卡)
            的可用空間. 16GB 的容量預設只能使用 8GB 或 12 GB.

            備註: 見上篇的結果:

    2. 需要有一台主機是跑 Linux 系統, 用來製作要給 Jetson TK1 的檔案系統.
        我是在 Mac 上的 Parallels 安裝 Ubuntu Linux.

    3. 重新安裝 Jetson TK1 的檔案系統, 大約需要一小時的時間來寫入 eMMC,
        並且會清除 Jetson TK1 上所有的資料.

-----------------------------------------------------------------------------------------------

B. 在 Mac 上安裝 Ubuntu Linux:
     1. 目前使用的版本: ubuntu-14.04.2-desktop-amd64.iso    

     2. Parallels 上的設定:
         a. 硬體 > USB 與藍牙 > USB 連結偏好設定...

         b. 設備 > 當檢測到新的外部設備時: 連接到運行的虛擬機器

         c. 配置完成 > 繼續

     3. 登入 Ubuntu (pass: pipixxxx)後, 打開 Terminal

-----------------------------------------------------------------------------------------------

C. 在 Ubuntu 上製作要給 Jetson TK1 使用的檔案系統

     接續 B 的步驟:

     1. 建立工作目錄:
         $ mkdir tk1_reflash
         $ cd tk1_reflash 

     2. Linux For Tegra Archive 下載 Linux For Tegra R21.4 檔案:

         a. Jetson TK1:
             $ wget http://developer.download.nvidia.com/embedded/L4T/r21_Release_v4.0/Tegra124_Linux_R21.4.0_armhf.tbz2

         b. Sample File System:
             $ wget http://developer.download.nvidia.com/embedded/L4T/r21_Release_v4.0/Tegra_Linux_Sample-Root-Filesystem_R21.4.0_armhf.tbz2

     3. 解壓縮檔案:
         a. $ sudo tar xpf Tegra124_Linux_R21.4.0_armhf.tbz2
         b. $ cd Linux_for_Tegra/rootfs
         c. $ sudo tar xpf ../../Tegra_Linux_Sample-Root-Filesystem_R21.4.0_armhf.tbz2

     4. Apply binaries:
         a. $ cd ..
         b. $ sudo ./apply_binaries.sh

-----------------------------------------------------------------------------------------------

D. Write to eMMC over USB:
     1. 將 USB Micro-B 線一端連接 Jetson TK1, 另一端連接 Ubuntu Linux

     2. Puts  Jetson TK1 in recovery mode:
         在  Jetson TK1 上先按住 "RECOVERY" 鈕不放, 接著按一次 "RESET" 鈕,
         約 2 秒後放開"RECOVERY" 鈕.

     3. Verify board is connected by running:
         $ lsusb | grep -i nvidia

         You should see the following:  

         $ Bus 002 Device 004: ID 0955:7140 NVidia Corp.

     4. flash the Jetson TK1:
         $ sudo ./flash.sh -S 14580MiB jetson-tk1 mmcblk0p1


         說明: 完成後, Jetson TK1 會自動重新開機

     5. 開機完成後, 登入 Jetson TK1, 檢查可用容量:
         $ df -h

     6. 其它請參考上一篇: Get Started On NVIDIA Jetson TK1C, D, EF
-----------------------------------------------------------------------------------------------

E.
some post-install housekeeping
    1. check internet
        $
sudo ping google.com -c 4

    2. get correct time
        $
date       
        $
sudo ntpdate pool.ntp.org       
        $
date

    3. setup timezone
       
$ sudo dpkg-reconfigure tzdata

       Current default time zone: 'Asia/Taipei'
       Local time is now:      Sat Aug  1 18:25:50 CST 2015.
       Universal Time is now:  Sat Aug  1 10:25:50 UTC 2015.


    4.
set sysclock, only if internet is down
       
#sudo date mmddhhmmyyyy.ss
       
$ sudo date 050607002014

    5.
check time on HW RTC
        $
sudo hwclock --debug

    6.
sync HW RTC to sysclock
        $
sudo hwclock -w

    7.
add automatic time update at startup
        $
sudo vi /etc/rc.local....
# By default this script does nothing.

# add automatic time update at startup

ntpdate-debian
hwclock -w


exit 0


    8.
add automatic time update to crontab
        $
sudo crontab -e
....
# m h  dom mon dow   command

5 * * * * ntpdate-debian
7 * * * * hwclock -w


    9. update and upgrade
        $ sudo apt-get update && sudo apt-get upgrade


   10. install useful packages
         $ sudo apt-get install git screen tree tcsh vim-gtk

   11. misc cleanup
         $ sudo apt-get autoclean
         $ sudo apt-get clean


-----------------------------------------------------------------------------------------------

F.
Installing Wireless Intel 7260 Adapter(Mini-PCIe)    
    1. 到
Debian -- Package Search Results -- firmware-iwlwifi        
        下載:
Binary firmware for Intel Wireless cards 0.43 (stable)     
                  ===>  檔名: firmware-iwlwifi_0.43_all.deb
                  ===>  直接在
Jetson TK1 上點二下安裝, 安裝好重新開機.

     2.新增 Wi-Fi 網路 


     3. 設定 SSID 與選取網卡的 MAC address

     4. 設定安全模式與連線密碼


-----------------------------------------------------------------------------------------------

G. Add CUDA bin Environment Variables    
    1. $ vi ~/.bashrc
....
# Add CUDA bin paths:
export CUDA_HOME=/usr/local/cuda-6.5
PATH=${CUDA_HOME}/bin:${PATH}
export PATH

# or: export PATH=/usr/local/cuda-6.5/bin:$PATH


    2. $ source ~/.bashrc

2015年7月23日 星期四

How to fix: Java(TM) Platform SE binary has stopped working

since: 2015/07/23
update: 2015/07/23

reference:
1. stack vs heap:執行時期儲存兩大要角
2. memory - Java default stack size - Stack Overflow
3. -X Command-line Options

A. 查詢目前 Java VM 的 stack 與 heap memory 的 space:
     1. stack memory:
         Thread stacks are memory areas allocated for each Java thread for their internal
         use. This is where the thread stores its local execution state.



     2. heap memory:
         The Java heap (the “heap”) is the part of the memory where blocks of memory
         are allocated to objects and freed during garbage collection.


         > java -XshowSettings:vm

-----------------------------------------------------------------------------------------------

B. 設定 stack 與 heap memory 的 space:
 
     1. 查詢設定參數:
         > java -X

         -Xms<size> 設定 Java 堆集(heap)大小上限
         -Xss<size> 設定 Java 執行緒堆疊(stack)大小

   2. 電腦 > 內容 > 進階系統設定:
       系統內容 > 進階 > 環境變數:

     3. 系統變數 > 新增:
         變數名稱: _JAVA_OPTIONS
         變數值: -Xss1M -Xmx2560M
         > 確定

         說明: 此處將 stack 設為 1 MB, max heap 設為 2560 MB

     4. 重新開機後, 檢查設定值:
         > java -XshowSettings:vm


2015年7月22日 星期三

Get Started On NVIDIA Jetson TK1

since: 2015/07/22
update: 2015/07/22

reference:
1. Getting Started with Jetson
2. Jetson TK1 - eLinux.org

A. Login Credentials

     Username:  ubuntu
     Password:  ubuntu

-----------------------------------------------------------------------------------------------

B. Installing the Linux Driver Binary
     1. Change directories into the NVIDIA installation directory:
         $ cd ${HOME}/NVIDIA-INSTALLER

     2. Run the installer script to extract and install the Linux drive r binary release:
         $ sudo ./installer.sh

     3. Reboot the system
         $ shutdown -h now

     NOTE: the installer.sh should only be run once.

-----------------------------------------------------------------------------------------------

C. An important step before connecting the Jetson to Internet
     It is really important to tell "apt" not to overwrite the file "libglx.so" if you
     upgrade the system. "libglx.so" is a specific file in NVIDIA's graphics driver
     that might get replaced by an incorrect version from Ubuntu that stops you
     from being able to boot into the graphical environment! So please execute
     this command on your Jetson before you connect it to Internet or perform
     an update:


     $ sudo apt-mark hold xserver-xorg-core

-----------------------------------------------------------------------------------------------

D. Recommended first steps now that your board has internet access
     1. Add the Universe package repositories, since you will often need packages
         from Universe for code development:


         $ sudo apt-add-repository universe
         $ sudo apt-get update

     2. If you will use the shell command-line a lot
         Install "bash-completion" (it allows you to hit the "Tab" key to auto-complete
         your shell commands) and "command-not-found" (it shows which package
         you probably need to install if you run an unavailable command).

         $ sudo apt-get install bash-completion command-not-found
         $ exit

     3. If you will use the graphical environment (Unity) a lot

         You might want to turn off the desktop shopping suggestions that are enabled
         by default in Ubuntu 14.04 (despite the spyware concerns discussed by huge
         numbers of people) by running this:

$ gsettings set com.canonical.Unity.Lenses disabled-scopes "['more_suggestions-amazon.scope', \
    'more_suggestions-u1ms.scope', 'more_suggestions-populartracks.scope', 'music-musicstore.scope', \
    'more_suggestions-ebay.scope', 'more_suggestions-ubuntushop.scope', 'more_suggestions-skimlinks.scope']"


-----------------------------------------------------------------------------------------------

E. Shutting down Jetson TK1 safely

    $ sudo shutdown -h now
-----------------------------------------------------------------------------------------------

F. 備註:
    1. 從 Ubuntu 的視窗模式開啟 Terminal

    2. 查詢 TK1IP:
        $ ifconfig


    3. 遠端 SSH 登入 TK1:
        $ ssh ubuntu@192.168.1.6

    4. 查詢 TK1 的容量記憶體:
        $ df -h
        $ free -h