2015-07-31

tips - how to convert jpeg to pdf wtih A4 size


To convert 300dpi JPG file to A4 size PDF file with imageMagick:
convert -density 300 -define pdf:fit-page=A4 source.jpg dest.pdf
Command line options of imageMagick
Scale PDF to A4 with imageMagick

2014-12-27

Debian Wheezy Tips

hime (中文輸入法)

sudo apt-get install hime im-config
sudo cp noseeing.gtab /usr/share/hime/table/
hime-setup > Default input method and toggle key > 勾選自已習慣的輸入法,例:詞音,希臘文
im-config -n hime
登出,再登入,啟動中文輸入法

2011-11-09

Setting up ZyXEL NWD2105 for CentOS-5 and Ubuntu (10.04)

driver info page: http://www.wikidevi.com/wiki/ZyXEL_NWD2105

driver installation guide: http://eimer.ch/nwd2105.html 

$ cd 2011_0107_RT3070_RT3370_Linux_STA_v2.5.0.1_DPO/

$ make; make install

$ edit /etc/Wireless/RT2870STA/RT2870STA.dat for
    SSID=_YOUR_AP's_SSID_
    NetworkType=Infra   
    WirelessMode=5
    Channel=0
    AuthMode=OPEN
    EncrypType=WEP
    DefaultKeyID=1
    Key1Type=1    # (for ASCII key)
    Key1Str=_YOUR_ASCII_PASSWORD_

$ refer to README_STA_usb for further parameter details

For CentOS-5:

$ edit /etc/modprobe.conf; append "alias ra0 rt3070sta" to it.
$ edit /etc/sysconfig/network-scripts/ifcfg-ra0:
   DEVICE='ra0'
   ONBOOT='yes'
   BOOTPROTO='dhcp'
$ edit /etc/sysconfig/network-scripts/ifup-wireless
   comment out the following two lines:
       line-65: iwconfig $DEVICE key off
       line-98: iwconfig $DEVICE essid any >/dev/null 2>&1

$ /sbin/reboot # to check if the wireless is working after reboot

For Ubuntu (10.04):

* edit /etc/modprobe.d/wireless.conf; add "alias ra0 rt3070sta" to it.
* edit /etc/network/interface:
        auto lo
        iface lo inet loopback
        auto wlan0
        iface wlan0 inet dhcp
* /etc/init.d/networking restart
* /sbin/reboot # to check if the wireless is working after reboot

 

2011-10-21

負整數 - 正整數 = 正整數?

「負整數 - 正整數 = 正整數」在數學上是不正確的,但在計算機上是可能的,詳細原因可以從布林代數的整數加減法的推算得到解答,這裡列舉一個可能的情形:
  • a, b, c 均是 32-bit 的整數 (signed integer)  
  • a = 2147483647
  • b = -2147483648
  • c = b - a = 1
  • 十進位表示:
    c(1) = b(-2147483648) - a(2147483647)
  • 十六進位表示:
    c(0x00000001) = b(0x80000000) - a(0x7FFFFFFF)

以下是對映的 C 程式:

void main(void)
{
    int32_t a;
    int32_t b;
    int32_t c;

    a = 0x7FFFFFFF;
    printf ("a(%d)\n", a);
    b = a+1;
    printf ("b(%d)\n", b);
    c = b - a;
    printf ("c(%d) = b(%d) - a(%d)\n", c, b, a);
    printf ("c(0x%08X) = b(0x%08X) - a(0x%08X)\n", c, b, a);
}

2011-06-30

Ubuntu 10.04 LTS for DELL Vostro 3350

I got my newly arrived Dell vostro 3350 on Jun 29, 2011. I love its anti-glare LCD screen as well as the back-lit keyboard. It was smooth to install Ubuntu 10.04 LTS on it. Everything works after rebooting, except that the LCD resolution was incorrect; also, the Wireless LAN was not working.

Here are my workaround to have them work correctly:

VGA:
  • Install backport-maverick kernel for LCD resolution detection (1366x768)
    sudo apt-get install linux-image-generic-pae-lts-backport-maverick \
    linux-headers-generic-pae-lts-backport-maverick
  • Reboot
Wireless LAN:

2010-08-25

Approaches to Trim OR1200



OR1200 Module Level Utilization:
1954 Slices, initial slice utilization for or1200_top


After removing CUST5 instruction from or1200_alu:
1873 slices, (1954-1873)/1873 = 4.32% area improvement.


After modifying "SHIFT and ROTATE" logic of or1200_alu:
1839 slices, (1954-1839)/1839 = 6.25% area improvement

2010-08-21

Customize minsoc as an OpenRISC sub-system

GOAL
To create a SoC sub-system based on minsoc and OpenRISC

STEPS
  1. obtain minsoc and OpenRISC from SVN repository
    $ (origin) svn co http://opencores.org/ocsvn/minsoc/minsoc/trunk minsoc
    $ (subsoc) git clone git://github.com/artek/minsoc.git minsoc
    $ svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk openrisc
  2. follow steps for "GNU tool chain with newlib"
    1. build and install or1ksim
      edit /etc/ld.so.conf.d/or32.conf, and add /opt/or1ksim/lib
    2. install required library (MFP, MPFR) for building toolchain
      $ sudo apt-get install libgmp3-dev libmpfr-dev dejagnu expectk
    3. build toolchain with newlib
      $ cd openrisc/gnu-src
      $ sudo ./bld.sh --prefix /opt/or32-elf-new --or1ksim /opt/or1ksim --force
    4. add or32-gcc and or1ksim binary to $PATH
      export PATH=${PATH}:/opt/or32-elf/bin:/opt/or1ksim/bin
  3. refer to "Howto: Porting Newlib" to bring up your own BSP
    • config new target as "NON-REENTRANT", "NOT NAMESPACE CLEAN" to reduce generated code size
    • config new target with "-DSMALL_MEMORY" to reduce page size from 4KB to 128B for malloc
    • edit configure.host:
      or32-*-*)
      # syscall_dir=syscalls
      newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DSMALL_MEMORY"
      ;;

  4. follow the minsoc-HOWTO for simulation
    evince minsoc/doc/howto.pdf
  5. FPGA Impmentation
    1. add minsoc_sub to your toplevel
    2. update "Verilog Include Directories" for minsoc to Synthesis options of ISE
      ../../rtl/minsoc/rtl/verilog/ (for minsoc)
      |../../rtl/minsoc/rtl/verilog/or1200/rtl/verilog/ (for or1200)
      |../../rtl/minsoc/rtl/verilog/uart16550/rtl/verilog/ (for uart16550)
  1. check out openrisc repository from opencores
    svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk openrisc
  2. build up toolchain
    cd toolchain_install_scripts/
    1. sudo ./crossbuild.sh
      build or32 toolchain and install it to /usr/local/
    2. sh MOF_ORSOC_TCHN_v5c_or32-elf.sh
      build toolchain and or1ksim to specified path


CONS
  • or32 ld does not support --gc-sections

2009-11-12

tips

tips

= unison (bi-directional synchronization)
    -testServer
    $ unison -sshargs -axC teal ssh://joulee.dyndns.org/proj/teal

= rsync (uni-directional synchronization)
    rsync -e 'ssh -ax' -avz ./teal joulee.dyndns.org:proj/teal

= LVM:
  • pvdisplay - display attributes of a physical volume
  • lvdisplay - display attributes of a logical volume
= LVM: Moving a volume group to another system
  • pvscan
  • vgexport vg_backup
  • vgimport vg_backup
  • vgchange -ay vg_backup
  • mount /dev/vg_backup/LogVol00 /mnt/backup
= LVM: add a disk partition to current system
  • initializing disk partition
    $ pvcreate /dev/sda2
  • adding physical volume to an existing
    volume group
    $ lvdisplay
    $ lvextend -l +100%FREE /dev/vg_system/eda_tools
    $ umount /dev/vg_system/eda_tools
    $ e2fsck -f /dev/vg_system/eda_tools
    $ resize2fs /dev/vg_system/eda_tools
    $ mount /tools

= octave, rlab: replacement of matlab

= gnuplot
    * gnuplot -persist <script>: keep x11 window after exec <script>
    * x11 plot window
        - help: move to x11 plot window; press 'h'
        - u: unzoom
        - p: previous zoom region
        - right-mouse-button: select zoom region
        - e:

= ssh: Warning: No xauth data; using fake authentication data for X11 forwarding
    details are here ; to fix this problem, run the following command on the local host:
    $ xauth add `echo "${DISPLAY}" | sed 's/.*\(:.*\)/\1/'` . `mcookie`

= Cygwin/X and ssh ForwardX11
    - copy ssh_config to ~/.ssh/config; and set ForwardX11 as yes
    - Or, ssh -Y <remote_host>

= Cygwin/X: Clean way to auto-read ~/.Xresources
    add the following to startxwin.bat:
        %RUN% xrdb -wait -merge ~/.Xresources

=Ten Steps To Higher Cygwin Productivity
    $ updatedb --localpaths='c:/ d:/'
    $ crontab ...
    $ ssh daemon ...

= ssh per-host configuration: specify to login as "ethan" for Host "pc*"
    - ~/.ssh/config:
            Host      pc*
            User      ethan

= keychain
    IBM article OpenSSH key management, Part 1
    - generate ssh key pairs (id_dsa)
    $ ssh-keygen.exe -t dsa
    - copy public DSA key to remote host
    $ scp .ssh/id_dsa.pub ethan@pc2005:
    - login to remote host and concatenate id_dsa.pub to .ssh/authorized_keys
    $ cat id_dsa.pub >> .ssh/authorized_keys
    - edit .bash_profile; add the following to it
        keychain ~/.ssh/id_dsa
        source ~/.keychain/`uname -n`-sh

= emacs
    - indent region: C-M-\
    - mark region:
M-< C-SPC M-> C-M-\

= vim
    - include-search /  definition-search [I, ]I, [i, ]i
        :checkpath
        :set path+=../inc
        :set path+=/usr/include/*
    - TODO: apply auto command for "set path"

= cscope
    - cscope -Rb
    - vim: ctrl \ s




= C: Bit Operators (Programming in C:  A Tutorial)
C has several operators for logical bit-operations.
For example,
x = x & 0177;
forms the bit-wise AND of x and 0177, effectively
retaining only the
last seven bits of x.  Other operators are
| inclusive OR
^ (circumflex) exclusive OR
~ (tilde) 1's complement
! logical NOT
<< left shift (as in x<<2)
>> right shift

= bzr
    Bazaar for CVS Users   
    - bzr pull
    - bzr revert
    - bzr update
    - bzr missing
    Using Launchpad and Bazaar
  bzr init-repo libmodbus
  cd libmodbus
  bzr branch lp:libmodbus/trunk
  bzr branch trunk mou
  cd mou
  (hack, hack, hack)
  bzr commit -m "..."
  cd ../trunk
  bzr pull
  cd ../mou
  bzr status
  bzr info
  bzr merge
  (resolve any conflicts)
  bzr commit -m "initial modbus_over_usb"
  bzr push lp:~yishin-li/libmodbus/mou

   
= svn
    - setup subversion on CentOS
    - Note for SELinux / Fedora Core 3+ / Red Hat Enterprise users:
       
$ chcon -R -h -t httpd_sys_content_t PATH_TO_REPOSITORY
    - consult docs and faqs from svn site
    - CVS to SVN Crossover Guide
    - Choosing a Repository Layout        . repo/
            projA/
                branches/
                tags/
                trunk/
            projB/
                branches/

                tags/

                trunk/
    $ create Repository Layout;
    $ cd repo;
svn import . file:///wrk/svn/ssd/repos (import empty layout dirs only)    $ svn import teal/ file:///wrk/svn/ssd/repos/teal/trunk --message "initial teal import"
    $ svn import csim/ file:///wrk/svn/ssd/repos/csim/trunk --message "initial csim import"
    $ svn co file:///wrk/svn/ssd/repos/teal/trunk teal
    $ svn co file:///wrk/svn/ssd/repos/csim/trunk csim
    - how to patch [1 ] [2]
  
    $ sudo svn import proto/ file:///home/svn/repos/proto/trunk --message "initial proto import"
    $ svn co http://taipei/repos/proto/trunk proto

= x264 related (TODO)
x264.exe -b 1 --qp 10 -B 1000 -o output.h264 foreman_part_qcif.yuv 176x144
mplayer.exe -vo yuv4mpeg -vf dect -nosound dolby-city.vob
x264 -o output.h264 stream.y4m --frames 200 --crf 24 -b3 -m9 -r3 --me tesa -8 -t1 --mixed-refs --progress
gprof path-to-x264.exe gmon.out > x264.profile
the most critical part is Motion Estimation (~50%)

what are you trying to do ? output a raw video file ?

ffmpeg -i input -f rawvideo -vcodec rawvideo output

or -f yuv4mpegpipe -vcodec rawvideo (or -f rawvideo -vcodec yuv4mpegpipe ?)

= change login shell: ypchsh
    3  cp ~ethan/.bash_profile .
    4  cp ~ethan/.bashrc .
    5  cp ~ethan/.sh_alias .
    6  cp ~ethan/.profile .
   15  cp ~ethan/bin/* .
   23  cp ~ethan/.eda_tools .
   77  cp -a ~ethan/.vim .
   78  cp -a ~ethan/.vimrc .
   79  cp -a ~ethan/.gvimrc .

= dnsmasq: a light weight tool for DHCP and DNS

= gdbtui
    + CTRL-L to refresh/redraw the screen

= hime (中文輸入法), ubuntu 12.04
    sudo apt-get install hime
    gsettings set com.canonical.Unity.Panel systray-whitelist "['all']"
    sudo glib-compile-schemas /usr/share/glib-2.0/schemas
    sudo cp noseeing.gtab /usr/share/hime/table/

= gcin, ubuntu 10.04
    + im-switch -s gcin
    + noseeing: /usr/share/gcin/script/noseeing-inst (install boshimi)
    + 系統->偏好設定->gcin 輸入法設定->Default input method and toggle key->勾選 Remote client support (port 9999-) (解決 gcin 被 GDM 預先啟動的問題)

= wagig, ubuntu
    sudo apt-get install wajig

    installr Install package and associated recommended packages
    installrs Install package and recommended and suggested packages
    installs Install package and associated suggested packages

       sudo wajig installrs mozilla-thunderbird
       (replace wajig with apt-get)
       http://ubuntuforums.org/showthread.php?t=43382

= update-rc.d, ubuntu
    - update-rc.d cadence defaults 99
    - How-To: Managing services with update-rc.d

= how to create torrent file
    - maketorrent: http://www.dessent.net/btfaq/#maketorrent
    - tracker list: http://torrentfreak.com/how-to-create-a-torrent/
    - example:
        maketorrent-console http://open.tracker.thepiratebay.org/announce <file/dir>

= dpkg-query -S (Find the package a file is from)

= Setting up VMWare shared folders on Ubuntu guest (for both 12.04 and 10.04)

2009-11-05

ubuntu tips

Ubuntu Server Settings
  • pppoe: sudo pppoeconf
  • Network Time Protocol: sudo apt-get install ntp
  • How-To: Manage services with "update-rc.d"
    sudo update-rc.d _service_name_ defaults 99
  • Internet Connection Sharing: dnsmasq(dns+dhcpd) + Firewall(ufw)
    sudo ufw allow 22
    sudo ufw allow 80
    sudo ufw allow from 10.1.1.0/24

    # to enable DHCPD on eth0:
    sudo ufw allow in on eth0 from any port 68 to any port 67 proto udp
    check also "ufw Masquerading"
  • Firewall (ufw) setting for vsftpd:
    sudo ufw allow ftp
    sudo ufw allow 20/tcp
  • DynDNS
  • gitosis: step to restore git repositories
    • restore ssh keys to /etc/ssh
    • restore git directory to /home/git
    • chown -Rf git:git git


2009-11-01

Ubuntu 安裝中文字型

從 vista 安裝標楷體、細明體等字型到 ubuntu :
sudo mount /dev/sda2 /mnt
sudo mkdir /usr/share/fonts/truetype/ttf-microsoft
cd /mnt/Windows/Fonts
sudo cp mingliu.ttc kaiu.ttf simkai.ttf simfang.ttf \
            simhei.ttf simsunb.ttf simsun.ttc msjh* \
            /usr/share/fonts/truetype/ttf-microsoft/
sudo fc-cache -f -v

sudo apt-get install ttf-mscorefonts-installer


參考文章:
[Ubuntu] 安裝中文字型(文鼎字型、微軟正黑體)
「親愛的」搞定ttf-mscorefonts-installer安裝時出現的錯誤

2009-10-29

Install dotProject on CentOS 5

Install required tools
  1. sudo yum install mysql-server gd php-gd php-ldap php-mysql
  2. sudo /sbin/chkconfig --levels 235 mysqld on
  3. sudo service mysqld start
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
/usr/bin/mysql_secure_installation

References

Installing dotProject on Centos 5
Installing dotProject
使用 DotProject 架設 Project Server,整合 LDAP
CentOS - Apache server with SSL 的作法

2009-10-15

[Ubuntu Netbook Remix] 如何不讓視窗自動放大?

在 Ubuntu Netbook Remix 中開啟的應用程式總是將視窗自動放大,可以用 gconf-editor 來關閉這個功能, 方法如下:
  1. 按 "Alt-F2" 鍵,跳出執行程式的輸入視窗
  2. 輸入 "gconf-editor" ,再點「執行」
  3. 在 "apps->maximux" 中點選 "no_maximize",以關閉視窗自動放大的功能
  4. 完成
  5. 參考討論文章

2009-05-26

Setup Dual Head for EeePC with Ubuntu


  1. refer to How to setup Dual Head for Intel Graphics with RandR 1.2
  2. edit /etc/X11/xorg.conf for Section "Screen"
    SubSection "Display"
    Depth 32

    Virtual 2048 2048

    EndSubSection

  3. restart X with "ctrl-alt-backspace"
  4. confirm the maximum "Screen 0" size is 2048x2048 with "xrandr -q"
  5. set the screen layout
    xrandr --output VGA --pos 0x0
    xrandr --output LVDS --pos 0x1024

EeePC model: 904
Linux distribution: Ubuntu 8.04 LTS

2009-05-04

Build EMC2 on CentOS 5.3 (x86_64)

Required packages:
  • pth-devel
  • bwidget
  • tcl-devel
  • tk-devel
  • libtermcap-devel
  • readline-devel
  • libXmu-devel
  • tkinter
sudo yum install pth-devel bwidget tcl-devel tk-devel libtermcap-devel readline-devel libXmu-devel tkinter
cd /usr/share/tcl8.4; sudo ln -sf ../../share/bwidget1.8.0 BWidget

edit src/hal/utils/Submakefile
  1. locate for ../bin/halrmt
  2. remove $(READLINE_LIBS) from its dependent list
  3. add $(READLINE_LIBS) to "@$(CXX) $(LDFLAGS) -o $@ $^ -lpthread"


../bin/halrmt: $(call TOOBJS, $(HALRMTSRCS)) ../lib/libemcini.so.0 ../lib/libnml.so.0 ../lib/libemchal.so.0
$(ECHO) Linking $(notdir $@)
@$(CXX) $(LDFLAGS) -o $@ $^ -lpthread $(READLINE_LIBS)


cd src
./configure --enable-simulator --enable-run-in-place
make
cd ../; . ./scripts/emc-environment
unset LD_LIBRARY_PATH # to disable incorrect xilinx library search path
emc

2009-05-03

Build EMC2 on Windwos

1. GNU PTH Library
2. BWidget:
  • download BWidget-*.tar.bz2 from tclib.sf.net
  • uncompress and copy it to /usr/share/BWidget
  • verify the installation with 'tclsh'
  • % set auto_path
  • % package require BWidget
Build emc2
  1. cd src
  2. ./configure --enable-simulator --enable-run-in-place
  3. make (stuck at here: cannot build libnml on Windows)
    # Before running the software, set the emc environment:
    # . (top dir)/scripts/emc-environment
    # To run the software type
    # emc
  4. libnml is forked from rcslib
  5. rcslib can be built with MinGW; cannot be built with cygwin
  6. replace libnml with rcslib?
  7. port libnml to cygwin?
  8. skip emc2 and try orocos?

2008-12-02

Teal, Truss, and NCsim: Resolved all the Random Crash Issuess

Finally, I've resolved yet another random crash issues for teal, truss, and ncsim. Now it has passed more than 100,000 verification loops without crashing. Thanks to Mike and Robert, who chose to open source teal and truss. As a result, I got a great chance to dig into the source code and learned the internal mechanism for a verification framework.

Today, I felt lucky to find another person at another corner of the world, who also chose teal and made customizations on it. Here's his post at Verification Guild:

"I am using teal right now. We picked it up about a year ago, and have done fairly extensive customization to it. I cannot, however, recommend the version we originally downloaded, it had some bugs, and I have not downloaded a newer version since then, so I can't say anything about the bug fixes. I have to say, that as far as the concepts and functionality of teal go, it is exactly what it should be. I couldn't imagine an easier and cleaner way to connect verilog to C++. I would suggest starting with it, and seeing how far it takes you. It is also free. -- Richard"

2008-11-26

Resolved a subtle teal::vout bug

I've confirmed a subtle teal::vout bug for multi-threaded truss verification environment. In my Linux box (both i686 and x86_64), the ncsim got crashed randomly. Although the crash rate is bellow 1%, it makes me not able to run regression test with teal/truss.

Here's the symptom:
./teal_vout.cpp: (set_file_and_line:631) test_component_0 thread(0x44606960) vout(0x2109718) [FILE: truss/trunk/cpp/inc/truss_test_component.h][line: 70] begin
... ... ...
./teal_vout.cpp: (set_file_and_line:631) test_component_0 thread(0x40A00960) vout(0x2109718) [FILE: ./test_component.cpp][line: 92] begin
... ... ...
=> crashed

Here's the reason:
  • Thread test_component_0 is with ID(0x44606960)
  • Thread verification_top is with ID(0x40A00960)
  • vout(0x2109718) is constructed by thread(0x40A00960) with test_component_0 as its function_area_ name
truss::verification_top calls "test_0->start()", which calls "lls::test_component_[0]->start()", which calls "truss::thread.start()" to create a new thread(0x44606960), which calls "truss::test_component.start_()" to start a new teal::vout message to vout(0x2109718).

However, before it was finished with teal::vout::end_message_() at thread(0x44606960), a new message to the same vout(0x2109718) was issued. It was called from "truss::verification_top::test_0->wait_for_completion ()", which calls "lls::test_component_[0]->wait_for_completion ()", which calls "truss::test_component.wait_for_completion()", which calls "lls::test_component::wait_for_completion_()" at thread (0x40A00960).

As a result, the message_list_ and the other maps of teal::vout got polluted. Sometime, it will end up with a "glibc detected double free or corruption error", which crashed the simulation.

And, here's my solution:
  1. remove internal_mutex_sentry() from teal::vout::put_message()
  2. put a pthread_mutex_lock() at teal::vout::set_file_and_line()
  3. put a pthread_mutex_unlock() at teal::vout::clear_message_()
Although this decreased the simulation crash rate dramatically (from 1% to bellow 0.1%). There's still a simulation error to be resolved: "Cannot place a value with no or zero delay at read only sync".

2008-08-31

使用 C++ 建構邏輯設計的驗證平台

在一般邏輯設計的教學範例中大多是利用硬體描述語言(HDL)來實作測試程序(testbench),如下圖所示:

圖一: Testbench with Stimuli and DUT

使用這種方法有以下幾種缺點:
  1. 必需手動檢查 DUT 的輸出結果,以確認設計的正確性。
  2. HDL 不是針對實作測試程序而最佳化的語言。
  3. 不易實作大型且複雜的測試程序。

因此,在 IC 設計產業中,針對邏輯設計的自動驗證流程,便有了許多種不同的解決方案。基本上,它必具備以下功能:(如圖二所示)
  1. 隨機產生 stimuli 給 Functional Model(FM) 及 DUT (Design Under Test)。
  2. 自動比對 FM 及 DUT 的輸出結果 (Results Checker)。
  3. 當比對結果不一致時,記錄當時的組態及錯誤情形,以重製該項錯誤及除錯。
  4. 能夠有效率地設計並處理複雜的驗證程序。

圖二: Basic Verification Framework

現在,我打算試用 Teal/Truss ,它定義了一套完整的邏輯驗證架構,透過 PLI/VPI ,它可以使用 C++ 建構驗證程序,以驗證使用 Verilog 製作的設計;並且它是開放源碼的自由軟體,我們可以免費取得並使用它。