SW 개발

[Linux Kernel] embeded linux kernel 에서 hot plug 기능사용

. . . 2012. 8. 2. 08:41
반응형

임베디드 리눅스에서 USB Hot Plug 기능을 활성화한 기록이다.

  • 테스트했던 환경은 arm-linux 에서 busybox 를 이용한 embedded 시스템이다.

Kernel Config 수정

make menuconfig 에서 다음의 내용을 찾아가보자

General setup ---> 으로 들어가면 아래의 화면이 나오고..

        [*] Prompt for development and/or incomplete code/drivers
        ()  Local version - append to kernel release
        [ ] Automatically append version information to the version string
        [ ] Support for paging of anonymous memory (swap)
        [*] System V IPC
        [ ] POSIX Message Queues
        [ ] BSD Process Accounting
        [ ] Export task/process statistics through netlink (EXPERIMENTAL)
        [ ] Auditing support
            RCU Subsystem  --->
        < > Kernel .config support
        (17) Kernel log buffer size (16 => 64KB, 17 => 128KB)
        [ ] Group CPU scheduler
        [ ] Control Group support  --->
        [ ] Create deprecated sysfs layout for older userspace tools
        [ ] Kernel->user space relay support (formerly relayfs)
        [ ] Namespaces support
        [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
        ()    Initramfs source file(s)
        [*] Optimize for size
        [*] Configure standard kernel features (for small systems)  --->
        [*] Disable heap randomization
            Choose SLAB allocator (SLOB (Simple Allocator))  --->
        [ ] Profiling support (EXPERIMENTAL)

Configure standard kernel features 부분으로 들어가면.. hot plug feature 가있다..

              --- Configure standard kernel features (for small systems)
              [*]   Sysctl syscall support
              [*]   Load all symbols for debugging/ksymoops
              [ ]     Include all symbols in kallsyms
              [ ]     Do an extra kallsyms pass
              [ ]   Support for hot-pluggable devices
              [*]   Enable support for printk
              [*]   BUG() support
              [*]   Enable ELF core dumps
              [*]   Enable full-sized data structures for core
              [*]   Enable futex support
              [*]   Enable eventpoll support
              [*]   Enable signalfd() system call
              [*]   Enable timerfd() system call
              [*]   Enable eventfd() system call
              [*]   Use full shmem filesystem
              [*]   Enable AIO support
              [ ]   Enable VM event counters for /proc/vmstat

아래는 CONFIG_HOTPLUG 켜면 자동으로 따라오는 Configuration

CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
CONFIG_STANDALONE=y
CONFIG_PREVENT_FIRMWARE_BUILD=y
CONFIG_FW_LOADER=y
CONFIG_FIRMWARE_IN_KERNEL=y
CONFIG_EXTRA_FIRMWARE=""

Hot Plug 의 활용... (자동마운트 설정..)

mdev 를 사용하기 위해서는 hotplug kernel config 가 enable 되어있어야 한다.

mdev 핫플러그 설정하기

mdev 를 다음과 같이 설정한다.

echo /sbin/mdev > /proc/sys/kernel/hotplug

위와같이 설정하면 장치가 꼽혔을때 /dev/mdev.conf 의 설정을 보고 동작을 하게 된다.

mdev.conf 설정하기

자동 마운트 스크립트를 짜기전에 mdev.conf 를 설정한다.

# /etc/mdev.conf
mmcblk[0-9]p[0-9] 0:0 0660 */etc/mdev/automount.sh $MDEV
  • 위의 정규식에서 알수있듯이.. hotplug 기능이 동작할때 생성되는 node 의 이름을 정규식으로 표현한다.
  • mmcblk 어쩌고 노드일때... /etc/mdev/automout.sh 를 실행하게 한다.

automount.sh 에서 원하는 동작(실제 마운트 코드)를 넣으면된다.

if [ $ACTION = "remove" ]
then
    umount /mnt/sd_card
        rm -rf /mnt/sd_card
else
        mkdir /mnt/sd_card
        mount -t vfat /dev/mmcblk0p1 /mnt/sd_card
fi
반응형