IPv6: 讓 OS X 開機時自動執行 gw6c

參考來源:個人收藏指令集:gw6c的LaunchDaemons http://cmd.hhmr.biz/2012/11/gw6claunchdaemons.html

建立檔案 /System/Library/LaunchDaemons/gw6c.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>UserName</key>
 <string>root</string>
 <key>GroupName</key>
 <string>wheel</string>
 <key>Label</key>
 <string>gw6c</string>
 <key>ProgramArguments</key>
 <array>
  <string>/usr/local/gw6c/bin/gw6c</string>
  <string>-f</string>
  <string>/usr/local/gw6c/bin/gw6c.conf</string>
 </array>
 <key>RunAtLoad</key>
 <true/>
 <key>OnDemand</key>
 <false/>
 <key>KeepAlive</key>
 <dict>
  <key>SuccessfulExit</key>
  <true/>
  <key>NetworkState</key>
  <true/>
 </dict>
</dict>
</plist>

之後 重新開機 或執行

$ sudo launchctl load /System/Library/LaunchDaemons/gw6c.plist

不過,gw6c 似乎會與 Tunnelblick OpenVPN Client 相衝!?
只要 gw6c 執行中,OpenVPN Client 就無法連接 OpenVPN Server
目前還無對策,只好在需要使用 openvpn 時,先結束 gw6c

$ sudo launchctl unload /System/Library/LaunchDaemons/gw6c.plist

加速Youtube: HiNet IPv6 Tunnel Broker for Mac OS X

聽說使用 IPv6 可以加快 Youtube 尤其是看 1080p 的時候
以下是安裝過程:

下載/安裝 TunTap for Mac OS X

$ sudo port install vpnc
$ sudo port load tuntaposx

下載/編譯 gw6c

$ wget http://nabla.googlecode.com/files/gw6c-6_0-RELEASE.tar.gz
$ tar -zxvf gw6c-6_0-RELEASE.tar.gz
$ cd gw6c-6_0-RELEASE/tspc-advanced
$ make target=darwin all
$ sudo make target=darwin installdir=/usr/local/gw6c install

設定 gw6c.conf

$ cd /usr/local/gw6c/bin
$ sudo vi gw6c.conf

#使用 HiNet  免認證模式:
userid=
passwd=
server=203.74.21.89
auth_method=anonymous

#使用 HiNet 認證模式:
userid=填入HiNet帳號 如8xxxxxx,只需要數字部分
passwd=填入HiNet密碼
server=203.74.21.88
auth_method=any

啟動 gw6c

$ sudo ./gw6c
$ ifconfig
看看 tun0 有沒有出現

測試網站: http://ipv6.google.com

Raspberry Pi 第一次設定

Remote Login into Raspberry Pi by SSH

host$ ssh pi@raspberry

Localise Setting

$ sudo raspi-config
    config_keyboard: “PC-104” “US”
    change_locale: “en_US.UTF-8 UTF-8”
    change_timezone: Asia/Taipei

Update Software

$ sudo apt-get update
$ sudo apt-get --auto-remove --purge dist-upgrade
$ sudo apt-get clean

Update Firmware and reboot

$ sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
$ sudo chmod +x /usr/bin/rpi-update
$ sudo apt-get install git-core
$ sudo rpi-update
$ sudo shutdown -r now

Enable I2C/SPI

$ sudo vi /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
#blacklist spi-bcm2708
#blacklist i2c-bcm2708

$ sudo vi /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-dev

$ sudo adduser pi i2c

Install I2C Tools

$ sudo apt-get install i2c-tools
$ sudo apt-get install python-smbus

Install C library for Broadcom BCM 2835

$ wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.5.tar.gz
$ tar xvfz bcm2835-1.5.tar.gz
$ cd bcm2835-1.5
$ ./configure
$ make
$ sudo make install

Mac OS X 10.8 安裝 SVN Server

自從買了新的 2012 Late Mac Mini 之後
就開始將舊的 資料 搬到 新機器上
不過發現無法啟動 SVN server on apache2 web server
後來發現 原來是 Mac OS X 10.8 把 mod_dav_svn.so 給拿掉了… 很奇怪耶?
只好自己 compile 再補回去 …

首先,先確認 Mac OS X 10.8 內建的 SVN 版本

$ svn --version
svn, version 1.6.18 (r1303927)
   compiled Nov  2 2012, 23:47:41

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.apache.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme

接下來要下載 相同版本的 SVN source code,並重新 Compile 後
將所缺少的 module 補回去

$ cd ~/Download
$ wget http://archive.apache.org/dist/subversion/subversion-1.6.18.tar.bz2
$ tar -jxvf subversion-1.6.18.tar.bz2
$ cd subversion-1.6.18
$ ./configure
$ make
$ sudo cp subversion/mod_dav_svn/.libs/mod_dav_svn.so /usr/libexec/apache2/
$ sudo cp subversion/mod_authz_svn/.libs/mod_authz_svn.so /usr/libexec/apache2/

接下來,建立 /etc/apache2/other/svn.conf

$ vi /etc/apache2/other/svn.conf
LoadModule dav_svn_module /usr/libexec/apache2/mod_dav_svn.so
LoadModule authz_svn_module /usr/libexec/apache2/mod_authz_svn.so
<Location /svn>;
    DAV svn
    SVNParentPath /PATH-TO-SVN-REPOSITORY
    SVNListParentPath on
    AuthType Basic
    AuthName &quot;Subversion repository&quot;
    AuthUserFile /etc/apache2/svn-auth-file
    Require valid-user
</Location>;

記得變更 svn repository 的 權限

$ chown -R www:www /PATH-TO-SVN-REPOSITORY

重新啟動 Apache

$ sudo apachectl restart

Simple Makefile used for SDCC 8051 C Compiler

因工作需要,做了個簡單的 makefile

#
# SDCC Makefile
#
# Memory Layout
#   Program Size: 4KB
#   Internal Mem: 256B
#   External Mem: 4KB


# ------------------------------------------------------
# PATH

INCDIR  = ../inc
SRCDIR  = ./src
OBJDIR  = ./obj

LIBDIR  =  

# ------------------------------------------------------
# UTILITY

UTILDIR = ../../util
HEX2BIN = $(UTILDIR)/hex2bin/bin/hex2bin

# ------------------------------------------------------
# Target and Source

TARGET = prom
OBJ = 
	$(OBJDIR)/printf.c.rel      
	$(OBJDIR)/debug.c.rel      
	$(OBJDIR)/gpio.c.rel       
	$(OBJDIR)/spi.c.rel        
	$(OBJDIR)/s25fl040a.c.rel  
	$(OBJDIR)/main.c.rel       
	$(OBJDIR)/crtstart.asm.rel

# ------------------------------------------------------
# SDCC

CC = sdcc
AS = sdas8051

# ------------------------------------------------------
# Memory Layout

# PRG Size = 4K Bytes
CODE_SIZE = --code-loc 0x0000 --code-size 4096

# INT-MEM Size = 256 Bytes
IRAM_SIZE = --idata-loc 0x0000  --iram-size 256

# EXT-MEM Size = 4K Bytes
XRAM_SIZE = --xram-loc 0x0000 --xram-size 4096

# ------------------------------------------------------
# MCS51 Options

# Memory Model (small, medium, large, huge)
MODEL  = medium

#LIBS    = 
#LIBPATH = -L $(LIBDIR)

#DEBUG = --debug
AFLAGS = -l -s
CFLAGS = -I./inc -I$(INCDIR) -mmcs51 --model-$(MODEL) --out-fmt-ihx --no-xinit-opt $(DEBUG)
LFLAGS = $(LIBPATH) $(LIBS) -mmcs51 --model-$(MODEL) $(CODE_SIZE) $(IRAM_SIZE) $(XRAM_SIZE) --out-fmt-ihx  $(DEBUG)

# ------------------------------------------------------
# S = @

.PHONY: all util clean
.SECONDARY:

all: util $(OBJDIR)/$(TARGET).memh

util:
	(cd $(UTILDIR)/hex2bin; make)

%.memh: %.bin
	$(S) hexdump -v -e '"@%04.4_ax " 16/1 "%02x " "n"' $^ > $@

%.bin: %.hex
	$(S) $(HEX2BIN) -s 0 -l 1000 -p ff $^

%.hex: %.ihx
	$(S) packihx $^ > $@

%.ihx: $(OBJ)
	$(S) $(CC) -o $@ $(LFLAGS) $^

$(OBJDIR)/%.c.rel: $(SRCDIR)/%.c
	$(S) $(CC) -o $@ $(CFLAGS) -c $^

$(OBJDIR)/%.asm.rel: $(SRCDIR)/%.asm
	$(S) $(AS) $(AFLAGS) -o $@ $^ 

clean:
	$(S) rm -rf $(OBJDIR)/*
	(cd $(UTILDIR)/hex2bin; make clean)

hex2bin 的用法

直接執行不加參數即可得到使用方法:

$./hex2bin 
hex2bin v1.0.10, Copyright (C) 2012 Jacques Pelletier & contributors


usage: hex2bin [OPTIONS] filename
Options:
  -s [address]  Starting address in hex (default: 0)
  -l [length]   Maximal Length (Starting address + Length -1 is Max Address)
                File will be filled with Pattern until Max Address is reached
                Length must be a power of 2 in hexadecimal:
                     Hex      Decimal
                    1000   =    4096   (4ki)
                    2000   =    8192   (8ki)
                    4000   =   16384  (16ki)
                    8000   =   32768  (32ki)
                   10000   =   65536  (64ki)
                   20000   =  131072 (128ki)
                   40000   =  262144 (256ki)
                   80000   =  524288 (512ki)
                  100000   = 1048576   (1Mi)
                  200000   = 2097152   (2Mi)
                  400000   = 4194304   (4Mi)
                  800000   = 8388608   (8Mi)
  -e [ext]      Output filename extension (without the dot)
  -c            Enable hex file checksum verification
  -p [value]    Pad-byte value in hex (default: ff)

  -k [0|1|2]    Select checksum type
                       0 = 8-bit,
                       1 = 16-bit little endian,
                       2 = 16-bit big endian
  -r [start] [end]     Range to compute checksum over (default is min and max addresses)
  -f [address] [value] Address and value of checksum to force

舉來說,我用 sdcc 編譯所得到的檔案為 hello.ihx (Intel-HEX format),
為了得到 hello.bin 所用命令如下:

$ hex2bin -s 0000 -l 1000 -p ff hello.ihx
hex2bin v1.0.10, Copyright (C) 2012 Jacques Pelletier & contributors

Lowest address  = 00000000
Highest address = 00000FFF
Pad Byte        = FF
8-bit Checksum = 1E
$  

“-s 0000 -l 1000 -p ff” 說明了:
起始位置: 0x0000,長度:0x1000,HEX File 中未定義的的值一律填入 0xff
並自動計算出 8-bit checksum = 0x1E (只是將 bin file 中所有的值加總)

有另外一種用法,
如果你想指定 8-bit checksum 的值(例如0x55),
例如 boot loader 從 Serial Flash 將 hello.bin 讀出來後,
要先做簡單的 checksum 檢查無誤之後,才進行下一個動作,

命令如下;

$ hex2bin -s 0000 -l 1000 -p ff -k 0 -f 0fff 55 hello.ihx
hex2bin v1.0.10, Copyright (C) 2012 Jacques Pelletier & contributors

Lowest address  = 00000000
Highest address = 00000FFF
Pad Byte        = FF
8-bit Checksum = 25
Addr 00000FFF set to 2F
$ 

這命令會在 位置 0x0fff 填入 0x2f
使得 8-bit checksim 從原先的 0x25 變成指定的 0x55