This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SD card automount at run-time

Other Parts Discussed in Thread: TPS65950, WL1271

Hi,

I'm considering "SD card automount" at run-time. As far as I know, there are three ways to automount SD card.

Is there possible way to automount SD card from the below methods?

1. Polling : after checking SD card /sys/* entry, if exsits, mount -t vfat /dev/mmcblk1 /sdcard 

2. Using hotplug : replace automount script with /proc/sys/kernel/hotplug

3. Using 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;
}

 

 

  • Hi,

     

    i would suggest

    method 4. use udev (or mdev from busybox).

     

    Regards

    Gururaja

  • Hai seung

    Did you solve that issue...????

  • Hai Gururaja...,I'm Sekra

    I'm using Beagleboard xm based custom board.I boot the OS from the internal memory card.i had one external SD mem.slot in my device.When i put my external SD card  in the device while before booting,it detects the memory card.But i put the memory card after booting the OS it doesn't detect.It doesn't automount or hotplug.i didn't know why.

    I modified  /etc/fstab also but nothing will happens...Is there any script there to automount my device whenever i hotplug it?

    Give a help to overcome it....

    Thanks in advance.....

  • 1,. is the card detected when the card is inserted.

    2. do you see the card device node created in /dev directory.

    It could be any of below 2 issues

    1. card insert detection using gpio method may not be working and hence udev is not seeing it

    2. udev config is improper and hence it is not able to detect the card insertion (very rare chance)

  • Hai Gururaja.....

    I really thank to u....when i saw ur reply.

    Here..

    1) No the card is not detected,when i insert while run time.

    2)NO the device doesn't detected in the /dev directory and /sys/* directory also.Only the bootable SD card will shows up (mmcblk0) not that external one(mmcblk1).

    Note: In my device,there are 2 SD card slots.One for Bootable SD card (Linux OS),another one for external R/W purposes.When i boot my device using memory card that put in internal slot(mmcblk0) it detects the another external SD card (mmcblk1) well while i put that card before booting.But it doesn't detects,when i insert my SD card in external slot after booting the device.Its also a GPIO problem???

    Thanks in advance

  • omap-hsmmc driver uses gpio for card insertion/removal detection. if the card is not properly detected then the gpio pins are not properly setup or not properly populated in mmc platform data from board file

  • Hai

    In omap-hsmmc driver file,which was using my GPIO .

    In that file omap-hsmmc.c (/drivers/mmc/host/omap-hsmmc.c) has all the card detect settings in that files,Where could i find the that GPIO configuration for card detect.?

    In my schematics:

    GPIO.01 is for external MMC3 card.

    GPIO.00 is for Bootable SD card.

    These GPIOs where from power management TPS65950 not from processor.Can you give an idea,How to access the GPIOs via linux kernel.

    Thanks in advance

    Thanks

  • Look at the board file (for am335x evm, look at arch/arm/mach-omap2/board-am335x.c file). Look at the mmc device platform data (struct omap2_hsmmc_info). There you need to update the gpio_cd & gpio_wp members for the mmc instance you are referring.

  • Hai

    I checked that file,such that for beagleboard xm (arch/arm/mach-omap2/beagle-omap3)

    In that file the function is here..... (Note:i changed the mmc to mmcbbt.Don't get confuse.ok)

    ->mmc1 = Bootable SD,mmc2=wifi,mmc3 = External MMC card.We were focussing on External mmc now( mmc3 )

    static struct omap2_hsmmc_info mmcbbt[] = {
    {
    .mmc = 1,
    .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
    .gpio_wp = -EINVAL,
    },

    {
    .name = "wl1271",
    .mmc = 2,
    .caps = MMC_CAP_4_BIT_DATA | MMC_CAP_POWER_OFF_CARD,
    .gpio_wp = -EINVAL,
    .gpio_cd = -EINVAL,
    //.ocr_mask = MMC_VDD_165_195,
    .nonremovable = true,
    },
    {
    .mmc = 3,
    .caps = MMC_CAP_4_BIT_DATA, //| MMC_CAP_NEEDS_POLL,
    .gpio_wp = -EINVAL,
    .gpio_cd = "twl4030_gpio"
    /*.gpio_cd = -EINVAL, */
    .ocr_mask = MMC_VDD_165_195 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32,

    },
    {} /* Terminator */
    };

    Reply me

  • Sekra Invos said:

    Hai

    I checked that file,such that for beagleboard xm (arch/arm/mach-omap2/beagle-omap3)

    In that file the function is here..... (Note:i changed the mmc to mmcbbt.Don't get confuse.ok)

    ->mmc1 = Bootable SD,mmc2=wifi,mmc3 = External MMC card.We were focussing on External mmc now( mmc3 )


    {
    .mmc = 3,
    .caps = MMC_CAP_4_BIT_DATA, //| MMC_CAP_NEEDS_POLL,
    .gpio_wp = -EINVAL,
    .gpio_cd = "twl4030_gpio"
    /*.gpio_cd = -EINVAL, */
    .ocr_mask = MMC_VDD_165_195 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32,

    },
    {} /* Terminator */
    };

    You are doing it the wrong way. you need to mention the gpio number for the same., Kindly look at how it is done on am335x evm. arch/arm/mach-omap2/board-am335xevm.c

  • Hai

    You are right. GPIO_TO_PIN( x, x) is using in that way.But actually I'm using the Power management's GPIO not from processor.In your Sitara AM335x processor,PMIC doesn't had any GPIOs. Here i want to program it via PMIC.(TPS65950).

    Ok if you are right,How can i use this function (GPIO_TO_PIN) for PMIC(TPS65950)'s GPIO.(GPIO.1) respectively.

  • Hai

    I'm Sekra.In my custom board with linux OS.When i insert externel memory card in my device after booting.The external SD acrd never automount.

    It doesn't shows up in /dev folder in the file system.

    Reply me.Thanks in advance.

  • if SD card is successfully detected, automount and unmount can be implemented by capturing uevents of SD card insert and remove events.
    Refer to the scripts in /etc/udev/rules.d directory for the procedures of capturing the uevents.

    for ADD event  SD card mount commands has to be executed.

    for REMOVE event  SD card un-mount commands has to be executed.

  • Hai Manjunath..

    My CD(card detect) pin doesn't works properly.when i boot with Ext.sd card it works.When i hotplug it ,that doesn't works..My Board details were given in previous query...

    Thanks

  • HI. I am a student. i come with the same problem as you .how can you tell me to solve it ? thank you very much .

  • -->for bealgeboard-xm .i want to mmc3=external MMC card . how can you solve it ? please replay me  thank you !