Homebrew: OS X 缺少的套件管理工具

一直以來都是使用 Mac Port 來安裝 Apple OS X 沒有內建的 軟體 或 套件
今天來試試另外一套: Homebrew
安裝很簡單

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

安裝好後,根據指示,先執行

$ brew doctor

它似乎會將原本 Mac Port 的目錄 /opt/local 先搬到 ~/macports
這樣就可以開始使用了..

先來裝個 wget 試試

$ brew install wget

安裝 wget 後,雖然 OK
但是出現一些警告訊息,似乎是希望我將 MacPort unistall

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

在 Mac OS 10.6 下安裝 SID Simulator

寫了一個 Makefile 來編譯並安裝 SID Simulator 在 Mac OS 10.6

#
# Build and Install SID
#

TAR_FILE    = $(CURDIR)/sid-20110301.tar.bz2
BUILD_DIR   = $(CURDIR)/SID_BUILD
SRC_DIR     = $(CURDIR)/SID_SRC
INSTALL_DIR = $(CURDIR)/SID_INSTALL

info:
        @echo "Current DIR is $(CURDIR)"
        @echo "make extract  ; Extraction Compressed File"
        @echo "make config   ; Build Makefile"
        @echo "make compile  ; Compile Source Code"
        @echo "make installe ; Install SID"

all: extract config compile install

extract: $(SRC_DIR)
        (cd $(SRC_DIR); tar -jxvf $(TAR_FILE))

config: $(BUILD_DIR) $(INSTRALL_DIR)
        (cd $(BUILD_DIR); $(SRC_DIR)/src/configure --prefix=$(INSTALL_DIR) LDFLAGS=-L/usr/X11/lib)

compile: $(BUILD_DIR)
        (cd $(BUILD_DIR); make)

install: $(BUILD_DIR) $(INSTALL_DIR)
        (cd $(BUILD_DIR); make install)

$(SRC_DIR):
        @echo [INFO] Create $@
        mkdir $@

$(BUILD_DIR):
        @echo [INFO] Create $@
        mkdir $@

$(INSTALL_DIR):
        @echo [INFO] Create $@
        mkdir $@

clean:
        rm -rf $(SRC_DIR)
        rm -rf $(BUILD_DIR)

Fail to Download Firmware to LPC2103

不知為什麼, 有時候要 Download Firmware to LPC2103 時會出現
下列錯誤訊息:

No Algorithm found for: 00000000H - 00001FC3H
Programming skipped!

後來發現要檢查 Options for Target -> Utilities -> Setting 設定:
1. RAM for Algorithm: Star: 0x40000000, Size: 0x0800
2. Programming Algorithm: LPC2000 IAP2 32KB Flash

How to Outputs PDF File from Gnuplot

之前都是直接在 視窗輸出 之後再手動 列印成 PDF File
其實也可以直接輸出 PDF File:

gnuplot> set term pdf (will produce PDF output)
gnuplot> set output "printme.pdf" (output to any filename you use)
gnuplot> replot (recreates plot but you don't see it, goes to file)

搞定收工。

OpenSuSE 11.1 上的 TCL Library

閒閒沒事
把之前在 Mac OS 上 跑的 NAND Flash Static Wear Leveling 的 EV程式
拿到 SuSE 上跑,結果居然 Compile 不起來
發現是 “-ltcl” 無法 link 到 正確的 TCL Library
若將之改為 “-ltcl8.5” 就 OK

好像是 TCL Library 在 Install 時有問題
自己動手修正:

$ (cd /usr/lib; sudo ln -s libtcl8.5.o libtcl.o)
$ (cd /usr/lib64; sudo ln -s libtcl8.5.o libtcl.o)

這樣 “-ltcl” 就 OK 了。