2014年12月25日 星期四

Add some file into /conf

1. Copy the files into "source/sys_defaultcfg-1.0.0-src/data/defaults/etc/defconfig"

or

2. Copy the files into source/sys_base-2.159.0-src/data/defaults/etc/defconfig/

[Linux]mount the jffs2 image.

modprobe jffs2;modprobe mtdram;modprobe mtdchar;modprobe mtdblock

dd if=conf.bin of=/dev/mtd0
mount -t jffs2 /dev/mtdblock0 /media

2014年10月7日 星期二

[Linux]使用dd清除raid config

 RAID的config通常是放在最後一個cylinder上的

dd if=/dev/zero of=/dev/sdb bs=100MB seek=4990

資訊來源: http://www.pczone.com.tw/vbb3/archive/t-151980.html

2014年9月2日 星期二

2014年4月24日 星期四

[Linux]How to execute reboot in the Linux driver module

 void rebootBMC(void) {
    int ret;
    char *cmd[2], *path[4];

    cmd[0] = "/sbin/reboot";
    cmd[1] = NULL;
    path[0] = "HOME=/";
    path[1] = "PWD=/";
    path[2] = "PATH=/sbin";
    path[3] = NULL;
    ret = call_usermodehelper(cnd[0], cnd, path, 0);
    printk(KERN_INFO "reboot to enable SMBus Sideband LAN (ret = %d).\n",  ret);
}


You can fill the parameter into cmd[1] and the cmd and path arrays should end with "NULL.


2014年4月10日 星期四

[Linux]Redirect stderr into stdout

Add 2>&1 in the command line.

e.g. ipmitool -H 10.99.6.8 -U USERID -P PASSW0RD sel 2>&1 | awk 'NR==1{print $2}'



2014年4月8日 星期二

[Linux]Read/Write config file in the driver module

#include linux/string.h

static int WriteBondConfToNCSI(void){
struct file *fp;
char buf[128],  *substring;
int indexofsubstring = 0;
mm_segment_t fs;

fp=filp_open("/conf/bond.conf",O_RDONLY,0);

fs = get_fs();
// Set segment descriptor associated to kernel space
set_fs(get_ds());

memset(buf, 0, sizeof(buf));

// Read the file
fp->f_op->read(fp, buf, 128, &fp->f_pos);
set_fs(fs);
filp_close(fp,NULL);

fp=filp_open("/conf/bond.conf",O_WRONLY | O_TRUNC,0);

substring = strstr(buf, "eth");
indexofsubstring = substring - buf;
buf[indexofsubstring+3] = '0';

fs = get_fs();
// Set segment descriptor associated to kernel space
set_fs(get_ds());

fp->f_op->write(fp, (char *)buf, strlen(buf), &fp->f_pos);

set_fs(fs);
filp_close(fp,NULL);

return 0;
}

如果想判斷某檔案是否存在,可利用下列方式:
filep=filp_open("/tmp/aa",O_RDONLY,0);
if(IS_ERR(filep)){
//Not exist
}
else{
//Exist
}

不可使用if(filep == NULL){}

2014年3月3日 星期一

[Linux]Mount the image file with jffs2 file system in the Linux OS.

1. modprobe mtdblock

2. modprobe mtdram total_size=512k erase_size=64k

3. dd if=jffs2.img of=/dev/mtdblock0

4. mount -t jffs2 /dev/mtdblock0 /mnt/