'kernel'에 해당되는 글 7건

  1. 2012.03.28 [LPC3250] bootargs
  2. 2012.03.28 [LPC3250] Kernel boot message
  3. 2012.03.28 [LPC3250] kernel partition
  4. 2012.03.28 [LPC3250] High Resoulution Timer Support
  5. 2011.11.16 linux kernel thread
  6. 2011.06.24 [s3c6410] linux 커널에서 HZ 기본값 변경하기
  7. 2011.03.25 커널 메세지 출력하지 않기

[LPC3250] bootargs

uboot에서 사용하는 bootargs 다

console=ttyS0,115200n81 root=1f03 rw rootfstype=jffs2 ip=192.168.10.104 init=/sbin/init


nfs용 bootargs

console=ttyS0,115200n81 root=/dev/nfs rw nfsroot=192.168.10.101:/home/shellbt/source/ramdisks/LPC3250/mini3250 ip=192.168.10.104


'임베디드 > LPC3250' 카테고리의 다른 글

u-boot 환경설정값  (0) 2012.04.06
stage1 app information  (0) 2012.04.05
[LPC3250] root 파일 시스템 파일명  (0) 2012.03.28
[LPC3250] Kernel boot message  (0) 2012.03.28
[LPC3250] kernel partition  (0) 2012.03.28

[LPC3250] Kernel boot message

Uncompressing Linux............................................................................................... done, booting the kernel.
�Linux version 2.6.27.8 (shellbt@ubuntu) (gcc version 4.3.2 (crosstool-NG-1.3.1) ) #1 PREEMPT Wed Mar 28 13:46:30 KST 2012
CPU: ARM926EJ-S [41069264] revision 4 (ARMv5TEJ), cr=00053177
Machine: Phytec 3250 board with the LPC3250 Microcontroller
Memory policy: ECC disabled, Data cache writeback
CPU0: D VIVT write-back cache
CPU0: I cache: 32768 bytes, associativity 4, 32 byte lines, 256 sets
CPU0: D cache: 32768 bytes, associativity 4, 32 byte lines, 256 sets
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: console=ttyS0,115200n81 root=/dev/mtdblock3 rw rootfstype=jffs2 ip=192.192.192.205 init=/sbin/init
PID hash table entries: 256 (order: 8, 1024 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60676KB available (3700K code, 238K data, 232K init)
Calibrating delay loop... 103.68 BogoMIPS (lpj=207360)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
net_namespace: 288 bytes
NET: Registered protocol family 16
Invalid board descriptor!
LPC32XX DMA driver
LPC32XX unique ID: 0005b6dd75701b6e591c8cb710af2800
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
NetWinder Floating Point Emulator V0.97 (double precision)
JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
yaffs Mar 28 2012 13:43:11 Installing.
msgmni has been set to 118
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
Serial: 8250/16550 driver4 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0x40090000 (irq = 9) is a 16550A
console [ttyS0] enabled
serial8250.0: ttyS1 at MMIO 0x40080000 (irq = 7) is a 16550A
serial8250.0: ttyS2 at MMIO 0x40088000 (irq = 8) is a 16550A
serial8250.0: ttyS3 at MMIO 0x40098000 (irq = 10) is a 16550A
lpc32xx_hsuart.0: ttyTX0 at MMIO 0x40014000 (irq = 26) is a lpc32xx_hsuart
lpc32xx_hsuart.0: ttyTX1 at MMIO 0x40018000 (irq = 25) is a lpc32xx_hsuart
lpc32xx_hsuart.0: ttyTX2 at MMIO 0x4001c000 (irq = 24) is a lpc32xx_hsuart
loop: module loaded
nbd: registered device at major 43
usbcore: registered new interface driver ub
LPC32XX_mii_bus: probed
eth0: LPC32XX mac at 0x31060000 irq 29
eth0: attached PHY driver [SMSC LAN8700] (mii_bus:phy_addr=0:1f, irq=-1)
Driver 'sd' needs updating - please use bus_type methods
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 0 at 0x00000000
Bad eraseblock 1 at 0x00020000
Creating 4 MTD partitions on "lpc32xx_nand":
0x00000000-0x00180000 : "phy3250-boot"
0x00180000-0x001c0000 : "phy3250-ubt-prms"
0x001c0000-0x005c0000 : "phy3250-kernel"
0x005c0000-0x08000000 : "phy3250-rootfs"
Enable SPI clock
ttySCMA0 at I/O 0x1 (irq = 79) is a sc16is752
ttySCMA1 at I/O 0x2 (irq = 79) is a sc16is752
usbmon: debugfs is not available
I2C device at address 0x2d<6>ISP1301 Vendor ID  : 0x04cc
ISP1301 Product ID : 0x1301
ISP1301 Version ID : 0x0210
usb-ohci usb-ohci: at 0xf3120000, irq 0
usb-ohci usb-ohci: pnx4008 OHCI
usb-ohci usb-ohci: new USB bus registered, assigned bus number 1
usb-ohci usb-ohci: irq 59, io mem 0xf3120000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver libusual
input: devkit3250-buttons as /class/input/input0
Initial gpio driver
rtc-lpc32xx rtc-lpc32xx: rtc core: registered rtc-lpc32xx as rtc0
i2c /dev entries driver
PNX4008-WDT: PNX4008 Watchdog Timer: heartbeat 19 sec
mmci-pl18x: DMA buffer(10000 bytes), P:0x839a0000, V:0xffc1c000
mmc0: MMCI rev 0 cfg 00 at 0x0000000020098000 irq 15,13
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.17.
ASoC version 0.13.2
UDA1380 Audio Codec 0.6<6>asoc: UDA1380 <-> lpc3xxx-i2s1 mapping ok
ALSA device list:
  #0: LPC32XX (UDA1380)
TCP cubic registered
NET: Registered protocol family 17
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
ieee80211: 802.11 data/management/control stack, git-1.1.13
ieee80211: Copyright (C) 2004-2005 Intel Corporation <jketreno@linux.intel.com>
VFP support v0.3: implementor 41 architecture 1 part 10 variant 9 rev 1
rtc-lpc32xx rtc-lpc32xx: setting system clock to 2016-06-20 20:47:54 UTC (1466455674)
IP-Config: Guessing netmask 255.255.255.0
IP-Config: Complete:
     device=eth0, addr=192.192.192.205, mask=255.255.255.0, gw=255.255.255.255,
     host=192.192.192.205, domain=, nis-domain=(none),
     bootserver=255.255.255.255, rootserver=255.255.255.255, rootpath=
VFS: Mounted root (jffs2 filesystem).
Freeing init memory: 232K
Warning: unable to open an initial console.
Failed to execute /sbin/init.  Attempting defaults...
Kernel panic - not syncing: No init found.  Try passing init= option to kernel.

'임베디드 > LPC3250' 카테고리의 다른 글

stage1 app information  (0) 2012.04.05
[LPC3250] bootargs  (0) 2012.03.28
[LPC3250] root 파일 시스템 파일명  (0) 2012.03.28
[LPC3250] kernel partition  (0) 2012.03.28
[LPC3250] High Resoulution Timer Support  (0) 2012.03.28

[LPC3250] kernel partition

LPC3250 devkit의 커널 파티션 정보

Creating 4 MTD partitions on "lpc32xx_nand":
0x00000000-0x00180000 : "phy3250-boot"
0x00180000-0x001c0000 : "phy3250-ubt-prms"
0x001c0000-0x005c0000 : "phy3250-kernel"
0x005c0000-0x08000000 : "phy3250-rootfs"

'임베디드 > LPC3250' 카테고리의 다른 글

stage1 app information  (0) 2012.04.05
[LPC3250] bootargs  (0) 2012.03.28
[LPC3250] root 파일 시스템 파일명  (0) 2012.03.28
[LPC3250] Kernel boot message  (0) 2012.03.28
[LPC3250] High Resoulution Timer Support  (0) 2012.03.28

[LPC3250] High Resoulution Timer Support

linux kernel 2.6.27.8에서 설정한다.

이 기능은 고분해능 타이머를 사용 할 수 있게 해 준다.

이 타이머는 나노초 단위로 작동한다.

해당하는 함수로는

void hrtimer_init( struct hrtimer *time, clockid_t which_clock,
enum hrtimer_mode mode ); int hrtimer_start(struct hrtimer *timer, ktime_t time,

const enum hrtimer_mode mode);

int hrtimer_cancel(struct hrtimer *timer);
int hrtimer_try_to_cancel(struct hrtimer *timer);
int hrtimer_callback_running(struct hrtimer *timer);

예)

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/hrtimer.h>
#include <linux/ktime.h>

MODULE_LICENSE( "GPL" );

#define MS_TO_NS(x)	(x * 1E6L)

static struct hrtimer hr_timer;

enum hrtimer_restart my_hrtimer_callback( struct hrtimer *timer )
{
  printk( "my_hrtimer_callback called (%ld).\n", jiffies );

  return HRTIMER_NORESTART;
}

int init_module( void )
{
  ktime_t ktime;
  unsigned long delay_in_ms = 200L;

  printk("HR Timer module installing\n");

  ktime = ktime_set( 0, MS_TO_NS(delay_in_ms) );

  hrtimer_init( &hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL );
  
  hr_timer.function = &my_hrtimer_callback;

  printk( "Starting timer to fire in %ldms (%ld)\n", 
delay_in_ms, jiffies ); hrtimer_start( &hr_timer, ktime, HRTIMER_MODE_REL ); return 0; } void cleanup_module( void ) { int ret; ret = hrtimer_cancel( &hr_timer ); if (ret) printk("The timer was still in use...\n"); printk("HR Timer module uninstalling\n"); return; }

'임베디드 > LPC3250' 카테고리의 다른 글

stage1 app information  (0) 2012.04.05
[LPC3250] bootargs  (0) 2012.03.28
[LPC3250] root 파일 시스템 파일명  (0) 2012.03.28
[LPC3250] Kernel boot message  (0) 2012.03.28
[LPC3250] kernel partition  (0) 2012.03.28

linux kernel thread

Linux Kernel Threads in Device Drivers

Purpose

This examples shows how to create and stop a kernel thread.
The driver is implemented as a loadable module. In the init_module() routine five kernel threads are created. This kernel threads sleep one second, wake up, print a message and fall asleep again. On unload of the module (cleanup_module), the kernel threads are killed.
The example has been tested with Linux kernel 2.4.2 on Intel (uni processor only) and Alpha platform (COMPAQ Personal Workstation 500au (uni processor), DS20 and ES40 (SMP).

A version for the 2.2 kernel can be found here. Note: depending on the context of the creator of the threads the new threads may inherit properties from the parent you do not want to have. The new version avoids this by having keventd create the threads. The 2.2. kernel do not have a keventd, so this approach is not implementable there.

Functions in example

  • start_kthread: creates a new kernel thread. Can be called from any process context but not from interrupt. The functions blocks until the thread started.
  • stop_kthread: stop the thread. Can be called from any process context but the thread to be terminated. Cannot be called from interrupt context. The function blocks until the thread terminated.
  • init_kthread: sets the environment of the new threads. Is to be called out of the created thread.
  • exit_kthread: needs to be called by the thread to be terminated on exit

Creation of new Thread

A new thread is created with kernel_thread(). The thread inherits properties from its parents. To make sure that we do not get any weired properties, we let keventd create the new thread.
The new thread is created with start_kthread(). It uses a semaphore to block until the new thread is running. A down() blocks the start_kthread() routine until the corresponding up() call in init_kthread() is executed. 
The new thread must call init_kthread() in order to let the creator continue.

Stop of new Thread

stop_kthread() sets a flag that the thread uses to determine whether do die or not and sends a SIGKILL to the thread. This signal causes the thread to be woken up. On wakeup it will check for the flag and then terminate itself by calling exit_kthread and returning from the thread function. With a semaphore the stop_kthread() function blocks until the thread terminated.

Initialization of new Thread

Within the new created thread, init_kthread() needs to be called. This function sets a signal mask, initialises a wait queue, the termination flag and sets a new name for the thread. With a up() call it notifies the creator that the setup is done.

Exit of new Thread

When the thread receives the notification to terminate itself, is calls the exit_kthread() function. It notifies the stop_kthread() function that it terminated with an up() call.

The new Thread itself

The new thread is implemented in the example_thread() function. It runs an endless loop (for(;;)). In the loop it falls asleep with the interruptible_sleep_on_timeout() function. It comes out of this function either when the timeout expires or when a signal got caught.
The "work" in the thread is to print out a message with printk.

Kernel Versions

The example has been tested on 2.4.2.

Example Device Driver Code

The example consists of four files: kthread.h, kthread.c, thread_drv.c and a Makefile

kthread.h

#ifndef _KTHREAD_H
#define _KTHREAD_H
#include <linux/config.h>
#include <linux/version.h>

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/tqueue.h>
#include <linux/wait.h>

#include <asm/unistd.h>
#include <asm/semaphore.h>

/* a structure to store all information we need
   for our thread */
typedef struct kthread_struct
{
        /* private data */

        /* Linux task structure of thread */
        struct task_struct *thread;
        /* Task queue need to launch thread */
        struct tq_struct tq;
        /* function to be started as thread */
        void (*function) (struct kthread_struct *kthread);
        /* semaphore needed on start and creation of thread. */
        struct semaphore startstop_sem;

        /* public data */

        /* queue thread is waiting on. Gets initialized by
           init_kthread, can be used by thread itself.
        */
        wait_queue_head_t queue;
        /* flag to tell thread whether to die or not.
           When the thread receives a signal, it must check
           the value of terminate and call exit_kthread and terminate
           if set.
        */
        int terminate;
        /* additional data to pass to kernel thread */
        void *arg;
} kthread_t;

/* prototypes */

/* start new kthread (called by creator) */
void start_kthread(void (*func)(kthread_t *), kthread_t *kthread);

/* stop a running thread (called by "killer") */
void stop_kthread(kthread_t *kthread);

/* setup thread environment (called by new thread) */
void init_kthread(kthread_t *kthread, char *name);

/* cleanup thread environment (called by thread upon receiving termination signal) */
void exit_kthread(kthread_t *kthread);

#endif

kthread.c

#include <linux/config.h>
#include <linux/version.h>

#if defined(MODVERSIONS)
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/tqueue.h>
#include <linux/wait.h>
#include <linux/signal.h>

#include <asm/semaphore.h>
#include <asm/smplock.h>

#include "kthread.h"

/* private functions */
static void kthread_launcher(void *data)
{
        kthread_t *kthread = data;
        kernel_thread((int (*)(void *))kthread->function, (void *)kthread, 0);
        
}

/* public functions */

/* create a new kernel thread. Called by the creator. */
void start_kthread(void (*func)(kthread_t *), kthread_t *kthread)
{
        /* initialize the semaphore:
           we start with the semaphore locked. The new kernel
           thread will setup its stuff and unlock it. This
           control flow (the one that creates the thread) blocks
           in the down operation below until the thread has reached
           the up() operation.
         */
        init_MUTEX_LOCKED(&kthread->startstop_sem);

        /* store the function to be executed in the data passed to
           the launcher */
        kthread->function=func;
        
        /* create the new thread my running a task through keventd */

        /* initialize the task queue structure */
        kthread->tq.sync = 0;
        INIT_LIST_HEAD(&kthread->tq.list);
        kthread->tq.routine =  kthread_launcher;
        kthread->tq.data = kthread;

        /* and schedule it for execution */
        schedule_task(&kthread->tq);

        /* wait till it has reached the setup_thread routine */
        down(&kthread->startstop_sem);
               
}

/* stop a kernel thread. Called by the removing instance */
void stop_kthread(kthread_t *kthread)
{
        if (kthread->thread == NULL)
        {
                printk("stop_kthread: killing non existing thread!\n");
                return;
        }

        /* this function needs to be protected with the big
	   kernel lock (lock_kernel()). The lock must be
           grabbed before changing the terminate
	   flag and released after the down() call. */
        lock_kernel();
        
        /* initialize the semaphore. We lock it here, the
           leave_thread call of the thread to be terminated
           will unlock it. As soon as we see the semaphore
           unlocked, we know that the thread has exited.
	*/
        init_MUTEX_LOCKED(&kthread->startstop_sem);

        /* We need to do a memory barrier here to be sure that
           the flags are visible on all CPUs. 
        */
        mb();

        /* set flag to request thread termination */
        kthread->terminate = 1;

        /* We need to do a memory barrier here to be sure that
           the flags are visible on all CPUs. 
        */
        mb();
        kill_proc(kthread->thread->pid, SIGKILL, 1);
       
        /* block till thread terminated */
        down(&kthread->startstop_sem);

        /* release the big kernel lock */
        unlock_kernel();

        /* now we are sure the thread is in zombie state. We
           notify keventd to clean the process up.
        */
        kill_proc(2, SIGCHLD, 1);

}

/* initialize new created thread. Called by the new thread. */
void init_kthread(kthread_t *kthread, char *name)
{
        /* lock the kernel. A new kernel thread starts without
           the big kernel lock, regardless of the lock state
           of the creator (the lock level is *not* inheritated)
        */
        lock_kernel();

        /* fill in thread structure */
        kthread->thread = current;

        /* set signal mask to what we want to respond */
        siginitsetinv(&current->blocked, sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGTERM));

        /* initialise wait queue */
        init_waitqueue_head(&kthread->queue);

        /* initialise termination flag */
        kthread->terminate = 0;

        /* set name of this process (max 15 chars + 0 !) */
        sprintf(current->comm, name);
        
        /* let others run */
        unlock_kernel();

        /* tell the creator that we are ready and let him continue */
        up(&kthread->startstop_sem);

}

/* cleanup of thread. Called by the exiting thread. */
void exit_kthread(kthread_t *kthread)
{
        /* we are terminating */

	/* lock the kernel, the exit will unlock it */
        lock_kernel();
        kthread->thread = NULL;
        mb();

        /* notify the stop_kthread() routine that we are terminating. */
	up(&kthread->startstop_sem);
	/* the kernel_thread that called clone() does a do_exit here. */

	/* there is no race here between execution of the "killer" and real termination
	   of the thread (race window between up and do_exit), since both the
	   thread and the "killer" function are running with the kernel lock held.
	   The kernel lock will be freed after the thread exited, so the code
	   is really not executed anymore as soon as the unload functions gets
	   the kernel lock back.
	   The init process may not have made the cleanup of the process here,
	   but the cleanup can be done safely with the module unloaded.
	*/

}

thread_drv.c

#include <linux/config.h>
#include <linux/version.h>

#include <linux/module.h>
#if defined(MODVERSIONS)
#include <linux/modversions.h>
#endif

#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/sched.h>

#include "kthread.h"

#define NTHREADS 5

/* the variable that contains the thread data */
kthread_t example[NTHREADS];

/* prototype for the example thread */
static void example_thread(kthread_t *kthread);

/* load the module */
int init_module(void)
{
        int i;
        
        /* create new kernel threads */
	for (i=0; i <NTHREADS; i++)
                start_kthread(example_thread, &example[i]);
        
        return(0);
}

/* remove the module */
void cleanup_module(void)
{
        int i;
        
        /* terminate the kernel threads */
	for (i=0; i<NTHREADS; i++)
                stop_kthread(&example[i]);
        
        return;
}

/* this is the thread function that we are executing */
static void example_thread(kthread_t *kthread)
{
        /* setup the thread environment */
        init_kthread(kthread, "example thread");
        
        printk("hi, here is the kernel thread\n");
        
        /* an endless loop in which we are doing our work */
        for(;;)
        {
                /* fall asleep for one second */
                interruptible_sleep_on_timeout(&kthread->queue, HZ);

                /* We need to do a memory barrier here to be sure that
                   the flags are visible on all CPUs. 
                */
                 mb();
                
                /* here we are back from sleep, either due to the timeout
                   (one second), or because we caught a signal.
                */
                if (kthread->terminate)
                {
                        /* we received a request to terminate ourself */
                        break;    
                }
                
                /* this is normal work to do */
                printk("example thread: thread woke up\n");
        }
        /* here we go only in case of termination of the thread */

        /* cleanup the thread, leave */
        exit_kthread(kthread);

	/* returning from the thread here calls the exit functions */
}

Makefile

# set to your kernel tree
KERNEL  = /usr/src/linux

# get the Linux architecture. Needed to find proper include file for CFLAGS
ARCH=$(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
# set default flags to compile module
CFLAGS = -D__KERNEL__ -DMODULE -I$(KERNEL)/include
CFLAGS+= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing

all:	thread_mod.o

# get configuration of kernel
include $(KERNEL)/.config
# modify CFLAGS with architecture specific flags
include $(KERNEL)/arch/${ARCH}/Makefile

# enable the module versions, if configured in kernel source tree
ifdef CONFIG_MODVERSIONS
CFLAGS+= -DMODVERSIONS -include $(KERNEL)/include/linux/modversions.h
endif
# enable SMP, if configured in kernel source tree
ifdef CONFIG_SMP
CFLAGS+= -D__SMP__
endif

# note: we are compiling the driver object file and then linking
# we link it into the module. With just one object file as in
# this example this is not needed. We can just load the object
# file produced by gcc 
# link the thread driver module
thread_mod.o:     thread_drv.o kthread.o
	ld -r -o thread_mod.o thread_drv.o kthread.o
# compile the kthread object file
kthread.o:	kthread.c kthread.h
	gcc $(CFLAGS) -c kthread.c
# compile the thread driver
thread_drv.o:     thread_drv.c kthread.h
	gcc $(CFLAGS) -c thread_drv.c

clean:
	rm -f *.o

Bugs

The code assumes that keventd is running with PID 2.

Comments, Corrections

Please send comments, corrections etc. to the address below.

'develop' 카테고리의 다른 글

eclipse 기존 프로젝트 불러오기  (0) 2012.01.26
ttf(truetype) 폰트로 bdf 폰트 만들기  (0) 2011.12.08
DEBUG macro  (0) 2011.11.11
[pastebin.com] 간단한 소스코드 공유 사이트  (0) 2011.10.12
bitmap header info  (0) 2011.10.11

[s3c6410] linux 커널에서 HZ 기본값 변경하기

arch/arm/Kconfig 안에서
"config HZ" 항목을 찾아서 fefault 값을 변경해 주면 된다.

커널 메세지 출력하지 않기

부트 옵션에 'quiet'을 넣어주면 콘솔로 커널 메세지가 나가지 않게 된다.
prev 1 next