Archive

Posts Tagged ‘Linux’

修改Linux Kernel启动画面

June 3rd, 2011 No comments

linux kernel的启动logo存放于KERNEL_PATH/drivers/video/logo/logo_linux_cult224.ppm

是被编译到内核的,所以不能简单的替换就改变原有的logo,按以下命令制作logo_linux_cult224.ppm:


pngtopnm logo.png > logo_linux_cult224.pnm       /*格式转换*/
pnmquant 224 logo_linux_cult224.pnm > logo_linux_cult224.pnm /*将图像改为224色*/
pnmtopnm logo_linux_cult224.pnm > logo_linux_cult224.ppm /*将图像转存为ppm格式*/

替换新内核中原有的logo_linux_cult224.ppm,注意备份原有的企鹅logo_linux_cult224.ppm。

内核编译后,且以framebuffer方式启动新内核,此时企鹅图标就变成了自定义的LOGO(注意LOGO图像的尺寸不能大于framebuffer的尺寸)

但是在启动中,logo上会有光标在闪烁,如果需要将光标去除(提示console的光标也会消失),将内核中的KERNEL_PATH/drivers/video/console/fbcon.c中的fb_flashcursor和fbcon_sursor函数体置空。重新编译安装内核即可。

参考: http://www.cnblogs.com/semo/archive/2011/01/05/1926295.html

–EOF–

 

Cross Compile SDL

August 3rd, 2010 No comments

==============================
jpeg-8b

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
libpng-1.2.44

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr/
make
make install

==============================
zlib-1.2.5

export CC=arm-linux-gcc
./configure –shared –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
e2fsprogs-1.41.12

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
freetype-2.3.12

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
DirectFB-1.4.3
依赖: JPEG, libpng, e2fsprogs(uuid), zlib, freetype2
make的时候如果在Makefile里面出现没有相关的头文件就进相关的Makefile修改CFLAGS增加你头文件和库文件的地址, 如果你不是Davinci平台,就进入gfxdrivers/Makefile把”DAVINCI_DIR”相关的东西都屏蔽掉。

./configure –host=arm-linux –prefix=/opt/rootfs/cross/arm/usr
make
make install

==============================
SDL-1.2.14
依赖: JPEG, libpng, e2fsprogs(uuid), zlib,
——

export NM=arm-linux-nm
export LD=arm-linux-ld
export CC=arm-linux-gcc
export CXX=arm-linux-g++
export RANLIB=arm-linux-ranlib
export AR=arm-linux-ar

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/arm/4.2.2-eabi/:/usr/local/arm/4.2.2-eabi/usr/:/opt/rootfs/cross/arm/usr/

如果找不到directfb库,修改Makefile, 在CFLAGS中增加你的相关库文件的路径

CFLAGS = -g -O2 -I/opt/rootfs/cross/arm/usr/include -L/opt/rootfs/cross/arm/usr/lib
LDFLAGS = $(CFLAGS)

./configure –enable-video-qtopia –enable-video-directfb –enable-video-opengl –disable-video-dummy –disable-video-fbcon –disable-video-dga –disable-arts-shared –disable-arts –disable-esd –disable-esd-shared –disable-alsa –disable-cdrom –disable-video-x11 –disable-nasm –disable-diskaudio –disable-mintaudio –disable-video-ps2gs –disable-atari-ldg –disable-video-photon –disable-nas –host=arm-linux –prefix=/opt/rootfs/cross/arm/libsdl

编译sdltest
cd test
修改Makefile增加一些库

CFLAGS = -g -O2 -I/opt/rootfs/cross/arm/libsdl/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -L/opt/rootfs/cross/arm/libsdl/lib -I/opt/rootfs/cross/arm/libsdl/include -I/opt/rootfs/cross/arm/usr/include -L/opt/rootfs/cross/arm/usr/lib -I/opt/rootfs/cross/arm/libsdl/include/SDL
LIBS = -L/opt/rootfs/cross/arm/libsdl/lib -lSDL -lpthread -ldirectfb -ljpeg -lpng -ldirect -lpng12 -lz -lfusion -lfreetype

*****************************************

1. 挂接命令:

mount -o nolock -t nfs 10.0.3.244:/long_nfs /tmp/
mount -o nolock 10.0.3.244:/long_nfs /tmp/

这两个都可以。
2. 可能出现的错误类型
a. 错误类型:

rpcbind: server localhost not responding, timed out
RPC: failed to contact local rpcbind server (errno 5).
lockd_up: makesock failed, error=-5
rpcbind: server localhost not responding, timed out
RPC: failed to contact local rpcbind server (errno 5).
mount: mounting 10.0.3.244:/long_nfs on /tmp/ failed: Input/output error

这个问题是因为挂接命令不对,要加上参数-o nolock就可以了

但是NFS不稳定

nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 OK
nfs: server 192.168.2.213 not responding, still trying
nfs: server 192.168.2.213 not responding, still trying

=============================

Categories: Embedded, Tech.Notes Tags: , ,

Pthread创建线程后必须使用join或detach释放线程资源

December 26th, 2009 No comments

这两天在看Pthread 资料的时候,无意中看到这样一句话(man pthread_detach):

Either pthread_join(3) or pthread_detach() should be called for each thread
       that an application creates, so that system resources for the thread can be
       released.  (But note that the resources of all threads are freed when the
       process terminates.)

也就是说:每个进程创建以后都应该调用pthread_join 或 pthread_detach 函数,只有这样在线程结束的时候资源(线程的描述信息和stack)才能被释放.

之后又查了pthread_join 但是没有明确说明必须调用pthread_join 或 pthread_detach.

但是再查了 Pthread for win32 pthread_join

When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called  once  for each joinable thread created to avoid memory leaks.


才知道如果在新线程里面没有调用pthread_join 或 pthread_detach会导致内存泄漏, 如果你创建的线程越多,你的内存利用率就会越高, 直到你再无法创建线程,最终只能结束进程。

解决方法有三个:
1.   线程里面调用 pthread_detach(pthread_self()) 这个方法最简单
2在创建线程的设置PTHREAD_CREATE_DETACHED属性
3. 创建线程后用 pthread_join() 一直等待子线程结束。

下面是几个简单的例子
1. 调用  pthread_detach(pthread_self())
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *PrintHello(void)
{
pthread_detach(pthread_self());
int stack[1024 * 20] = {0,};
//sleep(1);
long tid = 0;
//printf(“Hello World! It’s me, thread #%ld!\n”, tid);
//pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t pid;
int rc;
long t;
while (1) {
printf(“In main: creating thread %ld\n”, t);
rc = pthread_create(&pid, NULL, PrintHello, NULL);
if (rc){
printf(“ERROR; return code from pthread_create() is %d\n”, rc);
//exit(-1);
}
sleep(1);
}
printf(” \n— main End —- \n”);
pthread_exit(NULL);
}
2在创建线程的设置PTHREAD_CREATE_DETACHED属性

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *PrintHello(void)
{
int stack[1024 * 20] = {0,};
//pthread_exit(NULL);
//pthread_detach(pthread_self());
}
int main (int argc, char *argv[])
{
pthread_t pid;
int rc;
long t;
while (1) {
printf(“In main: creating thread %ld\n”, t);
pthread_attr_t attr;
pthread_t thread;
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
rc = pthread_create(&pid, &attr, PrintHello, NULL);
pthread_attr_destroy (&attr);
if (rc){
printf(“ERROR; return code from pthread_create() is %d\n”, rc);
//exit(-1);
}
sleep(1);
}
printf(” \n— main End —- \n”);
pthread_exit(NULL);
}

3. 创建线程后用 pthread_join() 一直等待子线程结束。

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *PrintHello(void)
{
int stack[1024 * 20] = {0,};
//sleep(1);
long tid = 0;
//pthread_exit(NULL);
//pthread_detach(pthread_self());
}
int main (int argc, char *argv[])
{
pthread_t pid;
int rc;
long t;
while (1) {
printf(“In main: creating thread %ld\n”, t);
rc = pthread_create(&pid, NULL, PrintHello, NULL);
if (rc){
printf(“ERROR; return code from pthread_create() is %d\n”, rc);
//exit(-1);
}
pthread_join(pid, NULL);
sleep(1);
}
printf(” \n— main End —- \n”);
pthread_exit(NULL);
}
2. Linux 多线程应用中如何编写安全的信号处理函数 http://www.ibm.com/developerworks/cn/linux/l-cn-signalsec/index.html?ca=drs-cn-0618
Categories: Kernel, Tech.Notes Tags: , , , ,

Google发布免费DNS解析服务

December 4th, 2009 No comments

本文来自: Solidot.
Google宣布 推出免费的DNS解析服务Google Public DNS

DNS协议是Web的重要组成部分,它就如同是互联网的“电话簿”。每次访问一个网站,计算机都须执行一次DNS查询。复杂的网页在载入之前需执行多次DNS查询,其结果是普通网民每天必须执行数百次DNS查询,这会降低用户的浏览体验。Google推出Public DNS便是试图改进浏览体验,让互联网变得更快(在TTL记录过期之前执行prefetching,更新缓存),更安全(支持新的DNS安全扩展DNSSEC)。Google Public DNS托管在Google分布在全世界的数据中心,它使用选播路由算法(Anycast Routing)把用户的DNS解析请求发送到地理位置最近的数据中心。Google Public DNS遵循DNS标准,向用户的计算机提供正确的响应,不会有任何屏蔽、过滤,或重新定向等妨碍用户浏览体验的行为。Google Public DNS的IP地址为:8.8.8.8以及8.8.4.4。

修改TCP/IP的DNS服务器地址:

Microsoft Windows

DNS settings are specified in the TCP/IP Properties window for the selected network connection.

Example: Changing DNS server settings on Microsoft Windows Vista

  1. Go the Control Panel.
  2. Click Network and Internet, then Network and Sharing Center, then Manage network connections.
  3. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, right-click Local Area Connection, and click Properties.
    • To change the settings for a wireless connection, right-click Wireless Network Connection, and click Properties.

    If you are prompted for an administrator password or confirmation, type the password or provide confirmation.

  4. Select the Networking tab. Under This connection uses the following items, clickInternet Protocol Version 4 (TCP/IPv4), and then click Properties.
  5. Click Advanced and select the DNS tab. If there are any DNS server IP addresses listed there, write them down for future reference, and remove them from this window.
  6. Click OK.
  7. Select Use the following DNS server addresses. If there are any IP addresses listed in the Preferred DNS server or Alternate DNS server, write them down for future reference.
  8. Replace those addresses with the IP addresses of the Google DNS servers: 8.8.8.8 and 8.8.4.4.
  9. Restart the connection you selected in step 3.
  10. Test that your setup is working correctly; see Testing your new settings below.
  11. Repeat the procedure for additional network connections you want to change.

Mac OS X

DNS settings are specified in the Network window.

Example: Changing DNS server settings on Mac OS 10.5

  1. From the Apple menu, click System Preferences, then click Network. If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
  2. Select the connection for which you want to configure Google Public DNS. For example:
    • To change the settings for an Ethernet connection, select Built-In Ethernet, and click Advanced.
    • To change the settings for a wireless connection, select Airport, and clickAdvanced.
  3. Select the DNS tab.
  4. Click + to replace any listed addresses with, or add, the Google IP addresses at the top of the list: 8.8.8.8 and 8.8.4.4.
  5. Click Apply and OK.
  6. Test that your setup is working correctly; see Testing your new settings below.
  7. Repeat the procedure for additional network connections you want to change.

Linux

DNS settings are specified in /etc/resolv.conf in most distributions.

Example: Changing DNS server settings on Ubuntu

  1. Edit /etc/resolv.conf:
    sudo vi /etc/resolv.conf
  2. If any nameserver lines appear, write down the IP addresses for future reference.
  3. Replace the nameserver lines with, or add, the following lines:
    nameserver 8.8.8.8
    nameserver 8.8.4.4
  4. Save and exit.
  5. Restart any Internet clients you are using.
  6. Test that your setup is working correctly; see Testing your new settings below.


Bian Jiang
Blog: http://www.wifihack.net/

Categories: Others Tags: , , , ,

vim 快速查找

December 3rd, 2009 No comments

在用vim的时候要经常搜索,但是有的时候会忘记*和 # 这两个快捷键,所以记录如下

在通常模式下:

/ 向下查找

? 向上查找

* 向下查找当前光标下的单词

# 向上查找当前光标下的单词.

f{char} 跳到当前行,当前位置右边的{char}的位置. 如

using namespace std;

用f; 将会跳到;所在的位置.

F{char} 类似f{char},不过,是左边.

t{char} 类似f{char},不过,把光标放在{char}的前一个位置.

T{char} 类似t{char},不过,是左边.

; 重复t T f T 指令

, 朝相反方向重复t T f T 指令


Bian Jiang
Blog:  http://www.wifihack.net/

Categories: Tech.Notes Tags: , , ,