How to build chromium OS on Ubuntu 9.04

Ref:

1. Download the Chromium depot tools
$svn co http://src.chromium.org/svn/trunk/tools/depot_tools
$export PATH=`pwd`/depot_tools:"$PATH"

2. Download the gitpackage

$apt-get install git

3. Get a copy of the Chromium OS repository

$mkdir [chromiumos]
$cd [chromiumos]
$gclient config http://src.chromium.org/git/chromiumos.git
$gclient sync


Linux Driver : Hello World (part 1)

Ref:

http://www.tldp.org/LDP/lkmpg/2.6/html/x121.html


1. Coding program : hello1.c


/*

* hello1.c - The simplest kernel module.

*/

#include <linux/module.h> /* Needed by all modules */

#include <linux/kernel.h> /* Needed for KERN_INFO */


int init_module(void)

{

printk(KERN_INFO "Hello world - GW1.\n");


/*

* A non 0 return means init_module failed; module can't be loaded.

*/

return 0;

}


void cleanup_module(void)

{

printk(KERN_INFO "Goodbye world - GW1.\n");

}


2. Coding program : Makefile


obj-m += hello1.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


3. Fixed try


$make

$insmod hello1.ko

$rmmod hello1

$dmesg






Linux Driver : /proc file system (Part1)

Ref:

http://www.wangcong.org/articles/lkmpg_cn/index.htm#AEN602



1. chardev.c

/*

* chardev.c: Creates a read-only char device that says how many times

* you've read from the dev file

*/


#include <linux/kernel.h>

#include <linux/module.h>

#include <linux/fs.h>

#include <asm/uaccess.h> /* for put_user */


/*

* Prototypes - this would normally go in a .h file

*/

int init_module(void);

void cleanup_module(void);

static int device_open(struct inode *, struct file *);

static int device_release(struct inode *, struct file *);

static ssize_t device_read(struct file *, char *, size_t, loff_t *);

static ssize_t device_write(struct file *, const char *, size_t, loff_t *);


#define SUCCESS 0

#define DEVICE_NAME "gw-chardev" /* Dev name as it appears in /proc/devices */

#define BUF_LEN 80 /* Max length of the message from the device */


/*

* Global variables are declared as static, so are global within the file.

*/


static int Major; /* Major number assigned to our device driver */

static int Device_Open = 0; /* Is device open?

* Used to prevent multiple access to device */

static char msg[BUF_LEN]; /* The msg the device will give when asked */

static char *msg_Ptr;


static struct file_operations fops = {

.read = device_read,

.write = device_write,

.open = device_open,

.release = device_release

};


/*

* This function is called when the module is loaded

*/

int init_module(void)

{

Major = register_chrdev(0, DEVICE_NAME, &fops);


if (Major < 0) {

printk(KERN_ALERT "Registering char device failed with %d\n", Major);

return Major;

}


printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);

printk(KERN_INFO "the driver, create a dev file with\n");

printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);

printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");

printk(KERN_INFO "the device file.\n");

printk(KERN_INFO "Remove the device file and module when done.\n");


return SUCCESS;

}


/*

* This function is called when the module is unloaded

*/

void cleanup_module(void)

{

unregister_chrdev(Major, DEVICE_NAME);

printk(KERN_ALERT "cleanup_module - GW\n");

}


/*

* Methods

*/


/*

* Called when a process tries to open the device file, like

* "cat /dev/mycharfile"

*/

static int device_open(struct inode *inode, struct file *file)

{

static int counter = 0;


if (Device_Open)

return -EBUSY;


Device_Open++;

sprintf(msg, "I already told you %d times Hello world!\n", counter++);

msg_Ptr = msg;

try_module_get(THIS_MODULE);

return SUCCESS;

}


/*

* Called when a process closes the device file.

*/

static int device_release(struct inode *inode, struct file *file)

{

Device_Open--; /* We're now ready for our next caller */


/*

* Decrement the usage count, or else once you opened the file, you'll

* never get get rid of the module.

*/

module_put(THIS_MODULE);


return 0;

}


/*

* Called when a process, which already opened the dev file, attempts to

* read from it.

*/

static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */

char *buffer, /* buffer to fill with data */

size_t length, /* length of the buffer */

loff_t * offset)

{

/*

* Number of bytes actually written to the buffer

*/

int bytes_read = 0;


/*

* If we're at the end of the message,

* return 0 signifying end of file

*/

if (*msg_Ptr == 0)

return 0;


/*

* Actually put the data into the buffer

*/

while (length && *msg_Ptr) {


/*

* The buffer is in the user data segment, not the kernel

* segment so "*" assignment won't work. We have to use

* put_user which copies data from the kernel data segment to

* the user data segment.

*/

put_user(*(msg_Ptr++), buffer++);

length--;

bytes_read++;

}


/*

* Most read functions return the number of bytes put into the buffer

*/

return bytes_read;

}


/*

* Called when a process writes to dev file: echo "hi" > /dev/hello

*/

static ssize_t

device_write(struct file *filp, const char *buff, size_t len, loff_t * off)

{

static int w_count = 0;

printk(KERN_INFO "You write message %d times.\n", w_count++);

return -EINVAL;

}


2. Makefile


obj-m += chardev.o

KERNELDIR := /lib/modules/$(shell uname -r)/build

PWD := $(shell pwd)


default:

$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

clean:

$(RM) *.o *.mod.c *.ko *.symvers


3. Fixed try


$make


#掛載driver module

$insmod chardev.ko


#建立裝置檔案節點

# mknod 裝置檔名 [bcp] [Major] [Minor]

#選項與參數:

#裝置種類:

# b :設定裝置名稱成為一個周邊儲存設備檔案,例如硬碟等;

# c :設定裝置名稱成為一個周邊輸入設備檔案,例如滑鼠/鍵盤等;

# p :設定裝置名稱成為一個 FIFO 檔案;


# Major :主要裝置代碼;

# Minor :次要裝置代碼;

$mknod /dev/gw-chardev c 250 0


#Testing1 - write message

$echo "Hello World" > /dev/gw-chardev


#Testing2 - read message

$cat /dev/gw-chardev


#卸載 driver module

$rmmod chardev



Linux Driver : Hello World (part 2)

Ref:


1. Coding program : hello2.c


/*

* hello2.c - Demonstrating the module_init() and module_exit() macros.

* This is preferred over using init_module() and cleanup_module().

*/

#include <linux/module.h> /* Needed by all modules */

#include <linux/kernel.h> /* Needed for KERN_INFO */

#include <linux/init.h> /* Needed for the macros */


static int __init hello2_init(void)

{

printk(KERN_INFO "Hello, world - GW2\n");

return 0;

}


static void __exit hello2_exit(void)

{

printk(KERN_INFO "Goodbye, world - GW2\n");

}


module_init(hello2_init);

module_exit(hello2_exit);


2. Makefile

obj-m += hello2.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

3. Fixed try

$make
$insmod hello2.ko
$rmmod hello2
$dmesg


Enable Flash support for Google Chrome Dev Build on Ubuntu 9.04

喜歡嘗鮮的網路宅宅應該多多少少都知道
Google Chrome 有 Debian/Ubuntu 的開發中版本可以安裝
http://dev.chromium.org/getting-involved/dev-channel
目前官方釋出開發中版本的最新版已經可以使用中文輸入了
不過一直都沒有看到有 Flash 的支援
剛剛看到一篇 Flash player in Google Chrome for Linux 有提到解決方法
於是在 Ubuntu 9.04上面嘗試了一下

1. 首先要找到 libflashplayer.so 的位置
$ locate libflashplayer.so
/usr/lib/adobe-flashplugin/libflashplayer.so
2. 在 Google Chrome 的目錄下建立一個 symbolic link
$ cd /opt/google/chrome/
$ sudo ln -s /usr/lib/adobe-flashplugin/libflashplayer.so .
3. 最後啟動 Google Chrome 時要多加一個參數
$ google-chrome --enable-plugins
還真的可以用耶~ :D
放了一張 YouTube 上的日蝕影片來當真象~ ^w^

虹光大成就-密教灌頂(一)