커널 2.6에서의 PCMCIA memory 사용

jocha의 이미지

현재 kernel 2.6.16을 사용하여 PXA270 보드에 포팅중입니다만,
PCMCIA관련해서 잘 이해가 안되서 질문드립니다.
2.4커널대 까진 cardmgr와 memory_cs 를 이용해서 ide장치로 마운트시켜 사용했지만 2.6.16에 와선 udev와 hotplug를 이용하도록 되어있고 pcmciautils를 사용하려다 보니 다음과 같은것들을 설치했습니다.
sysfsutils-2.1.0
module-init-tools-3.3-pre1
pcmciautils-014
udev-108
hotplug

부팅메시지는
Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2
ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx
...
pccard: PCMCIA card inserted into slot 0
...
Starting the hotplug events dispatcher udevd
Synthesizing the initial hotplug events
Waiting for /dev to be fully populated
...
0 1 2 0x100 0x3af
content is 0x00000100 - 0x000003af
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_io
0 1 2 0x3e0 0x4ff
content is 0x000003e0 - 0x000004ff
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_io
0 1 2 0x820 0x8ff
content is 0x00000820 - 0x000008ff
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_io
0 1 2 0xc00 0xcf7
content is 0x00000c00 - 0x00000cf7
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_io
0 0 2 0xc0000 0xfffff
content is 0x000c0000 - 0x000fffff
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_mem
0 0 2 0xa0000000 0xa0ffffff
content is 0xa0000000 - 0xa0ffffff
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_mem
0 0 2 0x60000000 0x60ffffff
content is 0x60000000 - 0x60ffffff
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_mem
0 1 2 0xa00 0xaff
content is 0x00000a00 - 0x00000aff
file is /sys/class/pcmcia_socket/pcmcia_socket0/available_resources_io
...
Starting PCMCIA services: pcmcia: Detected deprecated PCMCIA ioctl usage.
pcmcia: This interface will soon be removed from the kernel; please expect brea.
pcmcia: see http://www.kernel.org/pub/linux/utils/kernel/pcmcia/pcmcia.html for.
cardmgr[3719]: watching 1 socket
cardmgr[3719]: could not adjust resource: IO ports 0x100-0x3af: Function not imd
cardmgr[3719]: could not adjust resource: IO ports 0x3e0-0x4ff: Function not imd
cardmgr[3719]: could not adjust resource: IO ports 0x820-0x8ff: Function not imd
cardmgr[3719]: could not adjust resource: IO ports 0xc00-0xcf7: Function not imd
cardmgr[3719]: could not adjust resource: memory 0xc0000-0xfffff: Function not d
cardmgr[3719]: could not adjust resource: memory 0xa0000000-0xa0ffffff: Functiod
cardmgr[3719]: could not adjust resource: memory 0x60000000-0x60ffffff: Functiod
cardmgr[3719]: could not adjust resource: IO ports 0xa00-0xaff: Function not imd
cardmgr[3720]: socket 0: Anonymous Memory
done.
2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special
MTD handling any more.
cardmgr[3720]: executing: 'modprobe memory_cs 2>&1'
cardmgr[3720]: + FATAL: Module memory_cs not found.
cardmgr[3720]: modprobe exited with status 1
cardmgr[3720]: module /lib/modules/2.6.16-hh9/pcmcia/memory_cs.o not available
cardmgr[3720]: bind 'memory_cs' to socket 0 failed: Invalid argument

상기와 같이 나옵니다.
cardmgr 을 띄우지 않도록도 해보고, config파일을 수정하여 memory_cs대신 pcmciamtd를 띄우도록도 해봤지만 마찬가지로 ide장치로 바인딩이 안되는것 같습니다.(ide_cs도 물론 실행시켜줬습니다.)
sysfs정보를 보면 정상적인 pcmcia장치로 잡힌것 같습니다만,
어떻게 ide로 잡히게해야할지 상당히 혼란스럽습니다.
cardmgr, hotplug, udev, pcmciamtd, ide_cs, pccardctl 등
memory_cs를 쓸때는 아무고민없이 그냥 되니까 썼었는데요...
제가 hotplug구조에 익숙하질 않아서요... 도움주시면 감사하겠습니다.

bushi의 이미지

drivers/mtd/maps/pcmciamtd.c
실질적으로 MTD 와는 아무 관련도 없는...
소스보시고 insmod/modprobe 할 때 줘야 할 옵션 대강 파악하셔야겠습니다.

memory_cs.o 올리는 스크립트를 수정하셔서 pcmciamtd.ko 올리도록 바꾸셔야지요. (pcmcia 가 어떻게 바뀌었는지 몰라도, xxx.o 를 올리려고 시도하는 것은 무효입니다)

udev 는 커널 메시지를 받아서 디바이스 노드를 만들어주는 역할이 주된 임무이고,
이 udev에다가 hal 의 플러그인을 집어넣고, 각종 메시지를 hal 데몬 쪽으로 포워딩해서 dbus 로 지지고 볶고 난리치는 게 최근 gnome 입니다.
(데스크탑에 최근 배포본 설치하고 gnome 사용하신다면... dbus-monitor --system 을 실행하고 USB 메모리같은 것 탈착해보세요)

hotplug 는 좀 구식인데...
이벤트가 발생했을 때 커널에서는 /sbin/hotplug 라는 헬퍼를 실행시킵니다.
(커널 소스 중 lib/kobject_uevent.c 보세요)
storage 일 경우 디바이스 노드, 취해야 할 동작등이 아규먼트로 넘겨지는 것을 보실 수 있습니다.
최근 데스크탑 배포본은 /sbin/hotplug 라는 헬퍼가 아예 없지요.
요샌 이 설비를 안 씁니다.

같은 파일에 NETLINK_KOBJECT_UEVENT 를 지원하는 것도 보실 수 있습니다.
유저영역에서 이벤트를 받아보려면... 대강...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
#include <asm/types.h>
#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
 
#define NETLINK_KOBJECT_UEVENT (15)
 
int main(int argc, char **argv)
{
    int ret = EXIT_FAILURE;
    int ns = -1;
    struct sockaddr_nl sa;
    char buf[4096];
    struct iovec iov = { buf, sizeof(buf) };
    struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
    int len;
 
    memset (&sa, 0, sizeof(sa));
    sa.nl_family = AF_NETLINK;
    sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
 
    ns = socket(AF_NETLINK, SOCK_RAW, NETLINK_KOBJECT_UEVENT);
    if (ns < 0) {
        perror("socket()");
        goto sock_err;
    }
    if (bind(ns, (struct sockaddr*)&sa, sizeof(sa))) {
        perror("bind()");
        goto bind_err;
    }
 
    while (1) {
        len = recvmsg (ns, &msg, 0);
        if (len < 0) {
            perror("recvmsg()");
            break;
        }
 
        buf[4095] = 0;
        printf("%s\n", &buf[0]);
        fflush(stdout);
 
#if 0
        /* ... refer to 'man 7 netlink' */
        struct nlmsghdr *h;
        for (h = (struct nlmsghdr*)buf; NLMSG_OK(h, len);) {
            printf("nlmsg_len: %d\n", h->nlmsg_len);
            h = NLMSG_NEXT(h, len);
        }
#endif
    }
 
 bind_err:
    close(ns);
 
 sock_err:
    return ret;
}

제 데스크 탑에서 USB 메모리를 탈착시키면 다음과 같은 메시지가 나옵니다.
mount@/block/sda
umount@/block/sda

파티션을 나누지 않고 통째로 fat 포맷한 놈이라 sda 라고만 나옵니다.
어쨌든 실마리가 잡혔지요.
[bushi@rose internal]$ sudo cat /sys/block/sda/dev
8:0
[bushi@rose internal]$

이름이야 어찌됐건 major 8, minor 0 인 블럭 디바이스 노드를 만들어서라도 마운트하면 되는 겁니다.

C 코드가 마음에 안드시면 hotplug 헬퍼로 사용할 스크립트를 구성하셔도 됩니다.
만약 사용하고 계시는 데스크탑 혹은 노트북에서

[bushi@rose net]$ cat /proc/sys/kernel/hotplug
 
[bushi@rose net]$

와 같은 결과를 보인다면 신나게 장난쳐 볼 수 있습니다. 시스템에 전혀 지장을 주지 않고요.
[bushi@rose net]$ mesg
is n
[bushi@rose net]$ mesg y
[bushi@rose net]$ mesg
is y
[bushi@rose net]$
[bushi@rose net]$ cat > hotplug_test << EOF
> #!/bin/sh
> wall "ACTION=\$ACTION DEVPATH=\$DEVPATH SUBSYSTEM=\$SUBSYSTEM"
> EOF
[bushi@rose net]$ chmod 755 hotplug_test
[bushi@rose net]$
[bushi@rose net]$ sudo -s
[root@rose net]# echo $(pwd)/hotplug_test > /proc/sys/kernel/hotplug
[root@rose net]# cat /proc/sys/kernel/hotplug
/home/bushi/net/hotplug_test
[root@rose net]# exit
exit
[bushi@rose net]$

준비끝났습니다. USB 메모리 탈착시키면...
[bushi@rose net]$
Broadcast message from root (Sat Apr 28 07:27:32 2007):
 
ACTION=mount DEVPATH=/block/sda SUBSYSTEM=block
 
[bushi@rose net]$
Broadcast message from root (Sat Apr 28 07:28:22 2007):
 
ACTION=umount DEVPATH=/block/sda SUBSYSTEM=block
 
[bushi@rose net]$

결국 저 위의 netlink C 코드와 같습니다.

pcmcia utils ... 옛날엔 자체적으로 마운트를 하기 위해 스크립트를 구성했었는데,
어떻게 바뀌었는지는 잘 모르겠습니다.

덧.
와이프님께서 꼬맹이 동반하시고 친정에 놀러 가셨습니다.
여러분~ 아름다운 주말이예요~

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.