Katex

顯示具有 Linux 標籤的文章。 顯示所有文章
顯示具有 Linux 標籤的文章。 顯示所有文章

2011年6月23日 星期四

安裝舊Fedora/ kernel

1. download Fedora and install
    http://archives.fedoraproject.org/pub/archive/fedora/linux/core/4/i386/iso/


2. Fedora 裝完, 安裝相關compiler program for kernel rebuilding
    Fedora : Add or Remove Packages : Development


3. download kernel
    http://www.kernel.org/pub/linux/kernel/v2.6/

4. extract kernel to /usr/src/kernels

5. copy config file from /boot and then rebuild kernel
    # make
    # make install
    # make modules
    # make modules_install

Linux Cross Reference

Linux cross reference: http://lxr.linux.no/

Linux kernel 版本很多, 可以利用這個網站來看各版本的source

2011年6月19日 星期日

Add user to group / 把使用者加入某個 group

Suppose that you want to add the user ( named neo ) into the group ( named vboxusers )
假設你要將使用者 neo 加入群組 vboxusers


virtualbox

http://www.virtualbox.org/wiki/Linux_Downloads

Fedora :

1. download rpm

2. Install rpm 

    (1)  Open the file folder and double click on the rpm file
          打開檔案 folder, 在所下載的檔案上點兩下, 即可安裝

    (2)  Then you can see "Oracle VM VirtualBox" at Applications->System Tools
          在 Applications->System Tools 就能看到 "Oracle VM VirtualBox" 的應用程式


    

resize virtualbox .vdi file

$ VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

virtualbox 共享資料夾

1. Installing Guest Additions for Ubuntu Guests in VirtualBox
    安裝 Guest Additions
    將 virtualbox 中的 ubuntu 系統跑起來, 在 Devices->Install Guest Additions
    執行後如下:


2011年6月12日 星期日

[Linux] USB Device Driver

0. 告訴 USB core 此driver 支援的裝置

/* table of devices that work with this driver */
static struct usb_device_id skel_table [] = {
{ USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
{ }
/* Terminating entry */
}; 



MODULE_DEVICE_TABLE (usb, skel_table);



1. usb_register

建立一個值 struct usb_driver 架構, 只有 5 個成員需要被初始化:
static struct usb_driver skel_driver = {
.owner = THIS_MODULE,
.name = "skeleton",
.id_table = skel_table,
.probe = skel_probe,
.disconnect = skel_disconnect,
};
在module init 時, 呼叫

usb_register( skel_driver);

2. Probe 偵測裝置
static int usb_skel_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
1.檢查新裝置是否支援
2.初始化任何管理USB裝置所需的任何私有結構
3.將裝置相關訊息存入私有結構 usb_set_intfdata(interface, dev);
4.向usb core 註冊一個裝置 usb_register_dev(interface, &skel_class);
}

3. Disconnect 卸載裝置
static void usb_skel_disconnect(struct usb_interface *intf)
{
1.取回之前呼叫 usb_set_intfdata 所設定的數據
2.設定數據指標在 struct us_interface 架構為 NULL 來阻止在不正確存取
3.遞減使用次數
}
4. 卸載模組


使用 usb_deregister()



2011年2月12日 星期六

[Linux] SKB

1. socket buffer : struct sk_buff
    (1) 宣告在 include/linux/skbuff.h
    (2) 重要欄位有


  unsigned char *head;  // 配置空間起點
  unsigned char *data;   // 有效資料起點
  unsigned char *tail;     // 有效資料的最後一個 Octet
  unsigned char *end;    // 配置空間終點

2. 配置 sk_buff



(1) struct sk_buff *alloc_skb(unsigned int len, int priority);
比較原始. 配置完成會將 skb-> data 和 skb->tail 指向 skb->head

(2) struct sk_buff *dev_alloc_skb(unsigned int len);
供ISR使用而設計, 以GFP_ATOMIC優先度來配置, 並在 skb->head 和 skb->data 之間保留空間, 用以存放協定標頭.





3. void skb_reserve(struct sk_buff *skb, int len);
    保留前頭空間.
    大多數的Ethernet 介面在封包之前會保留 2-bytes空間,
    這樣可使得 IP header 對齊 16-bytes 邊緣
    ( 因為 IP header 之前的 Ethernet header 有 14-bytes )





4. unsigned char * skb_put(struct sk_buff *skb, int len);
    unsigned char * __skb_put(struct sk_buff *skb, int len);
    將資料加到tail room 區, 並將 skb->tail 往後移
    skb_put() : 會檢查是否有足夠空間
    __skb_put() : 會省略檢查

2011年1月9日 星期日

[Linux module program] 1. Hello World

編寫 hello.c 如下



##include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int __init hello_init(void)
{
    printk(KERN_INFO "Hello world \n");

    return 0;
}

static void __exit hello_exit(void)
{
    printk(KERN_INFO "Goodbye, world \n");
}

module_init(hello_init);
module_exit(hello_exit);


編寫 Makefile 如下



obj-m += hello.o

all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PwD) clean


PS: 請注意 make 前面為tab 而非空白

--
編譯前的準備:
1.  安裝所需程式:
     切換身份為 root, 執行
     yum install yum-utils
     yum install rpmdevtools
     yum install redhat-rpm-config
     yum install xmlto asciidoc elfutils-devel binutils-devel python-devel perl perl-ExtUtils-Embed

2.  Fedora 的 kernel source code
     (1) 先用指令 "uname -a" 查看 kernel 版本
           2.6.35.6-45.fc14.i686

     (2) 下載 kernel source rpm 檔
          http://download.fedora.redhat.com/pub/fedora/linux/releases/
          選擇 Fedora 的版本, 如 Fedora 14
          http://download.fedora.redhat.com/pub/fedora/linux/releases/14/Fedora/source/SRPMS/
         檔案:  kernel-2.6.35.6-45.fc14.src.rpm

     (3) 執行指令
          rpm -ivh kernel-2.6.35.6-45.fc14.src.rpm

          過程中會看到訊息:
          warning: user mockbuild does not exist - using root
          warning: group mockbuild does not exist - using root
          可以加入使用者後再執行一次
          su -c "groupadd mockbuild"
          su -c "useradd mockbuild -g mockbuild"

          安裝完後 會在使用者目錄下產生:  ~/rpmbuild
          切換目錄到 " cd ~/rpmbuild/SPEC"
          執行: rpmbuild -bp --target=$(uname -m) kernel.spec

          接著source會產生在BUILD底下, 可以copy 到 /usr/src/kernels 下
          cp -fr ./rpmbuild/BUILD/kernel-2.6.35.fc14/linux-2.6.35.i686 /usr/src/kernels/2.6.35.6-45.fc14.i686

          並確認 /lib/modules/2.6.35.6-45.fc14.i686/build -> ../../../usr/src/kernels/2.6.35.6-45.fc14.i686

    (4) 編譯 kernel 
          cd /usr/src/kernels/2.6.35.6-45.fc14.i686
          make

-- 編譯 Hello world
   在同 helloworld.c / Makefile 目錄下打 make , 出現問題: 
   (1) 缺少了 generated/bounds.h 檔
        可在 kernel source 目錄下執行 "make prepare"
   (2) insmod error : 
        insmod: error inserting 'hello.ko': -1 Invalid module format
        可用 dmesg 查看原因: 
        hello: version magic '2.6.35.6 SMP mod_unload 686 ' should be '2.6.35.6-45.fc14.i686 SMP mod_unload 686 '
        這是因為 module 版本與 kernel 版本不同的關係
        在 kernel source ( ) 的 Makefile 定義了
              VERSION = 2
              PATCHLEVEL = 6 
              SUBLEVEL = 35
              EXTRAVERSION = .6
        可將 EXTRAVERSION = .6 改為 EXTRAVERSION = .6-45.fc14.i686

-- 執行 "insmod hello.ko"
    dmesg : 可以看到 "Hello world"
    執行 "rmmod hello"
    dmesg : 可以看到 "Goodbye, world"
   
        




2010年12月26日 星期日

[Fedora 14] wifi adsl setting

setup PPPOE connection : 設定 PPPOE 連線
    "su" to change to root, and do "pppoe-setup"
    切換為 root, 執行 /usr/sbin/pppoe-setup

---
Enter your Login Name (default root):  輸入 ADSL 帳號


2009年4月8日 星期三

[Linux] High and low memory

Low memory
Memory for which logical addresses exist in kernel space. On almost every system you will likely encounter, all memory is low memory

High memory
Memory for which logical address do not exist, because it is beyond the address range set aside for kernel virtual addresses.

====
ZONE

ZONE_DMA (0-16 MB) - 包含設定 ISA/PCI 裝置所需的較低實體記憶體區域的範圍
ZONE_NORMAL (16-896 MB) - 直接由 kernel 對映上層實體記憶體區域的範圍ZONE_HIGHMEM (896 MB 或更高) - 並未被 kernel 所對映的剩餘有效記憶體區域

2007年11月4日 星期日

GTK clock - 時鐘

在Linux上, 用GTK2.0寫了一個時鐘的程式. 其實是參考別人的來改. 但是我從秒針每秒移動改成了1/10 秒. 有種機械表移動的感覺. 真好.

原程式的網站: http://www.brouhaha.com/~eric/software/glock/
需要套件:
GTK+ (ver:2.12.1) http://www.gtk.org/
cairo (ver:1.4.10) http://annarchy.cairographics.org/releases/
光是為了安裝這兩個套件, 就得再安裝其他套件
Pango 1.19.0 ftp://ftp.gtk.org/pub/pango/1.19/
ATK 1.20.0 http://www.icewalkers.com/download/ATK/1433/
libpng 1.2.22 http://libpng.sourceforge.net/
freetype 2.3.5 http://freetype.org/
fontconfig 2.4.2 http://fontconfig.org/
想放程式碼, 才發現pchome只能放圖片; 想放到sourceForge, 得要兩個工作天來審核.
只好先找個免費硬碟網站.
http://hosted.filefront.com/jpjou/下的clock.tgz
學習心得:

1. 安裝套件會放在 /usr/local/lib 下, 把這個目錄名稱加到 /etc/ld.so.conf 裡, 並執行ldconfig

2. pkg-config --modeversion glib-2.0, d可以知道目前安裝的套件glib-2.0的版本.

3. ldconfig -p 可以顯示所以可以link的library

4. rpm -i [src.rpm套件] , 會將source 放在 /usr/src/redhat/SOURCES, spec 會放在 /usr/src/redhat/SPECS

熱門文章