1/21/2012

lwIP網路卡驅動程式撰寫

lwIP網路卡驅動程式主要以輪詢模式(polling mode)運作。使用者將網路卡介面(network interface)透過netif_add()添加至lwIP後,其生命週期便由lwIP接管,之後只要在主程式迴圈(main program loop)中,按時輪詢網路卡驅動程式,將接收到的封包派送至通訊協定堆疊即可。驅動程式撰寫者,只需要專注於提供與lwIP相容之驅動程式介面即可。

11/17/2011

如何正確停止「live555 RTSP串流伺服器」

在前一篇文章裡,我介紹如何利用live555撰寫RTSP串流伺服器。文章的原始碼範例,並無針對一些例外訊號例如:「Ctrl+C(SIGINT)」進行捕捉處理。 在Linux中,這些例外訊號若沒有處理,其預設行為將是立刻終止程式,進而導致資源遺漏(resource leak)。
在Linux裡,我們可以透過signal()於程式中設立處理常式(signal handler),於對應之處理常式中,我們將可正確地停止RTSP伺服器。

11/06/2011

YAML簡介

什麼是YAML
YAML是YAML Ain't Markup Language的遞迴縮寫(一種來自Opensource界的奇怪幽默,如果你懂,你就...)。顧名思義,它設計的目的是作為表達、傳遞資料的一種資料描述方式(data serialization language)。與XML或類似的用途的語言相比,它著重於資料於人們的可(易)閱度讀性。
例如,以下兩個YAML的例子:
--- # 最喜愛的電影
- Casablanca
- North by Northwest
- Notorious
-
  name: Mark McGwire
  hr:   65
  avg:  0.278
-
  name: Sammy Sosa
  hr:   63
  avg:  0.288

11/04/2011

移植lwIP至U-Boot

U-Boot是嵌入式系統上被廣為運用的boot loader,它擁有極為活躍的開發社群,也支援許多不同類型的CPU核心架構。U-Boot目前並不支援完整的TCP/IP,僅有限度地支援TFTP,方便開發者上傳韌體或是網路開機(BOOTP)。U-Boot身為boot loader非嵌入式作業系統,依據開放原始碼社群秉持地「精簡就是美」原則,不支援TCP/IP是可以理解的。萬一真的需要網路功能,移植一套完整的TCP/IP協定堆疊的任務雖然富有挑戰性,實務上亦是可行之道。

lightweight IP(lwIP)是一個輕巧的開放原始碼之TCP/IP通訊協定之實作。lwIP首先由Adam Dunkels發表,目前則是以Kieran Mansley為計畫主持人,帶領開放原始碼社群進行該專案的維護與開發。
目前lwIP已實做的協定如下:
  • IP (Internet Protocol) including packet forwarding over multiple network interfaces
  • ICMP (Internet Control Message Protocol) for network maintenance and debugging
  • IGMP (Internet Group Management Protocol) for multicast traffic management
  • UDP (User Datagram Protocol) including experimental UDP-lite extensions
  • TCP (Transmission Control Protocol) with congestion control, RTT estimation and fast recovery/fast retransmit
  • Raw/native API for enhanced performance
  • DNS (Domain names resolver)
  • SNMP (Simple Network Management Protocol)
  • DHCP (Dynamic Host Configuration Protocol)
  • AUTOIP (for IPv4, conform with RFC 3927)
  • PPP (Point-to-Point Protocol)
  • ARP (Address Resolution Protocol) for Ethernet
  • Optional Berkeley-like socket API 
lwIP設計理念主要是希望於支援TCP/IP協定的同時,於執行時期也能精簡記憶體之運用,以達成支援小型的嵌入式裝置、平台或即時作業系統(RTOS)的目標;除此之外,lwIP也已經移植到眾多RTOS平台上,例如:eCos...等等。由此這些特性來看,使用lwIP搭配U-Boot是一個好的選擇。

9/04/2011

How to Install Ubuntu11.04 on Mac mini

This guide will explain how to install Ubuntu 11.04 on an external USB HDD.
  1. Download and install rEFIt under OSX.
  2. Insert Ubuntu Installation CD to an external USB CD drive.
  3. Reboot and hold Alt key to boot from the CD drive.
  4. Before installing Ubuntu, press F6 and select each options except the last one.
  5. Some options, noapci nopic nomodeset, should be turned off otherwise Linux will halt during the installation.There options would be disabled as well after the installation.
  6. Install Ubuntu on the USB HDD drive and do remember to install grub on the USB HDD as well.
  7. After the first reboot of installation, rEFIt should detect Linux.
  8. Choice to boot from Linux, GRUB will be loaded.
  9. Press "E" to edit boot options of GRUB.
  10. Find and add options to Linux boot arguments:
    linux /boot/vmlinuz-2.6.32-24-generic \
    root=UUID=xxxx-xxx-xxx-xxxx ro quiet \
    nosplash noapci nopci nomodeset reboot=apci
    
    Press Ctrl+X to boot Ubuntu after the modification.
  11. Install NVIDIA proprietary driver to enable 3D/OpenGL.
  12. Enjoy Ubuntu 11.04.

9/03/2011

How to transfer Ununtu11.04/Pandaboard to USB HDD

The pre-built Ubuntu 11.04/Pandaboard image is designed to be installed on a SD card. It could be transfer to the USB HDD with some extra efforts. Typically, a bootable OMAP4/Ubuntu SD card contains two partitions: boot and rootfs. Only rootfs should immigrate to a USB drive since Pandaboard requires booting form SD card.
  1. Prepares a bootable Ubuntu11.04 SD card. howto
  2. Create a ext3/4 partition on a USB HDD labeled "ubuntu".
  3. # /dev/sdXX should be the partition to be formatted,
    # for example /dev/sdc2
    $ sudo mkfs.ext3 -L ubuntu /dev/sdXX
    
  4. Copy rootfs on the SD card to USB HDD
  5. # Suppose USB is mounted on /mnt/ubuntu
    # and rootfs of SD is on /mnt/sd
    $ cd /mnt/ubuntu
    $ sudo cp -a /mnt/sd/* .
    
  6. Boot from SD card
  7. In order to mount USB HDD as rootfs, It'd update parameters that passed to the kernel. The configuration file is located at /boot/boot.script
    $ sudo vi /boot/boot.script
    
    You'd find bootargs have something like this:
    root=UUID=XXXX-XXXX-XXXX-XXXX
    
    Replace it to
    root=LABEL=ubuntu
    
    Then update boot.scr for uboot using:
    $ sudo flash-kernel
    
  8. Reboot it and Ubuntu should use USB HDD as root filesystem. :)

8/31/2011

To install Ubuntu 11.04 on PandaBoard

1. Download a prebuilt Ubuntu 11.04 image from here.
2. Create a bootable SD card(capacity >= 4GB).
    zcat ubuntu-11.04-preinstalled-netbook-armel+omap4.img.gz | \
    sudo dd of=/dev/sdX
    ## sdX should be the actual device node of SD card
3. Bring up PandaBoard with the SD card and enjoy it.